コード例 #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 releaseMultipleSharedLocks()
        public virtual void ReleaseMultipleSharedLocks()
        {
            ClientA.acquireShared(LockTracer.NONE, NODE, 10, 100, 1000);
            assertEquals(3, LockCount());

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

            assertFalse(ClientB.tryExclusiveLock(NODE, 10));
            assertTrue(ClientB.tryExclusiveLock(NODE, 100));
            assertTrue(ClientB.tryExclusiveLock(NODE, 1000));
        }
コード例 #3
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());
        }
コード例 #4
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);
        }
コード例 #5
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);
        }
コード例 #6
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));
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
                }
            }
        }