//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldUpdateDiscoveryHeaderWithContactingInstances() public virtual void ShouldUpdateDiscoveryHeaderWithContactingInstances() { // Given InstanceId me = new InstanceId(1); InstanceId joiningOne = new InstanceId(2); InstanceId joiningTwo = new InstanceId(3); CommonContextState commonContextState = mock(typeof(CommonContextState), RETURNS_MOCKS); Timeouts timeouts = mock(typeof(Timeouts)); Executor executor = mock(typeof(Executor)); HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext)); ClusterContext context = new ClusterContextImpl(me, commonContextState, NullLogProvider.Instance, timeouts, executor, mock(typeof(ObjectOutputStreamFactory)), mock(typeof(ObjectInputStreamFactory)), mock(typeof(LearnerContext)), heartbeatContext, mock(typeof(Config))); ClusterMessage.ConfigurationRequestState requestOne = mock(typeof(ClusterMessage.ConfigurationRequestState)); when(requestOne.JoiningId).thenReturn(joiningOne); ClusterMessage.ConfigurationRequestState requestTwo = mock(typeof(ClusterMessage.ConfigurationRequestState)); when(requestTwo.JoiningId).thenReturn(joiningTwo); // When // Instance 2 contacts us twice and Instance 3 contacts us once context.AddContactingInstance(requestOne, "4, 5"); // discovery headers are random here context.AddContactingInstance(requestOne, "4, 5"); context.AddContactingInstance(requestTwo, "2, 5"); // Then // The discovery header we generate should still contain one copy of each instance assertEquals("2,3", context.GenerateDiscoveryHeader()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldGracefullyHandleEmptyDiscoveryHeader() public virtual void ShouldGracefullyHandleEmptyDiscoveryHeader() { // Given InstanceId me = new InstanceId(1); InstanceId joining = new InstanceId(2); CommonContextState commonContextState = mock(typeof(CommonContextState), RETURNS_MOCKS); Timeouts timeouts = mock(typeof(Timeouts)); Executor executor = mock(typeof(Executor)); HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext)); ClusterContext context = new ClusterContextImpl(me, commonContextState, NullLogProvider.Instance, timeouts, executor, mock(typeof(ObjectOutputStreamFactory)), mock(typeof(ObjectInputStreamFactory)), mock(typeof(LearnerContext)), heartbeatContext, mock(typeof(Config))); ClusterMessage.ConfigurationRequestState request = mock(typeof(ClusterMessage.ConfigurationRequestState)); when(request.JoiningId).thenReturn(joining); // When // Instance 2 contacts us with a request but it is empty context.AddContactingInstance(request, ""); // Then // The discovery header we generate should still contain that instance assertEquals("2", context.GenerateDiscoveryHeader()); }
/* * This test ensures that an instance that is marked as failed has its elector version reset. This means that * the instance, once it comes back, will still be able to do elections even if it lost state */ //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void nonElectorFailingMustNotCauseElectorVersionToBeReset() public virtual void NonElectorFailingMustNotCauseElectorVersionToBeReset() { // Given InstanceId me = new InstanceId(1); InstanceId elector = new InstanceId(2); CommonContextState commonContextState = mock(typeof(CommonContextState), RETURNS_MOCKS); Timeouts timeouts = mock(typeof(Timeouts)); Executor executor = mock(typeof(Executor)); HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext)); ArgumentCaptor <HeartbeatListener> listenerCaptor = ArgumentCaptor.forClass(typeof(HeartbeatListener)); ClusterContext context = new ClusterContextImpl(me, commonContextState, NullLogProvider.Instance, timeouts, executor, mock(typeof(ObjectOutputStreamFactory)), mock(typeof(ObjectInputStreamFactory)), mock(typeof(LearnerContext)), heartbeatContext, mock(typeof(Config))); verify(heartbeatContext).addHeartbeatListener(listenerCaptor.capture()); HeartbeatListener theListener = listenerCaptor.Value; // This means instance 2 was the elector at version 8 context.LastElector = elector; context.LastElectorVersion = 8; // When theListener.Failed(new InstanceId(3)); // Then assertEquals(context.LastElector, elector); assertEquals(context.LastElectorVersion, 8); }
public override ProtocolServer NewProtocolServer(InstanceId me, TimeoutStrategy timeoutStrategy, MessageSource input, MessageSender output, AcceptorInstanceStore acceptorInstanceStore, ElectionCredentialsProvider electionCredentialsProvider, Executor stateMachineExecutor, ObjectInputStreamFactory objectInputStreamFactory, ObjectOutputStreamFactory objectOutputStreamFactory, Config config) { DelayedDirectExecutor executor = new DelayedDirectExecutor(_logging); // Create state machines Timeouts timeouts = new Timeouts(timeoutStrategy); //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(me, 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(initialConfig.getName(), logging, initialConfig.getMemberURIs()), executor, logging, objectInputStreamFactory, objectOutputStreamFactory, acceptorInstanceStore, timeouts, electionCredentialsProvider, config); MultiPaxosContext context = new MultiPaxosContext(me, Iterables.iterable(new ElectionRole(ClusterConfiguration.COORDINATOR)), new ClusterConfiguration(_initialConfig.Name, _logging, _initialConfig.MemberURIs), executor, _logging, objectInputStreamFactory, objectOutputStreamFactory, acceptorInstanceStore, timeouts, electionCredentialsProvider, config); SnapshotContext snapshotContext = new SnapshotContext(context.ClusterContext, context.LearnerContext); return(NewProtocolServer(me, input, output, stateMachineExecutor, executor, timeouts, context, snapshotContext)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldKeepTrackOfInstancesWeHaveContacted() public virtual void ShouldKeepTrackOfInstancesWeHaveContacted() { // Given InstanceId me = new InstanceId(1); InstanceId joiningOne = new InstanceId(2); InstanceId joiningTwo = new InstanceId(3); CommonContextState commonContextState = mock(typeof(CommonContextState), RETURNS_MOCKS); Timeouts timeouts = mock(typeof(Timeouts)); Executor executor = mock(typeof(Executor)); HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext)); ClusterContext context = new ClusterContextImpl(me, commonContextState, NullLogProvider.Instance, timeouts, executor, mock(typeof(ObjectOutputStreamFactory)), mock(typeof(ObjectInputStreamFactory)), mock(typeof(LearnerContext)), heartbeatContext, mock(typeof(Config))); ClusterMessage.ConfigurationRequestState requestOne = mock(typeof(ClusterMessage.ConfigurationRequestState)); when(requestOne.JoiningId).thenReturn(joiningOne); ClusterMessage.ConfigurationRequestState requestTwo = mock(typeof(ClusterMessage.ConfigurationRequestState)); when(requestTwo.JoiningId).thenReturn(joiningTwo); // When // Instance two contacts us but we are not in the header context.AddContactingInstance(requestOne, "4, 5"); // Then we haven't contacted instance 2 assertFalse(context.HaveWeContactedInstance(requestOne)); // When // Instance 2 reports that we have contacted it after all context.AddContactingInstance(requestOne, "4, 5, 1"); // Then assertTrue(context.HaveWeContactedInstance(requestOne)); // When // Instance 3 says we have contacted it context.AddContactingInstance(requestTwo, "2, 5, 1"); // Then assertTrue(context.HaveWeContactedInstance(requestTwo)); // When // For some reason we are not in the header of 3 in subsequent responses (a delayed one, for example) context.AddContactingInstance(requestTwo, "2, 5"); // Then // The state should still keep the fact we've contacted it already assertTrue(context.HaveWeContactedInstance(requestTwo)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldDeepClone() public virtual void ShouldDeepClone() { // Given ObjectStreamFactory objStream = new ObjectStreamFactory(); AcceptorInstanceStore acceptorInstances = mock(typeof(AcceptorInstanceStore)); Executor executor = mock(typeof(Executor)); Timeouts timeouts = mock(typeof(Timeouts)); ClusterConfiguration clusterConfig = new ClusterConfiguration("myCluster", NullLogProvider.Instance); ElectionCredentialsProvider electionCredentials = mock(typeof(ElectionCredentialsProvider)); Config config = mock(typeof(Config)); when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10); MultiPaxosContext ctx = new MultiPaxosContext(new InstanceId(1), Collections.emptyList(), clusterConfig, executor, NullLogProvider.Instance, objStream, objStream, acceptorInstances, timeouts, electionCredentials, config); // When MultiPaxosContext snapshot = ctx.Snapshot(NullLogProvider.Instance, timeouts, executor, acceptorInstances, objStream, objStream, electionCredentials); // Then assertEquals(ctx, snapshot); }
public virtual AtomicBroadcastContextImpl Snapshot(CommonContextState commonStateSnapshot, LogProvider logging, Timeouts timeouts, Executor executor, HeartbeatContext heartbeatContext) { return(new AtomicBroadcastContextImpl(Me, commonStateSnapshot, logging, timeouts, executor, heartbeatContext)); }
internal AtomicBroadcastContextImpl(Org.Neo4j.cluster.InstanceId me, CommonContextState commonState, LogProvider logging, Timeouts timeouts, Executor executor, HeartbeatContext heartbeatContext) : base(me, commonState, logging, timeouts) { this._executor = executor; this._heartbeatContext = heartbeatContext; }
/// <summary> /// Sets up the supporting infrastructure and communication hooks for our state machines. This is here to support /// an external requirement for assembling protocol servers given an existing set of state machines (used to prove /// correctness). /// </summary> //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("rawtypes") public ProtocolServer constructSupportingInfrastructureFor(InstanceId me, org.neo4j.cluster.com.message.MessageSource input, org.neo4j.cluster.com.message.MessageSender output, DelayedDirectExecutor executor, org.neo4j.cluster.timeout.Timeouts timeouts, java.util.concurrent.Executor stateMachineExecutor, final org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext context, org.neo4j.cluster.statemachine.StateMachine[] machines) //JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: public virtual ProtocolServer ConstructSupportingInfrastructureFor(InstanceId me, MessageSource input, MessageSender output, DelayedDirectExecutor executor, Timeouts timeouts, Executor stateMachineExecutor, MultiPaxosContext context, StateMachine[] machines) { StateMachines stateMachines = new StateMachines(_logging, _stateMachinesMonitor, input, output, timeouts, executor, stateMachineExecutor, me); foreach (StateMachine machine in machines) { stateMachines.AddStateMachine(machine); } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final ProtocolServer server = new ProtocolServer(me, stateMachines, logging); ProtocolServer server = new ProtocolServer(me, stateMachines, _logging); server.AddBindingListener(me1 => context.ClusterContext.setBoundAt(me1)); stateMachines.AddMessageProcessor(new HeartbeatRefreshProcessor(stateMachines.Outgoing, context.ClusterContext)); input.AddMessageProcessor(new HeartbeatIAmAliveProcessor(stateMachines.Outgoing, context.ClusterContext)); Cluster cluster = server.NewClient(typeof(Cluster)); cluster.AddClusterListener(new HeartbeatJoinListener(stateMachines.Outgoing)); cluster.AddClusterListener(new HeartbeatLeftListener(context.HeartbeatContext, _logging)); context.HeartbeatContext.addHeartbeatListener(new HeartbeatReelectionListener(server.NewClient(typeof(Election)), _logging)); context.ClusterContext.addClusterListener(new ClusterLeaveReelectionListener(server.NewClient(typeof(Election)), _logging)); StateMachineRules rules = (new StateMachineRules(stateMachines.Outgoing)).rule(ClusterState.start, ClusterMessage.create, ClusterState.entered, @internal(AtomicBroadcastMessage.entered), @internal(ProposerMessage.join), @internal(AcceptorMessage.join), @internal(LearnerMessage.join), @internal(HeartbeatMessage.join), @internal(ElectionMessage.created), @internal(SnapshotMessage.join)).rule(ClusterState.discovery, ClusterMessage.configurationResponse, ClusterState.joining, @internal(AcceptorMessage.join), @internal(LearnerMessage.join), @internal(AtomicBroadcastMessage.join)).rule(ClusterState.discovery, ClusterMessage.configurationResponse, ClusterState.entered, @internal(AtomicBroadcastMessage.entered), @internal(ProposerMessage.join), @internal(AcceptorMessage.join), @internal(LearnerMessage.join), @internal(HeartbeatMessage.join), @internal(ElectionMessage.join), @internal(SnapshotMessage.join)).rule(ClusterState.joining, ClusterMessage.configurationChanged, ClusterState.entered, @internal(AtomicBroadcastMessage.entered), @internal(ProposerMessage.join), @internal(AcceptorMessage.join), @internal(LearnerMessage.join), @internal(HeartbeatMessage.join), @internal(ElectionMessage.join), @internal(SnapshotMessage.join)).rule(ClusterState.joining, ClusterMessage.joinFailure, ClusterState.start, @internal(AtomicBroadcastMessage.leave), @internal(AcceptorMessage.leave), @internal(LearnerMessage.leave), @internal(ProposerMessage.leave)).rule(ClusterState.entered, ClusterMessage.leave, ClusterState.start, @internal(AtomicBroadcastMessage.leave), @internal(AcceptorMessage.leave), @internal(LearnerMessage.leave), @internal(HeartbeatMessage.leave), @internal(SnapshotMessage.leave), @internal(ElectionMessage.leave), @internal(ProposerMessage.leave)).rule(ClusterState.entered, ClusterMessage.leave, ClusterState.start, @internal(AtomicBroadcastMessage.leave), @internal(AcceptorMessage.leave), @internal(LearnerMessage.leave), @internal(HeartbeatMessage.leave), @internal(ElectionMessage.leave), @internal(SnapshotMessage.leave), @internal(ProposerMessage.leave)).rule(ClusterState.leaving, ClusterMessage.configurationChanged, ClusterState.start, @internal(AtomicBroadcastMessage.leave), @internal(AcceptorMessage.leave), @internal(LearnerMessage.leave), @internal(HeartbeatMessage.leave), @internal(ElectionMessage.leave), @internal(SnapshotMessage.leave), @internal(ProposerMessage.leave)).rule(ClusterState.leaving, ClusterMessage.leaveTimedout, ClusterState.start, @internal(AtomicBroadcastMessage.leave), @internal(AcceptorMessage.leave), @internal(LearnerMessage.leave), @internal(HeartbeatMessage.leave), @internal(ElectionMessage.leave), @internal(SnapshotMessage.leave), @internal(ProposerMessage.leave)); stateMachines.AddStateTransitionListener(rules); return(server); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") public ProtocolServer newProtocolServer(InstanceId me, org.neo4j.cluster.com.message.MessageSource input, org.neo4j.cluster.com.message.MessageSender output, java.util.concurrent.Executor stateMachineExecutor, DelayedDirectExecutor executor, org.neo4j.cluster.timeout.Timeouts timeouts, org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext context, org.neo4j.cluster.protocol.snapshot.SnapshotContext snapshotContext) public virtual ProtocolServer NewProtocolServer(InstanceId me, MessageSource input, MessageSender output, Executor stateMachineExecutor, DelayedDirectExecutor executor, Timeouts timeouts, MultiPaxosContext context, SnapshotContext snapshotContext) { return(ConstructSupportingInfrastructureFor(me, input, output, executor, timeouts, stateMachineExecutor, context, new StateMachine[] { new StateMachine(context.AtomicBroadcastContext, typeof(AtomicBroadcastMessage), AtomicBroadcastState.start, _logging), new StateMachine(context.AcceptorContext, typeof(AcceptorMessage), AcceptorState.start, _logging), new StateMachine(context.ProposerContext, typeof(ProposerMessage), ProposerState.start, _logging), new StateMachine(context.LearnerContext, typeof(LearnerMessage), LearnerState.start, _logging), new StateMachine(context.HeartbeatContext, typeof(HeartbeatMessage), HeartbeatState.start, _logging), new StateMachine(context.ElectionContext, typeof(ElectionMessage), ElectionState.start, _logging), new StateMachine(snapshotContext, typeof(SnapshotMessage), SnapshotState.start, _logging), new StateMachine(context.ClusterContext, typeof(ClusterMessage), ClusterState.start, _logging) })); }
public virtual AcceptorContextImpl Snapshot(CommonContextState commonStateSnapshot, LogProvider logging, Timeouts timeouts, AcceptorInstanceStore instanceStore) { return(new AcceptorContextImpl(Me, commonStateSnapshot, logging, timeouts, instanceStore)); }
internal AcceptorContextImpl(Org.Neo4j.cluster.InstanceId me, CommonContextState commonState, LogProvider logging, Timeouts timeouts, AcceptorInstanceStore instanceStore) : base(me, commonState, logging, timeouts) { this._instanceStore = instanceStore; }