예제 #1
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);
            }
        }
예제 #2
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);
            }
        }
예제 #3
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);
            }
        }
예제 #4
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);
            }
        }
예제 #5
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);
            }
        }
예제 #6
0
        public void TestSignalIllegalMonitor()
        {
            ReentrantLock locker = new ReentrantLock();
            Condition     c      = locker.NewCondition();

            try
            {
                c.Signal();
                ShouldThrow();
            }
            catch (ThreadStateException)
            {
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
예제 #7
0
        public void TestHasWaitersTSE()
        {
            ReentrantLock locker = new ReentrantLock();
            Condition     c      = (locker.NewCondition());

            try
            {
                locker.HasWaiters(c);
                ShouldThrow();
            }
            catch (ThreadStateException)
            {
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
예제 #8
0
        public void TestGetWaitQueueLengthTSE()
        {
            ReentrantLock locker = new ReentrantLock();
            Condition     c      = (locker.NewCondition());

            try
            {
                locker.GetWaitQueueLength(c);
                ShouldThrow();
            }
            catch (ThreadStateException)
            {
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
예제 #9
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);
            }
        }
예제 #10
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);
            }
        }
예제 #11
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);
            }
        }
예제 #12
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);
         }
     }
예제 #13
0
 public void TestSignalIllegalMonitor()
 {
     ReentrantLock locker = new ReentrantLock();
     Condition c = locker.NewCondition();
     try
     {
         c.Signal();
         ShouldThrow();
     }
     catch (ThreadStateException)
     {
     }
     catch (Exception e)
     {
         UnexpectedException(e);
     }
 }
예제 #14
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);
     }
 }
예제 #15
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);
     }
 }
예제 #16
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);
            }
        }
예제 #17
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);
     }
 }
예제 #18
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);
     }
 }
예제 #19
0
 public void TestHasWaitersTSE()
 {
     ReentrantLock locker = new ReentrantLock();
     Condition c = (locker.NewCondition());
     try
     {
         locker.HasWaiters(c);
         ShouldThrow();
     }
     catch (ThreadStateException)
     {
     }
     catch (Exception e)
     {
         UnexpectedException(e);
     }
 }
예제 #20
0
 public void TestGetWaitQueueLengthTSE()
 {
     ReentrantLock locker = new ReentrantLock();
     Condition c = (locker.NewCondition());
     try
     {
         locker.GetWaitQueueLength(c);
         ShouldThrow();
     }
     catch (ThreadStateException)
     {
     }
     catch (Exception e)
     {
         UnexpectedException(e);
     }
 }
예제 #21
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);
            }
        }
예제 #22
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);
            }
        }