Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 3
0
 public void TestConstructor()
 {
     ReentrantLock rl = new ReentrantLock();
     Assert.IsFalse(rl.IsFair);
     ReentrantLock r2 = new ReentrantLock(true);
     Assert.True(r2.IsFair);
 }
Ejemplo n.º 4
0
 public void TestLock()
 {
     ReentrantLock rl = new ReentrantLock();
     rl.Lock();
     Assert.IsTrue(rl.IsLocked);
     rl.UnLock();
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 8
0
        public void TestFairLock()
        {
            ReentrantLock rl = new ReentrantLock(true);

            rl.Lock();
            Assert.IsTrue(rl.IsLocked);
            rl.UnLock();
        }
Ejemplo n.º 9
0
        public void TestTryLock()
        {
            ReentrantLock rl = new ReentrantLock();

            Assert.IsTrue(rl.TryLock());
            Assert.IsTrue(rl.IsLocked);
            rl.UnLock();
        }
Ejemplo n.º 10
0
        public void TestConstructor()
        {
            ReentrantLock rl = new ReentrantLock();

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

            Assert.True(r2.IsFair);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 12
0
        private void InterruptibleLockRunnable(object state)
        {
            ReentrantLock locker = state as ReentrantLock;

            try
            {
                locker.LockInterruptibly();
            }
            catch (ThreadInterruptedException)
            {
            }
        }
Ejemplo n.º 13
0
        private void TestTryLockTimeoutRunnable(Object state)
        {
            ReentrantLock locker = state as ReentrantLock;

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

            try
            {
                rl.UnLock();
                ShouldThrow();
            }
            catch (ThreadStateException)
            {
            }
        }
Ejemplo n.º 15
0
        private void TestInterruptedException2Runnable(Object state)
        {
            ReentrantLock locker = state as ReentrantLock;

            try
            {
                locker.TryLock(MEDIUM_DELAY_MS);
                ThreadShouldThrow();
            }
            catch (ThreadInterruptedException)
            {
            }
        }
Ejemplo n.º 16
0
        public void TestHasQueuedThreadNRE()
        {
            ReentrantLock sync = new ReentrantLock();

            try
            {
                sync.HasQueuedThread(null);
                ShouldThrow();
            }
            catch (NullReferenceException)
            {
            }
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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)
            {
            }
        }
Ejemplo n.º 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)
            {
            }
        }
Ejemplo n.º 23
0
        public void TestGetWaitQueueLengthNRE()
        {
            ReentrantLock locker = new ReentrantLock();

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

            try
            {
                locker.HasWaiters(null);
                ShouldThrow();
            }
            catch (NullReferenceException)
            {
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 32
0
        public void TestSignalIllegalMonitor()
        {
            ReentrantLock locker = new ReentrantLock();
            Condition     c      = locker.NewCondition();

            try
            {
                c.Signal();
                ShouldThrow();
            }
            catch (ThreadStateException)
            {
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 39
0
 public void TestHasQueuedThreadNRE()
 {
     ReentrantLock sync = new ReentrantLock();
     try
     {
         sync.HasQueuedThread(null);
         ShouldThrow();
     }
     catch (NullReferenceException)
     {
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 43
0
 public void TestHasWaitersNRE()
 {
     ReentrantLock locker = new ReentrantLock();
     try
     {
         locker.HasWaiters(null);
         ShouldThrow();
     }
     catch (NullReferenceException)
     {
     }
     catch (Exception e)
     {
         UnexpectedException(e);
     }
 }
Ejemplo n.º 44
0
 public void TestGetWaitQueueLengthNRE()
 {
     ReentrantLock locker = new ReentrantLock();
     try
     {
         locker.GetWaitQueueLength(null);
         ShouldThrow();
     }
     catch (NullReferenceException)
     {
     }
     catch (Exception e)
     {
         UnexpectedException(e);
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 54
0
 public void TestSignalIllegalMonitor()
 {
     ReentrantLock locker = new ReentrantLock();
     Condition c = locker.NewCondition();
     try
     {
         c.Signal();
         ShouldThrow();
     }
     catch (ThreadStateException)
     {
     }
     catch (Exception e)
     {
         UnexpectedException(e);
     }
 }
Ejemplo n.º 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);
         }
     }
Ejemplo n.º 56
0
 public void TestUnlockThreadStateException()
 {
     ReentrantLock rl = new ReentrantLock();
     try
     {
         rl.UnLock();
         ShouldThrow();
     }
     catch(ThreadStateException)
     {
     }
 }