예제 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = 30_000) public void terminatingTransactionMustEagerlyReleaseTheirLocks() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TerminatingTransactionMustEagerlyReleaseTheirLocks()
        {
            AtomicBoolean nodeLockAcquired = new AtomicBoolean();
            AtomicBoolean lockerDone       = new AtomicBoolean();
            BinaryLatch   lockerPause      = new BinaryLatch();
            long          nodeId;

            using (Transaction tx = Database.beginTx())
            {
                nodeId = Database.createNode().Id;
                tx.Success();
            }
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.concurrent.Future<?> locker = executor.submit(() ->
            Future <object> locker = _executor.submit(() =>
            {
                using (Transaction tx = Database.beginTx())
                {
                    Node node = Database.getNodeById(nodeId);
                    tx.AcquireReadLock(node);
                    nodeLockAcquired.set(true);
                    lockerPause.Await();
                }
                lockerDone.set(true);
            });

            bool proceed;

            do
            {
                proceed = nodeLockAcquired.get();
            } while (!proceed);

            TerminateOngoingTransaction();

            assertFalse(lockerDone.get());                 // but the thread should still be blocked on the latch
            // Yet we should be able to proceed and grab the locks they once held
            using (Transaction tx = Database.beginTx())
            {
                // Write-locking is only possible if their shared lock was released
                tx.AcquireWriteLock(Database.getNodeById(nodeId));
                tx.Success();
            }
            // No exception from our lock client being stopped (e.g. we ended up blocked for too long) or from timeout
            lockerPause.Release();
            locker.get();
            assertTrue(lockerDone.get());
        }