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); } }
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); } }
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); } }
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); } }
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); } }
public void TestSignalIllegalMonitor() { ReentrantLock locker = new ReentrantLock(); Condition c = locker.NewCondition(); try { c.Signal(); ShouldThrow(); } catch (ThreadStateException) { } catch (Exception e) { UnexpectedException(e); } }
public void TestHasWaitersTSE() { ReentrantLock locker = new ReentrantLock(); Condition c = (locker.NewCondition()); try { locker.HasWaiters(c); ShouldThrow(); } catch (ThreadStateException) { } catch (Exception e) { UnexpectedException(e); } }
public void TestGetWaitQueueLengthTSE() { ReentrantLock locker = new ReentrantLock(); Condition c = (locker.NewCondition()); try { locker.GetWaitQueueLength(c); ShouldThrow(); } catch (ThreadStateException) { } catch (Exception e) { UnexpectedException(e); } }
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); } }
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); } }
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); } }