Esempio n. 1
0
        private int _marked;          // synch helper in LockManager

        internal RWLock(LockResource resource, RagManager ragManager, Clock clock, long lockAcquisitionTimeoutMillis)
        {
            this._resource   = resource;
            this._ragManager = ragManager;
            this._clock      = clock;
            this._lockAcquisitionTimeoutMillis = lockAcquisitionTimeoutMillis;
        }
Esempio n. 2
0
        public override bool TrySharedLock(ResourceType resourceType, long resourceId)
        {
            _stateHolder.incrementActiveClients(this);
            try
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.map.primitive.MutableLongObjectMap<LockResource> localLocks = localShared(resourceType);
                MutableLongObjectMap <LockResource> localLocks = LocalShared(resourceType);
                LockResource resource = localLocks.get(resourceId);
                if (resource != null)
                {
                    resource.AcquireReference();
                    return(true);
                }
                else
                {
                    resource = new LockResource(resourceType, resourceId);
                    if (_manager.tryReadLock(resource, _lockTransaction))
                    {
                        localLocks.put(resourceId, resource);
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            finally
            {
                _stateHolder.decrementActiveClients();
            }
        }
Esempio n. 3
0
 public override void AcquireShared(LockTracer tracer, ResourceType resourceType, params long[] resourceIds)
 {
     _stateHolder.incrementActiveClients(this);
     try
     {
         MutableLongObjectMap <LockResource> localLocks = LocalShared(resourceType);
         foreach (long resourceId in resourceIds)
         {
             LockResource resource = localLocks.get(resourceId);
             if (resource != null)
             {
                 resource.AcquireReference();
             }
             else
             {
                 resource = new LockResource(resourceType, resourceId);
                 if (_manager.getReadLock(tracer, resource, _lockTransaction))
                 {
                     localLocks.put(resourceId, resource);
                 }
                 else
                 {
                     throw new LockClientStoppedException(this);
                 }
             }
         }
     }
     finally
     {
         _stateHolder.decrementActiveClients();
     }
 }
Esempio n. 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCleanupNotUsedLocks()
        public virtual void ShouldCleanupNotUsedLocks()
        {
            // given
            LockResource    node            = new LockResource(ResourceTypes.NODE, 1L);
            LockTransaction lockTransaction = new LockTransaction();
            LockManagerImpl lockManager     = CreateLockManager();

            lockManager.GetWriteLock(LockTracer.NONE, node, lockTransaction);

            // expect
            assertTrue(lockManager.TryReadLock(node, lockTransaction));
            assertEquals(1, CountLocks(lockManager));

            // and when
            lockManager.ReleaseWriteLock(node, lockTransaction);

            // expect to see one old reader
            assertEquals(1, CountLocks(lockManager));

            // and when
            lockManager.ReleaseReadLock(node, lockTransaction);

            // no more locks left
            assertEquals(0, CountLocks(lockManager));
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
 private RWLock GetRWLockForAcquiring(LockResource resource, object tx)
 {
     AssertValidArguments(resource, tx);
     lock ( _resourceLockMap )
     {
         RWLock @lock = _resourceLockMap.computeIfAbsent(resource, k => CreateLock(resource));
         @lock.Mark();
         return(@lock);
     }
 }
Esempio n. 7
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 testLockRequestsTermination() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestLockRequestsTermination()
        {
            // given
            RagManager   ragManager = new RagManager();
            LockResource node1      = new LockResource(ResourceTypes.NODE, 1L);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final RWLock lock = createRWLock(ragManager, node1);
            RWLock @lock = CreateRWLock(ragManager, node1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LockTransaction mainTransaction = new LockTransaction();
            LockTransaction mainTransaction = new LockTransaction();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LockTransaction writerTransaction = new LockTransaction();
            LockTransaction writerTransaction = 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);
            ThreadStart conflictingWriter = CreateFailedWriter(@lock, writerTransaction, writerCompletedLatch);

//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);
            ThreadStart reader = CreateFailedReader(@lock, readerTransaction, readerCompletedLatch);

            // when
            @lock.Mark();
            assertTrue(@lock.AcquireWriteLock(LockTracer.NONE, mainTransaction));
            _executor.submit(reader);
            _executor.submit(conflictingWriter);

            // wait waiters to come
            WaitWaitingThreads(@lock, 2);
            assertEquals(3, @lock.TxLockElementCount);

            // when
            @lock.TerminateLockRequestsForLockTransaction(readerTransaction);
            @lock.TerminateLockRequestsForLockTransaction(writerTransaction);

            readerCompletedLatch.await();
            writerCompletedLatch.await();

            // expect only main write lock counters and elements present
            // all the rest should be cleaned up
            assertEquals(0, @lock.WaitingThreadsCount);
            assertEquals(0, @lock.ReadCount);
            assertEquals(1, @lock.WriteCount);
            assertEquals(1, @lock.TxLockElementCount);
        }
Esempio n. 8
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 testDeadlockDetection() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestDeadlockDetection()
        {
            RagManager   ragManager = new RagManager();
            LockResource node1      = new LockResource(ResourceTypes.NODE, 1L);
            LockResource node2      = new LockResource(ResourceTypes.NODE, 2L);
            LockResource node3      = new LockResource(ResourceTypes.NODE, 3L);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final RWLock lockNode1 = createRWLock(ragManager, node1);
            RWLock lockNode1 = CreateRWLock(ragManager, node1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final RWLock lockNode2 = createRWLock(ragManager, node2);
            RWLock lockNode2 = CreateRWLock(ragManager, node2);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final RWLock lockNode3 = createRWLock(ragManager, node3);
            RWLock lockNode3 = CreateRWLock(ragManager, node3);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LockTransaction client1Transaction = new LockTransaction();
            LockTransaction client1Transaction = new LockTransaction();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LockTransaction client2Transaction = new LockTransaction();
            LockTransaction client2Transaction = new LockTransaction();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LockTransaction client3Transaction = new LockTransaction();
            LockTransaction client3Transaction = new LockTransaction();

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

            lockNode1.Mark();
            lockNode1.AcquireWriteLock(LockTracer.NONE, client1Transaction);
            lockNode2.Mark();
            lockNode2.AcquireWriteLock(LockTracer.NONE, client2Transaction);
            lockNode3.Mark();
            lockNode3.AcquireWriteLock(LockTracer.NONE, client3Transaction);

            ThreadStart readerLockNode2 = CreateReaderForDeadlock(lockNode3, client1Transaction, deadLockDetector);
            ThreadStart readerLockNode3 = CreateReaderForDeadlock(lockNode1, client2Transaction, deadLockDetector);
            ThreadStart readerLockNode1 = CreateReaderForDeadlock(lockNode2, client3Transaction, deadLockDetector);

            _executor.execute(readerLockNode2);
            _executor.execute(readerLockNode3);
            _executor.execute(readerLockNode1);

            // Deadlock should occur
            assertTrue("Deadlock was detected as expected.", deadLockDetector.await(TEST_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));

            lockNode3.ReleaseWriteLock(client3Transaction);
            lockNode2.ReleaseWriteLock(client2Transaction);
            lockNode1.ReleaseWriteLock(client1Transaction);
        }
Esempio n. 9
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: public void accept(final org.neo4j.kernel.impl.locking.Locks_Visitor visitor)
        public override void Accept(Org.Neo4j.Kernel.impl.locking.Locks_Visitor visitor)
        {
            _manager.accept(element =>
            {
                object resource = element.resource();
                if (resource is LockResource)
                {
                    LockResource lockResource = ( LockResource )resource;
                    visitor.Visit(lockResource.Type(), lockResource.ResourceId(), element.describe(), element.maxWaitTime(), System.identityHashCode(lockResource));
                }
                return(false);
            });
        }
Esempio n. 10
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);
        }
Esempio n. 11
0
        private bool ReEnter(LongObjectMap <LockResource> localLocks, long resourceId)
        {
            LockResource resource = localLocks.get(resourceId);

            if (resource != null)
            {
                resource.AcquireReference();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotBePossibleReleaseNotExistingLock()
        public virtual void ShouldNotBePossibleReleaseNotExistingLock()
        {
            // given
            LockResource    node1           = new LockResource(ResourceTypes.NODE, 1L);
            LockTransaction lockTransaction = new LockTransaction();
            LockManagerImpl lockManager     = CreateLockManager();

            // expect
            ExpectedException.expect(typeof(LockNotFoundException));
            ExpectedException.expectMessage("Lock not found for: ");

            // when
            lockManager.ReleaseReadLock(node1, lockTransaction);
        }
Esempio n. 13
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null || this.GetType() != o.GetType())
            {
                return(false);
            }

            LockResource that = ( LockResource )o;

            return(_resourceId == that._resourceId && _resourceType.Equals(that._resourceType));
        }
Esempio n. 14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReleaseNotAcquiredLocks()
        public virtual void ShouldReleaseNotAcquiredLocks()
        {
            // given
            LockResource    node            = new LockResource(ResourceTypes.NODE, 1L);
            LockTransaction lockTransaction = new LockTransaction();
            RWLock          rwLock          = Mockito.mock(typeof(RWLock));
            LockManagerImpl lockManager     = new MockedLockLockManager(this, new RagManager(), rwLock);

            // expect
            lockManager.TryReadLock(node, lockTransaction);

            // during client close any of the attempts to get read/write lock can be scheduled as last one
            // in that case lock will hot have marks, readers, writers anymore and optimistically created lock
            // need to be removed from global map resource map
            assertEquals(0, CountLocks(lockManager));
        }
Esempio n. 15
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);
        }
