//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPresentLockStateInStringRepresentationOfLock() public virtual void ShouldPresentLockStateInStringRepresentationOfLock() { // given LockService locks = new ReentrantLockService(); Lock first; Lock second; // when using (Lock @lock = first = locks.AcquireNodeLock(666, LockService_LockType.WriteLock)) { // then assertEquals("LockedNode[id=666; HELD_BY=1*" + Thread.CurrentThread + "]", @lock.ToString()); // when using (Lock inner = second = locks.AcquireNodeLock(666, LockService_LockType.WriteLock)) { assertEquals("LockedNode[id=666; HELD_BY=2*" + Thread.CurrentThread + "]", @lock.ToString()); assertEquals(@lock.ToString(), inner.ToString()); } // then assertEquals("LockedNode[id=666; HELD_BY=1*" + Thread.CurrentThread + "]", @lock.ToString()); assertEquals("LockedNode[id=666; RELEASED]", second.ToString()); } // then assertEquals("LockedNode[id=666; RELEASED]", first.ToString()); assertEquals("LockedNode[id=666; RELEASED]", second.ToString()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotLeaveResidualLockStateAfterAllLocksHaveBeenReleased() public virtual void ShouldNotLeaveResidualLockStateAfterAllLocksHaveBeenReleased() { // given ReentrantLockService locks = new ReentrantLockService(); // when locks.AcquireNodeLock(42, LockService_LockType.WriteLock).release(); // then assertEquals(0, locks.LockCount()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAllowReEntrance() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldAllowReEntrance() { // given LockService locks = new ReentrantLockService(); ThreadRepository.Events events = Threads.events(); LockNode lock1once = new LockNode(locks, 1); LockNode lock1again = new LockNode(locks, 1); LockNode lock1inOtherThread = new LockNode(locks, 1); ThreadRepository.Signal lockedOnce = Threads.signal(); ThreadRepository.Signal ready = Threads.signal(); // when Threads.execute(lock1once, ready.Await(), lockedOnce, lock1again, events.Trigger("Double Locked"), lock1once.release, lock1again.release); Threads.execute(ready, lockedOnce.Await(), lock1inOtherThread, events.Trigger("Other Thread"), lock1inOtherThread.release); // then events.AssertInOrder("Double Locked", "Other Thread"); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldBlockOnLockedLock() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldBlockOnLockedLock() { // given LockService locks = new ReentrantLockService(); LockNode lockSameNode = new LockNode(locks, 17); ThreadRepository.Events events = Threads.events(); ThreadRepository.Signal ready = Threads.signal(); // when using (Lock ignored = locks.AcquireNodeLock(17, LockService_LockType.WriteLock)) { ThreadRepository.ThreadInfo thread = Threads.execute(ready, lockSameNode, events.Trigger("locked"), lockSameNode.release); ready.AwaitNow(); // then assertTrue(AwaitParked(thread, 5, TimeUnit.SECONDS)); assertTrue(events.Snapshot().Count == 0); } events.AssertInOrder("locked"); }