コード例 #1
0
        public void LockConversionTest3()
        {
            MyLM target = new MyLM();

            target.setDeadlockTimeout(1000);
            Transaction context  = new Transaction();
            Transaction context2 = new Transaction();
            Lockable    resource = new RID(RID.Type.CAR, "test");

            target.LockForUpdate(context, resource);
            target.LockForRead(context2, resource);
            ManualResetEvent e = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem((obj) =>
            {
                Thread.Sleep(200);
                target.UnlockRead(context2, resource);
                e.Set();
            });
            target.LockForWrite(context, resource);
            if (!e.WaitOne(2000))
            {
                Assert.Fail("Failed");
            }
        }
コード例 #2
0
ファイル: LM_UnitTest.cs プロジェクト: vlung/Citicenter
        public void LM_DowngradeWriteLockToReadLock()
        {
            MyLM lm   = new MyLM();
            RID  res1 = new RID();

            Transaction t1 = new Transaction();

            lm.LockForWrite(t1, res1);
            lm.LockForRead(t1, res1);
        }
コード例 #3
0
        public void LockConversionTest1()
        {
            MyLM target = new MyLM();

            target.setDeadlockTimeout(1000);
            Transaction context  = new Transaction();
            Lockable    resource = new RID(RID.Type.CAR, "test");

            target.LockForUpdate(context, resource);
            target.LockForWrite(context, resource);
        }
コード例 #4
0
        public void UnlockWriteTest()
        {
            MyLM        target   = new MyLM();
            Transaction context  = new Transaction();
            Transaction context2 = new Transaction();
            Lockable    resource = new RID(RID.Type.CAR, "test");

            target.LockForWrite(context, resource);
            target.UnlockWrite(context, resource);
            target.LockForWrite(context2, resource);
        }
コード例 #5
0
ファイル: LM_UnitTest.cs プロジェクト: vlung/Citicenter
        public void LM_GetReadLockForManyTransactions()
        {
            MyLM lm   = new MyLM();
            RID  res1 = new RID();

            Transaction t1 = new Transaction();
            Transaction t2 = new Transaction();

            lm.LockForRead(t1, res1);
            lm.LockForRead(t2, res1);
        }
コード例 #6
0
ファイル: LM_UnitTest.cs プロジェクト: vlung/Citicenter
        public void LM_UpgradeReadLockToWriteLock5()
        {
            MyLM lm   = new MyLM();
            RID  res1 = new RID();

            Transaction t1 = new Transaction();

            lm.LockForRead(t1, res1);
            lm.LockForWrite(t1, res1);
            lm.LockForWrite(t1, res1); // This should be a noop since the transaction already has a write lock on the resource.
        }
コード例 #7
0
        public void LockForReadTest()
        {
            MyLM target = new MyLM();

            target.setDeadlockTimeout(1000);
            Transaction context  = new Transaction();
            Transaction context2 = new Transaction();
            Lockable    resource = new RID(RID.Type.CAR, "test");

            target.LockForRead(context, resource);
            target.LockForRead(context2, resource);
        }
コード例 #8
0
ファイル: LM_UnitTest.cs プロジェクト: vlung/Citicenter
        public void LM_GetWritelockOnResLockedWithReadLock()
        {
            MyLM lm   = new MyLM();
            RID  res1 = new RID();

            Transaction t1 = new Transaction();
            Transaction t2 = new Transaction();

            lm.setDeadlockTimeout(500); // Shorten deadlock timeout to speed up unit test
            lm.LockForRead(t1, res1);
            lm.LockForWrite(t2, res1);
        }
コード例 #9
0
ファイル: LM_UnitTest.cs プロジェクト: vlung/Citicenter
        public void LM_UpgradeReadLockToWriteLock4()
        {
            MyLM lm   = new MyLM();
            RID  res1 = new RID();

            Transaction t1 = new Transaction();
            Transaction t2 = new Transaction();

            lm.setDeadlockTimeout(500); // Shorten deadlock timeout to speed up unit test
            lm.LockForWrite(t2, res1);
            lm.LockForWrite(t1, res1);
        }
コード例 #10
0
        public void LockConversionTest2()
        {
            MyLM target = new MyLM();

            target.setDeadlockTimeout(1000);
            Transaction context  = new Transaction();
            Transaction context2 = new Transaction();
            Lockable    resource = new RID(RID.Type.CAR, "test");

            target.setDeadlockTimeout(10);
            target.LockForUpdate(context, resource);
            target.LockForRead(context2, resource);
            target.LockForWrite(context, resource);
            Assert.Fail("shall not reach this line");
        }
コード例 #11
0
ファイル: LM_UnitTest.cs プロジェクト: vlung/Citicenter
        public void LM_UpgradeReadLockToWriteLock2()
        {
            MyLM lm   = new MyLM();
            RID  res1 = new RID();

            Transaction t1 = new Transaction();

            LM_Rid_Bundle param = new LM_Rid_Bundle(lm, res1);

            Thread thread = new Thread(AttemptWriteLockOnResource);

            lm.setDeadlockTimeout(3000); // Shorten deadlock timeout to 3 seconds speed up unit test
            lm.LockForRead(t1, res1);
            thread.Start(param);
            Thread.Sleep(1000);
            lm.LockForWrite(t1, res1);
            thread.Join();
            // Make sure that the second thread failed with deadlock exception.
            // This should happen because the first thread is still holding either the read lock or write lock
            // when the second thread trys to acquire a write lock. The second thread won't be able to steal the
            // lock from the first thread because two phase locking was used when the LM upgrades the read lock
            // to a write lock.
            Assert.AreEqual(param.status, 1);
        }
コード例 #12
0
ファイル: LM_UnitTest.cs プロジェクト: vlung/Citicenter
 public LM_Rid_Bundle(MyLM lm, RID rid)
 {
     this.lm = lm; this.rid = rid; status = 0; event1 = new AutoResetEvent(false);
 }