Esempio n. 16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowGetReadWriteLocks()
        public virtual void ShouldAllowGetReadWriteLocks()
        {
            // given
            LockResource    node1           = new LockResource(ResourceTypes.NODE, 1L);
            LockResource    node2           = new LockResource(ResourceTypes.NODE, 2L);
            LockTransaction lockTransaction = new LockTransaction();
            LockManagerImpl lockManager     = CreateLockManager();

            // expect
            assertTrue(lockManager.GetReadLock(LockTracer.NONE, node1, lockTransaction));
            assertTrue(lockManager.GetReadLock(LockTracer.NONE, node2, lockTransaction));
            assertTrue(lockManager.GetWriteLock(LockTracer.NONE, node2, lockTransaction));

            lockManager.ReleaseReadLock(node1, lockTransaction);
            lockManager.ReleaseReadLock(node2, lockTransaction);
            lockManager.ReleaseWriteLock(node2, lockTransaction);

            int lockCount = CountLocks(lockManager);

            assertEquals(0, lockCount);
        }
Esempio n. 17
0
        public override void ReleaseExclusive(ResourceType resourceType, params long[] resourceIds)
        {
            _stateHolder.incrementActiveClients(this);
            try
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.eclipse.collections.api.map.primitive.MutableLongObjectMap<LockResource> localLocks = localExclusive(resourceType);
                MutableLongObjectMap <LockResource> localLocks = LocalExclusive(resourceType);
                foreach (long resourceId in resourceIds)
                {
                    LockResource resource = localLocks.get(resourceId);
                    if (resource.ReleaseReference() == 0)
                    {
                        localLocks.remove(resourceId);
                        _manager.releaseWriteLock(new LockResource(resourceType, resourceId), _lockTransaction);
                    }
                }
            }
            finally
            {
                _stateHolder.decrementActiveClients();
            }
        }
