Ejemplo n.º 1
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.º 2
0
        public void TestGetWaitQueueLengthNRE()
        {
            ReentrantLock locker = new ReentrantLock();

            try
            {
                locker.GetWaitQueueLength(null);
                ShouldThrow();
            }
            catch (NullReferenceException)
            {
            }
            catch (Exception e)
            {
                UnexpectedException(e);
            }
        }
Ejemplo n.º 3
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.º 4
0
        private void TestGetWaitQueueLengthRunnable2(Object state)
        {
            Pair          data   = state as Pair;
            ReentrantLock locker = data.first as ReentrantLock;
            Condition     c      = data.second as Condition;

            try
            {
                locker.Lock();
                ThreadAssertTrue(locker.HasWaiters(c));
                ThreadAssertEquals(1, locker.GetWaitQueueLength(c));
                c.Await();
                locker.UnLock();
            }
            catch (ThreadInterruptedException e)
            {
                ThreadUnexpectedException(e);
            }
        }
Ejemplo n.º 5
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.º 6
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.º 7
0
 public void TestGetWaitQueueLengthNRE()
 {
     ReentrantLock locker = new ReentrantLock();
     try
     {
         locker.GetWaitQueueLength(null);
         ShouldThrow();
     }
     catch (NullReferenceException)
     {
     }
     catch (Exception e)
     {
         UnexpectedException(e);
     }
 }