//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void majorityOfNonSuspectedInstancesShouldBeEnoughToMarkAnInstanceAsFailed() public virtual void MajorityOfNonSuspectedInstancesShouldBeEnoughToMarkAnInstanceAsFailed() { // Given InstanceId me = new InstanceId(1); InstanceId member2 = new InstanceId(2); InstanceId member3 = new InstanceId(3); InstanceId member4 = new InstanceId(4); InstanceId member5 = new InstanceId(5); Timeouts timeouts = mock(typeof(Timeouts)); CommonContextState commonState = mock(typeof(CommonContextState)); ClusterConfiguration configuration = mock(typeof(ClusterConfiguration)); when(commonState.Configuration()).thenReturn(configuration); when(configuration.Members).thenReturn(members(5)); when(configuration.MemberIds).thenReturn(ids(5)); DelayedDirectExecutor executor = new DelayedDirectExecutor(NullLogProvider.Instance); HeartbeatContext context = new HeartbeatContextImpl(me, commonState, NullLogProvider.Instance, timeouts, executor); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.List<org.neo4j.cluster.InstanceId> failed = new java.util.ArrayList<>(4); IList <InstanceId> failed = new List <InstanceId>(4); HeartbeatListener listener = new HeartbeatListenerAnonymousInnerClass2(this, failed); context.AddHeartbeatListener(listener); // when // just two suspicions come, no extra failing action should be taken since this is not majority context.Suspect(member2); context.Suspect(member3); executor.Drain(); // then assertEquals(0, failed.Count); // when // the another instance suspects them, therefore have a majority of non suspected, then 2 and 3 must fail ISet <InstanceId> suspicionsFrom5 = new HashSet <InstanceId>(); suspicionsFrom5.Add(member2); suspicionsFrom5.Add(member3); context.Suspicions(member5, suspicionsFrom5); executor.Drain(); // then assertEquals(2, failed.Count); assertTrue(failed.Contains(member2)); assertTrue(failed.Contains(member3)); // when // an instance sends a heartbeat, it should be set as alive context.Alive(member2); executor.Drain(); // then assertEquals(1, failed.Count); assertTrue(failed.Contains(member3)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldFailAndAliveBothNotifyHeartbeatListenerInDelayedDirectExecutor() public virtual void ShouldFailAndAliveBothNotifyHeartbeatListenerInDelayedDirectExecutor() { // Given InstanceId me = new InstanceId(1); InstanceId failedMachine = new InstanceId(2); InstanceId goodMachine = new InstanceId(3); Timeouts timeouts = mock(typeof(Timeouts)); CommonContextState commonState = mock(typeof(CommonContextState)); ClusterConfiguration configuration = mock(typeof(ClusterConfiguration)); when(commonState.Configuration()).thenReturn(configuration); when(configuration.Members).thenReturn(members(3)); when(configuration.MemberIds).thenReturn(ids(3)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.List<Runnable> runnables = new java.util.ArrayList<>(); IList <ThreadStart> runnables = new List <ThreadStart>(); HeartbeatContext context = new HeartbeatContextImpl(me, commonState, NullLogProvider.Instance, timeouts, new DelayedDirectExecutorAnonymousInnerClass(this, NullLogProvider.Instance, runnables)); context.AddHeartbeatListener(mock(typeof(HeartbeatListener))); context.Suspicions(goodMachine, new HashSet <InstanceId>(singletonList(failedMachine))); context.Suspect(failedMachine); // fail context.Alive(failedMachine); // alive // Then assertEquals(2, runnables.Count); // fail + alive }
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; }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldFailAllInstancesIfAllOtherInstancesAreSuspected() public virtual void ShouldFailAllInstancesIfAllOtherInstancesAreSuspected() { // Given InstanceId me = new InstanceId(1); InstanceId member2 = new InstanceId(2); InstanceId member3 = new InstanceId(3); Timeouts timeouts = mock(typeof(Timeouts)); CommonContextState commonState = mock(typeof(CommonContextState)); ClusterConfiguration configuration = mock(typeof(ClusterConfiguration)); when(commonState.Configuration()).thenReturn(configuration); when(configuration.Members).thenReturn(members(3)); when(configuration.MemberIds).thenReturn(ids(3)); DelayedDirectExecutor executor = new DelayedDirectExecutor(NullLogProvider.Instance); HeartbeatContext context = new HeartbeatContextImpl(me, commonState, NullLogProvider.Instance, timeouts, executor); IList <InstanceId> failed = new List <InstanceId>(2); HeartbeatListener listener = new HeartbeatListenerAnonymousInnerClass(this, failed); context.AddHeartbeatListener(listener); // when // just one suspicion comes, no extra failing action should be taken context.Suspect(member2); executor.Drain(); // then assertEquals(0, failed.Count); // when // the other instance is suspected, all instances must be marked as failed context.Suspect(member3); executor.Drain(); // then assertEquals(2, failed.Count); assertTrue(failed.Contains(member2)); assertTrue(failed.Contains(member3)); // when // one of them comes alive again, only that instance should be marked as alive context.Alive(member2); executor.Drain(); // then assertEquals(1, failed.Count); assertTrue(failed.Contains(member3)); }
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); }
/// <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)); }
public override bool Equals(object o) { if (this == o) { return(true); } if (o == null || this.GetType() != o.GetType()) { return(false); } HeartbeatContextImpl that = ( HeartbeatContextImpl )o; if (_failed != null ?!_failed.SetEquals(that._failed) : that._failed != null) { return(false); } return(_nodeSuspicions != null?_nodeSuspicions.Equals(that._nodeSuspicions) : that._nodeSuspicions == 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 virtual LearnerContextImpl Snapshot(CommonContextState commonStateSnapshot, LogProvider logging, Timeouts timeouts, PaxosInstanceStore paxosInstancesSnapshot, AcceptorInstanceStore instanceStore, ObjectInputStreamFactory objectInputStreamFactory, ObjectOutputStreamFactory objectOutputStreamFactory, HeartbeatContextImpl snapshotHeartbeatContext) { return(new LearnerContextImpl(Me, commonStateSnapshot, logging, timeouts, _lastDeliveredInstanceId, _lastLearnedInstanceId, snapshotHeartbeatContext, instanceStore, objectInputStreamFactory, objectOutputStreamFactory, paxosInstancesSnapshot)); }
public virtual ClusterContextImpl Snapshot(CommonContextState commonStateSnapshot, LogProvider logging, Timeouts timeouts, Executor executor, ObjectOutputStreamFactory objectOutputStreamFactory, ObjectInputStreamFactory objectInputStreamFactory, LearnerContextImpl snapshotLearnerContext, HeartbeatContextImpl snapshotHeartbeatContext) { return(new ClusterContextImpl(Me, commonStateSnapshot, logging, timeouts, _joiningInstances == null ? null : new List <>(asList(_joiningInstances)), _joinDeniedConfigurationResponseState == null ? null : _joinDeniedConfigurationResponseState.snapshot(), executor, objectOutputStreamFactory, objectInputStreamFactory, snapshotLearnerContext, snapshotHeartbeatContext, _config)); }