示例#1
0
        public void TestLockInterruptibly2()
        {
            ReentrantLock locker = new ReentrantLock();

            try
            {
                locker.LockInterruptibly();
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }

            Thread t = new Thread(InterruptedLockRunnable);

            try
            {
                t.Start(locker);
                t.Interrupt();
                Assert.IsTrue(locker.IsLocked);
                Assert.IsTrue(locker.IsHeldByCurrentThread);
                t.Join();
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#2
0
        public void TestGetQueueLengthFair()
        {
            ReentrantLock locker = new ReentrantLock(true);
            Thread        t1     = new Thread(InterruptedLockRunnable);
            Thread        t2     = new Thread(InterruptibleLockRunnable);

            try
            {
                Assert.AreEqual(0, locker.QueueLength);
                locker.Lock();
                t1.Start(locker);
                Thread.Sleep(SHORT_DELAY_MS);
                Assert.AreEqual(1, locker.QueueLength);
                t2.Start(locker);
                Thread.Sleep(SHORT_DELAY_MS);
                Assert.AreEqual(2, locker.QueueLength);
                t1.Interrupt();
                Thread.Sleep(SHORT_DELAY_MS);
                Assert.AreEqual(1, locker.QueueLength);
                locker.UnLock();
                Thread.Sleep(SHORT_DELAY_MS);
                Assert.AreEqual(0, locker.QueueLength);
                t1.Join();
                t2.Join();
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#3
0
 public void TestConstructor()
 {
     ReentrantLock rl = new ReentrantLock();
     Assert.IsFalse(rl.IsFair);
     ReentrantLock r2 = new ReentrantLock(true);
     Assert.True(r2.IsFair);
 }
示例#4
0
 public void TestLock()
 {
     ReentrantLock rl = new ReentrantLock();
     rl.Lock();
     Assert.IsTrue(rl.IsLocked);
     rl.UnLock();
 }
示例#5
0
        public void TestHasQueuedThread()
        {
            ReentrantLock sync = new ReentrantLock();
            Thread        t1   = new Thread(InterruptedLockRunnable);
            Thread        t2   = new Thread(InterruptibleLockRunnable);

            try
            {
                Assert.IsFalse(sync.HasQueuedThread(t1));
                Assert.IsFalse(sync.HasQueuedThread(t2));
                sync.Lock();
                t1.Start();
                Thread.Sleep(SHORT_DELAY_MS);
                Assert.IsTrue(sync.HasQueuedThread(t1));
                t2.Start();
                Thread.Sleep(SHORT_DELAY_MS);
                Assert.IsTrue(sync.HasQueuedThread(t1));
                Assert.IsTrue(sync.HasQueuedThread(t2));
                t1.Interrupt();
                Thread.Sleep(SHORT_DELAY_MS);
                Assert.IsFalse(sync.HasQueuedThread(t1));
                Assert.IsTrue(sync.HasQueuedThread(t2));
                sync.UnLock();
                Thread.Sleep(SHORT_DELAY_MS);
                Assert.IsFalse(sync.HasQueuedThread(t1));
                Thread.Sleep(SHORT_DELAY_MS);
                Assert.IsFalse(sync.HasQueuedThread(t2));
                t1.Join();
                t2.Join();
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#6
0
        public void TestAwaitLockCount()
        {
            ReentrantLock locker = new ReentrantLock();
            Condition     c      = locker.NewCondition();
            Pair          data   = new Pair(locker, c);

            Thread t1 = new Thread(TestAwaitLockCountRunnable1);
            Thread t2 = new Thread(TestAwaitLockCountRunnable2);

            try
            {
                t1.Start(data);
                t2.Start(data);
                Thread.Sleep(SHORT_DELAY_MS);
                locker.Lock();
                c.SignalAll();
                locker.UnLock();
                t1.Join(SHORT_DELAY_MS);
                t2.Join(SHORT_DELAY_MS);
                Assert.IsFalse(t1.IsAlive);
                Assert.IsFalse(t2.IsAlive);
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#7
0
        public void TestGetWaitQueueLength()
        {
            ReentrantLock locker = new ReentrantLock();
            Condition     c      = locker.NewCondition();
            Pair          data   = new Pair(locker, c);

            Thread t1 = new Thread(TestGetWaitQueueLengthRunnable1);
            Thread t2 = new Thread(TestGetWaitQueueLengthRunnable2);

            try
            {
                t1.Start(data);
                Thread.Sleep(SHORT_DELAY_MS);
                t2.Start(data);
                Thread.Sleep(SHORT_DELAY_MS);
                locker.Lock();
                Assert.IsTrue(locker.HasWaiters(c));
                Assert.AreEqual(2, locker.GetWaitQueueLength(c));
                c.SignalAll();
                locker.UnLock();
                Thread.Sleep(SHORT_DELAY_MS);
                locker.Lock();
                Assert.IsFalse(locker.HasWaiters(c));
                Assert.AreEqual(0, locker.GetWaitQueueLength(c));
                locker.UnLock();
                t1.Join(SHORT_DELAY_MS);
                t2.Join(SHORT_DELAY_MS);
                Assert.IsFalse(t1.IsAlive);
                Assert.IsFalse(t2.IsAlive);
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#8
0
        public void TestFairLock()
        {
            ReentrantLock rl = new ReentrantLock(true);

            rl.Lock();
            Assert.IsTrue(rl.IsLocked);
            rl.UnLock();
        }
示例#9
0
        public void TestTryLock()
        {
            ReentrantLock rl = new ReentrantLock();

            Assert.IsTrue(rl.TryLock());
            Assert.IsTrue(rl.IsLocked);
            rl.UnLock();
        }
示例#10
0
        public void TestConstructor()
        {
            ReentrantLock rl = new ReentrantLock();

            Assert.IsFalse(rl.IsFair);
            ReentrantLock r2 = new ReentrantLock(true);

            Assert.True(r2.IsFair);
        }
示例#11
0
        public void TestToString()
        {
            ReentrantLock locker = new ReentrantLock();
            String        us     = locker.ToString();

            Assert.IsTrue(us.IndexOf("Unlocked") >= 0);
            locker.Lock();
            String ls = locker.ToString();

            Assert.IsTrue(ls.IndexOf("Locked") >= 0);
        }
示例#12
0
        private void InterruptibleLockRunnable(object state)
        {
            ReentrantLock locker = state as ReentrantLock;

            try
            {
                locker.LockInterruptibly();
            }
            catch (ThreadInterruptedException)
            {
            }
        }
示例#13
0
        private void TestTryLockTimeoutRunnable(Object state)
        {
            ReentrantLock locker = state as ReentrantLock;

            try
            {
                ThreadAssertFalse(locker.TryLock(1));
            }
            catch (Exception e)
            {
                ThreadUnexpectedException(e);
            }
        }
示例#14
0
        public void TestUnlockThreadStateException()
        {
            ReentrantLock rl = new ReentrantLock();

            try
            {
                rl.UnLock();
                ShouldThrow();
            }
            catch (ThreadStateException)
            {
            }
        }
示例#15
0
        private void TestInterruptedException2Runnable(Object state)
        {
            ReentrantLock locker = state as ReentrantLock;

            try
            {
                locker.TryLock(MEDIUM_DELAY_MS);
                ThreadShouldThrow();
            }
            catch (ThreadInterruptedException)
            {
            }
        }
示例#16
0
        public void TestHasQueuedThreadNRE()
        {
            ReentrantLock sync = new ReentrantLock();

            try
            {
                sync.HasQueuedThread(null);
                ShouldThrow();
            }
            catch (NullReferenceException)
            {
            }
        }
示例#17
0
        private void TestIsLockedRunnable(Object state)
        {
            ReentrantLock locker = state as ReentrantLock;

            locker.Lock();
            try
            {
                Thread.Sleep(SMALL_DELAY_MS);
            }
            catch (Exception e)
            {
                ThreadUnexpectedException(e);
            }
            locker.UnLock();
        }
示例#18
0
        public void TestAwaitTimeout()
        {
            ReentrantLock locker = new ReentrantLock();
            Condition     c      = locker.NewCondition();

            try
            {
                locker.Lock();
                c.Await(SHORT_DELAY_MS);
                locker.UnLock();
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#19
0
        public void TestAwaitUntilTimeout()
        {
            ReentrantLock locker = new ReentrantLock();
            Condition     c      = locker.NewCondition();

            try
            {
                locker.Lock();
                c.AwaitUntil(DateTime.Now.AddMilliseconds(100));
                locker.UnLock();
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#20
0
        public void TestGetHoldCount()
        {
            ReentrantLock locker = new ReentrantLock();

            for (int i = 1; i <= SIZE; i++)
            {
                locker.Lock();
                Assert.AreEqual(i, locker.HoldCount);
            }

            for (int i = SIZE; i > 0; i--)
            {
                locker.UnLock();
                Assert.AreEqual(i - 1, locker.HoldCount);
            }
        }
示例#21
0
        private void TestAwaitTimedInterruptRunnable(Object state)
        {
            Pair          data   = state as Pair;
            ReentrantLock locker = data.first as ReentrantLock;
            Condition     c      = data.second as Condition;

            try
            {
                locker.Lock();
                c.Await(1000); // 1 sec
                locker.UnLock();
                ThreadShouldThrow();
            }
            catch (ThreadInterruptedException)
            {
            }
        }
示例#22
0
        private void TestAwaitUntilInterruptRunnable(Object state)
        {
            Pair          data   = state as Pair;
            ReentrantLock locker = data.first as ReentrantLock;
            Condition     c      = data.second as Condition;

            try
            {
                locker.Lock();
                c.AwaitUntil(DateTime.Now.AddMilliseconds(10000));
                locker.UnLock();
                ThreadShouldThrow();
            }
            catch (ThreadInterruptedException)
            {
            }
        }
示例#23
0
        public void TestGetWaitQueueLengthNRE()
        {
            ReentrantLock locker = new ReentrantLock();

            try
            {
                locker.GetWaitQueueLength(null);
                ShouldThrow();
            }
            catch (NullReferenceException)
            {
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#24
0
        public void TestHasWaitersNRE()
        {
            ReentrantLock locker = new ReentrantLock();

            try
            {
                locker.HasWaiters(null);
                ShouldThrow();
            }
            catch (NullReferenceException)
            {
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#25
0
        private void TestAwaitRunnable(Object state)
        {
            Pair          data   = state as Pair;
            ReentrantLock locker = data.first as ReentrantLock;
            Condition     c      = data.second as Condition;

            try
            {
                locker.Lock();
                c.Await();
                locker.UnLock();
            }
            catch (ThreadInterruptedException e)
            {
                ThreadUnexpectedException(e);
            }
        }
示例#26
0
        public void TestAwaitWithTimeout()
        {
            ReentrantLock locker = new ReentrantLock();
            Condition     c      = locker.NewCondition();

            try
            {
                locker.Lock();
                long t = c.Await(1);
                Assert.IsTrue(t <= 0);
                locker.UnLock();
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#27
0
        private void TestGetWaitingThreadsRunnable2(Object state)
        {
            Pair          data   = state as Pair;
            ReentrantLock locker = data.first as ReentrantLock;
            Condition     c      = data.second as Condition;

            try
            {
                locker.Lock();
                ThreadAssertFalse(locker.GetWaitingThreads(c).IsEmpty());
                c.Await();
                locker.UnLock();
            }
            catch (ThreadInterruptedException e)
            {
                ThreadUnexpectedException(e);
            }
        }
示例#28
0
        public void TestTryLockTimeout()
        {
            ReentrantLock locker = new ReentrantLock();

            locker.Lock();
            Thread t = new Thread(TestTryLockTimeoutRunnable);

            try
            {
                t.Start(locker);
                t.Join();
                locker.UnLock();
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#29
0
        public void TestHasWaitersTSE()
        {
            ReentrantLock locker = new ReentrantLock();
            Condition     c      = (locker.NewCondition());

            try
            {
                locker.HasWaiters(c);
                ShouldThrow();
            }
            catch (ThreadStateException)
            {
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#30
0
        public void TestInterruptedException2()
        {
            ReentrantLock locker = new ReentrantLock();

            locker.Lock();
            Thread t = new Thread(TestInterruptedException2Runnable);

            try
            {
                t.Start(locker);
                t.Interrupt();
                t.Join();
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#31
0
        public void TestGetWaitQueueLengthTSE()
        {
            ReentrantLock locker = new ReentrantLock();
            Condition     c      = (locker.NewCondition());

            try
            {
                locker.GetWaitQueueLength(c);
                ShouldThrow();
            }
            catch (ThreadStateException)
            {
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#32
0
        public void TestSignalIllegalMonitor()
        {
            ReentrantLock locker = new ReentrantLock();
            Condition     c      = locker.NewCondition();

            try
            {
                c.Signal();
                ShouldThrow();
            }
            catch (ThreadStateException)
            {
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#33
0
        public void TestIsLocked()
        {
            ReentrantLock locker = new ReentrantLock();
            locker.Lock();
            Assert.IsTrue(locker.IsLocked);
            locker.UnLock();
            Assert.IsFalse(locker.IsLocked);
            Thread t = new Thread(TestIsLockedRunnable);

            try
            {
                t.Start(locker);
                Thread.Sleep(SHORT_DELAY_MS);
                Assert.IsTrue(locker.IsLocked);
                t.Join();
                Assert.IsFalse(locker.IsLocked);
            }
            catch(Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#34
0
 public void TestLockInterruptibly1()
 {
     ReentrantLock locker = new ReentrantLock();
     locker.Lock();
     Thread t = new Thread(InterruptedLockRunnable);
     try
     {
         t.Start(locker);
         Thread.Sleep(SHORT_DELAY_MS);
         t.Interrupt();
         Thread.Sleep(SHORT_DELAY_MS);
         locker.UnLock();
         t.Join();
     }
     catch(Exception e)
     {
         UnexpectedException(e);
     }
 }
示例#35
0
        public void TestLockInterruptibly2()
        {
            ReentrantLock locker = new ReentrantLock();
            try
            {
                locker.LockInterruptibly();
            }
            catch(Exception e)
            {
                UnexpectedException(e);
            }

            Thread t = new Thread(InterruptedLockRunnable);

            try
            {
                t.Start(locker);
                t.Interrupt();
                Assert.IsTrue(locker.IsLocked);
                Assert.IsTrue(locker.IsHeldByCurrentThread);
                t.Join();
            }
            catch(Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#36
0
 public void TestGetWaitQueueLengthTSE()
 {
     ReentrantLock locker = new ReentrantLock();
     Condition c = (locker.NewCondition());
     try
     {
         locker.GetWaitQueueLength(c);
         ShouldThrow();
     }
     catch (ThreadStateException)
     {
     }
     catch (Exception e)
     {
         UnexpectedException(e);
     }
 }
示例#37
0
        public void TestAwaitLockCount()
        {
            ReentrantLock locker = new ReentrantLock();
            Condition c = locker.NewCondition();
            Pair data = new Pair(locker, c);

            Thread t1 = new Thread(TestAwaitLockCountRunnable1);
            Thread t2 = new Thread(TestAwaitLockCountRunnable2);

            try
            {
                t1.Start(data);
                t2.Start(data);
                Thread.Sleep(SHORT_DELAY_MS);
                locker.Lock();
                c.SignalAll();
                locker.UnLock();
                t1.Join(SHORT_DELAY_MS);
                t2.Join(SHORT_DELAY_MS);
                Assert.IsFalse(t1.IsAlive);
                Assert.IsFalse(t2.IsAlive);
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#38
0
        public void TestInterruptedException2()
        {
            ReentrantLock locker = new ReentrantLock();
            locker.Lock();
            Thread t = new Thread(TestInterruptedException2Runnable);

            try
            {
                t.Start(locker);
                t.Interrupt();
                t.Join();
            }
            catch(Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#39
0
 public void TestHasQueuedThreadNRE()
 {
     ReentrantLock sync = new ReentrantLock();
     try
     {
         sync.HasQueuedThread(null);
         ShouldThrow();
     }
     catch (NullReferenceException)
     {
     }
 }
示例#40
0
 public void TestAwaitUntilTimeout()
 {
     ReentrantLock locker = new ReentrantLock();
     Condition c = locker.NewCondition();
     try
     {
         locker.Lock();
         c.AwaitUntil(DateTime.Now.AddMilliseconds(100));
         locker.UnLock();
     }
     catch (Exception e)
     {
         UnexpectedException(e);
     }
 }
示例#41
0
        public void TestGetHoldCount()
        {
            ReentrantLock locker = new ReentrantLock();
            for(int i = 1; i <= SIZE; i++)
            {
                locker.Lock();
                Assert.AreEqual(i,locker.HoldCount);
            }

            for(int i = SIZE; i > 0; i--)
            {
                locker.UnLock();
                Assert.AreEqual(i-1,locker.HoldCount);
            }
        }
示例#42
0
        public void TestAwait()
        {
            ReentrantLock locker = new ReentrantLock();
            Condition c = locker.NewCondition();
            Pair data = new Pair(locker, c);
            Thread t = new Thread(TestAwaitRunnable);

            try
            {
                t.Start(data);
                Thread.Sleep(MEDIUM_DELAY_MS);
                locker.Lock();
                c.Signal();
                locker.UnLock();
                t.Join(SMALL_DELAY_MS);
                Assert.IsFalse(t.IsAlive);
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#43
0
 public void TestHasWaitersNRE()
 {
     ReentrantLock locker = new ReentrantLock();
     try
     {
         locker.HasWaiters(null);
         ShouldThrow();
     }
     catch (NullReferenceException)
     {
     }
     catch (Exception e)
     {
         UnexpectedException(e);
     }
 }
示例#44
0
 public void TestGetWaitQueueLengthNRE()
 {
     ReentrantLock locker = new ReentrantLock();
     try
     {
         locker.GetWaitQueueLength(null);
         ShouldThrow();
     }
     catch (NullReferenceException)
     {
     }
     catch (Exception e)
     {
         UnexpectedException(e);
     }
 }
示例#45
0
 public void TestHasWaitersIAE()
 {
     ReentrantLock locker = new ReentrantLock();
     Condition c = (locker.NewCondition());
     ReentrantLock locker2 = new ReentrantLock();
     try
     {
         locker2.HasWaiters(c);
         ShouldThrow();
     }
     catch (ArgumentException)
     {
     }
     catch (Exception e)
     {
         UnexpectedException(e);
     }
 }
示例#46
0
 public void TestHasWaitersTSE()
 {
     ReentrantLock locker = new ReentrantLock();
     Condition c = (locker.NewCondition());
     try
     {
         locker.HasWaiters(c);
         ShouldThrow();
     }
     catch (ThreadStateException)
     {
     }
     catch (Exception e)
     {
         UnexpectedException(e);
     }
 }
示例#47
0
        public void TestTryLockTimeout()
        {
            ReentrantLock locker = new ReentrantLock();
            locker.Lock();
            Thread t = new Thread(TestTryLockTimeoutRunnable);

            try
            {
                t.Start(locker);
                t.Join();
                locker.UnLock();
            }
            catch(Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#48
0
 public void TestAwaitTimeout()
 {
     ReentrantLock locker = new ReentrantLock();
     Condition c = locker.NewCondition();
     try
     {
         locker.Lock();
         c.Await(SHORT_DELAY_MS);
         locker.UnLock();
     }
     catch (Exception e)
     {
         UnexpectedException(e);
     }
 }
示例#49
0
        public void TestHasQueuedThread()
        {
            ReentrantLock sync = new ReentrantLock();
            Thread t1 = new Thread(InterruptedLockRunnable);
            Thread t2 = new Thread(InterruptibleLockRunnable);

            try
            {
                Assert.IsFalse(sync.HasQueuedThread(t1));
                Assert.IsFalse(sync.HasQueuedThread(t2));
                sync.Lock();
                t1.Start();
                Thread.Sleep(SHORT_DELAY_MS);
                Assert.IsTrue(sync.HasQueuedThread(t1));
                t2.Start();
                Thread.Sleep(SHORT_DELAY_MS);
                Assert.IsTrue(sync.HasQueuedThread(t1));
                Assert.IsTrue(sync.HasQueuedThread(t2));
                t1.Interrupt();
                Thread.Sleep(SHORT_DELAY_MS);
                Assert.IsFalse(sync.HasQueuedThread(t1));
                Assert.IsTrue(sync.HasQueuedThread(t2));
                sync.UnLock();
                Thread.Sleep(SHORT_DELAY_MS);
                Assert.IsFalse(sync.HasQueuedThread(t1));
                Thread.Sleep(SHORT_DELAY_MS);
                Assert.IsFalse(sync.HasQueuedThread(t2));
                t1.Join();
                t2.Join();
            }
            catch(Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#50
0
 public void TestToString()
 {
     ReentrantLock locker = new ReentrantLock();
     String us = locker.ToString();
     Assert.IsTrue(us.IndexOf("Unlocked") >= 0);
     locker.Lock();
     String ls = locker.ToString();
     Assert.IsTrue(ls.IndexOf("Locked") >= 0);
 }
示例#51
0
 public void TestAwaitWithTimeout()
 {
     ReentrantLock locker = new ReentrantLock();
     Condition c = locker.NewCondition();
     try
     {
         locker.Lock();
         long t = c.Await(1);
         Assert.IsTrue(t <= 0);
         locker.UnLock();
     }
     catch (Exception e)
     {
         UnexpectedException(e);
     }
 }
示例#52
0
        public void TestGetWaitQueueLength()
        {
            ReentrantLock locker = new ReentrantLock();
            Condition c = locker.NewCondition();
            Pair data = new Pair(locker, c);

            Thread t1 = new Thread(TestGetWaitQueueLengthRunnable1);
            Thread t2 = new Thread(TestGetWaitQueueLengthRunnable2);
    
            try
            {
                t1.Start(data);
                Thread.Sleep(SHORT_DELAY_MS);
                t2.Start(data);
                Thread.Sleep(SHORT_DELAY_MS);
                locker.Lock();
                Assert.IsTrue(locker.HasWaiters(c));
                Assert.AreEqual(2, locker.GetWaitQueueLength(c));
                c.SignalAll();
                locker.UnLock();
                Thread.Sleep(SHORT_DELAY_MS);
                locker.Lock();
                Assert.IsFalse(locker.HasWaiters(c));
                Assert.AreEqual(0, locker.GetWaitQueueLength(c));
                locker.UnLock();
                t1.Join(SHORT_DELAY_MS);
                t2.Join(SHORT_DELAY_MS);
                Assert.IsFalse(t1.IsAlive);
                Assert.IsFalse(t2.IsAlive);
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
示例#53
0
 public void TestGetQueueLengthFair()
 {
     ReentrantLock locker = new ReentrantLock(true);
     Thread t1 = new Thread(InterruptedLockRunnable);
     Thread t2 = new Thread(InterruptibleLockRunnable);
     try
     {
         Assert.AreEqual(0, locker.QueueLength);
         locker.Lock();
         t1.Start(locker);
         Thread.Sleep(SHORT_DELAY_MS);
         Assert.AreEqual(1, locker.QueueLength);
         t2.Start(locker);
         Thread.Sleep(SHORT_DELAY_MS);
         Assert.AreEqual(2, locker.QueueLength);
         t1.Interrupt();
         Thread.Sleep(SHORT_DELAY_MS);
         Assert.AreEqual(1, locker.QueueLength);
         locker.UnLock();
         Thread.Sleep(SHORT_DELAY_MS);
         Assert.AreEqual(0, locker.QueueLength);
         t1.Join();
         t2.Join();
     }
     catch(Exception e)
     {
         UnexpectedException(e);
     }
 }
示例#54
0
 public void TestSignalIllegalMonitor()
 {
     ReentrantLock locker = new ReentrantLock();
     Condition c = locker.NewCondition();
     try
     {
         c.Signal();
         ShouldThrow();
     }
     catch (ThreadStateException)
     {
     }
     catch (Exception e)
     {
         UnexpectedException(e);
     }
 }
示例#55
0
     public void TestAwaitUntilInterrupt()
     {
         ReentrantLock locker = new ReentrantLock();
         Condition c = locker.NewCondition();
         Pair data = new Pair(locker, c);
         Thread t = new Thread(TestAwaitUntilInterruptRunnable);
 
         try
         {
             t.Start(data);
             Thread.Sleep(SHORT_DELAY_MS);
             t.Interrupt();
             t.Join(SHORT_DELAY_MS);
             Assert.IsFalse(t.IsAlive);
         }
         catch (Exception e)
         {
             UnexpectedException(e);
         }
     }
示例#56
0
 public void TestUnlockThreadStateException()
 {
     ReentrantLock rl = new ReentrantLock();
     try
     {
         rl.UnLock();
         ShouldThrow();
     }
     catch(ThreadStateException)
     {
     }
 }