示例#1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testLockCounters() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestLockCounters()
        {
            RagManager   ragManager = new RagManager();
            LockResource resource   = new LockResource(ResourceTypes.NODE, 1L);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final RWLock lock = createRWLock(ragManager, resource);
            RWLock          @lock              = CreateRWLock(ragManager, resource);
            LockTransaction lockTransaction    = new LockTransaction();
            LockTransaction anotherTransaction = new LockTransaction();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LockTransaction writeTransaction = new LockTransaction();
            LockTransaction writeTransaction = new LockTransaction();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch writerCompletedLatch = new java.util.concurrent.CountDownLatch(1);
            System.Threading.CountdownEvent writerCompletedLatch = new System.Threading.CountdownEvent(1);

            @lock.Mark();
            @lock.AcquireReadLock(LockTracer.NONE, lockTransaction);
            @lock.Mark();
            @lock.AcquireReadLock(LockTracer.NONE, anotherTransaction);

            assertEquals(2, @lock.ReadCount);
            assertEquals(0, @lock.WriteCount);
            assertEquals(2, @lock.TxLockElementCount);

            ThreadStart writer = CreateWriter(@lock, writeTransaction, writerCompletedLatch);

            _executor.submit(writer);

            WaitWaitingThreads(@lock, 1);

            // check that all reader, writes, threads counters are correct
            assertEquals(2, @lock.ReadCount);
            assertEquals(0, @lock.WriteCount);
            assertEquals(3, @lock.TxLockElementCount);
            assertEquals(1, @lock.WaitingThreadsCount);

            @lock.ReleaseReadLock(lockTransaction);
            @lock.ReleaseReadLock(anotherTransaction);
            writerCompletedLatch.await();

            // test readers and waiting thread gone
            assertEquals(0, @lock.ReadCount);
            assertEquals(1, @lock.WriteCount);
            assertEquals(1, @lock.TxLockElementCount);
            assertEquals(0, @lock.WaitingThreadsCount);

            @lock.ReleaseWriteLock(writeTransaction);

            // check lock is clean in the end
            assertEquals(0, @lock.TxLockElementCount);
            assertEquals(0, @lock.WaitingThreadsCount);
            assertEquals(0, @lock.ReadCount);
            assertEquals(0, @lock.WriteCount);
        }
示例#2
0
        /*
         * In case if writer thread can't grab write lock now, it should be added to
         * into a waiting list, wait till resource will be free and grab it.
         */
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = TEST_TIMEOUT_MILLIS) public void testWaitingWriterLock() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestWaitingWriterLock()
        {
            RagManager   ragManager = new RagManager();
            LockResource resource   = new LockResource(ResourceTypes.NODE, 1L);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final RWLock lock = createRWLock(ragManager, resource);
            RWLock @lock = CreateRWLock(ragManager, resource);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LockTransaction lockTransaction = new LockTransaction();
            LockTransaction lockTransaction = new LockTransaction();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LockTransaction anotherTransaction = new LockTransaction();
            LockTransaction anotherTransaction = new LockTransaction();

            @lock.Mark();
            @lock.AcquireReadLock(LockTracer.NONE, lockTransaction);
            @lock.Mark();
            @lock.AcquireReadLock(LockTracer.NONE, anotherTransaction);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch writerCompletedLatch = new java.util.concurrent.CountDownLatch(1);
            System.Threading.CountdownEvent writerCompletedLatch = new System.Threading.CountdownEvent(1);

            ThreadStart writer = CreateWriter(@lock, lockTransaction, writerCompletedLatch);

            // start writer that will be placed in a wait list
            _executor.execute(writer);

            // wait till writer will be added into a list of waiters
            WaitWaitingThreads(@lock, 1);

            assertEquals("No writers for now.", 0, @lock.WriteCount);
            assertEquals(2, @lock.ReadCount);

            // releasing read locks that will allow writer to grab the lock
            @lock.ReleaseReadLock(lockTransaction);
            @lock.ReleaseReadLock(anotherTransaction);

            // wait till writer will have write lock
            writerCompletedLatch.await();

            assertEquals(1, @lock.WriteCount);
            assertEquals(0, @lock.ReadCount);

            // now releasing write lock
            @lock.ReleaseWriteLock(lockTransaction);

            assertEquals("Lock should not have any writers left.", 0, @lock.WriteCount);
            assertEquals("No waiting threads left.", 0, @lock.WaitingThreadsCount);
            assertEquals("No lock elements left.", 0, @lock.TxLockElementCount);
        }
示例#3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = TEST_TIMEOUT_MILLIS) public void testWaitingReaderLock() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestWaitingReaderLock()
        {
            RagManager   ragManager = new RagManager();
            LockResource resource   = new LockResource(ResourceTypes.NODE, 1L);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final RWLock lock = createRWLock(ragManager, resource);
            RWLock @lock = CreateRWLock(ragManager, resource);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LockTransaction transaction = new LockTransaction();
            LockTransaction transaction = new LockTransaction();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LockTransaction readerTransaction = new LockTransaction();
            LockTransaction readerTransaction = new LockTransaction();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch readerCompletedLatch = new java.util.concurrent.CountDownLatch(1);
            System.Threading.CountdownEvent readerCompletedLatch = new System.Threading.CountdownEvent(1);

            @lock.Mark();
            @lock.AcquireWriteLock(LockTracer.NONE, transaction);

            ThreadStart reader = CreateReader(@lock, readerTransaction, readerCompletedLatch);

            // start reader that should wait for writer to release write lock
            _executor.execute(reader);

            WaitWaitingThreads(@lock, 1);

            assertEquals(1, @lock.WriteCount);
            assertEquals("No readers for now", 0, @lock.ReadCount);

            @lock.ReleaseWriteLock(transaction);

            // wait till reader finish lock grab
            readerCompletedLatch.await();

            assertEquals(0, @lock.WriteCount);
            assertEquals(1, @lock.ReadCount);

            @lock.ReleaseReadLock(readerTransaction);

            assertEquals("Lock should not have any readers left.", 0, @lock.ReadCount);
            assertEquals("No waiting threads left.", 0, @lock.WaitingThreadsCount);
            assertEquals("No lock elements left.", 0, @lock.TxLockElementCount);
        }
示例#4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void assertReadLockDoesNotLeakMemory()
        public virtual void AssertReadLockDoesNotLeakMemory()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final RagManager ragManager = new RagManager();
            RagManager ragManager = new RagManager();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LockResource resource = new LockResource(org.neo4j.kernel.impl.locking.ResourceTypes.NODE, 0);
            LockResource resource = new LockResource(ResourceTypes.NODE, 0);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final RWLock lock = createRWLock(ragManager, resource);
            RWLock @lock = CreateRWLock(ragManager, resource);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Transaction tx1 = mock(org.neo4j.graphdb.Transaction.class);
            Transaction tx1 = mock(typeof(Transaction));

            @lock.Mark();
            @lock.AcquireReadLock(LockTracer.NONE, tx1);
            @lock.Mark();

            assertEquals(1, @lock.TxLockElementCount);
            @lock.ReleaseReadLock(tx1);
            assertEquals(0, @lock.TxLockElementCount);
        }