예제 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAcquireMultipleExclusiveLocks()
        public virtual void ShouldAcquireMultipleExclusiveLocks()
        {
            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());
        }
예제 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldListLocksHeldByTheCurrentClient()
        public virtual void ShouldListLocksHeldByTheCurrentClient()
        {
            // given
            ClientA.acquireExclusive(LockTracer.NONE, NODE, 1, 2, 3);
            ClientA.acquireShared(LockTracer.NONE, NODE, 3, 4, 5);

            // when
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.stream.Stream<? extends ActiveLock> locks = clientA.activeLocks();
            Stream <ActiveLock> locks = ClientA.activeLocks();

            // then
            assertEquals(new HashSet <>(asList(exclusiveLock(NODE, 1), exclusiveLock(NODE, 2), exclusiveLock(NODE, 3), sharedLock(NODE, 3), sharedLock(NODE, 4), sharedLock(NODE, 5))), locks.collect(toSet()));
        }
예제 #3
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);
        }
예제 #4
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());
        }
예제 #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustReleaseUnpreparedLocksOnStop()
        public virtual void MustReleaseUnpreparedLocksOnStop()
        {
            // Given
            ClientA.acquireShared(_tracer, NODE, 1L);
            ClientA.acquireExclusive(_tracer, NODE, 2L);

            // When
            ClientA.stop();

            // The client was stopped before it could enter the prepare phase, so all of its locks are released
            LockCountVisitor lockCountVisitor = new LockCountVisitor();

            Locks.accept(lockCountVisitor);
            assertEquals(0, lockCountVisitor.LockCount);
        }
예제 #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void prepareMustAllowAcquiringNewLocksAfterStop()
        public virtual void PrepareMustAllowAcquiringNewLocksAfterStop()
        {
            // Given
            ClientA.prepare();
            ClientA.stop();

            // When
            ClientA.acquireShared(_tracer, NODE, 1);
            ClientA.acquireExclusive(_tracer, NODE, 2);

            // Stopped essentially has no effect when it comes after the client has entered the prepare phase
            LockCountVisitor lockCountVisitor = new LockCountVisitor();

            Locks.accept(lockCountVisitor);
            assertEquals(2, lockCountVisitor.LockCount);
        }
예제 #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustNotReleaseLocksAfterPrepareOnStop()
        public virtual void MustNotReleaseLocksAfterPrepareOnStop()
        {
            // Given
            ClientA.acquireShared(_tracer, NODE, 1L);
            ClientA.acquireExclusive(_tracer, NODE, 2L);
            ClientA.prepare();

            // When
            ClientA.stop();

            // The client entered the prepare phase, so it gets to keep its locks
            LockCountVisitor lockCountVisitor = new LockCountVisitor();

            Locks.accept(lockCountVisitor);
            assertEquals(2, lockCountVisitor.LockCount);
        }
예제 #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void releaseMultipleAlreadyAcquiredExclusiveLocks()
        public virtual void ReleaseMultipleAlreadyAcquiredExclusiveLocks()
        {
            ClientA.acquireExclusive(LockTracer.NONE, NODE, 10, 100, 1000);
            ClientA.acquireExclusive(LockTracer.NONE, NODE, 100, 1000, 10000);

            ClientA.releaseExclusive(NODE, 100, 1000);
            assertEquals(4, LockCount());

            assertFalse(ClientB.trySharedLock(NODE, 10));
            assertFalse(ClientB.trySharedLock(NODE, 100));
            assertFalse(ClientB.trySharedLock(NODE, 1000));
            assertFalse(ClientB.trySharedLock(NODE, 10000));

            ClientA.releaseExclusive(NODE, 100, 1000);

            assertEquals(2, LockCount());
        }
예제 #9
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);
        }
예제 #10
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));
        }
예제 #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustReleaseReadLockWaitersOnStop()
        public virtual void MustReleaseReadLockWaitersOnStop()
        {
            // Given
            ClientA.acquireExclusive(_tracer, NODE, 1L);
            ClientB.acquireExclusive(_tracer, NODE, 2L);
            AcquireShared(ClientB, _tracer, NODE, 1L).callAndAssertWaiting();

            // When
            ClientB.stop();
            ClientA.stop();

            // All locks clients should be stopped at this point, and all all locks should be released because none of the
            // clients entered the prepare phase
            LockCountVisitor lockCountVisitor = new LockCountVisitor();

            Locks.accept(lockCountVisitor);
            assertEquals(0, lockCountVisitor.LockCount);
        }
예제 #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void releaseMultipleExclusiveLocksWhileHavingSomeSharedLocks()
        public virtual void ReleaseMultipleExclusiveLocksWhileHavingSomeSharedLocks()
        {
            ClientA.acquireShared(LockTracer.NONE, NODE, 100, 1000, 10000);
            ClientA.acquireExclusive(LockTracer.NONE, NODE, 10, 100, 1000);

            assertFalse(ClientB.trySharedLock(NODE, 10));
            assertFalse(ClientB.trySharedLock(NODE, 100));
            assertFalse(ClientB.trySharedLock(NODE, 1000));
            assertFalse(ClientB.tryExclusiveLock(NODE, 10000));
            assertEquals(4, LockCount());

            ClientA.releaseExclusive(NODE, 100, 1000);

            assertFalse(ClientB.trySharedLock(NODE, 10));
            assertFalse(ClientB.tryExclusiveLock(NODE, 100));
            assertFalse(ClientB.tryExclusiveLock(NODE, 1000));
            assertFalse(ClientB.tryExclusiveLock(NODE, 10000));

            assertEquals(4, LockCount());
        }
예제 #13
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);
        }
예제 #14
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);
        }
예제 #15
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);
        }
예제 #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = LockClientStoppedException.class) public void shouldNotBeAbleToAcquireExclusiveLockFromClosedClient()
        public virtual void ShouldNotBeAbleToAcquireExclusiveLockFromClosedClient()
        {
            ClientA.close();
            ClientA.acquireExclusive(LockTracer.NONE, NODE, 1L);
        }
예제 #17
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);
                }
            }
        }