private void CreateIndex(HighlyAvailableGraphDatabase master, Label label, string property) { using (Transaction transaction = master.BeginTx()) { master.Schema().indexFor(label).on(property).create(); transaction.Success(); } using (Transaction transaction = master.BeginTx()) { master.Schema().awaitIndexesOnline(1, TimeUnit.MINUTES); transaction.Success(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCreateConstraintOnMaster() public virtual void ShouldCreateConstraintOnMaster() { // given ClusterManager.ManagedCluster cluster = ClusterRule.startCluster(); HighlyAvailableGraphDatabase master = cluster.Master; string type = type(0); string key = key(0); // when using (Transaction tx = master.BeginTx()) { CreateConstraint(master, type, key); tx.Success(); } cluster.Sync(); // then foreach (HighlyAvailableGraphDatabase clusterMember in cluster.AllMembers) { using (Transaction tx = clusterMember.BeginTx()) { ConstraintDefinition constraint = GetConstraint(clusterMember, type, key); ValidateLabelOrRelationshipType(constraint, type); assertEquals(key, single(constraint.PropertyKeys)); tx.Success(); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCopyStoreFromMasterIfBranched() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldCopyStoreFromMasterIfBranched() { // GIVEN File dir = _directory.directory(); ClusterManager clusterManager = _life.add(new ClusterManager.Builder(dir) .withCluster(clusterOfSize(2)).build()); ClusterManager.ManagedCluster cluster = clusterManager.Cluster; cluster.Await(allSeesAllAsAvailable()); CreateNode(cluster.Master, "A"); cluster.Sync(); // WHEN HighlyAvailableGraphDatabase slave = cluster.AnySlave; File databaseDir = slave.DatabaseLayout().databaseDirectory(); ClusterManager.RepairKit starter = cluster.Shutdown(slave); HighlyAvailableGraphDatabase master = cluster.Master; CreateNode(master, "B1"); CreateNode(master, "C"); CreateNodeOffline(databaseDir, "B2"); slave = starter.Repair(); // THEN cluster.Await(allSeesAllAsAvailable()); slave.BeginTx().close(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static void createClusterWithNode(org.neo4j.kernel.impl.ha.ClusterManager clusterManager) throws Throwable private static void CreateClusterWithNode(ClusterManager clusterManager) { try { clusterManager.Start(); clusterManager.Cluster.await(allSeesAllAsAvailable()); long nodeId; HighlyAvailableGraphDatabase master = clusterManager.Cluster.Master; using (Transaction tx = master.BeginTx()) { Node node = master.CreateNode(); nodeId = node.Id; node.SetProperty("foo", "bar"); tx.Success(); } HighlyAvailableGraphDatabase slave = clusterManager.Cluster.AnySlave; using (Transaction ignored = slave.BeginTx()) { Node node = slave.GetNodeById(nodeId); assertThat(node.GetProperty("foo").ToString(), CoreMatchers.equalTo("bar")); } } finally { clusterManager.SafeShutdown(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void terminatedTransactionDoesNotForceUpdatePulling() public virtual void TerminatedTransactionDoesNotForceUpdatePulling() { int testTxsOnMaster = 42; ClusterManager.ManagedCluster cluster = ClusterRule.withSharedSetting(HaSettings.pull_interval, "0s").withSharedSetting(HaSettings.tx_push_factor, "0").startCluster(); HighlyAvailableGraphDatabase master = cluster.Master; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.ha.HighlyAvailableGraphDatabase slave = cluster.getAnySlave(); HighlyAvailableGraphDatabase slave = cluster.AnySlave; CreateNodeOn(master); cluster.Sync(); long lastClosedTxIdOnMaster = LastClosedTxIdOn(master); long lastClosedTxIdOnSlave = LastClosedTxIdOn(slave); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.CountDownLatch slaveTxStarted = new java.util.concurrent.CountDownLatch(1); System.Threading.CountdownEvent slaveTxStarted = new System.Threading.CountdownEvent(1); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.CountDownLatch slaveShouldCommit = new java.util.concurrent.CountDownLatch(1); System.Threading.CountdownEvent slaveShouldCommit = new System.Threading.CountdownEvent(1); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicReference<org.neo4j.graphdb.Transaction> slaveTx = new java.util.concurrent.atomic.AtomicReference<>(); AtomicReference <Transaction> slaveTx = new AtomicReference <Transaction>(); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.concurrent.Future<?> slaveCommit = java.util.concurrent.Executors.newSingleThreadExecutor().submit(() -> Future <object> slaveCommit = Executors.newSingleThreadExecutor().submit(() => { using (Transaction tx = slave.BeginTx()) { slaveTx.set(tx); slaveTxStarted.Signal(); Await(slaveShouldCommit); tx.success(); } }); Await(slaveTxStarted); CreateNodesOn(master, testTxsOnMaster); assertNotNull(slaveTx.get()); slaveTx.get().terminate(); slaveShouldCommit.Signal(); try { slaveCommit.get(); fail("Exception expected"); } catch (Exception e) { assertThat(e, instanceOf(typeof(ExecutionException))); assertThat(e.InnerException, instanceOf(typeof(TransientTransactionFailureException))); } assertEquals(lastClosedTxIdOnMaster + testTxsOnMaster, LastClosedTxIdOn(master)); assertEquals(lastClosedTxIdOnSlave, LastClosedTxIdOn(slave)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void newSlaveJoiningClusterShouldNotAcceptOperationsUntilConstraintIsOnline() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void NewSlaveJoiningClusterShouldNotAcceptOperationsUntilConstraintIsOnline() { // Given ClusterManager.ManagedCluster cluster = ClusterRule.startCluster(); string type = type(4); string key = key(4); HighlyAvailableGraphDatabase master = cluster.Master; HighlyAvailableGraphDatabase slave = cluster.AnySlave; File slaveStoreDirectory = cluster.GetDatabaseDir(slave); // Crash the slave ClusterManager.RepairKit shutdownSlave = cluster.Shutdown(slave); deleteRecursively(slaveStoreDirectory); using (Transaction tx = master.BeginTx()) { CreateConstraint(master, type, key); tx.Success(); } // When slave = shutdownSlave.Repair(); // Then using (Transaction ignored = slave.BeginTx()) { ConstraintDefinition definition = GetConstraint(slave, type, key); assertThat(definition, instanceOf(ConstraintDefinitionClass())); assertThat(single(definition.PropertyKeys), equalTo(key)); ValidateLabelOrRelationshipType(definition, type); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void givenClusterWithReadOnlySlaveWhenChangePropertyOnSlaveThenThrowException() public virtual void GivenClusterWithReadOnlySlaveWhenChangePropertyOnSlaveThenThrowException() { // Given ManagedCluster cluster = ClusterRule.startCluster(); Node node; HighlyAvailableGraphDatabase master = cluster.Master; using (Transaction tx = master.BeginTx()) { node = master.CreateNode(); tx.Success(); } // When HighlyAvailableGraphDatabase readOnlySlave = cluster.GetMemberByServerId(new InstanceId(2)); try { using (Transaction tx = readOnlySlave.BeginTx()) { Node slaveNode = readOnlySlave.GetNodeById(node.Id); // Then slaveNode.SetProperty("foo", "bar"); tx.Success(); fail("Should have thrown exception"); } } catch (WriteOperationsNotAllowedException) { // Ok! } }
private void CreateSingleTestLabeledNode(HighlyAvailableGraphDatabase master) { using (Transaction tx = master.BeginTx()) { master.CreateNode(_testLabel); tx.Success(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldRemoveConstraints() public virtual void ShouldRemoveConstraints() { // given ClusterManager.ManagedCluster cluster = ClusterRule.startCluster(); HighlyAvailableGraphDatabase master = cluster.Master; string type = type(2); string key = key(2); long constraintCountBefore; long indexCountBefore; using (Transaction tx = master.BeginTx()) { constraintCountBefore = count(master.Schema().Constraints); indexCountBefore = count(master.Schema().Indexes); CreateConstraint(master, type, key); tx.Success(); } cluster.Sync(); // and given I have some data for the constraint CreateEntityInTx(cluster.AnySlave, type, key, "Foo"); // when using (Transaction tx = master.BeginTx()) { GetConstraint(master, type, key).drop(); tx.Success(); } cluster.Sync(); // then the constraint should be gone, and not be enforced anymore foreach (HighlyAvailableGraphDatabase clusterMember in cluster.AllMembers) { using (Transaction tx = clusterMember.BeginTx()) { assertNull(GetConstraint(clusterMember, type, key)); assertNull(GetIndex(clusterMember, type, key)); CreateConstraintViolation(clusterMember, type, key, "Foo"); tx.Success(); } } }
private void CreateLabeledNodeOnMaster(ClusterManager.ManagedCluster cluster, Label label) { HighlyAvailableGraphDatabase master = cluster.Master; using (Transaction transaction = master.BeginTx()) { Node masterNode = master.CreateNode(); masterNode.AddLabel(label); transaction.Success(); } }
private void CheckLabeledNodeExistenceOnSlave(ClusterManager.ManagedCluster cluster, Label label) { HighlyAvailableGraphDatabase slave = cluster.AnySlave; using (Transaction transaction = slave.BeginTx()) { ResourceIterator <Node> slaveNodes = slave.FindNodes(label); assertEquals(1, Iterators.asList(slaveNodes).Count); transaction.Success(); } }
private Node CreateNodeOnMaster(Label testLabel, HighlyAvailableGraphDatabase master) { Node node; using (Transaction transaction = master.BeginTx()) { node = master.CreateNode(testLabel); transaction.Success(); } return(node); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void onlineSchemaIndicesOnMasterShouldBeBroughtOnlineOnSlavesAfterStoreCopy() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void OnlineSchemaIndicesOnMasterShouldBeBroughtOnlineOnSlavesAfterStoreCopy() { /* * The master has an index that is online. * Then a slave comes online and contacts the master to get copies of the store files. * Because the index is online, it should be copied, and the slave should successfully bring the index online. */ // GIVEN ControlledGraphDatabaseFactory dbFactory = new ControlledGraphDatabaseFactory(); ClusterManager.ManagedCluster cluster = ClusterRule.withDbFactory(dbFactory).withSharedSetting(GraphDatabaseSettings.default_schema_provider, _controlledProviderDescriptor.name()).startCluster(); cluster.Await(allSeesAllAsAvailable(), 120); HighlyAvailableGraphDatabase slave = cluster.AnySlave; // All slaves in the cluster, except the one I care about, proceed as normal ProceedAsNormalWithIndexPopulationOnAllSlavesExcept(dbFactory, cluster, slave); // A slave is offline, and has no store files ClusterManager.RepairKit slaveDown = BringSlaveOfflineAndRemoveStoreFiles(cluster, slave); // And I create an index on the master, and wait for population to start HighlyAvailableGraphDatabase master = cluster.Master; IDictionary <object, Node> data = CreateSomeData(master); CreateIndex(master); dbFactory.AwaitPopulationStarted(master); // And the population finishes dbFactory.TriggerFinish(master); IndexDefinition index; using (Transaction tx = master.BeginTx()) { index = single(master.Schema().Indexes); AwaitIndexOnline(index, master, data); tx.Success(); } // WHEN the slave comes online after population has finished on the master slave = slaveDown.Repair(); cluster.Await(allSeesAllAsAvailable()); cluster.Sync(); // THEN the index should work on the slave dbFactory.TriggerFinish(slave); using (Transaction tx = slave.BeginTx()) { AwaitIndexOnline(index, slave, data); tx.Success(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void givenClusterWhenShutdownMasterThenCannotStartTransactionOnSlave() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void GivenClusterWhenShutdownMasterThenCannotStartTransactionOnSlave() { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.ha.HighlyAvailableGraphDatabase master = cluster.getMaster(); HighlyAvailableGraphDatabase master = _cluster.Master; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.ha.HighlyAvailableGraphDatabase slave = cluster.getAnySlave(); HighlyAvailableGraphDatabase slave = _cluster.AnySlave; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final long nodeId; long nodeId; using (Transaction tx = master.BeginTx()) { nodeId = master.CreateNode().Id; tx.Success(); } _cluster.sync(); // When //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.FutureTask<bool> result = new java.util.concurrent.FutureTask<>(() -> FutureTask <bool> result = new FutureTask <bool>(() => { try { using (Transaction tx = slave.BeginTx()) { tx.AcquireWriteLock(slave.GetNodeById(nodeId)); } } catch (Exception e) { return(contains(e, typeof(TransactionFailureException))); } // Fail otherwise return(false); }); DatabaseAvailabilityGuard masterGuard = master.DependencyResolver.resolveDependency(typeof(DatabaseAvailabilityGuard)); masterGuard.AddListener(new UnavailabilityListener(result)); master.Shutdown(); // Then assertThat(result.get(), equalTo(true)); }
private long CreateNode(HighlyAvailableGraphDatabase author, string key, object value, bool index) { using (Transaction tx = author.BeginTx()) { Node node = author.CreateNode(); node.SetProperty(key, value); if (index) { author.Index().forNodes(key).add(node, key, value); } tx.Success(); return(node.Id); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void oneOrTheOtherShouldDeadlock() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void OneOrTheOtherShouldDeadlock() { AtomicInteger deadlockCount = new AtomicInteger(); HighlyAvailableGraphDatabase master = _cluster.Master; Node masterA = CreateNodeOnMaster(_testLabel, master); Node masterB = CreateNodeOnMaster(_testLabel, master); HighlyAvailableGraphDatabase slave = _cluster.AnySlave; using (Transaction transaction = slave.BeginTx()) { Node slaveA = slave.GetNodeById(masterA.Id); Node slaveB = slave.GetNodeById(masterB.Id); System.Threading.CountdownEvent latch = new System.Threading.CountdownEvent(1); transaction.AcquireWriteLock(slaveB); Thread masterTx = new Thread(() => { try { using (Transaction tx = master.BeginTx()) { tx.acquireWriteLock(masterA); latch.Signal(); tx.acquireWriteLock(masterB); } } catch (DeadlockDetectedException) { deadlockCount.incrementAndGet(); } }); masterTx.Start(); latch.await(); try { transaction.AcquireWriteLock(slaveA); } catch (DeadlockDetectedException) { deadlockCount.incrementAndGet(); } masterTx.Join(); } assertEquals(1, deadlockCount.get()); }
private static int NodesHavingProperty(HighlyAvailableGraphDatabase slave, string key, string value) { using (Transaction tx = slave.BeginTx()) { int count = 0; foreach (Node node in slave.AllNodes) { if (value.Equals(node.GetProperty(key, null))) { count++; } } tx.Success(); return(count); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void slaveMustConnectLockManagerToNewMasterAfterTwoOtherClusterMembersRoleSwitch() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void SlaveMustConnectLockManagerToNewMasterAfterTwoOtherClusterMembersRoleSwitch() { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.ha.HighlyAvailableGraphDatabase initialMaster = cluster.getMaster(); HighlyAvailableGraphDatabase initialMaster = _cluster.Master; HighlyAvailableGraphDatabase firstSlave = _cluster.AnySlave; HighlyAvailableGraphDatabase secondSlave = _cluster.getAnySlave(firstSlave); // Run a transaction on the slaves, to make sure that a master connection has been initialised in all // internal pools. using (Transaction tx = firstSlave.BeginTx()) { firstSlave.CreateNode(); tx.Success(); } using (Transaction tx = secondSlave.BeginTx()) { secondSlave.CreateNode(); tx.Success(); } _cluster.sync(); ClusterManager.RepairKit failedMaster = _cluster.fail(initialMaster); _cluster.await(ClusterManager.masterAvailable(initialMaster)); failedMaster.Repair(); _cluster.await(ClusterManager.masterAvailable(initialMaster)); _cluster.await(ClusterManager.allSeesAllAsAvailable()); // The cluster has now switched the master role to one of the slaves. // The slave that didn't switch, should still have done the work to reestablish the connection to the new // master. HighlyAvailableGraphDatabase slave = _cluster.getAnySlave(initialMaster); using (Transaction tx = slave.BeginTx()) { slave.CreateNode(); tx.Success(); } // We assert that the transaction above does not throw any exceptions, and that we have now created 3 nodes. HighlyAvailableGraphDatabase master = _cluster.Master; using (Transaction tx = master.BeginTx()) { assertThat(Iterables.count(master.AllNodes), @is(3L)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void indexPopulationJobsShouldContinueThroughRoleSwitch() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void IndexPopulationJobsShouldContinueThroughRoleSwitch() { // GIVEN a cluster of 3 ControlledGraphDatabaseFactory dbFactory = new ControlledGraphDatabaseFactory(); ClusterManager.ManagedCluster cluster = ClusterRule.withDbFactory(dbFactory).withSharedSetting(GraphDatabaseSettings.default_schema_provider, _controlledProviderDescriptor.name()).startCluster(); HighlyAvailableGraphDatabase firstMaster = cluster.Master; // where the master gets some data created as well as an index IDictionary <object, Node> data = CreateSomeData(firstMaster); CreateIndex(firstMaster); //dbFactory.awaitPopulationStarted( firstMaster ); dbFactory.TriggerFinish(firstMaster); // Pick a slave, pull the data and the index HighlyAvailableGraphDatabase aSlave = cluster.AnySlave; aSlave.DependencyResolver.resolveDependency(typeof(UpdatePuller)).pullUpdates(); // and await the index population to start. It will actually block as long as we want it to dbFactory.AwaitPopulationStarted(aSlave); // WHEN we shut down the master cluster.Shutdown(firstMaster); dbFactory.TriggerFinish(aSlave); cluster.Await(masterAvailable(firstMaster)); // get the new master, which should be the slave we pulled from above HighlyAvailableGraphDatabase newMaster = cluster.Master; // THEN assertEquals("Unexpected new master", aSlave, newMaster); using (Transaction tx = newMaster.BeginTx()) { IndexDefinition index = single(newMaster.Schema().Indexes); AwaitIndexOnline(index, newMaster, data); tx.Success(); } // FINALLY: let all db's finish foreach (HighlyAvailableGraphDatabase db in cluster.AllMembers) { dbFactory.TriggerFinish(db); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void givenClusterWhenMasterGoesDownAndTxIsRunningThenDontWaitToSwitch() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void GivenClusterWhenMasterGoesDownAndTxIsRunningThenDontWaitToSwitch() { ClusterManager clusterManager = (new ClusterManager.Builder(TestDirectory.directory(TestName.MethodName))).withCluster(ClusterManager.clusterOfSize(3)).build(); try { clusterManager.Start(); ClusterManager.ManagedCluster cluster = clusterManager.Cluster; cluster.Await(allSeesAllAsAvailable()); HighlyAvailableGraphDatabase slave = cluster.AnySlave; Transaction tx = slave.BeginTx(); // Do a little write operation so that all "write" aspects of this tx is initializes properly slave.CreateNode(); // Shut down master while we're keeping this transaction open cluster.Shutdown(cluster.Master); cluster.Await(masterAvailable()); cluster.Await(masterSeesSlavesAsAvailable(1)); // Ending up here means that we didn't wait for this transaction to complete tx.Success(); try { tx.Close(); fail("Exception expected"); } catch (Exception e) { assertThat(e, instanceOf(typeof(TransientTransactionFailureException))); Exception rootCause = rootCause(e); assertThat(rootCause, instanceOf(typeof(TransactionTerminatedException))); assertThat((( TransactionTerminatedException )rootCause).status(), Matchers.equalTo(Org.Neo4j.Kernel.Api.Exceptions.Status_General.DatabaseUnavailable)); } } finally { clusterManager.Stop(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void givenClusterWithReadOnlySlaveWhenWriteTxOnSlaveThenCommitFails() public virtual void GivenClusterWithReadOnlySlaveWhenWriteTxOnSlaveThenCommitFails() { // When ManagedCluster cluster = ClusterRule.startCluster(); HighlyAvailableGraphDatabase readOnlySlave = cluster.GetMemberByServerId(new InstanceId(2)); try { using (Transaction tx = readOnlySlave.BeginTx()) { readOnlySlave.CreateNode(); tx.Success(); fail("Should have thrown exception"); } } catch (WriteOperationsNotAllowedException) { // Then } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void doNotAcquireSharedLocksDuringSlaveReadTx() public virtual void DoNotAcquireSharedLocksDuringSlaveReadTx() { HighlyAvailableGraphDatabase anySlave = _managedCluster.AnySlave; HighlyAvailableGraphDatabase master = _managedCluster.Master; using (Transaction tx = master.BeginTx()) { Node node = master.CreateNode(_testLabel); node.SetProperty(TEST_PROPERTY, "a"); tx.Success(); } CreateIndex(master, _testLabel, TEST_PROPERTY); using (Transaction transaction = anySlave.BeginTx()) { assertEquals(1, Iterables.count(anySlave.Schema().getIndexes(_testLabel))); transaction.Success(); } assertTrue(GetRequestedLocks(anySlave).Count == 0); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotBePossibleToCreateConstraintsDirectlyOnSlaves() public virtual void ShouldNotBePossibleToCreateConstraintsDirectlyOnSlaves() { // given ClusterManager.ManagedCluster cluster = ClusterRule.startCluster(); HighlyAvailableGraphDatabase slave = cluster.AnySlave; string type = type(1); string key = key(1); // when try { using (Transaction ignored = slave.BeginTx()) { CreateConstraint(slave, type, key); fail("We expected to not be able to create a constraint on a slave in a cluster."); } } catch (QueryExecutionException e) { assertThat(Exceptions.rootCause(e), instanceOf(typeof(InvalidTransactionTypeKernelException))); } }
//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 Runnable readContestant(final ReadContestantActions action, final long entityId, final org.neo4j.kernel.ha.HighlyAvailableGraphDatabase slave, final java.util.concurrent.atomic.AtomicBoolean end) private ThreadStart ReadContestant(ReadContestantActions action, long entityId, HighlyAvailableGraphDatabase slave, AtomicBoolean end) { return(() => { while (!end.get()) { try { using (Transaction tx = slave.BeginTx()) { for (int i = 0; i < 10; i++) { action.VerifyProperties(slave, entityId); } tx.success(); } } catch (Exception ignored) when(ignored is TransactionTerminatedException || ignored is TransientTransactionFailureException) { } } }); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void aPendingMemberShouldBeAbleToServeReads() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void APendingMemberShouldBeAbleToServeReads() { // given CreateNodeOnMaster(_testLabel, _cluster.Master); _cluster.sync(); HighlyAvailableGraphDatabase slave = _cluster.AnySlave; _cluster.fail(slave, Enum.GetValues(typeof(ClusterManager.NetworkFlag))); _cluster.await(instanceEvicted(slave)); assertEquals(PENDING, slave.InstanceState); // when for (int i = 0; i < 10; i++) { try { using (Transaction tx = slave.BeginTx()) { Node single = Iterables.single(slave.AllNodes); Label label = Iterables.single(single.Labels); assertEquals(_testLabel, label); tx.Success(); break; } } catch (TransactionTerminatedException) { // Race between going to pending and reading, try again in a little while Thread.Sleep(1_000); } } // then no exceptions thrown }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void givenClusterWithReadOnlySlaveWhenAddNewRelTypeOnSlaveThenThrowException() public virtual void GivenClusterWithReadOnlySlaveWhenAddNewRelTypeOnSlaveThenThrowException() { // Given ManagedCluster cluster = ClusterRule.startCluster(); Node node; Node node2; HighlyAvailableGraphDatabase master = cluster.Master; using (Transaction tx = master.BeginTx()) { node = master.CreateNode(); node2 = master.CreateNode(); tx.Success(); } // When HighlyAvailableGraphDatabase readOnlySlave = cluster.GetMemberByServerId(new InstanceId(2)); try { using (Transaction tx = readOnlySlave.BeginTx()) { Node slaveNode = readOnlySlave.GetNodeById(node.Id); Node slaveNode2 = readOnlySlave.GetNodeById(node2.Id); // Then slaveNode.CreateRelationshipTo(slaveNode2, RelationshipType.withName("KNOWS")); tx.Success(); fail("Should have thrown exception"); } } catch (WriteOperationsNotAllowedException) { // Ok! } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void givenClusterWithReadOnlySlaveWhenCreatingNodeOnMasterThenSlaveShouldBeAbleToPullUpdates() public virtual void GivenClusterWithReadOnlySlaveWhenCreatingNodeOnMasterThenSlaveShouldBeAbleToPullUpdates() { ManagedCluster cluster = ClusterRule.startCluster(); HighlyAvailableGraphDatabase master = cluster.Master; Label label = Label.label("label"); using (Transaction tx = master.BeginTx()) { master.CreateNode(label); tx.Success(); } IEnumerable <HighlyAvailableGraphDatabase> allMembers = cluster.AllMembers; foreach (HighlyAvailableGraphDatabase member in allMembers) { using (Transaction tx = member.BeginTx()) { long count = count(member.FindNodes(label)); tx.Success(); assertEquals(1, count); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void populatingSchemaIndicesOnMasterShouldBeBroughtOnlineOnSlavesAfterStoreCopy() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void PopulatingSchemaIndicesOnMasterShouldBeBroughtOnlineOnSlavesAfterStoreCopy() { /* * The master has an index that is currently populating. * Then a slave comes online and contacts the master to get copies of the store files. * Because the index is still populating, it won't be copied. Instead the slave will build its own. * We want to observe that the slave builds an index that eventually comes online. */ // GIVEN ControlledGraphDatabaseFactory dbFactory = new ControlledGraphDatabaseFactory(_isMaster); ClusterManager.ManagedCluster cluster = ClusterRule.withDbFactory(dbFactory).withSharedSetting(GraphDatabaseSettings.default_schema_provider, NativeLuceneFusionIndexProviderFactory20.DESCRIPTOR.name()).startCluster(); try { cluster.Await(allSeesAllAsAvailable()); HighlyAvailableGraphDatabase slave = cluster.AnySlave; // A slave is offline, and has no store files ClusterManager.RepairKit slaveDown = BringSlaveOfflineAndRemoveStoreFiles(cluster, slave); // And I create an index on the master, and wait for population to start HighlyAvailableGraphDatabase master = cluster.Master; IDictionary <object, Node> data = CreateSomeData(master); CreateIndex(master); dbFactory.AwaitPopulationStarted(master); // WHEN the slave comes online before population has finished on the master slave = slaveDown.Repair(); cluster.Await(allSeesAllAsAvailable(), 180); cluster.Sync(); // THEN, population should finish successfully on both master and slave dbFactory.TriggerFinish(master); // Check master IndexDefinition index; using (Transaction tx = master.BeginTx()) { index = single(master.Schema().Indexes); AwaitIndexOnline(index, master, data); tx.Success(); } // Check slave using (Transaction tx = slave.BeginTx()) { AwaitIndexOnline(index, slave, data); tx.Success(); } } finally { foreach (HighlyAvailableGraphDatabase db in cluster.AllMembers) { dbFactory.TriggerFinish(db); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void makeSureSlaveCanJoinEvenIfTooFarBackComparedToMaster() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void MakeSureSlaveCanJoinEvenIfTooFarBackComparedToMaster() { string key = "foo"; string value = "bar"; HighlyAvailableGraphDatabase master = null; HighlyAvailableGraphDatabase slave = null; File masterDir = TestDirectory.databaseDir("master"); File slaveDir = TestDirectory.databaseDir("slave"); try { int masterClusterPort = PortAuthority.allocatePort(); int masterHaPort = PortAuthority.allocatePort(); master = Start(masterDir, 0, stringMap(keep_logical_logs.name(), "1 txs", ClusterSettings.initial_hosts.name(), "127.0.0.1:" + masterClusterPort), masterClusterPort, masterHaPort); CreateNode(master, "something", "unimportant"); CheckPoint(master); // Need to start and shutdown the slave so when we start it up later it verifies instead of copying int slaveClusterPort = PortAuthority.allocatePort(); int slaveHaPort = PortAuthority.allocatePort(); slave = Start(slaveDir, 1, stringMap(ClusterSettings.initial_hosts.name(), "127.0.0.1:" + masterClusterPort), slaveClusterPort, slaveHaPort); slave.Shutdown(); CreateNode(master, key, value); CheckPoint(master); // Rotating, moving the above transactions away so they are removed on shutdown. RotateLog(master); /* * We need to shutdown - rotating is not enough. The problem is that log positions are cached and they * are not removed from the cache until we run into the cache limit. This means that the information * contained in the log can actually be available even if the log is removed. So, to trigger the case * of the master information missing from the master we need to also flush the log entry cache - hence, * restart. */ master.Shutdown(); master = Start(masterDir, 0, stringMap(keep_logical_logs.name(), "1 txs", ClusterSettings.initial_hosts.name(), "127.0.0.1:" + masterClusterPort), masterClusterPort, masterHaPort); /* * The new log on master needs to have at least one transaction, so here we go. */ int importantNodeCount = 10; for (int i = 0; i < importantNodeCount; i++) { CreateNode(master, key, value); CheckPoint(master); RotateLog(master); } CheckPoint(master); slave = Start(slaveDir, 1, stringMap(ClusterSettings.initial_hosts.name(), "127.0.0.1:" + masterClusterPort), slaveClusterPort, slaveHaPort); slave.DependencyResolver.resolveDependency(typeof(UpdatePuller)).pullUpdates(); using (Transaction ignore = slave.BeginTx()) { assertEquals("store contents differ", importantNodeCount + 1, NodesHavingProperty(slave, key, value)); } } finally { if (slave != null) { slave.Shutdown(); } if (master != null) { master.Shutdown(); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPullUpdatesOnStartupNoMatterWhat() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldPullUpdatesOnStartupNoMatterWhat() { HighlyAvailableGraphDatabase slave = null; HighlyAvailableGraphDatabase master = null; try { File testRootDir = ClusterRule.cleanDirectory("shouldPullUpdatesOnStartupNoMatterWhat"); File masterDir = ClusterRule.TestDirectory.databaseDir("master"); int masterClusterPort = PortAuthority.allocatePort(); master = ( HighlyAvailableGraphDatabase )(new TestHighlyAvailableGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(masterDir).setConfig(ClusterSettings.server_id, "1").setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + masterClusterPort).setConfig(ClusterSettings.initial_hosts, "localhost:" + masterClusterPort).setConfig(HaSettings.ha_server, "127.0.0.1:" + PortAuthority.allocatePort()).setConfig(OnlineBackupSettings.online_backup_enabled, Settings.FALSE).newGraphDatabase(); // Copy the store, then shutdown, so update pulling later makes sense File slaveDir = ClusterRule.TestDirectory.databaseDir("slave"); slave = ( HighlyAvailableGraphDatabase )(new TestHighlyAvailableGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(slaveDir).setConfig(ClusterSettings.server_id, "2").setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + PortAuthority.allocatePort()).setConfig(ClusterSettings.initial_hosts, "localhost:" + masterClusterPort).setConfig(HaSettings.ha_server, "127.0.0.1:" + PortAuthority.allocatePort()).setConfig(OnlineBackupSettings.online_backup_enabled, Settings.FALSE).newGraphDatabase(); // Required to block until the slave has left for sure //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.CountDownLatch slaveLeftLatch = new java.util.concurrent.CountDownLatch(1); System.Threading.CountdownEvent slaveLeftLatch = new System.Threading.CountdownEvent(1); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.cluster.client.ClusterClient masterClusterClient = master.getDependencyResolver().resolveDependency(org.neo4j.cluster.client.ClusterClient.class); ClusterClient masterClusterClient = master.DependencyResolver.resolveDependency(typeof(ClusterClient)); masterClusterClient.AddClusterListener(new ClusterListener_AdapterAnonymousInnerClass(this, slaveLeftLatch, masterClusterClient)); master.DependencyResolver.resolveDependency(typeof(LogService)).getInternalLog(this.GetType()).info("SHUTTING DOWN SLAVE"); slave.Shutdown(); slave = null; // Make sure that the slave has left, because shutdown() may return before the master knows assertTrue("Timeout waiting for slave to leave", slaveLeftLatch.await(60, TimeUnit.SECONDS)); long nodeId; using (Transaction tx = master.BeginTx()) { Node node = master.CreateNode(); node.SetProperty("from", "master"); nodeId = node.Id; tx.Success(); } // Store is already in place, should pull updates slave = ( HighlyAvailableGraphDatabase )(new TestHighlyAvailableGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(slaveDir).setConfig(ClusterSettings.server_id, "2").setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + PortAuthority.allocatePort()).setConfig(ClusterSettings.initial_hosts, "localhost:" + masterClusterPort).setConfig(HaSettings.ha_server, "127.0.0.1:" + PortAuthority.allocatePort()).setConfig(HaSettings.pull_interval, "0").setConfig(OnlineBackupSettings.online_backup_enabled, Settings.FALSE).newGraphDatabase(); slave.BeginTx().close(); // Make sure switch to slave completes and so does the update pulling on startup using (Transaction tx = slave.BeginTx()) { assertEquals("master", slave.GetNodeById(nodeId).getProperty("from")); tx.Success(); } } finally { if (slave != null) { slave.Shutdown(); } if (master != null) { master.Shutdown(); } } }