Exemple #1
0
        public void TestSetGetCommitTs4Event()
        {
            TransactionExecution texUpdate = new TransactionExecution(null, this.versionDb);

            while (texUpdate.Progress == TxProgress.Initi)
            {
                this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0);
                texUpdate.InitTx();
            }
            texUpdate.Read(TABLE_ID, DEFAULT_KEY, out bool receivedUpdate, out object payloadUpdate);
            while (!receivedUpdate)
            {
                this.versionDb.Visit(TABLE_ID, 0);
                texUpdate.Read(TABLE_ID, DEFAULT_KEY, out receivedUpdate, out payloadUpdate);
            }
            texUpdate.Update(TABLE_ID, DEFAULT_KEY, "value_update");
            texUpdate.Commit();
            while (texUpdate.Progress != TxProgress.Close)
            {
                this.versionDb.Visit(TABLE_ID, 0);
                this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0);
                texUpdate.CurrentProc();
            }

            TransactionExecution tex = new TransactionExecution(null, this.versionDb);

            while (tex.Progress == TxProgress.Initi)
            {
                this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0);
                tex.InitTx();
            }
            tex.Read(TABLE_ID, DEFAULT_KEY, out bool received, out object payload);
            while (!received)
            {
                this.versionDb.Visit(TABLE_ID, 0);
                tex.Read(TABLE_ID, DEFAULT_KEY, out received, out payload);
            }
            tex.Update(TABLE_ID, DEFAULT_KEY, "value_update_1");
            tex.Commit();
            while (tex.Progress != TxProgress.Close)
            {
                this.versionDb.Visit(TABLE_ID, 0);
                this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0);
                tex.CurrentProc();
            }

            GetTxEntryRequest getTxReq = new GetTxEntryRequest(tex.txId);

            this.versionDb.EnqueueTxEntryRequest(tex.txId, getTxReq);
            this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0);
            while (getTxReq.Result == null)
            {
                this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0);
            }
            TxTableEntry txEntry = getTxReq.Result as TxTableEntry;

            Assert.AreEqual(2L, txEntry.CommitTime);
        }
        public void TestValidation2Event()
        {
            //Test the function of UpdateCommitLowerBound() in the event-driven senario.
            TransactionExecution tex1 = new TransactionExecution(null, this.versionDb);

            while (tex1.Progress == TxProgress.Initi)
            {
                this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0);
                tex1.InitTx();
            }

            UpdateCommitLowerBoundRequest txCommitReq = new UpdateCommitLowerBoundRequest(tex1.txId, 5L);

            this.versionDb.EnqueueTxEntryRequest(tex1.txId, txCommitReq);

            this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0);
            while (txCommitReq.Result == null)
            {
                this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0);
            }
            long txCommitTs            = txCommitReq.Result == null ? VersionDb.RETURN_ERROR_CODE : (long)txCommitReq.Result;
            GetTxEntryRequest getTxReq = new GetTxEntryRequest(tex1.txId);

            this.versionDb.EnqueueTxEntryRequest(tex1.txId, getTxReq);
            while (getTxReq.Result == null)
            {
                this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0);
            }
            TxTableEntry txEntry = getTxReq.Result as TxTableEntry;

            Assert.AreEqual(5L, txEntry.CommitLowerBound);
            Assert.AreEqual(-1L, txCommitTs);

            //Test the function of SetCommitTs() in the event-driven senario.
            SetCommitTsRequest setTsReq = new SetCommitTsRequest(tex1.txId, 6L);

            this.versionDb.EnqueueTxEntryRequest(tex1.txId, setTsReq);
            while (setTsReq.Result == null)
            {
                this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0);
            }
            long commitTime = setTsReq.Result == null ? -1 : (long)setTsReq.Result;

            Assert.AreEqual(6L, commitTime);
        }
        public void TestValidation6Event()
        {
            TransactionExecution tex1 = new TransactionExecution(null, this.versionDb);

            tex1.DEBUG_MODE = true;
            while (tex1.Progress == TxProgress.Initi)
            {
                this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0);
                tex1.InitTx();
            }
            tex1.Read(TABLE_ID, DEFAULT_KEY, out bool received, out object payload);
            while (!received)
            {
                this.versionDb.Visit(TABLE_ID, 0);
                tex1.Read(TABLE_ID, DEFAULT_KEY, out received, out payload);
            }
            tex1.Upload();
            while (tex1.CurrentProc == null)
            {
                this.versionDb.Visit(TABLE_ID, 0);
                tex1.Upload();
            }

            TransactionExecution tex = new TransactionExecution(null, this.versionDb);

            tex.DEBUG_MODE = true;
            while (tex.Progress == TxProgress.Initi)
            {
                this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0);
                tex.InitTx();
            }
            tex.Read(TABLE_ID, DEFAULT_KEY, out bool receivedRead, out object payloadRead);
            while (!receivedRead)
            {
                this.versionDb.Visit(TABLE_ID, 0);
                tex.Read(TABLE_ID, DEFAULT_KEY, out receivedRead, out payloadRead);
            }
            tex.Delete(TABLE_ID, DEFAULT_KEY, out object payloadDelete);
            tex.Upload();
            while (tex.CurrentProc == null)
            {
                this.versionDb.Visit(TABLE_ID, 0);
                tex.Upload();
            }

            tex1.maxCommitTsOfWrites = 3L;
            tex1.SetCommitTimestamp();
            while (tex1.CurrentProc == new Procedure(tex1.SetCommitTimestamp))
            {
                this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0);
                tex1.SetCommitTimestamp();
            }
            tex1.Validate();
            while (tex1.CurrentProc == new Procedure(tex1.Validate))
            {
                this.versionDb.Visit(TABLE_ID, 0);
                this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0);
                tex1.Validate();
            }
            Assert.AreEqual(new Procedure(tex1.WriteToLog), tex1.CurrentProc);

            tex.SetCommitTimestamp();
            while (tex.CurrentProc == new Procedure(tex.SetCommitTimestamp))
            {
                this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0);
                tex.SetCommitTimestamp();
            }
            tex.Validate();
            while (tex.CurrentProc == new Procedure(tex.Validate))
            {
                this.versionDb.Visit(TABLE_ID, 0);
                this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0);
                tex.Validate();
            }
            Assert.AreEqual(new Procedure(tex.WriteToLog), tex.CurrentProc);

            GetTxEntryRequest getTxReq = new GetTxEntryRequest(tex.txId);

            this.versionDb.EnqueueTxEntryRequest(tex.txId, getTxReq);
            this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0);
            while (getTxReq.Result == null)
            {
                this.versionDb.Visit(RedisVersionDb.TX_TABLE, 0);
            }
            TxTableEntry txEntry = getTxReq.Result as TxTableEntry;

            Assert.AreEqual(5L, txEntry.CommitTime);
        }