Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldUpgradeExclusiveOnTry()
        public virtual void ShouldUpgradeExclusiveOnTry()
        {
            // Given I've grabbed a shared lock
            ClientA.acquireShared(LockTracer.NONE, NODE, 1L);

            // When
            assertTrue(ClientA.tryExclusiveLock(NODE, 1L));

            // Then I should be able to release it
            ClientA.releaseExclusive(NODE, 1L);
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void sharedShouldWaitForExclusive()
        public virtual void SharedShouldWaitForExclusive()
        {
            // When
            ClientA.acquireExclusive(LockTracer.NONE, NODE, 1L);

            // Then shared locks should wait
            Future <object> clientBLock = AcquireShared(ClientB, LockTracer.NONE, NODE, 1L).callAndAssertWaiting();

            // And when
            ClientA.releaseExclusive(NODE, 1L);

            // Then this should not block
            AssertNotWaiting(ClientB, clientBLock);
        }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReleaseExclusiveLocksAcquiredInABatch()
        public virtual void ShouldReleaseExclusiveLocksAcquiredInABatch()
        {
            ClientA.acquireExclusive(LockTracer.NONE, NODE, 1, 10, 100);
            assertEquals(3, LockCount());

            ClientA.releaseExclusive(NODE, 1);
            assertEquals(2, LockCount());

            ClientA.releaseExclusive(NODE, 10);
            assertEquals(1, LockCount());

            ClientA.releaseExclusive(NODE, 100);
            assertEquals(0, LockCount());
        }
Example #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void releaseMultipleExclusiveLocks()
        public virtual void ReleaseMultipleExclusiveLocks()
        {
            ClientA.acquireExclusive(LockTracer.NONE, NODE, 10, 100, 1000);

            assertFalse(ClientB.trySharedLock(NODE, 10));
            assertFalse(ClientB.trySharedLock(NODE, 100));
            assertFalse(ClientB.trySharedLock(NODE, 1000));
            assertEquals(3, LockCount());

            ClientA.releaseExclusive(NODE, 10, 100);
            assertEquals(1, LockCount());

            assertTrue(ClientB.trySharedLock(NODE, 10));
            assertTrue(ClientB.trySharedLock(NODE, 100));
            assertFalse(ClientB.trySharedLock(NODE, 1000));
        }
Example #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTraceWaitTimeWhenTryingToAcquireSharedLockAndExclusiveIsHeld() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTraceWaitTimeWhenTryingToAcquireSharedLockAndExclusiveIsHeld()
        {
            // given
            Tracer tracerA = new Tracer();
            Tracer tracerB = new Tracer();

            ClientA.acquireExclusive(tracerA, NODE, 17);

            // when
            Future <object> future = AcquireShared(ClientB, tracerB, NODE, 17).callAndAssertWaiting();

            // then
            ClientA.releaseExclusive(NODE, 17);
            future.get();
            tracerA.AssertCalls(0);
            tracerB.AssertCalls(1);
        }
Example #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void releaseExclusiveLocksAcquiredSeparately()
        public virtual void ReleaseExclusiveLocksAcquiredSeparately()
        {
            ClientA.acquireExclusive(LockTracer.NONE, NODE, 1);
            ClientA.acquireExclusive(LockTracer.NONE, NODE, 2);
            ClientA.acquireExclusive(LockTracer.NONE, NODE, 3);
            assertEquals(3, LockCount());

            assertFalse(ClientB.trySharedLock(NODE, 1));
            assertFalse(ClientB.trySharedLock(NODE, 2));
            assertFalse(ClientB.trySharedLock(NODE, 3));

            ClientA.releaseExclusive(NODE, 1, 2, 3);

            assertEquals(0, LockCount());
            assertTrue(ClientB.trySharedLock(NODE, 1));
            assertTrue(ClientB.trySharedLock(NODE, 2));
            assertTrue(ClientB.trySharedLock(NODE, 3));
        }
Example #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRetainSharedLockWhenAcquiredAfterExclusiveLock()
        public virtual void ShouldRetainSharedLockWhenAcquiredAfterExclusiveLock()
        {
            // When
            ClientA.acquireExclusive(LockTracer.NONE, NODE, 1L);
            ClientA.acquireShared(LockTracer.NONE, NODE, 1L);

            // Then this should wait
            Future <object> clientBLock = AcquireExclusive(ClientB, LockTracer.NONE, NODE, 1L).callAndAssertWaiting();

            // And when
            ClientA.releaseExclusive(NODE, 1L);

            // Then other thread should still wait
            AssertWaiting(ClientB, clientBLock);

            // But when
            ClientA.releaseShared(NODE, 1L);

            // Then
            AssertNotWaiting(ClientB, clientBLock);
        }
Example #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAcquireExclusiveIfClientIsOnlyOneHoldingShared()
        public virtual void ShouldAcquireExclusiveIfClientIsOnlyOneHoldingShared()
        {
            // When
            ClientA.acquireShared(LockTracer.NONE, NODE, 1L);
            ClientA.acquireExclusive(LockTracer.NONE, NODE, 1L);

            // Then shared locks should wait
            Future <object> clientBLock = AcquireExclusive(ClientB, LockTracer.NONE, NODE, 1L).callAndAssertWaiting();

            // And when
            ClientA.releaseExclusive(NODE, 1L);

            // Then other thread should still wait
            AssertWaiting(ClientB, clientBLock);

            // But when
            ClientA.releaseShared(NODE, 1L);

            // Then
            AssertNotWaiting(ClientB, clientBLock);
        }
Example #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void exclusiveLocksShouldBeReentrantAndBlockOtherSharedLocks()
        public virtual void ExclusiveLocksShouldBeReentrantAndBlockOtherSharedLocks()
        {
            // When
            ClientA.acquireExclusive(LockTracer.NONE, NODE, 1L);
            ClientA.acquireShared(LockTracer.NONE, NODE, 1L);
            ClientA.tryExclusiveLock(NODE, 1L);

            // Then exclusive locks should wait
            Future <object> clientBLock = AcquireShared(ClientB, LockTracer.NONE, NODE, 1L).callAndAssertWaiting();

            // And when
            ClientA.releaseExclusive(NODE, 1L);
            ClientA.releaseShared(NODE, 1L);

            // Then other thread should still wait
            AssertWaiting(ClientB, clientBLock);

            // But when
            ClientA.releaseExclusive(NODE, 1L);

            // Then
            AssertNotWaiting(ClientB, clientBLock);
        }
Example #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testSingleThread()
        public virtual void TestSingleThread()
        {
            try
            {
                ClientA.releaseExclusive(NODE, 1L);
                fail("Invalid release should throw exception");
            }
            catch (Exception)
            {
                // good
            }
            try
            {
                ClientA.releaseShared(NODE, 1L);
                fail("Invalid release should throw exception");
            }
            catch (Exception)
            {
                // good
            }

            ClientA.acquireShared(LockTracer.NONE, NODE, 1L);
            try
            {
                ClientA.releaseExclusive(NODE, 1L);
                fail("Invalid release should throw exception");
            }
            catch (Exception)
            {
                // good
            }

            ClientA.releaseShared(NODE, 1L);
            ClientA.acquireExclusive(LockTracer.NONE, NODE, 1L);
            try
            {
                ClientA.releaseShared(NODE, 1L);
                fail("Invalid release should throw exception");
            }
            catch (Exception)
            {
                // good
            }
            ClientA.releaseExclusive(NODE, 1L);

            ClientA.acquireShared(LockTracer.NONE, NODE, 1L);
            ClientA.acquireExclusive(LockTracer.NONE, NODE, 1L);
            ClientA.releaseExclusive(NODE, 1L);
            ClientA.releaseShared(NODE, 1L);

            ClientA.acquireExclusive(LockTracer.NONE, NODE, 1L);
            ClientA.acquireShared(LockTracer.NONE, NODE, 1L);
            ClientA.releaseShared(NODE, 1L);
            ClientA.releaseExclusive(NODE, 1L);

            for (int i = 0; i < 10; i++)
            {
                if ((i % 2) == 0)
                {
                    ClientA.acquireExclusive(LockTracer.NONE, NODE, 1L);
                }
                else
                {
                    ClientA.acquireShared(LockTracer.NONE, NODE, 1L);
                }
            }
            for (int i = 9; i >= 0; i--)
            {
                if ((i % 2) == 0)
                {
                    ClientA.releaseExclusive(NODE, 1L);
                }
                else
                {
                    ClientA.releaseShared(NODE, 1L);
                }
            }
        }