Esempio n. 18
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);
        }
Esempio n. 19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @VisibleForTesting protected RWLock createLock(LockResource resource)
        protected internal virtual RWLock CreateLock(LockResource resource)
        {
            return(new RWLock(resource, _ragManager, _clock, _lockAcquisitionTimeoutMillis));
        }
Esempio n. 20
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 testThreadRemovedFromWaitingListOnDeadlock() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestThreadRemovedFromWaitingListOnDeadlock()
        {
            RagManager   ragManager = Mockito.mock(typeof(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();

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

            Mockito.doNothing().doAnswer(invocation =>
            {
                exceptionLatch.Signal();
                throw new DeadlockDetectedException("Deadlock");
            }).when(ragManager).checkWaitOn(@lock, lockTransaction);

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

            // writer will be added to a waiting list
            // then spurious wake up will be simulated
            // and deadlock will be detected
            ThreadStart writer = () =>
            {
                try
                {
                    @lock.Mark();
                    @lock.AcquireWriteLock(LockTracer.NONE, lockTransaction);
                }
                catch (DeadlockDetectedException)
                {
                    // ignored
                }
                completionLatch.Signal();
            };

            _executor.execute(writer);

            WaitWaitingThreads(@lock, 1);

            // sending notify for all threads till our writer will not cause deadlock exception
            do
            {
                //noinspection SynchronizationOnLocalVariableOrMethodParameter
                lock ( @lock )
                {
                    Monitor.PulseAll(@lock);
                }
            } while (exceptionLatch.CurrentCount == 1);

            // waiting for writer to finish
            completionLatch.await();

            assertEquals("In case of deadlock caused by spurious wake up " + "thread should be removed from waiting list", 0, @lock.WaitingThreadsCount);
        }
Esempio n. 21
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public boolean getWriteLock(org.neo4j.storageengine.api.lock.LockTracer tracer, LockResource resource, Object tx) throws org.neo4j.kernel.DeadlockDetectedException, org.neo4j.kernel.impl.transaction.IllegalResourceException
        public virtual bool GetWriteLock(LockTracer tracer, LockResource resource, object tx)
        {
            return(UnusedResourceGuard(resource, tx, GetRWLockForAcquiring(resource, tx).acquireWriteLock(tracer, tx)));
        }
Esempio n. 22
0
 protected internal override RWLock CreateLock(LockResource resource)
 {
     return(Lock);
 }
Esempio n. 23
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public boolean tryWriteLock(LockResource resource, Object tx) throws org.neo4j.kernel.impl.transaction.IllegalResourceException
        public virtual bool TryWriteLock(LockResource resource, object tx)
        {
            return(UnusedResourceGuard(resource, tx, GetRWLockForAcquiring(resource, tx).tryAcquireWriteLock(tx)));
        }
Esempio n. 24
0
 private RWLock CreateRWLock(RagManager ragManager, LockResource resource)
 {
     return(new RWLock(resource, ragManager, Clocks.systemClock(), 0));
 }