public TestEmbeddedGraphDatabaseAnonymousInnerClass(PartialTransactionFailureIT outerInstance, File storeDir, IDictionary <string, string> @params, ClassGuardedAdversary adversary) : base(storeDir, @params) { this.outerInstance = outerInstance; this._adversary = adversary; this._storeDir = storeDir; this.@params = @params; }
/* * There was an issue where if multiple concurrent appending threads did append and they moved on * to await a force, where the force would fail and the one doing the force would raise a panic... * the other threads may not notice the panic and move on to mark those transactions as committed * and notice the panic later (which would be too late). */ //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHaveAllConcurrentAppendersSeePanic() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHaveAllConcurrentAppendersSeePanic() { // GIVEN Adversary adversary = new ClassGuardedAdversary(new CountingAdversary(1, true), FailMethod(typeof(BatchingTransactionAppender), "force")); EphemeralFileSystemAbstraction efs = new EphemeralFileSystemAbstraction(); FileSystemAbstraction fs = new AdversarialFileSystemAbstraction(adversary, efs); _life.add(new FileSystemLifecycleAdapter(fs)); DatabaseHealth databaseHealth = new DatabaseHealth(mock(typeof(DatabasePanicEventGenerator)), NullLog.Instance); LogFiles logFiles = LogFilesBuilder.builder(_testDirectory.databaseLayout(), fs).withLogVersionRepository(_logVersionRepository).withTransactionIdStore(_transactionIdStore).build(); _life.add(logFiles); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final BatchingTransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, logRotation, transactionMetadataCache, transactionIdStore, explicitIndexTransactionOrdering, databaseHealth)); BatchingTransactionAppender appender = _life.add(new BatchingTransactionAppender(logFiles, _logRotation, _transactionMetadataCache, _transactionIdStore, _explicitIndexTransactionOrdering, databaseHealth)); _life.start(); // WHEN int numberOfAppenders = 10; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.CountDownLatch trap = new java.util.concurrent.CountDownLatch(numberOfAppenders); System.Threading.CountdownEvent trap = new System.Threading.CountdownEvent(numberOfAppenders); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.tracing.LogAppendEvent beforeForceTrappingEvent = new org.neo4j.kernel.impl.transaction.tracing.LogAppendEvent_Empty() LogAppendEvent beforeForceTrappingEvent = new LogAppendEvent_EmptyAnonymousInnerClass(this, trap); Race race = new Race(); for (int i = 0; i < numberOfAppenders; i++) { race.AddContestant(() => { try { // Append to the log, the LogAppenderEvent will have all of the appending threads // do wait for all of the other threads to start the force thing appender.Append(Tx(), beforeForceTrappingEvent); fail("No transaction should be considered appended"); } catch (IOException) { // Good, we know that this test uses an adversarial file system which will throw // an exception in BatchingTransactionAppender#force, and since all these transactions // will append and be forced in the same batch, where the force will fail then // all these transactions should fail. If there's any transaction not failing then // it just didn't notice the panic, which would be potentially hazardous. } }); } // THEN perform the race. The relevant assertions are made inside the contestants. race.Go(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(timeout = 60_000) public void possibleToShutdownDbWhenItIsNotHealthyAndNotAllTransactionsAreApplied() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void PossibleToShutdownDbWhenItIsNotHealthyAndNotAllTransactionsAreApplied() { // adversary that makes page cache throw exception when node store is used ClassGuardedAdversary adversary = new ClassGuardedAdversary(new CountingAdversary(1, true), typeof(NodeStore)); adversary.Disable(); GraphDatabaseService db = AdversarialPageCacheGraphDatabaseFactory.create(_fs, adversary).newEmbeddedDatabaseBuilder(_testDir.databaseDir()).newGraphDatabase(); System.Threading.CountdownEvent txStartLatch = new System.Threading.CountdownEvent(1); System.Threading.CountdownEvent txCommitLatch = new System.Threading.CountdownEvent(1); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.concurrent.Future<?> result = java.util.concurrent.ForkJoinPool.commonPool().submit(() -> Future <object> result = ForkJoinPool.commonPool().submit(() => { using (Transaction tx = Db.beginTx()) { txStartLatch.Signal(); Db.createNode(); Await(txCommitLatch); tx.success(); } }); Await(txStartLatch); adversary.Enable(); txCommitLatch.Signal(); try { result.get(); fail("Exception expected"); } catch (ExecutionException ee) { // transaction is expected to fail because write through the page cache fails assertThat(ee.InnerException, instanceOf(typeof(TransactionFailureException))); } adversary.Disable(); // shutdown should complete without any problems Db.shutdown(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void concurrentlyCommittingTransactionsMustNotRotateOutLoggedCommandsOfFailingTransaction() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ConcurrentlyCommittingTransactionsMustNotRotateOutLoggedCommandsOfFailingTransaction() { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.adversaries.ClassGuardedAdversary adversary = new org.neo4j.adversaries.ClassGuardedAdversary(new org.neo4j.adversaries.CountingAdversary(1, false), org.neo4j.kernel.impl.transaction.command.Command.RelationshipCommand.class); ClassGuardedAdversary adversary = new ClassGuardedAdversary(new CountingAdversary(1, false), typeof(Command.RelationshipCommand)); adversary.Disable(); File storeDir = Dir.storeDir(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.Map<String,String> params = stringMap(org.neo4j.graphdb.factory.GraphDatabaseSettings.pagecache_memory.name(), "8m"); IDictionary <string, string> @params = stringMap(GraphDatabaseSettings.pagecache_memory.name(), "8m"); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.graphdb.facade.embedded.EmbeddedGraphDatabase db = new TestEmbeddedGraphDatabase(storeDir, params) EmbeddedGraphDatabase db = new TestEmbeddedGraphDatabaseAnonymousInnerClass(this, storeDir, @params, adversary); Node a; Node b; Node c; Node d; using (Transaction tx = Db.beginTx()) { a = Db.createNode(); b = Db.createNode(); c = Db.createNode(); d = Db.createNode(); tx.Success(); } adversary.Enable(); System.Threading.CountdownEvent latch = new System.Threading.CountdownEvent(1); Thread t1 = new Thread(CreateRelationship(db, a, b, latch), "T1"); Thread t2 = new Thread(CreateRelationship(db, c, d, latch), "T2"); t1.Start(); t2.Start(); // Wait for both threads to get going t1.Join(10); t2.Join(10); latch.Signal(); // Wait for the transactions to finish t1.Join(25000); t2.Join(25000); Db.shutdown(); // We should observe the store in a consistent state EmbeddedGraphDatabase db2 = new TestEmbeddedGraphDatabase(storeDir, @params); try { using (Transaction tx = db2.BeginTx()) { Node x = db2.GetNodeById(a.Id); Node y = db2.GetNodeById(b.Id); Node z = db2.GetNodeById(c.Id); Node w = db2.GetNodeById(d.Id); IEnumerator <Relationship> itrRelX = x.Relationships.GetEnumerator(); IEnumerator <Relationship> itrRelY = y.Relationships.GetEnumerator(); IEnumerator <Relationship> itrRelZ = z.Relationships.GetEnumerator(); IEnumerator <Relationship> itrRelW = w.Relationships.GetEnumerator(); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: if (itrRelX.hasNext() != itrRelY.hasNext()) { fail("Node x and y have inconsistent relationship counts"); } //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: else if (itrRelX.hasNext()) { //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: Relationship rel = itrRelX.next(); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertEquals(rel, itrRelY.next()); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse(itrRelX.hasNext()); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse(itrRelY.hasNext()); } //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: if (itrRelZ.hasNext() != itrRelW.hasNext()) { fail("Node z and w have inconsistent relationship counts"); } //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: else if (itrRelZ.hasNext()) { //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: Relationship rel = itrRelZ.next(); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertEquals(rel, itrRelW.next()); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse(itrRelZ.hasNext()); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse(itrRelW.hasNext()); } } } finally { db2.Shutdown(); } }