Esempio n. 1
0
        public void TestWriteLock()
        {
            var systemClock = new SystemClock();

            var site = new Site(1, new SiteList(systemClock), systemClock);
            var tempVariable = new Variable(1, site, systemClock);

            var transactionOne = new Transaction("T1", systemClock);
            var transactionTwo = new Transaction("T2", systemClock);

            var result = tempVariable.GetWriteLock(transactionOne);

            Assert.IsTrue(result.Contains(transactionOne));
            Assert.IsTrue(tempVariable.WriteLockHolder == transactionOne);

            var resultTwo = tempVariable.GetReadLock(transactionTwo);
            Assert.IsFalse(resultTwo.Contains(transactionTwo));
            Assert.IsTrue(resultTwo.Contains(transactionOne));

            var resultThree = tempVariable.GetWriteLock(transactionTwo);
            Assert.IsFalse(resultThree.Contains(transactionTwo));
            Assert.IsTrue(resultThree.Contains(transactionOne));

            tempVariable.RemoveWriteLock(transactionOne);

            Assert.IsTrue(tempVariable.WriteLockHolder == null);
        }
        public void TestVariableResetOnFailure()
        {
            var systemClock = new SystemClock();
            var site = new Site(1, new SiteList(systemClock), systemClock);
            var variable = new Variable(1, site, systemClock);

            var transactionOne = new Transaction("T1", systemClock);

            variable.GetReadLock(transactionOne);
            variable.GetWriteLock(transactionOne);

            Assert.IsTrue(variable.IsReadLocked);
            Assert.IsTrue(variable.IsWriteLocked);
            Assert.IsTrue(variable.ReadLockHolders.Contains(transactionOne));
            Assert.IsTrue(variable.WriteLockHolder == transactionOne);

            variable.ResetToComitted();

            Assert.IsFalse(variable.IsReadLocked);
            Assert.IsFalse(variable.IsWriteLocked);
            Assert.IsFalse(variable.ReadLockHolders.Contains(transactionOne));
            Assert.IsFalse(variable.WriteLockHolder == transactionOne);
        }
        //[TestMethod]
        public void TestMethod1()
        {
            var systemClock = new SystemClock();
            var siteList = new SiteList(systemClock);

            var siteOne = new Site(1, siteList, systemClock);
            var siteTwo = new Site(2, siteList, systemClock);

            siteList.AddSite(siteOne);
            siteList.AddSite(siteTwo);

            var variableOne = new Variable(2, siteOne, systemClock);
            var variableTwo = new Variable(2, siteTwo, systemClock);

            var transaction = new Transaction("test", systemClock);

            siteOne.VariableList.Add(variableOne);
            siteTwo.VariableList.Add(variableTwo);

            Assert.IsTrue(variableOne.GetWriteLock(transaction).Contains(transaction));
            Assert.IsTrue(variableTwo.GetWriteLock(transaction).Contains(transaction));
            variableOne.Set("5");
            variableOne.CommitValue();

            variableOne.Set("4");

            var affectedTranasactions = siteOne.Fail();
            Assert.IsTrue(siteOne.IsFailed);

            siteOne.Recover();

            Assert.IsTrue(affectedTranasactions.Contains(transaction));
            Assert.IsTrue(
                transaction.AwaitingReReplication.Contains(new ValueSitePair() { Site = siteOne, Variable = variableOne }));
            Assert.IsFalse(siteOne.IsFailed);
        }