//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(timeout = 10_000) public void shouldWaitForCompletionInHalt() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldWaitForCompletionInHalt() { // GIVEN PageCache pageCache = mock(typeof(PageCache)); Org.Neo4j.Test.Barrier_Control barrier = new Org.Neo4j.Test.Barrier_Control(); doAnswer(invocation => { barrier.Reached(); return(null); }).when(pageCache).flushAndForce(); PageCacheFlusher flusher = new PageCacheFlusher(pageCache); flusher.Start(); // WHEN barrier.Await(); Future <object> halt = T2.execute(state => { flusher.Halt(); return(null); }); T2.get().waitUntilWaiting(details => details.isAt(typeof(PageCacheFlusher), "halt")); barrier.Release(); // THEN halt call exits normally after (confirmed) ongoing flushAndForce call completed. halt.get(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHaveTaskQueueSizeEqualToMaxNumberOfProcessors() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHaveTaskQueueSizeEqualToMaxNumberOfProcessors() { // GIVEN StageControl control = mock(typeof(StageControl)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.CountDownLatch latch = new java.util.concurrent.CountDownLatch(1); System.Threading.CountdownEvent latch = new System.Threading.CountdownEvent(1); const int processors = 2; int maxProcessors = 5; Configuration configuration = new ConfigurationAnonymousInnerClass(this, maxProcessors); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final ProcessorStep<Void> step = new BlockingProcessorStep(control, configuration, processors, latch); ProcessorStep <Void> step = new BlockingProcessorStep(control, configuration, processors, latch); step.Start(ORDER_SEND_DOWNSTREAM); step.Processors(1); // now at 2 // adding up to max processors should be fine for (int i = 0; i < processors + maxProcessors; i++) { step.Receive(i, null); } // WHEN Future <Void> receiveFuture = T2.execute(Receive(processors, step)); T2.get().waitUntilThreadState(Thread.State.TIMED_WAITING); latch.Signal(); // THEN receiveFuture.get(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void sendingButNotReceivingClientShouldBeKilledWhenWriteThrottleMaxDurationIsReached() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void SendingButNotReceivingClientShouldBeKilledWhenWriteThrottleMaxDurationIsReached() { int numberOfRunDiscardPairs = 10_000; string largeString = StringUtils.repeat(" ", 8 * 1024); _client.connect(_address).send(_util.acceptedVersions(1, 0, 0, 0)).send(_util.chunk(new InitMessage("TestClient/1.1", emptyMap()))); assertThat(_client, eventuallyReceives(new sbyte[] { 0, 0, 0, 1 })); assertThat(_client, _util.eventuallyReceives(msgSuccess())); Future sender = OtherThread.execute(state => { for (int i = 0; i < numberOfRunDiscardPairs; i++) { _client.send(_util.chunk(new RunMessage("RETURN $data as data", ValueUtils.asMapValue(singletonMap("data", largeString))), PullAllMessage.INSTANCE)); } return(null); }); try { OtherThread.get().awaitFuture(sender); fail("should throw ExecutionException instead"); } catch (ExecutionException e) { assertThat(Exceptions.rootCause(e), instanceOf(typeof(SocketException))); } _logProvider.assertAtLeastOnce(inLog(Matchers.containsString(typeof(BoltConnection).Assembly.GetName().Name)).error(startsWith("Unexpected error detected in bolt session"), hasProperty("cause", matchesExceptionMessage(containsString("will be closed because the client did not consume outgoing buffers for "))))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void givenDatabaseAndStartedTxWhenShutdownThenWaitForTxToFinish() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void GivenDatabaseAndStartedTxWhenShutdownThenWaitForTxToFinish() { // Given //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final GraphDatabaseService db = getTemporaryDatabase(); GraphDatabaseService db = TemporaryDatabase; // When Org.Neo4j.Test.Barrier_Control barrier = new Org.Neo4j.Test.Barrier_Control(); Future <object> txFuture = _t2.execute(state => { using (Transaction tx = Db.beginTx()) { barrier.Reached(); Db.createNode(); tx.Success(); } return(null); }); // i.e. wait for transaction to start barrier.Await(); // now there's a transaction open, blocked on continueTxSignal Future <object> shutdownFuture = _t3.execute(state => { Db.shutdown(); return(null); }); _t3.get().waitUntilWaiting(location => location.isAt(typeof(DatabaseAvailability), "stop")); barrier.Release(); try { txFuture.get(); } catch (ExecutionException) { // expected } shutdownFuture.get(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void assertBlock(Runnable runLock, Runnable runUnlock) throws Exception private void AssertBlock(ThreadStart runLock, ThreadStart runUnlock) { Future <object> future = Executor.execute(state => { runLock.run(); return(null); }); Executor.get().waitUntilWaiting(details => details.isAt(typeof(GBPTreeLock), "doLock")); runUnlock.run(); future.get(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldLetDetectedDeadlocksDuringCommitBeThrownInTheirOriginalForm() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldLetDetectedDeadlocksDuringCommitBeThrownInTheirOriginalForm() { // GIVEN a database with a couple of entities: // (n1) --> (r1) --> (r2) --> (r3) // (n2) GraphDatabaseService db = GlobalDb; Node n1 = CreateNode(db); Node n2 = CreateNode(db); Relationship r3 = CreateRelationship(n1); Relationship r2 = CreateRelationship(n1); Relationship r1 = CreateRelationship(n1); // WHEN creating a deadlock scenario where the final deadlock would have happened due to locks // acquired during linkage of relationship records // // (r1) <-- (t1) // | ^ // v | // (t2) --> (n2) Transaction t1Tx = Db.beginTx(); Transaction t2Tx = _t2.execute(BeginTx(db)).get(); // (t1) <-- (n2) n2.SetProperty("locked", "indeed"); // (t2) <-- (r1) _t2.execute(SetProperty(r1, "locked", "absolutely")).get(); // (t2) --> (n2) Future <object> t2n2Wait = _t2.execute(SetProperty(n2, "locked", "In my dreams")); _t2.get().waitUntilWaiting(); // (t1) --> (r1) although delayed until commit, this is accomplished by deleting an adjacent // relationship so that its surrounding relationships are locked at commit time. r2.Delete(); t1Tx.Success(); try { t1Tx.Close(); fail("Should throw exception about deadlock"); } catch (Exception e) { assertEquals(typeof(DeadlockDetectedException), e.GetType()); } finally { t2n2Wait.get(); _t2.execute(Close(t2Tx)).get(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void processNextBatchShouldReturnWhenConnectionIsStopped() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ProcessNextBatchShouldReturnWhenConnectionIsStopped() { BoltConnection connection = NewConnection(1); connection.Enqueue(Jobs.noop()); connection.Enqueue(Jobs.noop()); // force to a message waiting loop when(_stateMachine.shouldStickOnThread()).thenReturn(true); Future <bool> future = OtherThread.execute(state => connection.ProcessNextBatch()); connection.Stop(); OtherThread.get().awaitFuture(future); verify(_stateMachine).close(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotDeadlock() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotDeadlock() { IList <TransactionRepresentation> transactions = CreateConstraintCreatingTransactions(); Monitors monitors = new Monitors(); GraphDatabaseAPI db = ( GraphDatabaseAPI )(new TestGraphDatabaseFactory()).setMonitors(monitors).newImpermanentDatabase(); Org.Neo4j.Test.Barrier_Control controller = new Org.Neo4j.Test.Barrier_Control(); bool success = false; try { IndexingService.Monitor monitor = new MonitorAdapterAnonymousInnerClass(this, controller); monitors.AddMonitorListener(monitor); Future <object> applier = ApplyInT2(db, transactions); controller.Await(); // At this point the index population has completed and the population thread is ready to // acquire the counts store read lock for initializing some samples there. We're starting the // check pointer, which will eventually put itself in queue for acquiring the write lock Future <object> checkPointer = T3.execute(state => Db.DependencyResolver.resolveDependency(typeof(CheckPointer)).forceCheckPoint(new SimpleTriggerInfo("MANUAL"))); try { T3.get().waitUntilWaiting(details => details.isAt(typeof(LockWrapper), "writeLock")); } catch (System.InvalidOperationException) { // Thrown when the fix is in, basically it's thrown if the check pointer didn't get blocked checkPointer.get(); // to assert that no exception was thrown during in check point thread } // Alright the trap is set. Let the population thread move on and seal the deal controller.Release(); // THEN these should complete applier.get(10, SECONDS); checkPointer.get(10, SECONDS); success = true; using (Transaction tx = Db.beginTx()) { ConstraintDefinition constraint = single(Db.schema().getConstraints(LABEL)); assertEquals(KEY, single(constraint.PropertyKeys)); tx.Success(); } CreateNode(db, "A"); try { CreateNode(db, "A"); fail("Should have failed"); } catch (ConstraintViolationException) { // THEN good } } finally { if (!success) { T2.interrupt(); T3.interrupt(); // so that shutdown won't hang too } Db.shutdown(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldBeAbleToShutdownWhenThereAreTransactionsWaitingForLocks() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldBeAbleToShutdownWhenThereAreTransactionsWaitingForLocks() { // GIVEN //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final Node node; Node node; using (Transaction tx = _db.beginTx()) { node = _db.createNode(); tx.Success(); } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.CountDownLatch nodeLockedLatch = new java.util.concurrent.CountDownLatch(1); System.Threading.CountdownEvent nodeLockedLatch = new System.Threading.CountdownEvent(1); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.CountDownLatch shutdownCalled = new java.util.concurrent.CountDownLatch(1); System.Threading.CountdownEvent shutdownCalled = new System.Threading.CountdownEvent(1); // WHEN // one thread locks previously created node and initiates graph db shutdown Future <Void> shutdownFuture = T2.execute(state => { using (Transaction tx = _db.beginTx()) { node.AddLabel(label("ABC")); nodeLockedLatch.Signal(); // Wait for T3 to start waiting for this node write lock T3.get().waitUntilWaiting(details => details.isAt(typeof(CommunityLockClient), "acquireExclusive")); _db.shutdown(); shutdownCalled.Signal(); tx.Success(); } return(null); }); // other thread tries to lock the same node while it has been locked and graph db is being shutdown Future <Void> secondTxResult = T3.execute(state => { using (Transaction tx = _db.beginTx()) { nodeLockedLatch.await(); // T2 awaits this thread to get into a waiting state for this node write lock node.AddLabel(label("DEF")); shutdownCalled.await(); tx.Success(); } return(null); }); // start waiting when the trap has been triggered try { secondTxResult.get(60, SECONDS); fail("Exception expected"); } catch (Exception e) { assertThat(rootCause(e), instanceOf(typeof(TransactionTerminatedException))); } try { shutdownFuture.get(); fail("Should thrown exception since transaction should be canceled."); } catch (Exception e) { assertThat(rootCause(e), instanceOf(typeof(TransactionTerminatedException))); } }