internal AcquiredLock(Locks_Client client, bool shared, ResourceType resourceType, long resourceId) { this.Client = client; this.SharedConflict = shared; this.ResourceType = resourceType; this.ResourceId = resourceId; }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldStopLockSessionOnFailureWhereThereIsAnActiveLockAcquisition() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldStopLockSessionOnFailureWhereThereIsAnActiveLockAcquisition() { // GIVEN System.Threading.CountdownEvent latch = new System.Threading.CountdownEvent(1); try { Locks_Client client = NewWaitingLocksClient(latch); MasterImpl master = NewMasterWithLocksClient(client); HandshakeResult handshake = master.Handshake(1, newStoreIdForCurrentVersion()).response(); // WHEN RequestContext context = new RequestContext(handshake.Epoch(), 1, 2, 0, 0); master.NewLockSession(context); Future <Void> acquireFuture = OtherThread.execute(state => { master.AcquireExclusiveLock(context, ResourceTypes.NODE, 1L); return(null); }); OtherThread.get().waitUntilWaiting(); master.EndLockSession(context, false); verify(client).stop(); verify(client, never()).close(); latch.Signal(); acquireFuture.get(); // THEN verify(client).close(); } finally { latch.Signal(); } }
private Locks_Client NewLockClient(LockAcquisition lockAcquisition) { Locks_Client client = Locks.newClient(); lockAcquisition.Client = client; return(client); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAllowStartNewTransactionAfterClientSessionWasRemovedOnTimeout() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldAllowStartNewTransactionAfterClientSessionWasRemovedOnTimeout() { //Given MasterImpl.SPI spi = MockedSpi(); DefaultConversationSPI conversationSpi = MockedConversationSpi(); Monitor monitor = mock(typeof(Monitor)); Config config = config(); Locks_Client client = mock(typeof(Locks_Client)); ConversationManager conversationManager = new ConversationManager(conversationSpi, config); int machineId = 1; MasterImpl master = new MasterImpl(spi, conversationManager, monitor, config); when(spi.Accessible).thenReturn(true); when(conversationSpi.AcquireClient()).thenReturn(client); master.Start(); HandshakeResult handshake = master.Handshake(1, newStoreIdForCurrentVersion()).response(); RequestContext requestContext = new RequestContext(handshake.Epoch(), machineId, 0, 0, 0); // When master.NewLockSession(requestContext); master.AcquireSharedLock(requestContext, ResourceTypes.NODE, 1L); conversationManager.Stop(requestContext); master.NewLockSession(requestContext); //Then IDictionary <int, ICollection <RequestContext> > transactions = master.OngoingTransactions; assertEquals(1, transactions.Count); assertThat(transactions[machineId], org.hamcrest.Matchers.hasItem(requestContext)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void setUp() public virtual void SetUp() { _customConfig = Config.defaults(GraphDatabaseSettings.lock_acquisition_timeout, "100ms"); _clock = Clocks.fakeClock(100000, TimeUnit.MINUTES); _lockManager = Suite.createLockManager(_customConfig, _clock); _client = _lockManager.newClient(); _client2 = _lockManager.newClient(); }
internal StressThread(RWLockCompatibility outerInstance, string name, int numberOfIterations, int depthCount, float readWriteRatio, long nodeId, System.Threading.CountdownEvent startSignal) : base() { this._outerInstance = outerInstance; this.NodeId = nodeId; this.Client = outerInstance.Locks.newClient(); this.Name = name; this.NumberOfIterations = numberOfIterations; this.DepthCount = depthCount; this.ReadWriteRatio = readWriteRatio; this.StartSignal = startSignal; }
protected internal virtual void AssertNotWaiting(Locks_Client client, Future <object> @lock) { try { @lock.get(5, TimeUnit.SECONDS); } catch (Exception e) when(e is ExecutionException || e is TimeoutException || e is InterruptedException) { throw new Exception("Waiting for lock timed out!"); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void before() public virtual void Before() { this.Locks = Suite.createLockManager(Config.defaults(), Clocks.systemClock()); ClientA = this.Locks.newClient(); ClientB = this.Locks.newClient(); ClientC = this.Locks.newClient(); ClientToThreadMap[ClientA] = ThreadA; ClientToThreadMap[ClientB] = ThreadB; ClientToThreadMap[ClientC] = ThreadC; }
public override StatementLocks NewInstance() { if (_locks == null) { throw new System.InvalidOperationException("Factory has not been initialized"); } Locks_Client client = _locks.newClient(); return(_deferredLocksEnabled ? new DeferringStatementLocks(client) : new SimpleStatementLocks(client)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCloseUnderlyingClient() public virtual void ShouldCloseUnderlyingClient() { // GIVEN Locks_Client actualClient = mock(typeof(Locks_Client)); DeferringLockClient client = new DeferringLockClient(actualClient); // WHEN client.Close(); // THEN verify(actualClient).close(); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: //ORIGINAL LINE: private org.neo4j.kernel.impl.locking.Locks_Client newWaitingLocksClient(final java.util.concurrent.CountDownLatch latch) private Locks_Client NewWaitingLocksClient(System.Threading.CountdownEvent latch) { Locks_Client client = mock(typeof(Locks_Client)); doAnswer(invocation => { latch.await(); return(null); }).when(client).acquireExclusive(eq(LockTracer.NONE), any(typeof(ResourceType)), anyLong()); return(client); }
/// <summary> /// Increment active number of clients that use current state instance. /// </summary> /// <param name="client"> the locks client associated with this state; used only to create pretty exception /// with <seealso cref="LockClientStoppedException.LockClientStoppedException(Locks.Client)"/>. </param> /// <exception cref="LockClientStoppedException"> when stopped. </exception> public void IncrementActiveClients(Locks_Client client) { int currentState; do { currentState = _clientState.get(); if (IsStopped(currentState)) { throw new LockClientStoppedException(client); } } while (!_clientState.compareAndSet(currentState, IncrementActiveClients(currentState))); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: //ORIGINAL LINE: private LockAcquisition acquireTwoLocksInAnotherThread(final boolean firstShared, final boolean secondShared, final java.util.concurrent.CountDownLatch firstLockFailed, final java.util.concurrent.CountDownLatch startSecondLock) private LockAcquisition AcquireTwoLocksInAnotherThread(bool firstShared, bool secondShared, System.Threading.CountdownEvent firstLockFailed, System.Threading.CountdownEvent startSecondLock) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final LockAcquisition lockAcquisition = new LockAcquisition(); LockAcquisition lockAcquisition = new LockAcquisition(); Future <Void> future = ThreadA.execute(state => { using (Locks_Client client = NewLockClient(lockAcquisition)) { try { if (firstShared) { client.AcquireShared(_tracer, NODE, FIRST_NODE_ID); } else { client.AcquireExclusive(_tracer, NODE, FIRST_NODE_ID); } fail("Transaction termination expected"); } catch (Exception e) { assertThat(e, instanceOf(typeof(LockClientStoppedException))); } } lockAcquisition.Client = null; firstLockFailed.Signal(); Await(startSecondLock); using (Locks_Client client = NewLockClient(lockAcquisition)) { if (secondShared) { client.AcquireShared(_tracer, NODE, FIRST_NODE_ID); } else { client.AcquireExclusive(_tracer, NODE, FIRST_NODE_ID); } } return(null); }); lockAcquisition.SetFuture(future, ThreadA.get()); return(lockAcquisition); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldUseCorrectClientForImplicitAndExplicit() public virtual void ShouldUseCorrectClientForImplicitAndExplicit() { // GIVEN //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final Locks_Client client = mock(Locks_Client.class); Locks_Client client = mock(typeof(Locks_Client)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final DeferringStatementLocks statementLocks = new DeferringStatementLocks(client); DeferringStatementLocks statementLocks = new DeferringStatementLocks(client); // THEN assertSame(client, statementLocks.Pessimistic()); assertThat(statementLocks.Optimistic(), instanceOf(typeof(DeferringLockClient))); }
private MasterImpl NewMasterWithLocksClient(Locks_Client client) { SPI spi = MockedSpi(); DefaultConversationSPI conversationSpi = MockedConversationSpi(); when(spi.Accessible).thenReturn(true); when(conversationSpi.AcquireClient()).thenReturn(client); Config config = config(); ConversationManager conversationManager = new ConversationManager(conversationSpi, config); MasterImpl master = new MasterImpl(spi, conversationManager, mock(typeof(Monitor)), config); master.Start(); return(master); }
/// <summary> /// Move the client to the PREPARE state, unless it is already STOPPED. /// </summary> public void Prepare(Locks_Client client) { int currentValue; int newValue; do { currentValue = _clientState.get(); if (IsStopped(currentValue)) { throw new LockClientStoppedException(client); } newValue = StateWithNewStatus(currentValue, _prepare); } while (!_clientState.compareAndSet(currentValue, newValue)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCloseUnderlyingClient() public virtual void ShouldCloseUnderlyingClient() { // GIVEN //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final Locks_Client client = mock(Locks_Client.class); Locks_Client client = mock(typeof(Locks_Client)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final DeferringStatementLocks statementLocks = new DeferringStatementLocks(client); DeferringStatementLocks statementLocks = new DeferringStatementLocks(client); // WHEN statementLocks.Close(); // THEN verify(client).close(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldDoNothingWithClientWhenPreparingForCommitWithNoLocksAcquired() public virtual void ShouldDoNothingWithClientWhenPreparingForCommitWithNoLocksAcquired() { // GIVEN //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final Locks_Client client = mock(Locks_Client.class); Locks_Client client = mock(typeof(Locks_Client)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final DeferringStatementLocks statementLocks = new DeferringStatementLocks(client); DeferringStatementLocks statementLocks = new DeferringStatementLocks(client); // WHEN statementLocks.PrepareForCommit(LockTracer.NONE); // THEN verify(client).prepare(); verifyNoMoreInteractions(client); }
protected internal virtual void AssertWaiting(Locks_Client client, Future <object> @lock) { try { @lock.get(10, TimeUnit.MILLISECONDS); fail("Should be waiting."); } catch (TimeoutException) { // Ok } catch (Exception e) when(e is ExecutionException || e is InterruptedException) { throw new Exception(e); } assertThat(ClientToThreadMap[client], Waiting); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldThrowWhenReleaseNotYetAcquiredShared() public virtual void ShouldThrowWhenReleaseNotYetAcquiredShared() { // GIVEN Locks_Client actualClient = mock(typeof(Locks_Client)); DeferringLockClient client = new DeferringLockClient(actualClient); try { // WHEN client.ReleaseShared(ResourceTypes.Node, 1); fail("Expected exception"); } catch (System.InvalidOperationException) { // THEN } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void loadSimpleStatementLocksFactoryWhenNoServices() public virtual void LoadSimpleStatementLocksFactoryWhenNoServices() { Locks locks = mock(typeof(Locks)); Locks_Client locksClient = mock(typeof(Locks_Client)); when(locks.NewClient()).thenReturn(locksClient); StatementLocksFactorySelector loader = NewLoader(locks); StatementLocksFactory factory = loader.Select(); StatementLocks statementLocks = factory.NewInstance(); assertThat(factory, instanceOf(typeof(SimpleStatementLocksFactory))); assertThat(statementLocks, instanceOf(typeof(SimpleStatementLocks))); assertSame(locksClient, statementLocks.Optimistic()); assertSame(locksClient, statementLocks.Pessimistic()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldThrowOnAcquireWhenClosed() public virtual void ShouldThrowOnAcquireWhenClosed() { // GIVEN Locks_Client actualClient = mock(typeof(Locks_Client)); DeferringLockClient client = new DeferringLockClient(actualClient); client.Close(); try { // WHEN client.AcquireExclusive(LockTracer.NONE, ResourceTypes.Node, 1); fail("Expected exception"); } catch (LockClientStoppedException) { // THEN } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void newInstanceCreatesDeferredLocksWhenConfigSet() public virtual void NewInstanceCreatesDeferredLocksWhenConfigSet() { Locks locks = mock(typeof(Locks)); Locks_Client client = mock(typeof(Locks_Client)); when(locks.NewClient()).thenReturn(client); Config config = Config.defaults(deferred_locks_enabled, Settings.TRUE); DeferringStatementLocksFactory factory = new DeferringStatementLocksFactory(); factory.Initialize(locks, config); StatementLocks statementLocks = factory.NewInstance(); assertThat(statementLocks, instanceOf(typeof(DeferringStatementLocks))); assertThat(statementLocks.Optimistic(), instanceOf(typeof(DeferringLockClient))); assertSame(client, statementLocks.Pessimistic()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldThrowWhenReleasingLockMultipleTimes() public virtual void ShouldThrowWhenReleasingLockMultipleTimes() { // GIVEN Locks_Client actualClient = mock(typeof(Locks_Client)); DeferringLockClient client = new DeferringLockClient(actualClient); client.AcquireExclusive(LockTracer.NONE, ResourceTypes.Node, 1); client.ReleaseExclusive(ResourceTypes.Node, 1); try { // WHEN client.ReleaseShared(ResourceTypes.Node, 1); fail("Expected exception"); } catch (System.InvalidOperationException) { // THEN } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotBeAbleToHandOutClientsIfClosed() public virtual void ShouldNotBeAbleToHandOutClientsIfClosed() { // GIVEN a lock manager and working clients using (Locks_Client client = Locks.newClient()) { client.AcquireExclusive(LockTracer.NONE, ResourceTypes.Node, 0); } // WHEN Locks.close(); // THEN try { Locks.newClient(); fail("Should fail"); } catch (System.InvalidOperationException) { // Good } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPrepareExplicitForCommitWhenLocksAcquire() public virtual void ShouldPrepareExplicitForCommitWhenLocksAcquire() { // GIVEN //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final Locks_Client client = mock(Locks_Client.class); Locks_Client client = mock(typeof(Locks_Client)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final DeferringStatementLocks statementLocks = new DeferringStatementLocks(client); DeferringStatementLocks statementLocks = new DeferringStatementLocks(client); // WHEN statementLocks.Optimistic().acquireExclusive(LockTracer.NONE, ResourceTypes.Node, 1); statementLocks.Optimistic().acquireExclusive(LockTracer.NONE, ResourceTypes.Relationship, 42); verify(client, never()).acquireExclusive(eq(LockTracer.NONE), any(typeof(ResourceType)), anyLong()); statementLocks.PrepareForCommit(LockTracer.NONE); // THEN verify(client).prepare(); verify(client).acquireExclusive(LockTracer.NONE, ResourceTypes.Node, 1); verify(client).acquireExclusive(LockTracer.NONE, ResourceTypes.Relationship, 42); verifyNoMoreInteractions(client); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: //ORIGINAL LINE: private LockAcquisition tryAcquireTwoLocksLockInAnotherThread(final boolean shared, final java.util.concurrent.CountDownLatch firstLockAcquired) private LockAcquisition TryAcquireTwoLocksLockInAnotherThread(bool shared, System.Threading.CountdownEvent firstLockAcquired) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final LockAcquisition lockAcquisition = new LockAcquisition(); LockAcquisition lockAcquisition = new LockAcquisition(); Future <Void> future = ThreadA.execute(state => { using (Locks_Client client = NewLockClient(lockAcquisition)) { if (shared) { client.AcquireShared(_tracer, NODE, SECOND_NODE_ID); } else { client.AcquireExclusive(_tracer, NODE, SECOND_NODE_ID); } firstLockAcquired.Signal(); if (shared) { client.AcquireShared(_tracer, NODE, FIRST_NODE_ID); } else { client.AcquireExclusive(_tracer, NODE, FIRST_NODE_ID); } } return(null); }); lockAcquisition.SetFuture(future, ThreadA.get()); return(lockAcquisition); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: //ORIGINAL LINE: private LockAcquisition acquireLockInAnotherThread(final boolean shared) private LockAcquisition AcquireLockInAnotherThread(bool shared) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final LockAcquisition lockAcquisition = new LockAcquisition(); LockAcquisition lockAcquisition = new LockAcquisition(); Future <Void> future = ThreadA.execute(state => { Locks_Client client = NewLockClient(lockAcquisition); if (shared) { client.AcquireShared(_tracer, NODE, FIRST_NODE_ID); } else { client.AcquireExclusive(_tracer, NODE, FIRST_NODE_ID); } return(null); }); lockAcquisition.SetFuture(future, ThreadA.get()); return(lockAcquisition); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void lockResultMustHaveMessageWhenAcquiringSharedLockThrowsIllegalResource() public virtual void LockResultMustHaveMessageWhenAcquiringSharedLockThrowsIllegalResource() { MasterImpl.SPI spi = MockedSpi(); DefaultConversationSPI conversationSpi = MockedConversationSpi(); Config config = config(); ConversationManager conversationManager = new ConversationManager(conversationSpi, config); conversationManager.Start(); Locks_Client locks = mock(typeof(Locks_Client)); MasterImpl master = new MasterImpl(spi, conversationManager, null, config); RequestContext context = CreateRequestContext(master); when(conversationSpi.AcquireClient()).thenReturn(locks); ResourceTypes type = ResourceTypes.NODE; doThrow(new IllegalResourceException("")).when(locks).acquireExclusive(LockTracer.NONE, type, 1); master.AcquireSharedLock(context, type, 1); ArgumentCaptor <LockResult> captor = ArgumentCaptor.forClass(typeof(LockResult)); verify(spi).packTransactionObligationResponse(MockitoHamcrest.argThat(@is(context)), captor.capture()); assertThat(captor.Value.Message, @is(not(nullValue()))); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: //ORIGINAL LINE: private LockAcquisition acquireSharedAndExclusiveLocksInAnotherThread(final java.util.concurrent.CountDownLatch sharedLockAcquired, final java.util.concurrent.CountDownLatch startExclusiveLock) private LockAcquisition AcquireSharedAndExclusiveLocksInAnotherThread(System.Threading.CountdownEvent sharedLockAcquired, System.Threading.CountdownEvent startExclusiveLock) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final LockAcquisition lockAcquisition = new LockAcquisition(); LockAcquisition lockAcquisition = new LockAcquisition(); Future <Void> future = ThreadA.execute(state => { using (Locks_Client client = NewLockClient(lockAcquisition)) { client.AcquireShared(_tracer, NODE, FIRST_NODE_ID); sharedLockAcquired.Signal(); Await(startExclusiveLock); client.AcquireExclusive(_tracer, NODE, FIRST_NODE_ID); } return(null); }); lockAcquisition.SetFuture(future, ThreadA.get()); return(lockAcquisition); }