//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 cleanly leaves the cluster but is not the elector has no effect on * elector id and last version */ //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void nonElectorLeavingTheClusterMustNotAffectElectorInformation() public virtual void NonElectorLeavingTheClusterMustNotAffectElectorInformation() { // Given InstanceId me = new InstanceId(1); InstanceId elector = new InstanceId(2); InstanceId other = new InstanceId(3); ClusterConfiguration clusterConfiguration = mock(typeof(ClusterConfiguration)); when(clusterConfiguration.GetUriForId(other)).thenReturn(URI.create("cluster://instance2")); CommonContextState commonContextState = mock(typeof(CommonContextState)); when(commonContextState.Configuration()).thenReturn(clusterConfiguration); ClusterContext context = new ClusterContextImpl(me, commonContextState, NullLogProvider.Instance, mock(typeof(Timeouts)), mock(typeof(Executor)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(ObjectInputStreamFactory)), mock(typeof(LearnerContext)), mock(typeof(HeartbeatContext)), mock(typeof(Config))); // This means instance 2 was the elector at version 8 context.LastElector = elector; context.LastElectorVersion = 8; // When context.Left(other); // Then assertEquals(context.LastElector, elector); assertEquals(context.LastElectorVersion, 8); }
//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()); }
/* * 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); }
private MultiPaxosContext(ProposerContextImpl proposerContext, AcceptorContextImpl acceptorContext, LearnerContextImpl learnerContext, HeartbeatContextImpl heartbeatContext, ElectionContextImpl electionContext, AtomicBroadcastContextImpl atomicBroadcastContext, CommonContextState commonState, PaxosInstanceStore paxosInstances, ClusterContextImpl clusterContext) { this._clusterContext = clusterContext; this._proposerContext = proposerContext; this._acceptorContext = acceptorContext; this._learnerContext = learnerContext; this._heartbeatContext = heartbeatContext; this._electionContext = electionContext; this._atomicBroadcastContext = atomicBroadcastContext; this._commonState = commonState; this._paxosInstances = paxosInstances; }
public MultiPaxosContext(InstanceId me, IEnumerable <ElectionRole> roles, ClusterConfiguration configuration, Executor executor, LogProvider logging, ObjectInputStreamFactory objectInputStreamFactory, ObjectOutputStreamFactory objectOutputStreamFactory, AcceptorInstanceStore instanceStore, Timeouts timeouts, ElectionCredentialsProvider electionCredentialsProvider, Config config) { _commonState = new CommonContextState(configuration, config.Get(ClusterSettings.max_acceptors)); _paxosInstances = new PaxosInstanceStore(); _heartbeatContext = new HeartbeatContextImpl(me, _commonState, logging, timeouts, executor); _learnerContext = new LearnerContextImpl(me, _commonState, logging, timeouts, _paxosInstances, instanceStore, objectInputStreamFactory, objectOutputStreamFactory, _heartbeatContext); _clusterContext = new ClusterContextImpl(me, _commonState, logging, timeouts, executor, objectOutputStreamFactory, objectInputStreamFactory, _learnerContext, _heartbeatContext, config); _electionContext = new ElectionContextImpl(me, _commonState, logging, timeouts, roles, _clusterContext, _heartbeatContext, electionCredentialsProvider); _proposerContext = new ProposerContextImpl(me, _commonState, logging, timeouts, _paxosInstances, _heartbeatContext); _acceptorContext = new AcceptorContextImpl(me, _commonState, logging, timeouts, instanceStore); _atomicBroadcastContext = new AtomicBroadcastContextImpl(me, _commonState, logging, timeouts, executor, _heartbeatContext); _heartbeatContext.setCircularDependencies(_clusterContext, _learnerContext); }
//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)); }
/// <summary> /// Create a state snapshot. The snapshot will not duplicate services, and expects the caller to duplicate /// <seealso cref="AcceptorInstanceStore"/>, since that is externally provided. /// </summary> public virtual MultiPaxosContext Snapshot(LogProvider logging, Timeouts timeouts, Executor executor, AcceptorInstanceStore instanceStore, ObjectInputStreamFactory objectInputStreamFactory, ObjectOutputStreamFactory objectOutputStreamFactory, ElectionCredentialsProvider electionCredentialsProvider) { CommonContextState commonStateSnapshot = _commonState.snapshot(logging.GetLog(typeof(ClusterConfiguration))); PaxosInstanceStore paxosInstancesSnapshot = _paxosInstances.snapshot(); HeartbeatContextImpl snapshotHeartbeatContext = _heartbeatContext.snapshot(commonStateSnapshot, logging, timeouts, executor); LearnerContextImpl snapshotLearnerContext = _learnerContext.snapshot(commonStateSnapshot, logging, timeouts, paxosInstancesSnapshot, instanceStore, objectInputStreamFactory, objectOutputStreamFactory, snapshotHeartbeatContext); ClusterContextImpl snapshotClusterContext = _clusterContext.snapshot(commonStateSnapshot, logging, timeouts, executor, objectOutputStreamFactory, objectInputStreamFactory, snapshotLearnerContext, snapshotHeartbeatContext); ElectionContextImpl snapshotElectionContext = _electionContext.snapshot(commonStateSnapshot, logging, timeouts, snapshotClusterContext, snapshotHeartbeatContext, electionCredentialsProvider); ProposerContextImpl snapshotProposerContext = _proposerContext.snapshot(commonStateSnapshot, logging, timeouts, paxosInstancesSnapshot, _heartbeatContext); AcceptorContextImpl snapshotAcceptorContext = _acceptorContext.snapshot(commonStateSnapshot, logging, timeouts, instanceStore); AtomicBroadcastContextImpl snapshotAtomicBroadcastContext = _atomicBroadcastContext.snapshot(commonStateSnapshot, logging, timeouts, executor, snapshotHeartbeatContext); snapshotHeartbeatContext.SetCircularDependencies(snapshotClusterContext, snapshotLearnerContext); return(new MultiPaxosContext(snapshotProposerContext, snapshotAcceptorContext, snapshotLearnerContext, snapshotHeartbeatContext, snapshotElectionContext, snapshotAtomicBroadcastContext, commonStateSnapshot, paxosInstancesSnapshot, snapshotClusterContext)); }
/* * This test ensures that an instance that enters the cluster has its elector version reset. That means that * if it was the elector before its version is now reset so results can be applied. This and the previous tests * actually perform the same things at different events, one covering for the other. */ //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void instanceEnteringTheClusterMustBeRemovedAsElector() public virtual void InstanceEnteringTheClusterMustBeRemovedAsElector() { // Given InstanceId me = new InstanceId(1); InstanceId elector = new InstanceId(2); CommonContextState commonContextState = mock(typeof(CommonContextState), RETURNS_MOCKS); ClusterContext context = new ClusterContextImpl(me, commonContextState, NullLogProvider.Instance, mock(typeof(Timeouts)), mock(typeof(Executor)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(ObjectInputStreamFactory)), mock(typeof(LearnerContext)), mock(typeof(HeartbeatContext)), mock(typeof(Config))); // This means instance 2 was the elector at version 8 context.LastElector = elector; context.LastElectorVersion = 8; // When context.Joined(elector, URI.create("cluster://elector")); // Then assertEquals(context.LastElector, InstanceId.NONE); assertEquals(context.LastElectorVersion, -1); }
public override bool Equals(object o) { if (this == o) { return(true); } if (o == null || this.GetType() != o.GetType()) { return(false); } ClusterContextImpl that = ( ClusterContextImpl )o; if (_currentlyJoiningInstances != null ?!_currentlyJoiningInstances.Equals(that._currentlyJoiningInstances) : that._currentlyJoiningInstances != null) { return(false); } //JAVA TO C# CONVERTER WARNING: LINQ 'SequenceEqual' is not always identical to Java AbstractList 'equals': //ORIGINAL LINE: if (discoveredInstances != null ? !discoveredInstances.equals(that.discoveredInstances) : that.discoveredInstances != null) if (_discoveredInstances != null ?!_discoveredInstances.SequenceEqual(that._discoveredInstances) : that._discoveredInstances != null) { return(false); } if (_heartbeatContext != null ?!_heartbeatContext.Equals(that._heartbeatContext) : that._heartbeatContext != null) { return(false); } if (_joinDeniedConfigurationResponseState != null ?!_joinDeniedConfigurationResponseState.Equals(that._joinDeniedConfigurationResponseState) : that._joinDeniedConfigurationResponseState != null) { return(false); } if (_joiningInstances != null ?!_joiningInstances.Equals(that._joiningInstances) : that._joiningInstances != null) { return(false); } return(_learnerContext != null?_learnerContext.Equals(that._learnerContext) : that._learnerContext == null); }
public virtual ElectionContextImpl Snapshot(CommonContextState commonStateSnapshot, LogProvider logging, Timeouts timeouts, ClusterContextImpl snapshotClusterContext, HeartbeatContextImpl snapshotHeartbeatContext, ElectionCredentialsProvider credentialsProvider) { IDictionary <string, Election> electionsSnapshot = new Dictionary <string, Election>(); foreach (KeyValuePair <string, Election> election in _elections.SetOfKeyValuePairs()) { electionsSnapshot[election.Key] = election.Value.snapshot(); } return(new ElectionContextImpl(Me, commonStateSnapshot, logging, timeouts, snapshotClusterContext, snapshotHeartbeatContext, new List <ElectionRole>(_roles), electionsSnapshot, credentialsProvider)); }
public HeartbeatListener_AdapterAnonymousInnerClass(ClusterContextImpl outerInstance) { this.outerInstance = outerInstance; }