//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 WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void recoverFromConstraintAppliedBeforeCrash(System.Action<org.neo4j.kernel.internal.GraphDatabaseAPI> constraintCreator) throws Exception private void RecoverFromConstraintAppliedBeforeCrash(System.Action <GraphDatabaseAPI> constraintCreator) { IList <TransactionRepresentation> transactions = CreateTransactionsForCreatingConstraint(constraintCreator); EphemeralFileSystemAbstraction crashSnapshot; { GraphDatabaseAPI db = NewDb(); Org.Neo4j.Test.Barrier_Control barrier = new Org.Neo4j.Test.Barrier_Control(); _monitors.addMonitorListener(new MonitorAdapterAnonymousInnerClass(this, barrier)); try { // Create two nodes that have duplicate property values string value = "v"; using (Transaction tx = Db.beginTx()) { for (int i = 0; i < 2; i++) { Db.createNode(LABEL).setProperty(KEY, value); } tx.Success(); } T2.execute(state => { Apply(db, transactions.subList(0, transactions.Count - 1)); return(null); }); barrier.Await(); FlushStores(db); // Crash before index population have discovered that there are duplicates // (nowadays happens in between index population and creating the constraint) crashSnapshot = Fs.snapshot(); barrier.Release(); } finally { Db.shutdown(); } } { // WHEN GraphDatabaseAPI db = ( GraphDatabaseAPI )(new TestEnterpriseGraphDatabaseFactory()).setFileSystem(crashSnapshot).newImpermanentDatabase(); try { Recreate(constraintCreator).accept(db, transactions); fail("Should not be able to create constraint on non-unique data"); } catch (Exception e) when(e is ConstraintViolationException || e is QueryExecutionException) { // THEN good } finally { Db.shutdown(); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldBeAbleToReadUpToDateValueWhileAnotherThreadIsPerformingRotation() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldBeAbleToReadUpToDateValueWhileAnotherThreadIsPerformingRotation() { // given CountsOracle oracle = SomeData(); const int firstTransaction = 2; int secondTransaction = 3; using (Lifespan life = new Lifespan()) { CountsTracker tracker = life.Add(NewTracker()); oracle.Update(tracker, firstTransaction); tracker.Rotate(firstTransaction); } // when //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.impl.store.CountsOracle delta = new org.neo4j.kernel.impl.store.CountsOracle(); CountsOracle delta = new CountsOracle(); { CountsOracle.Node n1 = delta.Node(1); CountsOracle.Node n2 = delta.Node(1, 4); // Label 4 has not been used before... delta.Relationship(n1, 1, n2); delta.Relationship(n2, 2, n1); // relationshipType 2 has not been used before... } delta.Update(oracle); using (Lifespan life = new Lifespan()) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.test.Barrier_Control barrier = new org.neo4j.test.Barrier_Control(); Org.Neo4j.Test.Barrier_Control barrier = new Org.Neo4j.Test.Barrier_Control(); CountsTracker tracker = life.Add(new CountsTrackerAnonymousInnerClass(this, ResourceManager.logProvider(), ResourceManager.fileSystem(), ResourceManager.pageCache(), Config.defaults(), EmptyVersionContextSupplier.EMPTY, barrier)); Future <Void> task = Threading.execute(t => { try { delta.Update(t, secondTransaction); t.rotate(secondTransaction); } catch (IOException e) { throw new AssertionError(e); } return(null); }, tracker); // then barrier.Await(); oracle.Verify(tracker); barrier.Release(); task.get(); oracle.Verify(tracker); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldAwaitCompletionOfAllTasks() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldAwaitCompletionOfAllTasks() { // given //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final TaskCoordinator coordinator = new TaskCoordinator(1, java.util.concurrent.TimeUnit.MILLISECONDS); TaskCoordinator coordinator = new TaskCoordinator(1, TimeUnit.MILLISECONDS); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicReference<String> state = new java.util.concurrent.atomic.AtomicReference<>(); AtomicReference <string> state = new AtomicReference <string>(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.List<String> states = new java.util.ArrayList<>(); IList <string> states = new List <string>(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.test.Barrier_Control phaseA = new org.neo4j.test.Barrier_Control(); Org.Neo4j.Test.Barrier_Control phaseA = new Org.Neo4j.Test.Barrier_Control(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.test.Barrier_Control phaseB = new org.neo4j.test.Barrier_Control(); Org.Neo4j.Test.Barrier_Control phaseB = new Org.Neo4j.Test.Barrier_Control(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.test.Barrier_Control phaseC = new org.neo4j.test.Barrier_Control(); Org.Neo4j.Test.Barrier_Control phaseC = new Org.Neo4j.Test.Barrier_Control(); state.set("A"); new Thread("awaitCompletion" () => { try { states.Add(state.get()); // expects A phaseA.Reached(); states.Add(state.get()); // expects B phaseB.Await(); phaseB.Release(); coordinator.AwaitCompletion(); states.Add(state.get()); // expects C phaseC.Reached(); } catch (InterruptedException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } });
//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 TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void givenDatabaseAndStartedTxWhenShutdownAndStartNewTxThenBeginTxTimesOut() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void GivenDatabaseAndStartedTxWhenShutdownAndStartNewTxThenBeginTxTimesOut() { // Given GraphDatabaseService db = TemporaryDatabase; // When Org.Neo4j.Test.Barrier_Control barrier = new Org.Neo4j.Test.Barrier_Control(); _t2.execute(state => { using (Transaction tx = Db.beginTx()) { barrier.Reached(); // <-- this triggers t3 to start a db.shutdown() } return(null); }); barrier.Await(); Future <object> shutdownFuture = _t3.execute(state => { Db.shutdown(); return(null); }); _t3.get().waitUntilWaiting(location => location.isAt(typeof(DatabaseAvailability), "stop")); barrier.Release(); // <-- this triggers t2 to continue its transaction shutdownFuture.get(); try { Db.beginTx(); fail("Should fail"); } catch (DatabaseShutdownException) { //THEN good } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotSeeFreedIdsCrossRoleSwitch() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotSeeFreedIdsCrossRoleSwitch() { // GIVEN ManagedCluster cluster = ClusterRule.startCluster(); HighlyAvailableGraphDatabase firstMaster = cluster.Master; // WHEN // a node with a property Node node = CreateNodeWithProperties(firstMaster, 1); // sync cluster cluster.Sync(); // a transaction on master which deletes the property DeleteNode(node, firstMaster); TriggerIdMaintenance(firstMaster); CreateNodeWithProperties(firstMaster, 1); // <-- this one reuses the same property id 0 // a transaction T on slave which will be kept open using a barrier GraphDatabaseAPI slave = cluster.AnySlave; Org.Neo4j.Test.Barrier_Control barrier = new Org.Neo4j.Test.Barrier_Control(); Future <Void> t = T2.execute(BarrierControlledReadTransaction(slave, barrier)); // pull updates on slave barrier.Await(); slave.DependencyResolver.resolveDependency(typeof(UpdatePuller)).pullUpdates(); // a role switch cluster.Shutdown(firstMaster); cluster.Await(masterAvailable(firstMaster)); // close T barrier.Release(); t.get(); TriggerIdMaintenance(slave); // THEN the deleted property record should now not be in freelist on new master CreateNodeWithProperties(slave, 10); // <-- this transaction should introduce inconsistencies cluster.Stop(); // <-- CC will be run here since that's configured above ^^^ }
//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(); } }