private ProposerContextImpl(Org.Neo4j.cluster.InstanceId me, CommonContextState commonState, LogProvider logging, Timeouts timeouts, Deque <Message> pendingValues, IDictionary <InstanceId, Message> bookedInstances, PaxosInstanceStore paxosInstances, HeartbeatContext heartbeatContext) : base(me, commonState, logging, timeouts) { this._pendingValues = pendingValues; this._bookedInstances = bookedInstances; this._paxosInstances = paxosInstances; this._heartbeatContext = heartbeatContext; }
//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; }
internal ProposerContextImpl(Org.Neo4j.cluster.InstanceId me, CommonContextState commonState, LogProvider logging, Timeouts timeouts, PaxosInstanceStore paxosInstances, HeartbeatContext heartbeatContext) : base(me, commonState, logging, timeouts) { this._paxosInstances = paxosInstances; this._heartbeatContext = heartbeatContext; _pendingValues = new LinkedList <Message>(); _bookedInstances = new Dictionary <InstanceId, Message>(); }
//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)); }
internal LearnerContextImpl(Org.Neo4j.cluster.InstanceId me, CommonContextState commonState, LogProvider logging, Timeouts timeouts, PaxosInstanceStore paxosInstances, AcceptorInstanceStore instanceStore, ObjectInputStreamFactory objectInputStreamFactory, ObjectOutputStreamFactory objectOutputStreamFactory, HeartbeatContext heartbeatContext) : base(me, commonState, logging, timeouts) { this._heartbeatContext = heartbeatContext; this._instanceStore = instanceStore; this._objectInputStreamFactory = objectInputStreamFactory; this._objectOutputStreamFactory = objectOutputStreamFactory; this._paxosInstances = paxosInstances; this._learnMissLogger = (new CappedLogger(logging.GetLog(typeof(LearnerState)))).setDuplicateFilterEnabled(true); }
internal ClusterContextImpl(InstanceId me, CommonContextState commonState, LogProvider logging, Timeouts timeouts, Executor executor, ObjectOutputStreamFactory objectOutputStreamFactory, ObjectInputStreamFactory objectInputStreamFactory, LearnerContext learnerContext, HeartbeatContext heartbeatContext, Config config) : base(me, commonState, logging, timeouts) { this._executor = executor; this._objectOutputStreamFactory = objectOutputStreamFactory; this._objectInputStreamFactory = objectInputStreamFactory; this._learnerContext = learnerContext; this._heartbeatContext = heartbeatContext; this._config = config; heartbeatContext.AddHeartbeatListener(new HeartbeatListener_AdapterAnonymousInnerClass(this)); }
internal ElectionContextImpl(InstanceId me, CommonContextState commonState, LogProvider logging, Timeouts timeouts, ClusterContext clusterContext, HeartbeatContext heartbeatContext, IList <ElectionRole> roles, IDictionary <string, Election> elections, ElectionCredentialsProvider electionCredentialsProvider) : base(me, commonState, logging, timeouts) { this._clusterContext = clusterContext; this._heartbeatContext = heartbeatContext; this._roles = roles; this._elections = elections; this._electionCredentialsProvider = electionCredentialsProvider; heartbeatContext.AddHeartbeatListener(this); }
public virtual void VerifyConfigurations(string description) { Logger.Logger.fine("Verify configurations"); IList <URI> members = null; IDictionary <string, InstanceId> roles = null; ISet <InstanceId> failed = null; IList <AssertionError> errors = new LinkedList <AssertionError>(); IList <TestProtocolServer> protocolServers = Network.Servers; for (int j = 0; j < protocolServers.Count; j++) { StateMachines stateMachines = protocolServers[j].Server.StateMachines; //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: org.neo4j.cluster.statemachine.State<?, ?> clusterState = stateMachines.getStateMachine(ClusterMessage.class).getState(); State <object, ?> clusterState = stateMachines.GetStateMachine(typeof(ClusterMessage)).State; if (!clusterState.Equals(ClusterState.Entered)) { Logger.Logger.fine("Instance " + (j + 1) + " is not in the cluster (" + clusterState + ")"); continue; } ClusterContext context = ( ClusterContext )stateMachines.GetStateMachine(typeof(ClusterMessage)).Context; HeartbeatContext heartbeatContext = ( HeartbeatContext )stateMachines.GetStateMachine(typeof(HeartbeatMessage)).Context; ClusterConfiguration clusterConfiguration = context.Configuration; if (clusterConfiguration.MemberURIs.Count > 0) { Logger.Logger.fine(" Server " + (j + 1) + ": Cluster:" + clusterConfiguration.MemberURIs + ", Roles:" + clusterConfiguration.Roles + ", Failed:" + heartbeatContext.Failed); if (members == null) { members = clusterConfiguration.MemberURIs; roles = clusterConfiguration.Roles; failed = heartbeatContext.Failed; } else { VerifyConfigurations(stateMachines, members, roles, failed, errors); } } } assertEquals(description + ": In:" + In + ", Out:" + Out, protocolServers.Count, Iterables.count(Iterables.flatten(In, Out))); if (errors.Count > 0) { foreach (AssertionError error in errors) { Logger.Logger.severe(error.ToString()); } throw errors[0]; } }
private ClusterContextImpl(InstanceId me, CommonContextState commonState, LogProvider logging, Timeouts timeouts, IEnumerable <URI> joiningInstances, ClusterMessage.ConfigurationResponseState joinDeniedConfigurationResponseState, Executor executor, ObjectOutputStreamFactory objectOutputStreamFactory, ObjectInputStreamFactory objectInputStreamFactory, LearnerContext learnerContext, HeartbeatContext heartbeatContext, Config config) : base(me, commonState, logging, timeouts) { this._joiningInstances = joiningInstances; this._joinDeniedConfigurationResponseState = joinDeniedConfigurationResponseState; this._executor = executor; this._objectOutputStreamFactory = objectOutputStreamFactory; this._objectInputStreamFactory = objectInputStreamFactory; this._learnerContext = learnerContext; this._heartbeatContext = heartbeatContext; this._config = config; }
public virtual void VerifyConfigurations(VerifyInstanceConfiguration[] toCheckAgainst) { Logger.Logger.fine("Verify configurations against given"); IList <URI> members; IDictionary <string, InstanceId> roles; ISet <InstanceId> failed; IList <AssertionError> errors = new LinkedList <AssertionError>(); IList <TestProtocolServer> protocolServers = Network.Servers; assertEquals("You must provide a configuration for all instances", protocolServers.Count, toCheckAgainst.Length); for (int j = 0; j < protocolServers.Count; j++) { members = toCheckAgainst[j].Members; roles = toCheckAgainst[j].Roles; failed = toCheckAgainst[j].Failed; StateMachines stateMachines = protocolServers[j].Server.StateMachines; //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: org.neo4j.cluster.statemachine.State<?, ?> clusterState = stateMachines.getStateMachine(ClusterMessage.class).getState(); State <object, ?> clusterState = stateMachines.GetStateMachine(typeof(ClusterMessage)).State; if (!clusterState.Equals(ClusterState.Entered)) { Logger.Logger.warning("Instance " + (j + 1) + " is not in the cluster (" + clusterState + ")"); continue; } ClusterContext context = ( ClusterContext )stateMachines.GetStateMachine(typeof(ClusterMessage)).Context; HeartbeatContext heartbeatContext = ( HeartbeatContext )stateMachines.GetStateMachine(typeof(HeartbeatMessage)).Context; ClusterConfiguration clusterConfiguration = context.Configuration; if (clusterConfiguration.MemberURIs.Count > 0) { Logger.Logger.fine(" Server " + (j + 1) + ": Cluster:" + clusterConfiguration.MemberURIs + ", Roles:" + clusterConfiguration.Roles + ", Failed:" + heartbeatContext.Failed); VerifyConfigurations(stateMachines, members, roles, failed, errors); } } // assertEquals( "In:" + in + ", Out:" + out, protocolServers.size(), Iterables.count( Iterables.<Cluster, // List<Cluster>>flatten( in, out ) ) ); if (errors.Count > 0) { foreach (AssertionError error in errors) { Logger.Logger.severe(error.ToString()); } throw errors[0]; } }
private int LimitedAcceptors(int maxAcceptors, IList <InstanceId> alive) { CommonContextState commonContextState = new CommonContextState(null, maxAcceptors); HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext)); when(heartbeatContext.Alive).thenReturn(alive); when(heartbeatContext.GetUriForId(any(typeof(InstanceId)))).thenReturn(URI.create("http://localhost:8080")); // when ProposerContextImpl proposerContext = new ProposerContextImpl(new InstanceId(1), commonContextState, null, null, null, heartbeatContext); return(proposerContext.Acceptors.Count); }
private void VerifyConfigurations(StateMachines stateMachines, IList <URI> members, IDictionary <string, InstanceId> roles, ISet <InstanceId> failed, IList <AssertionError> errors) { ClusterContext context = ( ClusterContext )stateMachines.GetStateMachine(typeof(ClusterMessage)).Context; int myId = context.MyId.toIntegerIndex(); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: org.neo4j.cluster.statemachine.State<?, ?> clusterState = stateMachines.getStateMachine(ClusterMessage.class).getState(); State <object, ?> clusterState = stateMachines.GetStateMachine(typeof(ClusterMessage)).State; if (!clusterState.Equals(ClusterState.Entered)) { Logger.Logger.warning("Instance " + myId + " is not in the cluster (" + clusterState + ")"); return; } HeartbeatContext heartbeatContext = ( HeartbeatContext )stateMachines.GetStateMachine(typeof(HeartbeatMessage)).Context; ClusterConfiguration clusterConfiguration = context.Configuration; try { assertEquals("Config for server" + myId + " is wrong", new HashSet <>(members), new HashSet <>(clusterConfiguration.MemberURIs) ); } catch (AssertionError e) { errors.Add(e); } try { assertEquals("Roles for server" + myId + " is wrong", roles, clusterConfiguration.Roles); } catch (AssertionError e) { errors.Add(e); } try { assertEquals("Failed for server" + myId + " is wrong", failed, heartbeatContext.Failed); } catch (AssertionError e) { errors.Add(e); } }
//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); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void electionBeingForgottenMustIncreaseElectionId() public virtual void ElectionBeingForgottenMustIncreaseElectionId() { // Given const string coordinatorRole = "coordinator"; HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext)); when(heartbeatContext.Failed).thenReturn(Collections.emptySet()); Config config = mock(typeof(Config)); when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10); ElectionContext context = (new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole(coordinatorRole)), mock(typeof(ClusterConfiguration)), mock(typeof(Executor)), NullLogProvider.Instance, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config)).ElectionContext; ElectionContext_VoteRequest voteRequestBefore = context.VoteRequestForRole(new ElectionRole(coordinatorRole)); context.ForgetElection(coordinatorRole); ElectionContext_VoteRequest voteRequestAfter = context.VoteRequestForRole(new ElectionRole(coordinatorRole)); assertEquals(voteRequestBefore.Version + 1, voteRequestAfter.Version); }
//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 voteFromPreviousSuccessfulElectionMustNotBeCounted() public virtual void VoteFromPreviousSuccessfulElectionMustNotBeCounted() { // Given const string coordinatorRole = "coordinator"; HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext)); when(heartbeatContext.Failed).thenReturn(Collections.emptySet()); Config config = mock(typeof(Config)); when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10); ElectionContext context = (new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole(coordinatorRole)), mock(typeof(ClusterConfiguration)), mock(typeof(Executor)), NullLogProvider.Instance, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config)).ElectionContext; // When ElectionContext_VoteRequest voteRequestBefore = context.VoteRequestForRole(new ElectionRole(coordinatorRole)); context.ForgetElection(coordinatorRole); // Then assertFalse(context.Voted(coordinatorRole, new InstanceId(2), null, voteRequestBefore.Version - 1)); }
//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"))); }
public HeartbeatLeftListener(HeartbeatContext heartbeatContext, LogProvider logProvider) { this._heartbeatContext = heartbeatContext; this._log = logProvider.getLog(this.GetType()); }
public virtual ProposerContextImpl Snapshot(CommonContextState commonStateSnapshot, LogProvider logging, Timeouts timeouts, PaxosInstanceStore paxosInstancesSnapshot, HeartbeatContext heartbeatContext) { return(new ProposerContextImpl(Me, commonStateSnapshot, logging, timeouts, new LinkedList <>(_pendingValues), new Dictionary <>(_bookedInstances), paxosInstancesSnapshot, heartbeatContext)); }