//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldIgnoreSuspicionsForOurselves() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldIgnoreSuspicionsForOurselves() { // Given InstanceId instanceId = new InstanceId(1); HeartbeatState heartbeat = HeartbeatState.Heartbeat; ClusterConfiguration configuration = new ClusterConfiguration("whatever", NullLogProvider.Instance, "cluster://1", "cluster://2"); configuration.Joined(instanceId, URI.create("cluster://1")); configuration.Joined(new InstanceId(2), URI.create("cluster://2")); Config config = mock(typeof(Config)); when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10); MultiPaxosContext context = new MultiPaxosContext(instanceId, iterable(new ElectionRole("coordinator")), configuration, Mockito.mock(typeof(Executor)), NullLogProvider.Instance, Mockito.mock(typeof(ObjectInputStreamFactory)), Mockito.mock(typeof(ObjectOutputStreamFactory)), Mockito.mock(typeof(AcceptorInstanceStore)), Mockito.mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config); HeartbeatContext heartbeatContext = context.HeartbeatContext; Message received = Message.@internal(HeartbeatMessage.Suspicions, new HeartbeatMessage.SuspicionsState(asSet(iterable(instanceId)))); received.setHeader(Message.HEADER_FROM, "cluster://2").SetHeader(Message.HEADER_INSTANCE_ID, "2"); // When heartbeat.handle(heartbeatContext, received, mock(typeof(MessageHolder))); // Then assertThat(heartbeatContext.GetSuspicionsOf(instanceId).Count, equalTo(0)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testElectionNotOkQuorumFailedTwoInstances() public virtual void TestElectionNotOkQuorumFailedTwoInstances() { ISet <InstanceId> failed = new HashSet <InstanceId>(); failed.Add(new InstanceId(2)); IDictionary <InstanceId, URI> members = new Dictionary <InstanceId, URI>(); members[new InstanceId(1)] = URI.create("server1"); members[new InstanceId(2)] = URI.create("server2"); Config config = mock(typeof(Config)); when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10); ClusterConfiguration clusterConfiguration = mock(typeof(ClusterConfiguration)); when(clusterConfiguration.Members).thenReturn(members); ClusterContext clusterContext = mock(typeof(ClusterContext)); when(clusterContext.Configuration).thenReturn(clusterConfiguration); MultiPaxosContext context = new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole("coordinator")), clusterConfiguration, mock(typeof(Executor)), NullLogProvider.Instance, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config); context.HeartbeatContext.Failed.addAll(failed); ElectionContext toTest = context.ElectionContext; assertFalse(toTest.ElectionOk()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void setup() public virtual void Setup() { IDictionary <InstanceId, URI> members = new Dictionary <InstanceId, URI>(); for (int i = 0; i < _instanceIds.Length; i++) { members[_instanceIds[i]] = URI.create(_initialHosts[i]); } ClusterConfiguration config = new ClusterConfiguration("clusterName", NullLogProvider.Instance, _initialHosts); config.Members = members; _context = mock(typeof(ClusterContext)); Config configuration = mock(typeof(Config)); when(configuration.Get(ClusterSettings.max_acceptors)).thenReturn(10); when(_context.Configuration).thenReturn(config); when(_context.MyId).thenReturn(_instanceIds[0]); MultiPaxosContext context = new MultiPaxosContext(_instanceIds[0], Iterables.iterable(new ElectionRole("coordinator")), config, Mockito.mock(typeof(Executor)), NullLogProvider.Instance, Mockito.mock(typeof(ObjectInputStreamFactory)), Mockito.mock(typeof(ObjectOutputStreamFactory)), Mockito.mock(typeof(AcceptorInstanceStore)), Mockito.mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), configuration); _toTest = context.HeartbeatContext; }
private void BaseTestForElectionOk(ISet <InstanceId> failed, bool moreThanQuorum) { IDictionary <InstanceId, URI> members = new Dictionary <InstanceId, URI>(); members[new InstanceId(1)] = URI.create("server1"); members[new InstanceId(2)] = URI.create("server2"); members[new InstanceId(3)] = URI.create("server3"); Config config = mock(typeof(Config)); when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10); ClusterConfiguration clusterConfiguration = mock(typeof(ClusterConfiguration)); when(clusterConfiguration.Members).thenReturn(members); ClusterContext clusterContext = mock(typeof(ClusterContext)); when(clusterContext.Configuration).thenReturn(clusterConfiguration); MultiPaxosContext context = new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole("coordinator")), clusterConfiguration, mock(typeof(Executor)), NullLogProvider.Instance, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config); context.HeartbeatContext.Failed.addAll(failed); ElectionContext toTest = context.ElectionContext; assertEquals(moreThanQuorum, !toTest.ElectionOk()); }
public static ClusterInstance NewClusterInstance(InstanceId id, URI uri, Monitors monitors, ClusterConfiguration configuration, int maxSurvivableFailedMembers, LogProvider logging) { MultiPaxosServerFactory factory = new MultiPaxosServerFactory(configuration, logging, monitors.NewMonitor(typeof(StateMachines.Monitor))); ClusterInstanceInput input = new ClusterInstanceInput(); ClusterInstanceOutput output = new ClusterInstanceOutput(uri); ObjectStreamFactory objStreamFactory = new ObjectStreamFactory(); ProverTimeouts timeouts = new ProverTimeouts(uri); InMemoryAcceptorInstanceStore acceptorInstances = new InMemoryAcceptorInstanceStore(); Config config = mock(typeof(Config)); when(config.Get(ClusterSettings.max_acceptors)).thenReturn(maxSurvivableFailedMembers); DelayedDirectExecutor executor = new DelayedDirectExecutor(logging); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext context = new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext(id, org.neo4j.helpers.collection.Iterables.iterable(new org.neo4j.cluster.protocol.election.ElectionRole(org.neo4j.cluster.protocol.cluster.ClusterConfiguration.COORDINATOR)), new org.neo4j.cluster.protocol.cluster.ClusterConfiguration(configuration.getName(), logging, configuration.getMemberURIs()), executor, logging, objStreamFactory, objStreamFactory, acceptorInstances, timeouts, new org.neo4j.kernel.ha.cluster.DefaultElectionCredentialsProvider(id, new StateVerifierLastTxIdGetter(), new MemberInfoProvider()), config); MultiPaxosContext context = new MultiPaxosContext(id, Iterables.iterable(new ElectionRole(ClusterConfiguration.COORDINATOR)), new ClusterConfiguration(configuration.Name, logging, configuration.MemberURIs), executor, logging, objStreamFactory, objStreamFactory, acceptorInstances, timeouts, new DefaultElectionCredentialsProvider(id, new StateVerifierLastTxIdGetter(), new MemberInfoProvider()), config); context.ClusterContext.BoundAt = uri; SnapshotContext snapshotContext = new SnapshotContext(context.ClusterContext, context.LearnerContext); DelayedDirectExecutor taskExecutor = new DelayedDirectExecutor(logging); ProtocolServer ps = factory.NewProtocolServer(id, input, output, DirectExecutor, taskExecutor, timeouts, context, snapshotContext); return(new ClusterInstance(DirectExecutor, logging, factory, ps, context, acceptorInstances, timeouts, input, output, uri)); }
public virtual ClusterInstance NewCopy() { // A very invasive method of cloning a protocol server. Nonetheless, since this is mostly an experiment at this // point, it seems we can refactor later on to have a cleaner clone mechanism. // Because state machines share state, and are simultaneously conceptually unaware of each other, implementing // a clean snapshot mechanism is very hard. I've opted for having a dirty one here in the test code rather // than introducing a hack into the runtime code. ProverTimeouts timeoutsSnapshot = _timeouts.snapshot(); InMemoryAcceptorInstanceStore snapshotAcceptorInstances = _acceptorInstanceStore.snapshot(); ClusterInstanceOutput output = new ClusterInstanceOutput(_uri); ClusterInstanceInput input = new ClusterInstanceInput(); DelayedDirectExecutor executor = new DelayedDirectExecutor(_logging); ObjectStreamFactory objectStreamFactory = new ObjectStreamFactory(); MultiPaxosContext snapshotCtx = _ctx.snapshot(_logging, timeoutsSnapshot, executor, snapshotAcceptorInstances, objectStreamFactory, objectStreamFactory, new DefaultElectionCredentialsProvider(_server.ServerId, new StateVerifierLastTxIdGetter(), new MemberInfoProvider()) ); IList <StateMachine> snapshotMachines = new List <StateMachine>(); foreach (StateMachine stateMachine in _server.StateMachines.StateMachines) { snapshotMachines.Add(SnapshotStateMachine(_logging, snapshotCtx, stateMachine)); } ProtocolServer snapshotProtocolServer = _factory.constructSupportingInfrastructureFor(_server.ServerId, input, output, executor, timeoutsSnapshot, _stateMachineExecutor, snapshotCtx, snapshotMachines.ToArray()); return(new ClusterInstance(_stateMachineExecutor, _logging, _factory, snapshotProtocolServer, snapshotCtx, snapshotAcceptorInstances, timeoutsSnapshot, input, output, _uri)); }
internal ClusterInstance(Executor stateMachineExecutor, LogProvider logging, MultiPaxosServerFactory factory, ProtocolServer server, MultiPaxosContext ctx, InMemoryAcceptorInstanceStore acceptorInstanceStore, ProverTimeouts timeouts, ClusterInstanceInput input, ClusterInstanceOutput output, URI uri) { this._stateMachineExecutor = stateMachineExecutor; this._logging = logging; this._factory = factory; this._server = server; this._ctx = ctx; this._acceptorInstanceStore = acceptorInstanceStore; this._timeouts = timeouts; this._input = input; this._output = output; this._uri = uri; }
private StateMachine SnapshotStateMachine(LogProvider logProvider, MultiPaxosContext snapshotCtx, StateMachine stateMachine) { // This is done this way because all the state machines are sharing one piece of global state // (MultiPaxosContext), which is snapshotted as one coherent component. This means the state machines // cannot snapshot themselves, an external service needs to snapshot the full shared state and then create // new state machines sharing that state. object ctx; Type msgType = stateMachine.MessageType; if (msgType == typeof(AtomicBroadcastMessage)) { ctx = snapshotCtx.AtomicBroadcastContext; } else if (msgType == typeof(AcceptorMessage)) { ctx = snapshotCtx.AcceptorContext; } else if (msgType == typeof(ProposerMessage)) { ctx = snapshotCtx.ProposerContext; } else if (msgType == typeof(LearnerMessage)) { ctx = snapshotCtx.LearnerContext; } else if (msgType == typeof(HeartbeatMessage)) { ctx = snapshotCtx.HeartbeatContext; } else if (msgType == typeof(ElectionMessage)) { ctx = snapshotCtx.ElectionContext; } else if (msgType == typeof(SnapshotMessage)) { ctx = new SnapshotContext(snapshotCtx.ClusterContext, snapshotCtx.LearnerContext); } else if (msgType == typeof(ClusterMessage)) { ctx = snapshotCtx.ClusterContext; } else { throw new System.ArgumentException("I don't know how to snapshot this state machine: " + stateMachine); } return(new StateMachine(ctx, stateMachine.MessageType, stateMachine.State, logProvider)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldLogFirstHeartbeatAfterTimeout() public virtual void ShouldLogFirstHeartbeatAfterTimeout() { // given InstanceId instanceId = new InstanceId(1); InstanceId otherInstance = new InstanceId(2); ClusterConfiguration configuration = new ClusterConfiguration("whatever", NullLogProvider.Instance, "cluster://1", "cluster://2"); configuration.Members[otherInstance] = URI.create("cluster://2"); AssertableLogProvider internalLog = new AssertableLogProvider(true); TimeoutStrategy timeoutStrategy = mock(typeof(TimeoutStrategy)); Timeouts timeouts = new Timeouts(timeoutStrategy); Config config = mock(typeof(Config)); when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10); MultiPaxosContext context = new MultiPaxosContext(instanceId, iterable(new ElectionRole("coordinator")), configuration, mock(typeof(Executor)), internalLog, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), timeouts, mock(typeof(ElectionCredentialsProvider)), config); StateMachines stateMachines = new StateMachines(internalLog, mock(typeof(StateMachines.Monitor)), mock(typeof(MessageSource)), mock(typeof(MessageSender)), timeouts, mock(typeof(DelayedDirectExecutor)), ThreadStart.run, instanceId); stateMachines.AddStateMachine(new StateMachine(context.HeartbeatContext, typeof(HeartbeatMessage), HeartbeatState.Start, internalLog)); timeouts.Tick(0); when(timeoutStrategy.TimeoutFor(any(typeof(Message)))).thenReturn(5L); // when stateMachines.Process(Message.@internal(HeartbeatMessage.Join)); stateMachines.Process(Message.@internal(HeartbeatMessage.IAmAlive, new HeartbeatMessage.IAmAliveState(otherInstance)).setHeader(Message.HEADER_CREATED_BY, otherInstance.ToString())); for (int i = 1; i <= 15; i++) { timeouts.Tick(i); } // then verify(timeoutStrategy, times(3)).timeoutTriggered(argThat(new MessageArgumentMatcher <>() .onMessageType(HeartbeatMessage.TimedOut))); internalLog.AssertExactly(inLog(typeof(HeartbeatState)).debug("Received timed out for server 2"), inLog(typeof(HeartbeatContext)).info("1(me) is now suspecting 2"), inLog(typeof(HeartbeatState)).debug("Received timed out for server 2"), inLog(typeof(HeartbeatState)).debug("Received timed out for server 2")); internalLog.Clear(); // when stateMachines.Process(Message.@internal(HeartbeatMessage.IAmAlive, new HeartbeatMessage.IAmAliveState(otherInstance)).setHeader(Message.HEADER_CREATED_BY, otherInstance.ToString())); // then internalLog.AssertExactly(inLog(typeof(HeartbeatState)).debug("Received i_am_alive[2] after missing 3 (15ms)")); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testInstanceWithLowestIdFailedIsNotConsideredTheElector() public virtual void TestInstanceWithLowestIdFailedIsNotConsideredTheElector() { // Given // A cluster of 5 of which the two lowest instances are failed ISet <InstanceId> failed = new HashSet <InstanceId>(); failed.Add(new InstanceId(1)); failed.Add(new InstanceId(2)); // This is the instance that must discover that it is the elector and whose state machine we'll test InstanceId lowestNonFailedInstanceId = new InstanceId(3); IDictionary <InstanceId, URI> members = new Dictionary <InstanceId, URI>(); members[new InstanceId(1)] = URI.create("server1"); members[new InstanceId(2)] = URI.create("server2"); members[lowestNonFailedInstanceId] = URI.create("server3"); members[new InstanceId(4)] = URI.create("server4"); members[new InstanceId(5)] = URI.create("server5"); Config config = Config.defaults(); ClusterConfiguration clusterConfiguration = mock(typeof(ClusterConfiguration)); when(clusterConfiguration.Members).thenReturn(members); when(clusterConfiguration.MemberIds).thenReturn(members.Keys); ClusterContext clusterContext = mock(typeof(ClusterContext)); when(clusterContext.Configuration).thenReturn(clusterConfiguration); MultiPaxosContext context = new MultiPaxosContext(lowestNonFailedInstanceId, Iterables.iterable(new ElectionRole("coordinator")), clusterConfiguration, mock(typeof(Executor)), NullLogProvider.Instance, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config); ElectionContext toTest = context.ElectionContext; // Sanity check that before learning about lowest failed ids it does not consider itself the elector assertFalse(toTest.Elector); // When // The lowest numbered alive instance receives word about other failed instances context.HeartbeatContext.Failed.addAll(failed); // Then // It should realise it is the elector (lowest instance id alive) assertTrue(toTest.Elector); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testElectionVersionIsResetWhenElectorChangesFromMeToOther() public virtual void TestElectionVersionIsResetWhenElectorChangesFromMeToOther() { const string coordinatorRole = "coordinator"; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.cluster.InstanceId me = new org.neo4j.cluster.InstanceId(1); InstanceId me = new InstanceId(1); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.cluster.InstanceId winner = new org.neo4j.cluster.InstanceId(2); InstanceId winner = new InstanceId(2); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.cluster.InstanceId elector = new org.neo4j.cluster.InstanceId(2); InstanceId elector = new InstanceId(2); HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext)); when(heartbeatContext.Failed).thenReturn(Collections.emptySet()); Config config = mock(typeof(Config)); when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10); MultiPaxosContext multiPaxosContext = new MultiPaxosContext(me, Iterables.iterable(new ElectionRole(coordinatorRole)), mock(typeof(ClusterConfiguration)), ThreadStart.run, NullLogProvider.Instance, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config); ClusterContext context = multiPaxosContext.ClusterContext; ElectionContext electionContext = multiPaxosContext.ElectionContext; ClusterListener listener = mock(typeof(ClusterListener)); context.LastElectorVersion = 5; context.LastElector = me; context.AddClusterListener(listener); long expectedVersion = electionContext.NewConfigurationStateChange().Version; context.Elected(coordinatorRole, winner, me, expectedVersion); verify(listener, times(1)).elected(coordinatorRole, winner, null); context.Elected(coordinatorRole, winner, elector, 2); verify(listener, times(2)).elected(coordinatorRole, winner, null); context.Elected(coordinatorRole, winner, elector, 3); verify(listener, times(3)).elected(coordinatorRole, winner, null); context.Elected(coordinatorRole, winner, elector, 2); verifyNoMoreInteractions(listener); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void failedElectorRejoiningMustHaveItsVersionFromVoteRequestsSetTheElectorVersion() public virtual void FailedElectorRejoiningMustHaveItsVersionFromVoteRequestsSetTheElectorVersion() { // Given const string role1 = "coordinator1"; InstanceId me = new InstanceId(1); InstanceId failingInstance = new InstanceId(2); InstanceId forQuorum = new InstanceId(3); Config config = mock(typeof(Config)); when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10); ClusterConfiguration clusterConfiguration = mock(typeof(ClusterConfiguration)); IList <InstanceId> clusterMemberIds = new LinkedList <InstanceId>(); clusterMemberIds.Add(failingInstance); clusterMemberIds.Add(me); clusterMemberIds.Add(forQuorum); when(clusterConfiguration.MemberIds).thenReturn(clusterMemberIds); MultiPaxosContext context = new MultiPaxosContext(me, Iterables.iterable(new ElectionRole(role1)), clusterConfiguration, ThreadStart.run, NullLogProvider.Instance, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config); HeartbeatContext heartbeatContext = context.HeartbeatContext; ClusterContext clusterContext = context.ClusterContext; clusterContext.LastElector = failingInstance; clusterContext.LastElectorVersion = 8; // When the elector fails heartbeatContext.Suspicions(forQuorum, Collections.singleton(failingInstance)); heartbeatContext.Suspect(failingInstance); // Then the elector is reset to defaults assertEquals(clusterContext.LastElector, InstanceId.NONE); assertEquals(clusterContext.LastElectorVersion, Org.Neo4j.cluster.protocol.cluster.ClusterContext_Fields.NO_ELECTOR_VERSION); // When the elector comes back with an election result clusterContext.Elected(role1, forQuorum, failingInstance, 9); // Then the result is actually respected assertEquals(clusterContext.LastElector, failingInstance); assertEquals(clusterContext.LastElectorVersion, 9); }
/* * This assumes an instance leaves the cluster normally and then rejoins, without any elections in between. The * expected result is that it will succeed in sending election results. */ //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void electorLeavingAndRejoiningWithNoElectionsInBetweenMustStillHaveElectionsGoThrough() public virtual void ElectorLeavingAndRejoiningWithNoElectionsInBetweenMustStillHaveElectionsGoThrough() { // Given const string role1 = "coordinator1"; InstanceId me = new InstanceId(1); InstanceId leavingInstance = new InstanceId(2); InstanceId forQuorum = new InstanceId(3); Config config = mock(typeof(Config)); when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10); ClusterConfiguration clusterConfiguration = mock(typeof(ClusterConfiguration)); IList <InstanceId> clusterMemberIds = new LinkedList <InstanceId>(); clusterMemberIds.Add(leavingInstance); clusterMemberIds.Add(me); clusterMemberIds.Add(forQuorum); when(clusterConfiguration.MemberIds).thenReturn(clusterMemberIds); MultiPaxosContext context = new MultiPaxosContext(me, Iterables.iterable(new ElectionRole(role1)), clusterConfiguration, ThreadStart.run, NullLogProvider.Instance, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config); ClusterContext clusterContext = context.ClusterContext; clusterContext.LastElector = leavingInstance; clusterContext.LastElectorVersion = 8; // When the elector leaves the cluster clusterContext.Left(leavingInstance); // Then the elector is reset to defaults assertEquals(clusterContext.LastElector, InstanceId.NONE); assertEquals(clusterContext.LastElectorVersion, Org.Neo4j.cluster.protocol.cluster.ClusterContext_Fields.NO_ELECTOR_VERSION); // When the elector comes back with an election result // We don't need to join, election results do not check for elector membership clusterContext.Elected(role1, forQuorum, leavingInstance, 9); // Then the result is actually respected assertEquals(clusterContext.LastElector, leavingInstance); assertEquals(clusterContext.LastElectorVersion, 9); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void instanceFailingShouldHaveItsVotesInvalidated() public virtual void InstanceFailingShouldHaveItsVotesInvalidated() { // Given const string role1 = "coordinator1"; const string role2 = "coordinator2"; InstanceId me = new InstanceId(1); InstanceId failingInstance = new InstanceId(2); InstanceId otherInstance = new InstanceId(3); Config config = mock(typeof(Config)); when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10); ClusterConfiguration clusterConfiguration = mock(typeof(ClusterConfiguration)); IList <InstanceId> clusterMemberIds = new LinkedList <InstanceId>(); clusterMemberIds.Add(failingInstance); clusterMemberIds.Add(otherInstance); clusterMemberIds.Add(me); when(clusterConfiguration.MemberIds).thenReturn(clusterMemberIds); MultiPaxosContext context = new MultiPaxosContext(me, Iterables.iterable(new ElectionRole(role1), new ElectionRole(role2)), clusterConfiguration, ThreadStart.run, NullLogProvider.Instance, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config); HeartbeatContext heartbeatContext = context.HeartbeatContext; ElectionContext electionContext = context.ElectionContext; electionContext.StartElectionProcess(role1); electionContext.StartElectionProcess(role2); electionContext.Voted(role1, failingInstance, mock(typeof(ElectionCredentials)), 2); electionContext.Voted(role2, failingInstance, mock(typeof(ElectionCredentials)), 2); electionContext.Voted(role1, otherInstance, mock(typeof(ElectionCredentials)), 2); electionContext.Voted(role2, otherInstance, mock(typeof(ElectionCredentials)), 2); heartbeatContext.Suspect(failingInstance); assertEquals(1, electionContext.GetVoteCount(role1)); assertEquals(1, electionContext.GetVoteCount(role2)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void twoVotesFromSameInstanceForSameRoleShouldBeConsolidated() public virtual void TwoVotesFromSameInstanceForSameRoleShouldBeConsolidated() { // Given const string coordinatorRole = "coordinator"; HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext)); when(heartbeatContext.Failed).thenReturn(Collections.emptySet()); IDictionary <InstanceId, URI> members = new Dictionary <InstanceId, URI>(); members[new InstanceId(1)] = URI.create("server1"); members[new InstanceId(2)] = URI.create("server2"); members[new InstanceId(3)] = URI.create("server3"); Config config = mock(typeof(Config)); when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10); ClusterConfiguration clusterConfiguration = mock(typeof(ClusterConfiguration)); when(clusterConfiguration.Members).thenReturn(members); ClusterContext clusterContext = mock(typeof(ClusterContext)); when(clusterContext.Configuration).thenReturn(clusterConfiguration); MultiPaxosContext context = new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole(coordinatorRole)), clusterConfiguration, mock(typeof(Executor)), NullLogProvider.Instance, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config); ElectionContext toTest = context.ElectionContext; // When toTest.StartElectionProcess(coordinatorRole); toTest.Voted(coordinatorRole, new InstanceId(1), new IntegerElectionCredentials(100), Org.Neo4j.cluster.protocol.cluster.ClusterContext_Fields.NO_ELECTOR_VERSION); toTest.Voted(coordinatorRole, new InstanceId(2), new IntegerElectionCredentials(100), Org.Neo4j.cluster.protocol.cluster.ClusterContext_Fields.NO_ELECTOR_VERSION); toTest.Voted(coordinatorRole, new InstanceId(2), new IntegerElectionCredentials(101), Org.Neo4j.cluster.protocol.cluster.ClusterContext_Fields.NO_ELECTOR_VERSION); // Then assertNull(toTest.GetElectionWinner(coordinatorRole)); assertEquals(2, toTest.GetVoteCount(coordinatorRole)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAddInstanceIdHeaderInCatchUpMessages() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldAddInstanceIdHeaderInCatchUpMessages() { // Given InstanceId instanceId = new InstanceId(1); HeartbeatState heartbeat = HeartbeatState.Heartbeat; ClusterConfiguration configuration = new ClusterConfiguration("whatever", NullLogProvider.Instance, "cluster://1", "cluster://2"); configuration.Joined(instanceId, URI.create("cluster://1")); InstanceId otherInstance = new InstanceId(2); configuration.Joined(otherInstance, URI.create("cluster://2")); Config config = mock(typeof(Config)); when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10); MultiPaxosContext context = new MultiPaxosContext(instanceId, iterable(new ElectionRole("coordinator")), configuration, Mockito.mock(typeof(Executor)), NullLogProvider.Instance, Mockito.mock(typeof(ObjectInputStreamFactory)), Mockito.mock(typeof(ObjectOutputStreamFactory)), Mockito.mock(typeof(AcceptorInstanceStore)), Mockito.mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config); int lastDeliveredInstanceId = 100; context.LearnerContext.LastDeliveredInstanceId = lastDeliveredInstanceId; // This gap will trigger the catchUp message that we'll test against lastDeliveredInstanceId += 20; HeartbeatContext heartbeatContext = context.HeartbeatContext; Message received = Message.@internal(HeartbeatMessage.IAmAlive, new HeartbeatMessage.IAmAliveState(otherInstance)); received.setHeader(Message.HEADER_FROM, "cluster://2").SetHeader(Message.HEADER_INSTANCE_ID, "2").setHeader("last-learned", Convert.ToString(lastDeliveredInstanceId)); // When MessageHolder holder = mock(typeof(MessageHolder)); heartbeat.handle(heartbeatContext, received, holder); // Then verify(holder, times(1)).offer(ArgumentMatchers.argThat(new MessageArgumentMatcher <LearnerMessage>() .onMessageType(LearnerMessage.catchUp).withHeader(Message.HEADER_INSTANCE_ID, "2"))); }