예제 #1
0
//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());
        }
예제 #2
0
//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());
        }
예제 #3
0
//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");
        }