Exemplo n.º 1
0
//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());
        }
Exemplo n.º 2
0
 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>();
 }
Exemplo n.º 3
0
 internal AbstractContextImpl(InstanceId me, CommonContextState commonState, LogProvider logProvider, Timeouts timeouts)
 {
     this.Me          = me;
     this.CommonState = commonState;
     this.LogProvider = logProvider;
     this.Timeouts    = timeouts;
 }
Exemplo n.º 4
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null || this.GetType() != o.GetType())
            {
                return(false);
            }

            CommonContextState that = ( CommonContextState )o;

            if (_lastKnownLearnedInstanceInCluster != that._lastKnownLearnedInstanceInCluster)
            {
                return(false);
            }
            if (_nextInstanceId != that._nextInstanceId)
            {
                return(false);
            }
            if (_boundAt != null ?!_boundAt.Equals(that._boundAt) : that._boundAt != null)
            {
                return(false);
            }
            return(_configuration != null?_configuration.Equals(that._configuration) : that._configuration == null);
        }
Exemplo n.º 5
0
 private HeartbeatContextImpl(InstanceId me, CommonContextState commonState, LogProvider logging, Timeouts timeouts, ISet <InstanceId> failed, IDictionary <InstanceId, ISet <InstanceId> > nodeSuspicions, Listeners <HeartbeatListener> heartBeatListeners, Executor executor) : base(me, commonState, logging, timeouts)
 {
     this._failed             = failed;
     this._nodeSuspicions     = nodeSuspicions;
     this._heartBeatListeners = heartBeatListeners;
     this._executor           = executor;
 }
Exemplo n.º 6
0
//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));
        }
Exemplo n.º 7
0
//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
        }
Exemplo n.º 8
0
        /*
         * 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);
        }
Exemplo n.º 9
0
 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;
 }
Exemplo n.º 10
0
        /*
         * 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);
        }
Exemplo n.º 11
0
//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());
        }
Exemplo n.º 12
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);
 }
Exemplo n.º 13
0
 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));
 }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
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;
 }
Exemplo n.º 16
0
        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));
        }
Exemplo n.º 17
0
 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;
 }
Exemplo n.º 18
0
//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));
        }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
0
        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);
        }
Exemplo n.º 21
0
//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));
        }
Exemplo n.º 22
0
        /// <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));
        }
Exemplo n.º 23
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHasQuorumWhenOneMachineAliveInAClusterWithOneMachine()
        public virtual void ShouldHasQuorumWhenOneMachineAliveInAClusterWithOneMachine()
        {
            //Given
            HeartbeatContext     heartbeatContext = mock(typeof(HeartbeatContext));
            CommonContextState   commonState      = mock(typeof(CommonContextState));
            ClusterConfiguration configuration    = mock(typeof(ClusterConfiguration));

            when(heartbeatContext.Alive).thenReturn(ids(1));
            when(commonState.Configuration()).thenReturn(configuration);
            when(configuration.Members).thenReturn(members(1));

            AtomicBroadcastContextImpl context = new AtomicBroadcastContextImpl(null, commonState, null, null, null, heartbeatContext);                 // we do not care about other args
            //When
            bool hasQuorum = context.HasQuorum();

            //Then
            assertTrue(hasQuorum);
        }
Exemplo n.º 24
0
        /*
         * 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);
        }
Exemplo n.º 25
0
 public virtual AtomicBroadcastContextImpl Snapshot(CommonContextState commonStateSnapshot, LogProvider logging, Timeouts timeouts, Executor executor, HeartbeatContext heartbeatContext)
 {
     return(new AtomicBroadcastContextImpl(Me, commonStateSnapshot, logging, timeouts, executor, heartbeatContext));
 }
Exemplo n.º 26
0
 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;
 }
Exemplo n.º 27
0
 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));
 }
Exemplo n.º 28
0
 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));
 }
Exemplo n.º 29
0
 internal HeartbeatContextImpl(InstanceId me, CommonContextState commonState, LogProvider logging, Timeouts timeouts, Executor executor) : base(me, commonState, logging, timeouts)
 {
     this._executor           = executor;
     this._heartBeatListeners = new Listeners <HeartbeatListener>();
 }
Exemplo n.º 30
0
 public virtual HeartbeatContextImpl Snapshot(CommonContextState commonStateSnapshot, LogProvider logging, Timeouts timeouts, Executor executor)
 {
     return(new HeartbeatContextImpl(Me, commonStateSnapshot, logging, timeouts, new HashSet <>(_failed), new Dictionary <>(_nodeSuspicions), new Listeners <>(_heartBeatListeners), executor));
 }