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 AddSite(Site site) { if (Sites.Where(x => x.Id == site.Id).Count() != 0) throw new Exception("Error: Detected Duplicate Site Id: " + site.Id); Sites.Add(site); }
public Variable(int id, Site site, SystemClock systemClock) { ReadLockHolders = new List<Transaction>(); WriteLockHolder = null; SystemClock = systemClock; Site = site; VariableHistory = new List<VariableValue>(); UncomittedValue = string.Empty; IsReadable = true; Id = id; }
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); }
public void TestAcquireAndRemoveReadLock() { 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.GetReadLock(transactionOne); Assert.IsTrue(result.Contains(transactionOne)); var result2 = tempVariable.GetReadLock(transactionTwo); Assert.IsTrue(result.Contains(transactionOne)); Assert.IsTrue(result.Contains(transactionTwo)); tempVariable.RemoveReadLock(transactionOne); Assert.IsFalse(tempVariable.ReadLockHolders.Contains(transactionOne)); tempVariable.RemoveReadLock(transactionTwo); Assert.IsFalse(tempVariable.ReadLockHolders.Contains(transactionTwo)); }
//[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); }
/// <summary> /// Add a new location the transaction holds a lock at. /// </summary> /// <param name="location">The location.</param> public void AddLockHeldLocation(Site location) { LocksHeld.SilentAdd(location); }