//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 ^^^ }
private WorkerCommand <object, int> PerformConstraintViolatingInserts(HighlyAvailableGraphDatabase slave) { return(PerformInserts(slave, false)); }
private WorkerCommand <object, int> PerformConstraintCompliantInserts(HighlyAvailableGraphDatabase slave) { return(PerformInserts(slave, true)); }
//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.test.OtherThreadExecutor.WorkerCommand<Object,bool> createConstraint(final HighlyAvailableGraphDatabase master) private WorkerCommand <object, bool> CreateConstraint(HighlyAvailableGraphDatabase master) { return(ConstraintOps.createConstraint(master, _labelOrRelType, _property)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void assertConstraintsNotViolated(java.util.concurrent.Future<bool> constraintCreation, java.util.concurrent.Future<int> constraintViolation, HighlyAvailableGraphDatabase master) throws InterruptedException, java.util.concurrent.ExecutionException private void AssertConstraintsNotViolated(Future <bool> constraintCreation, Future <int> constraintViolation, HighlyAvailableGraphDatabase master) { bool constraintCreationFailed = constraintCreation.get(); int txSuccessCount = constraintViolation.get(); if (constraintCreationFailed) { // Constraint creation failed, some of the violating operations should have been successful. assertThat(txSuccessCount, greaterThan(0)); // And the graph should contain some duplicates. assertThat(ConstraintOps.isValid(master, _labelOrRelType, _property), equalTo(false)); } else { // Constraint creation was successful, all the violating operations should have failed. assertThat(txSuccessCount, equalTo(0)); // And the graph should not contain duplicates. assertThat(ConstraintOps.isValid(master, _labelOrRelType, _property), equalTo(true)); } }
//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 void setupForWaitOnSwitchToDetached(HighlyAvailableGraphDatabase db, final java.util.concurrent.CountDownLatch latch) private void SetupForWaitOnSwitchToDetached(HighlyAvailableGraphDatabase db, System.Threading.CountdownEvent latch) { Db.DependencyResolver.resolveDependency(typeof(HighAvailabilityMemberStateMachine)).addHighAvailabilityMemberListener(new HighAvailabilityMemberListener_AdapterAnonymousInnerClass(this, latch)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test @Ignore public void slaveShouldServeTxsAfterMasterLostQuorumWentToPendingAndThenQuorumWasRestored() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void SlaveShouldServeTxsAfterMasterLostQuorumWentToPendingAndThenQuorumWasRestored() { // GIVEN: cluster with 3 members HighlyAvailableGraphDatabase master = _cluster.Master; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final HighlyAvailableGraphDatabase slave1 = cluster.getAnySlave(); HighlyAvailableGraphDatabase slave1 = _cluster.AnySlave; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final HighlyAvailableGraphDatabase slave2 = cluster.getAnySlave(slave1); HighlyAvailableGraphDatabase slave2 = _cluster.getAnySlave(slave1); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.CountDownLatch slave1Left = new java.util.concurrent.CountDownLatch(1); System.Threading.CountdownEvent slave1Left = new System.Threading.CountdownEvent(1); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.CountDownLatch slave2Left = new java.util.concurrent.CountDownLatch(1); System.Threading.CountdownEvent slave2Left = new System.Threading.CountdownEvent(1); ClusterClientOf(master).addHeartbeatListener(new HeartbeatListener_AdapterAnonymousInnerClass(this, slave1, slave2, slave1Left, slave2Left)); // fail slave1 and await master to spot the failure ClusterManager.RepairKit slave1RepairKit = _cluster.fail(slave1); assertTrue(slave1Left.await(60, SECONDS)); // fail slave2 and await master to spot the failure ClusterManager.RepairKit slave2RepairKit = _cluster.fail(slave2); assertTrue(slave2Left.await(60, SECONDS)); // master loses quorum and goes to PENDING, cluster is unavailable _cluster.await(masterAvailable().negate()); assertEquals(HighAvailabilityMemberState.PENDING, master.InstanceState); // WHEN: both slaves are repaired, majority restored, quorum can be achieved slave1RepairKit.Repair(); slave2RepairKit.Repair(); // whole cluster looks fine, but slaves have stale value of the epoch if they rejoin the cluster in SLAVE state _cluster.await(masterAvailable()); _cluster.await(masterSeesSlavesAsAvailable(2)); HighlyAvailableGraphDatabase newMaster = _cluster.Master; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final HighlyAvailableGraphDatabase newSlave1 = cluster.getAnySlave(); HighlyAvailableGraphDatabase newSlave1 = _cluster.AnySlave; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final HighlyAvailableGraphDatabase newSlave2 = cluster.getAnySlave(newSlave1); HighlyAvailableGraphDatabase newSlave2 = _cluster.getAnySlave(newSlave1); // now adding another failing listener and wait for the failure due to stale epoch //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.CountDownLatch slave1Unavailable = new java.util.concurrent.CountDownLatch(1); System.Threading.CountdownEvent slave1Unavailable = new System.Threading.CountdownEvent(1); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.CountDownLatch slave2Unavailable = new java.util.concurrent.CountDownLatch(1); System.Threading.CountdownEvent slave2Unavailable = new System.Threading.CountdownEvent(1); ClusterMemberEvents clusterEvents = newMaster.DependencyResolver.resolveDependency(typeof(ClusterMemberEvents)); clusterEvents.AddClusterMemberListener(new ClusterMemberListener_AdapterAnonymousInnerClass(this, newSlave1, newSlave2, slave1Unavailable, slave2Unavailable)); // attempt to perform transactions on both slaves throws, election is triggered AttemptTransactions(newSlave1, newSlave2); // set a timeout in case the instance does not have stale epoch assertTrue(slave1Unavailable.await(60, TimeUnit.SECONDS)); assertTrue(slave2Unavailable.await(60, TimeUnit.SECONDS)); // THEN: done with election, cluster feels good and able to serve transactions _cluster.info("Waiting for cluster to stabilize"); _cluster.await(allSeesAllAsAvailable()); _cluster.info("Assert ok"); assertNotNull(CreateNodeOn(newMaster)); assertNotNull(CreateNodeOn(newSlave1)); assertNotNull(CreateNodeOn(newSlave2)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testMasterSwitchHappensOnKillMinus9() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void TestMasterSwitchHappensOnKillMinus9() { Process proc = null; HighlyAvailableGraphDatabase dbWithId2 = null; HighlyAvailableGraphDatabase dbWithId3 = null; HighlyAvailableGraphDatabase oldMaster = null; int clusterPort1 = PortAuthority.allocatePort(); int clusterPort2 = PortAuthority.allocatePort(); int clusterPort3 = PortAuthority.allocatePort(); int haPort1 = PortAuthority.allocatePort(); int haPort2 = PortAuthority.allocatePort(); int haPort3 = PortAuthority.allocatePort(); try { proc = Run(1, clusterPort1, haPort1, clusterPort1, clusterPort2); dbWithId2 = StartDb(2, Path(2), clusterPort2, haPort2, clusterPort1, clusterPort2); dbWithId3 = StartDb(3, Path(3), clusterPort3, haPort3, clusterPort1, clusterPort2); WaitUntilAllProperlyAvailable(dbWithId2, 1, MASTER, 2, SLAVE, 3, SLAVE); WaitUntilAllProperlyAvailable(dbWithId3, 1, MASTER, 2, SLAVE, 3, SLAVE); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.CountDownLatch newMasterAvailableLatch = new java.util.concurrent.CountDownLatch(1); System.Threading.CountdownEvent newMasterAvailableLatch = new System.Threading.CountdownEvent(1); dbWithId2.DependencyResolver.resolveDependency(typeof(ClusterClient)).addAtomicBroadcastListener(value => { try { object @event = (new AtomicBroadcastSerializer(new ObjectStreamFactory(), new ObjectStreamFactory())).receive(value); if (@event is MemberIsAvailable) { if (HighAvailabilityModeSwitcher.MASTER.Equals((( MemberIsAvailable )@event).Role)) { newMasterAvailableLatch.Signal(); } } } catch (Exception e) { fail(e.ToString()); } }); proc.destroy(); proc = null; assertTrue(newMasterAvailableLatch.await(60, SECONDS)); assertTrue(dbWithId2.Master); assertTrue(!dbWithId3.Master); // Ensure that everyone has marked the killed instance as failed, otherwise it cannot rejoin WaitUntilAllProperlyAvailable(dbWithId2, 1, UNKNOWN, 2, MASTER, 3, SLAVE); WaitUntilAllProperlyAvailable(dbWithId3, 1, UNKNOWN, 2, MASTER, 3, SLAVE); oldMaster = StartDb(1, Path(1), clusterPort1, haPort1, clusterPort1, clusterPort2); long oldMasterNode = CreateNamedNode(oldMaster, "Old master"); assertEquals(oldMasterNode, GetNamedNode(dbWithId2, "Old master")); } finally { if (proc != null) { proc.destroy(); } if (oldMaster != null) { oldMaster.Shutdown(); } if (dbWithId2 != null) { dbWithId2.Shutdown(); } if (dbWithId3 != null) { dbWithId3.Shutdown(); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void losingQuorumAbruptlyShouldMakeAllInstancesPendingAndReadOnly() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void LosingQuorumAbruptlyShouldMakeAllInstancesPendingAndReadOnly() { int clusterSize = 5; // we need 5 to differentiate between all other instances gone and just quorum being gone assumeTrue(TestRunConditions.shouldRunAtClusterSize(clusterSize)); ClusterManager manager = (new ClusterManager.Builder()).withRootDirectory(Dir.cleanDirectory("testcluster")).withCluster(ClusterManager.clusterOfSize(clusterSize)).withSharedConfig(Config()).build(); try { manager.Start(); ClusterManager.ManagedCluster cluster = manager.Cluster; cluster.Await(allSeesAllAsAvailable()); cluster.Await(masterAvailable()); HighlyAvailableGraphDatabase master = cluster.Master; AddSomeData(master); /* * we need 3 failures. We'll end up with the old master and a slave connected. They should both be in * PENDING state, allowing reads but not writes. Repairing just one of the removed instances should * result in a master being elected and all instances being read and writable. * The instances we remove do not need additional verification for their state. Their behaviour is already * known by other tests. */ HighlyAvailableGraphDatabase failed1; ClusterManager.RepairKit rk1; HighlyAvailableGraphDatabase failed2; HighlyAvailableGraphDatabase failed3; HighlyAvailableGraphDatabase remainingSlave; failed1 = cluster.AnySlave; failed2 = cluster.GetAnySlave(failed1); failed3 = cluster.GetAnySlave(failed1, failed2); remainingSlave = cluster.GetAnySlave(failed1, failed2, failed3); System.Threading.CountdownEvent masterTransitionLatch = new System.Threading.CountdownEvent(1); System.Threading.CountdownEvent slaveTransitionLatch = new System.Threading.CountdownEvent(1); SetupForWaitOnSwitchToDetached(master, masterTransitionLatch); SetupForWaitOnSwitchToDetached(remainingSlave, slaveTransitionLatch); rk1 = KillAbruptly(cluster, failed1, failed2, failed3); cluster.Await(memberSeesOtherMemberAsFailed(remainingSlave, failed1)); cluster.Await(memberSeesOtherMemberAsFailed(remainingSlave, failed2)); cluster.Await(memberSeesOtherMemberAsFailed(remainingSlave, failed3)); cluster.Await(memberSeesOtherMemberAsFailed(master, failed1)); cluster.Await(memberSeesOtherMemberAsFailed(master, failed2)); cluster.Await(memberSeesOtherMemberAsFailed(master, failed3)); masterTransitionLatch.await(); slaveTransitionLatch.await(); EnsureInstanceIsReadOnlyInPendingState(master); EnsureInstanceIsReadOnlyInPendingState(remainingSlave); rk1.Repair(); cluster.Await(masterAvailable(failed2, failed3)); cluster.Await(masterSeesSlavesAsAvailable(2)); EnsureInstanceIsWritable(master); EnsureInstanceIsWritable(remainingSlave); EnsureInstanceIsWritable(failed1); } finally { manager.Shutdown(); } }
private static KernelTransaction KernelTransaction(HighlyAvailableGraphDatabase db) { return(Db.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static void assertOnIndexCounts(int expectedIndexUpdates, int expectedIndexSize, int expectedUniqueValues, int expectedSampleSize, org.neo4j.storageengine.api.schema.IndexDescriptor indexDescriptor, HighlyAvailableGraphDatabase db) throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException, org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException private static void AssertOnIndexCounts(int expectedIndexUpdates, int expectedIndexSize, int expectedUniqueValues, int expectedSampleSize, IndexDescriptor indexDescriptor, HighlyAvailableGraphDatabase db) { using ([email protected] tx = Db.DependencyResolver.resolveDependency(typeof(Kernel)).beginTransaction(@explicit, AUTH_DISABLED)) { IndexReference indexReference = tx.SchemaRead().index(indexDescriptor.Schema()); AssertDoubleLongEquals(expectedIndexUpdates, expectedIndexSize, tx.SchemaRead().indexUpdatesAndSize(indexReference, newDoubleLongRegister())); AssertDoubleLongEquals(expectedUniqueValues, expectedSampleSize, tx.SchemaRead().indexSample(indexReference, newDoubleLongRegister())); } }
private static void AssertOnNodeCounts(int expectedTotalNodes, int expectedLabelledNodes, Label label, HighlyAvailableGraphDatabase db) { using (Transaction ignored = Db.beginTx()) { KernelTransaction transaction = KernelTransaction(db); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int labelId = transaction.tokenRead().nodeLabel(label.name()); int labelId = transaction.TokenRead().nodeLabel(label.Name()); assertEquals(expectedTotalNodes, transaction.DataRead().countsForNode(-1)); assertEquals(expectedLabelledNodes, transaction.DataRead().countsForNode(labelId)); } }
private static InstanceId InstanceIdOf(HighlyAvailableGraphDatabase db) { return(ClusterClientOf(db).ServerId); }
private static ClusterClient ClusterClientOf(HighlyAvailableGraphDatabase db) { return(Db.DependencyResolver.resolveDependency(typeof(ClusterClient))); }
public void createEntity(HighlyAvailableGraphDatabase db, string type, string propertyKey, object value, bool constraintCompliant) { Db.createNode(label(type)).setProperty(propertyKey, value); }
public WorkerCommand <object, bool> createConstraint(HighlyAvailableGraphDatabase db, string type, string property) { string query = format("CREATE CONSTRAINT ON ()-[r:`%s`]-() ASSERT exists(r.`%s`)", type, property); return(CreatePropertyExistenceConstraintCommand(db, query)); }
private ClusterManager.RepairKit KillIncrementally(ClusterManager.ManagedCluster cluster, HighlyAvailableGraphDatabase failed1, HighlyAvailableGraphDatabase failed2, HighlyAvailableGraphDatabase failed3) { ClusterManager.RepairKit firstFailure = cluster.Fail(failed1); cluster.Await(instanceEvicted(failed1)); cluster.Fail(failed2); cluster.Await(instanceEvicted(failed2)); cluster.Fail(failed3); cluster.Await(instanceEvicted(failed3)); return(firstFailure); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void concurrentStartupShouldWork() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ConcurrentStartupShouldWork() { // Ensures that the instances don't race to create the test's base directory and only care about their own. TestDirectory.directory("nothingToSeeHereMoveAlong"); int[] clusterPorts = new int[] { PortAuthority.allocatePort(), PortAuthority.allocatePort(), PortAuthority.allocatePort() }; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final String initialHosts = initialHosts(clusterPorts); string initialHosts = initialHosts(clusterPorts); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.CyclicBarrier barrier = new java.util.concurrent.CyclicBarrier(clusterPorts.length); CyclicBarrier barrier = new CyclicBarrier(clusterPorts.Length); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.List<Thread> daThreads = new java.util.ArrayList<>(clusterPorts.length); IList <Thread> daThreads = new List <Thread>(clusterPorts.Length); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final HighlyAvailableGraphDatabase[] dbs = new HighlyAvailableGraphDatabase[clusterPorts.length]; HighlyAvailableGraphDatabase[] dbs = new HighlyAvailableGraphDatabase[clusterPorts.Length]; for (int i = 0; i < clusterPorts.Length; i++) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int finalI = i; int finalI = i; Thread t = new Thread(() => { try { barrier.await(); dbs[finalI] = StartDbAtBase(finalI, initialHosts, clusterPorts[finalI]); } catch (Exception e) when(e is InterruptedException || e is BrokenBarrierException) { throw new Exception(e); } }); daThreads.Add(t); t.Start(); } foreach (Thread daThread in daThreads) { daThread.Join(); } bool masterDone = false; foreach (HighlyAvailableGraphDatabase db in dbs) { if (Db.Master) { if (masterDone) { throw new Exception("Two masters discovered"); } masterDone = true; } using (Transaction tx = Db.beginTx()) { Db.createNode(); tx.Success(); } } assertTrue(masterDone); foreach (HighlyAvailableGraphDatabase db in dbs) { Db.shutdown(); } }
private void EnsureInstanceIsWritable(HighlyAvailableGraphDatabase instance) { tx(instance, retryACoupleOfTimesOn(TRANSIENT_ERRORS), db => Db.createNode().setProperty(_testPropKey, _testPropValue)); }