//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testBasicPropagationFromSlaveToMaster() public virtual void TestBasicPropagationFromSlaveToMaster() { // given ClusterManager.ManagedCluster cluster = ClusterRule.startCluster(); HighlyAvailableGraphDatabase master = cluster.Master; HighlyAvailableGraphDatabase slave = cluster.AnySlave; long nodeId; // a node with a property using (Transaction tx = master.BeginTx()) { Node node = master.CreateNode(); nodeId = node.Id; node.SetProperty("foo", "bar"); tx.Success(); } cluster.Sync(); // when // the slave does a change using (Transaction tx = slave.BeginTx()) { slave.GetNodeById(nodeId).setProperty("foo", "bar2"); tx.Success(); } // then // the master must pick up the change using (Transaction tx = master.BeginTx()) { assertEquals("bar2", master.GetNodeById(nodeId).getProperty("foo")); tx.Success(); } }
/// <summary> /// The problem would manifest even if the transaction was performed on the Master, it would then occur when the /// Slave pulls updates and tries to apply the transaction. The reason for the test to run transactions against the /// Slave is because it makes guarantees for when the master has to apply the transaction. /// </summary> //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldDeleteRecords() public virtual void ShouldDeleteRecords() { // given ManagedCluster cluster = ClusterRule.startCluster(); HighlyAvailableGraphDatabase master = cluster.Master; HighlyAvailableGraphDatabase slave = cluster.AnySlave; Relationship rel; using (Transaction tx = slave.BeginTx()) { rel = slave.CreateNode().createRelationshipTo(slave.CreateNode(), withName("FOO")); tx.Success(); } using (Transaction transaction = master.BeginTx()) { assertNotNull(master.GetRelationshipById(rel.Id)); } // when using (Transaction tx = slave.BeginTx()) { rel.Delete(); tx.Success(); } // then - there should have been no exceptions slave.Shutdown(); master.Shutdown(); }
/// <summary> /// Inserts a bunch of new nodes with the label and property key currently set in the fields in this class, where /// running this method twice will insert nodes with duplicate property values, assuming property key or label has /// not changed. /// </summary> //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,int> performInserts(final HighlyAvailableGraphDatabase slave, final boolean constraintCompliant) private WorkerCommand <object, int> PerformInserts(HighlyAvailableGraphDatabase slave, bool constraintCompliant) { return(state => { int i = 0; try { for ( ; i < 100; i++) { using (Transaction tx = slave.BeginTx()) { ConstraintOps.createEntity(slave, _labelOrRelType, _property, ValueGenerator.apply(i), constraintCompliant); tx.success(); } } } catch (Exception e) when(e is TransactionFailureException || e is TransientTransactionFailureException || e is ComException || e is ConstraintViolationException) { // TransactionFailureException and TransientTransactionFailureException // Swallowed on purpose, we except it to fail sometimes due to either // - constraint violation on master // - concurrent schema operation on master // ConstraintViolationException // Constraint violation detected on slave while building transaction // ComException // Happens sometimes, cause: // - The lock session requested to start is already in use. // Please retry your request in a few seconds. } return i; }); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void slaveShouldMoveToPendingAndThenRecoverIfMasterDiesAndThenRecovers() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void SlaveShouldMoveToPendingAndThenRecoverIfMasterDiesAndThenRecovers() { HighlyAvailableGraphDatabase master = _cluster.Master; HighlyAvailableGraphDatabase theSlave = _cluster.AnySlave; string propertyName = "prop"; string propertyValue = "value1"; long slaveNodeId; ClusterManager.RepairKit repairKit = _cluster.fail(master); _cluster.await(memberSeesOtherMemberAsFailed(theSlave, master)); assertEquals(HighAvailabilityMemberState.PENDING, theSlave.InstanceState); repairKit.Repair(); _cluster.await(allSeesAllAsAvailable()); using (Transaction tx = theSlave.BeginTx()) { Node node = theSlave.CreateNode(); slaveNodeId = node.Id; node.SetProperty(propertyName, propertyValue); tx.Success(); } using (Transaction tx = master.BeginTx()) { assertEquals(propertyValue, master.GetNodeById(slaveNodeId).getProperty(propertyName)); tx.Success(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testBasicPropagationFromMasterToSlave() public virtual void TestBasicPropagationFromMasterToSlave() { // given ClusterManager.ManagedCluster cluster = ClusterRule.startCluster(); long nodeId = 4; HighlyAvailableGraphDatabase master = cluster.Master; using (Transaction tx = master.BeginTx()) { Node node = master.CreateNode(); node.SetProperty("Hello", "World"); nodeId = node.Id; tx.Success(); } cluster.Sync(); // No need to wait, the push factor is 2 HighlyAvailableGraphDatabase slave1 = cluster.AnySlave; CheckNodeOnSlave(nodeId, slave1); HighlyAvailableGraphDatabase slave2 = cluster.GetAnySlave(slave1); CheckNodeOnSlave(nodeId, slave2); }
private void AddSomeData(HighlyAvailableGraphDatabase instance) { using (Transaction tx = instance.BeginTx()) { Node testNode = instance.CreateNode(); _testNodeId = testNode.Id; testNode.SetProperty(_testPropKey, _testPropValue); tx.Success(); } }
private void CheckNodeOnSlave(long nodeId, HighlyAvailableGraphDatabase slave2) { using (Transaction tx = slave2.BeginTx()) { string value = slave2.GetNodeById(nodeId).getProperty("Hello").ToString(); Logger.Logger.info("Hello=" + value); assertEquals("World", value); tx.Success(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void masterShouldRemainAvailableIfTheSlaveDiesAndRecovers() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void MasterShouldRemainAvailableIfTheSlaveDiesAndRecovers() { HighlyAvailableGraphDatabase master = _cluster.Master; HighlyAvailableGraphDatabase theSlave = _cluster.AnySlave; string propertyName = "prop"; string propertyValue1 = "value1"; string propertyValue2 = "value2"; long masterNodeId; long slaveNodeId; ClusterManager.RepairKit repairKit = _cluster.fail(theSlave); _cluster.await(memberSeesOtherMemberAsFailed(master, theSlave)); using (Transaction tx = master.BeginTx()) { Node node = master.CreateNode(); node.SetProperty(propertyName, propertyValue1); masterNodeId = node.Id; tx.Success(); } repairKit.Repair(); _cluster.await(allSeesAllAsAvailable()); using (Transaction tx = theSlave.BeginTx()) { Node node = theSlave.CreateNode(); node.SetProperty(propertyName, propertyValue2); assertEquals(propertyValue1, theSlave.GetNodeById(masterNodeId).getProperty(propertyName)); slaveNodeId = node.Id; tx.Success(); } using (Transaction tx = master.BeginTx()) { assertEquals(propertyValue2, master.GetNodeById(slaveNodeId).getProperty(propertyName)); tx.Success(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testConflictingIdDoesNotSilentlyFail() public virtual void TestConflictingIdDoesNotSilentlyFail() { HighlyAvailableGraphDatabase master = null; HighlyAvailableGraphDatabase dbWithId21 = null; HighlyAvailableGraphDatabase dbWithId22 = null; try { int masterClusterPort = PortAuthority.allocatePort(); GraphDatabaseBuilder masterBuilder = (new TestHighlyAvailableGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(Path(1)).setConfig(ClusterSettings.initial_hosts, "127.0.0.1:" + masterClusterPort).setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + masterClusterPort).setConfig(ClusterSettings.server_id, "" + 1).setConfig(HaSettings.HaServer, ":" + PortAuthority.allocatePort()).setConfig(HaSettings.TxPushFactor, "0").setConfig(OnlineBackupSettings.online_backup_enabled, false.ToString()); master = ( HighlyAvailableGraphDatabase )masterBuilder.NewGraphDatabase(); GraphDatabaseBuilder db21Builder = (new TestHighlyAvailableGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(Path(2)).setConfig(ClusterSettings.initial_hosts, "127.0.0.1:" + masterClusterPort).setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + PortAuthority.allocatePort()).setConfig(ClusterSettings.server_id, "" + 2).setConfig(HaSettings.HaServer, ":" + PortAuthority.allocatePort()).setConfig(HaSettings.TxPushFactor, "0").setConfig(OnlineBackupSettings.online_backup_enabled, false.ToString()); dbWithId21 = ( HighlyAvailableGraphDatabase )db21Builder.NewGraphDatabase(); GraphDatabaseBuilder db22Builder = (new TestHighlyAvailableGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(Path(3)).setConfig(ClusterSettings.initial_hosts, "127.0.0.1:" + masterClusterPort).setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + PortAuthority.allocatePort()).setConfig(ClusterSettings.server_id, "" + 2).setConfig(HaSettings.HaServer, ":" + PortAuthority.allocatePort()).setConfig(HaSettings.TxPushFactor, "0").setConfig(OnlineBackupSettings.online_backup_enabled, false.ToString()); try { dbWithId22 = ( HighlyAvailableGraphDatabase )db22Builder.NewGraphDatabase(); fail("Should not be able to startup when a cluster already has my id"); } catch (Exception) { // awesome } assertTrue(master.Master); assertTrue(!dbWithId21.Master); using (Transaction transaction = dbWithId21.BeginTx()) { transaction.Success(); } } finally { if (dbWithId21 != null) { dbWithId21.Shutdown(); } if (dbWithId22 != null) { dbWithId22.Shutdown(); } if (master != null) { master.Shutdown(); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void setup() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void Setup() { CustomGraphDatabaseFactory customGraphDatabaseFactory = new CustomGraphDatabaseFactory( this ); _cluster = ClusterRule.withSharedSetting( GraphDatabaseSettings.snapshot_query, TRUE ).withDbFactory( customGraphDatabaseFactory ).startCluster(); HighlyAvailableGraphDatabase master = _cluster.Master; for ( int i = 0; i < 3; i++ ) { using ( Transaction tx = master.BeginTx() ) { master.CreateNode( _nodeLabel ); tx.Success(); } } _cluster.sync(); }
/* * This method must be called on an instance that has had addSomeData() called on it. */ private void EnsureInstanceIsReadOnlyInPendingState(HighlyAvailableGraphDatabase instance) { assertEquals(PENDING, instance.InstanceState); tx(instance, retryACoupleOfTimesOn(TRANSIENT_ERRORS), db => assertEquals(_testPropValue, instance.GetNodeById(_testNodeId).getProperty(_testPropKey))); try { using (Transaction ignored = instance.BeginTx()) { instance.GetNodeById(_testNodeId).delete(); fail("Should not be able to do write transactions when detached"); } } catch (Exception expected) when(expected is TransientDatabaseFailureException || expected is TransactionFailureException) { // expected } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void updatePullerTriggerPageTransactionTracking() public virtual void UpdatePullerTriggerPageTransactionTracking() { HighlyAvailableGraphDatabase slave = _cluster.AnySlave; TransactionIdStore slaveTransactionIdStore = slave.DependencyResolver.resolveDependency( typeof( TransactionIdStore ) ); assertEquals( 5, slaveTransactionIdStore.LastClosedTransactionId ); ByzantineLongSupplier byzantineIdSupplier = _contextSupplier.ByzantineIdSupplier; byzantineIdSupplier.UseWrongTxId(); try { using ( Transaction ignored = slave.BeginTx() ) { slave.Execute( "match (n) return n" ); } } catch ( QueryExecutionException executionException ) { assertEquals( "Unable to get clean data snapshot for query 'match (n) return n' after 5 attempts.", executionException.Message ); } byzantineIdSupplier.UseCorrectTxId(); slave.Execute( "match (n) return n" ).close(); }