예제 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldUpgradeAndDowngradeSameSharedLock()
        public virtual void ShouldUpgradeAndDowngradeSameSharedLock()
        {
            // when
            ClientA.acquireShared(LockTracer.NONE, NODE, 1L);
            ClientB.acquireShared(LockTracer.NONE, NODE, 1L);

            LockIdentityExplorer sharedLockExplorer = new LockIdentityExplorer(NODE, 1L);

            Locks.accept(sharedLockExplorer);

            // then xclusive should wait for shared from other client to be released
            Future <object> exclusiveLockFuture = AcquireExclusive(ClientB, LockTracer.NONE, NODE, 1L).callAndAssertWaiting();

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

            // exclusive lock should be received
            AssertNotWaiting(ClientB, exclusiveLockFuture);

            // and when releasing exclusive
            ClientB.releaseExclusive(NODE, 1L);

            // we still should have same read lock
            LockIdentityExplorer releasedLockExplorer = new LockIdentityExplorer(NODE, 1L);

            Locks.accept(releasedLockExplorer);

            // we still hold same lock as before
            assertEquals(sharedLockExplorer.LockIdentityHashCode, releasedLockExplorer.LockIdentityHashCode);
        }
예제 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAcquireMultipleSharedLocks()
        public virtual void ShouldAcquireMultipleSharedLocks()
        {
            ClientA.acquireShared(LockTracer.NONE, NODE, 10, 100, 1000);

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

            assertEquals(3, LockCount());
        }
예제 #3
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);
        }
예제 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCountNumberOfActiveLocks()
        public virtual void ShouldCountNumberOfActiveLocks()
        {
            // given
            ClientA.acquireShared(LockTracer.NONE, LABEL, 0);
            ClientA.acquireShared(LockTracer.NONE, RELATIONSHIP, 17);
            ClientA.acquireShared(LockTracer.NONE, NODE, 12);

            // when
            long count = ClientA.activeLockCount();

            // then
            assertEquals(3, count);
        }
예제 #5
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()));
        }
예제 #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void releaseMultipleAlreadyAcquiredSharedLocks()
        public virtual void ReleaseMultipleAlreadyAcquiredSharedLocks()
        {
            ClientA.acquireShared(LockTracer.NONE, NODE, 10, 100, 1000);
            ClientA.acquireShared(LockTracer.NONE, NODE, 100, 1000, 10000);

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

            assertFalse(ClientB.tryExclusiveLock(NODE, 100));
            assertFalse(ClientB.tryExclusiveLock(NODE, 1000));

            ClientA.releaseShared(NODE, 100, 1000);
            assertEquals(2, LockCount());
        }
예제 #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReleaseSharedLocksAcquiredInABatch()
        public virtual void ShouldReleaseSharedLocksAcquiredInABatch()
        {
            ClientA.acquireShared(LockTracer.NONE, NODE, 1, 10, 100);
            assertEquals(3, LockCount());

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

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

            ClientA.releaseShared(NODE, 100);
            assertEquals(0, LockCount());
        }
예제 #8
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);
        }
예제 #9
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);
        }
예제 #10
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);
        }
예제 #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTraceWaitTimeWhenTryingToAcquireExclusiveLockAndSharedIsHeld() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTraceWaitTimeWhenTryingToAcquireExclusiveLockAndSharedIsHeld()
        {
            // given
            Tracer tracerA = new Tracer();
            Tracer tracerB = new Tracer();

            ClientA.acquireShared(tracerA, NODE, 17);

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

            // then
            ClientA.releaseShared(NODE, 17);
            future.get();
            tracerA.AssertCalls(0);
            tracerB.AssertCalls(1);
        }
예제 #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void releaseSharedLocksAcquiredSeparately()
        public virtual void ReleaseSharedLocksAcquiredSeparately()
        {
            ClientA.acquireShared(LockTracer.NONE, NODE, 1);
            ClientA.acquireShared(LockTracer.NONE, NODE, 2);
            ClientA.acquireShared(LockTracer.NONE, NODE, 3);
            assertEquals(3, LockCount());

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

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

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

            // Then other shared locks are allowed
            ClientC.acquireShared(LockTracer.NONE, NODE, 1L);

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

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

            // Then this should not block
            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 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());
        }
예제 #15
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);
        }
예제 #16
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);
        }
예제 #17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustReleaseWriteLockWaitersOnStop()
        public virtual void MustReleaseWriteLockWaitersOnStop()
        {
            // Given
            ClientA.acquireShared(_tracer, NODE, 1L);
            ClientB.acquireShared(_tracer, NODE, 2L);
            ClientC.acquireShared(_tracer, NODE, 3L);
            AcquireExclusive(ClientB, _tracer, NODE, 1L).callAndAssertWaiting();
            AcquireExclusive(ClientC, _tracer, NODE, 1L).callAndAssertWaiting();

            // When
            ClientC.stop();
            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);
        }
예제 #18
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);
        }
예제 #19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void closeShouldWaitAllOperationToFinish()
        public virtual void CloseShouldWaitAllOperationToFinish()
        {
            // given
            ClientA.acquireShared(LockTracer.NONE, NODE, 1L);
            ClientA.acquireShared(LockTracer.NONE, NODE, 3L);
            ClientB.acquireShared(LockTracer.NONE, NODE, 1L);
            AcquireShared(ClientC, LockTracer.NONE, NODE, 2L);
            AcquireExclusive(ClientB, LockTracer.NONE, NODE, 1L).callAndAssertWaiting();
            AcquireExclusive(ClientC, LockTracer.NONE, NODE, 1L).callAndAssertWaiting();

            // when
            ClientB.close();
            ClientC.close();
            ClientA.close();

            // all locks should be closed at this point regardless of
            // reader/writer waiter in any threads
            // those should be gracefully finish and client should be closed

            LockCountVisitor lockCountVisitor = new LockCountVisitor();

            Locks.accept(lockCountVisitor);
            assertEquals(0, lockCountVisitor.LockCount);
        }
예제 #20
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 shouldNotBeAbleToAcquireSharedLockFromClosedClient()
        public virtual void ShouldNotBeAbleToAcquireSharedLockFromClosedClient()
        {
            ClientA.close();
            ClientA.acquireShared(LockTracer.NONE, NODE, 1L);
        }
예제 #21
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);
                }
            }
        }