Exemple #1
0
//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);
        }
Exemple #2
0
//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));
        }