コード例 #1
0
ファイル: Site.cs プロジェクト: maorleger/RepCRec
 /// <summary>
 ///   10/20/2011
 ///   Initializes a new instance of the <see cref = "Site" /> class.
 /// </summary>
 /// <remarks>
 ///   Side effects: lastFailed, lockManager, messageBuffQueue, status are all initialized
 /// </remarks>
 public Site()
 {
     lastFailed = new List<int>();
     lockManager = new LockManager();
     messageBuffQueue = new Queue<Operation>();
     status = Enumerations.SiteStatus.Active;
 }
コード例 #2
0
ファイル: LockManagerTest.cs プロジェクト: maorleger/RepCRec
 public void RecoverTest()
 {
     LockManager target = new LockManager();
     target.Recover();
 }
コード例 #3
0
ファイル: LockManagerTest.cs プロジェクト: maorleger/RepCRec
 public void LockManagerConstructorTest()
 {
     LockManager target = new LockManager();
 }
コード例 #4
0
ファイル: LockManagerTest.cs プロジェクト: maorleger/RepCRec
 public void LockManagerLockTest()
 {
     LockManager target = new LockManager();
     int transId = 1;
     int dataItem = 1;
     List<int> actual = target.Lock(transId, dataItem, Enumerations.OperationMode.Read);
     Assert.IsNull(actual);
     transId = 2;
     actual = target.Lock(transId, dataItem, Enumerations.OperationMode.Read);
     Assert.IsNull(actual);
     actual = target.Lock(transId, dataItem, Enumerations.OperationMode.Write);
     Assert.AreEqual(1, actual[0]);
     Assert.AreEqual(2, actual[1]);
     dataItem = 2;
     actual = target.Lock(transId, dataItem, Enumerations.OperationMode.Write);
     Assert.IsNull(actual);
     transId = 1;
     actual = target.Lock(transId, dataItem, Enumerations.OperationMode.Read);
     Assert.AreEqual(2, actual[0]);
 }
コード例 #5
0
ファイル: LockManagerTest.cs プロジェクト: maorleger/RepCRec
        public void LockConflictsTest()
        {
            LockManager target = new LockManager();
            int transId = 1;
            int dataItem = 1;
            target.Lock(transId, dataItem, Enumerations.OperationMode.Read);
            Lock test = new Lock(transId, Enumerations.OperationMode.Read);
            // lock never conflicts with a lock from its own transaction
            Assert.IsFalse(target.LockConflicts(test, target.lockEntries[dataItem]));
            test = new Lock(transId, Enumerations.OperationMode.Write);
            Assert.IsFalse(target.LockConflicts(test, target.lockEntries[dataItem]));
            test = new Lock(2,Enumerations.OperationMode.Read);
            // two read locks do not conflict
            Assert.IsFalse(target.LockConflicts(test, target.lockEntries[dataItem]));
            test = new Lock(2, Enumerations.OperationMode.Write);
            // A read lock conflicts with a write lock
            Assert.IsTrue(target.LockConflicts(test, target.lockEntries[dataItem]));
            transId = dataItem = 2;

            target.Lock(transId, dataItem, Enumerations.OperationMode.Write);
            // lock never conflicts with a lock from its own transaction
            Assert.IsFalse(target.LockConflicts(test, target.lockEntries[dataItem]));
            test = new Lock(transId, Enumerations.OperationMode.Read);
            Assert.IsFalse(target.LockConflicts(test, target.lockEntries[dataItem]));

            // a write lock or read lock from another transaction always conflicts with an active write lock
            transId = 1;
            test = new Lock(transId, Enumerations.OperationMode.Read);
            Assert.IsTrue(target.LockConflicts(test, target.lockEntries[dataItem]));
            test = new Lock(transId, Enumerations.OperationMode.Write);
            Assert.IsTrue(target.LockConflicts(test, target.lockEntries[dataItem]));

            // reset everything and just test that a recovered lockmanager denies read locks until a write op comes in
            target = new LockManager();
            // mock up what happens in a recovery - this is covered in a unit test in Site
            for (int i = 2; i <= 20; i += 2)
            {
                target.lockEntries[i] = new LockManagerTableEntry();
                target.lockEntries[i].ActiveLocks.Add(new Lock(int.MinValue, Enumerations.OperationMode.Write));
            }

            // try to issue a read op
            transId = 1;
            dataItem = 2;
            test = new Lock(transId, Enumerations.OperationMode.Read);
            Assert.IsTrue(target.LockConflicts(test, target.lockEntries[dataItem]));

            // issue a write op which will work
            test = new Lock(transId, Enumerations.OperationMode.Write);
            Assert.IsFalse(target.LockConflicts(test, target.lockEntries[dataItem]));
        }