Exemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldUpgradeToUpdateLock()
        public virtual void ShouldUpgradeToUpdateLock()
        {
            // Given
            ForsetiClient clientA = mock(typeof(ForsetiClient));
            ForsetiClient clientB = mock(typeof(ForsetiClient));

            SharedLock @lock = new SharedLock(clientA);

            @lock.Acquire(clientB);

            // When
            assertTrue(@lock.TryAcquireUpdateLock(clientA));

            // Then
            assertThat(@lock.NumberOfHolders(), equalTo(2));
            assertThat(@lock.UpdateLock, equalTo(true));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Attempt to upgrade a share lock to an exclusive lock, grabbing the share lock if we don't hold it.
        ///
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private boolean tryUpgradeSharedToExclusive(org.neo4j.storageengine.api.lock.LockTracer tracer, org.neo4j.storageengine.api.lock.LockWaitEvent waitEvent, org.neo4j.storageengine.api.lock.ResourceType resourceType, java.util.concurrent.ConcurrentMap<long,ForsetiLockManager.Lock> lockMap, long resourceId, SharedLock sharedLock, long waitStartMillis) throws org.neo4j.storageengine.api.lock.AcquireLockTimeoutException
        private bool TryUpgradeSharedToExclusive(LockTracer tracer, LockWaitEvent waitEvent, ResourceType resourceType, ConcurrentMap <long, ForsetiLockManager.Lock> lockMap, long resourceId, SharedLock sharedLock, long waitStartMillis)
        {
            int  tries           = 0;
            bool holdsSharedLock = _sharedLockCounts[resourceType.TypeId()].containsKey(resourceId);

            if (!holdsSharedLock)
            {
                // We don't hold the shared lock, we need to grab it to upgrade it to an exclusive one
                if (!sharedLock.Acquire(this))
                {
                    return(false);
                }

                try
                {
                    if (TryUpgradeToExclusiveWithShareLockHeld(tracer, waitEvent, resourceType, resourceId, sharedLock, tries, waitStartMillis))
                    {
                        return(true);
                    }
                    else
                    {
                        ReleaseGlobalLock(lockMap, resourceId);
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    ReleaseGlobalLock(lockMap, resourceId);
                    throw e;
                }
            }
            else
            {
                // We do hold the shared lock, so no reason to deal with the complexity in the case above.
                return(TryUpgradeToExclusiveWithShareLockHeld(tracer, waitEvent, resourceType, resourceId, sharedLock, tries, waitStartMillis));
            }
        }