Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void electionBeingForgottenMustIncreaseElectionId()
        public virtual void ElectionBeingForgottenMustIncreaseElectionId()
        {
            // Given
            const string     coordinatorRole  = "coordinator";
            HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext));

            when(heartbeatContext.Failed).thenReturn(Collections.emptySet());

            Config config = mock(typeof(Config));

            when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10);

            ElectionContext context = (new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole(coordinatorRole)), mock(typeof(ClusterConfiguration)), mock(typeof(Executor)), NullLogProvider.Instance, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config)).ElectionContext;

            ElectionContext_VoteRequest voteRequestBefore = context.VoteRequestForRole(new ElectionRole(coordinatorRole));

            context.ForgetElection(coordinatorRole);
            ElectionContext_VoteRequest voteRequestAfter = context.VoteRequestForRole(new ElectionRole(coordinatorRole));

            assertEquals(voteRequestBefore.Version + 1, voteRequestAfter.Version);
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void electionShouldRemainLocalIfStartedBySingleInstanceWhichIsTheRoleHolder() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ElectionShouldRemainLocalIfStartedBySingleInstanceWhichIsTheRoleHolder()
        {
            /*
             * Ensures that when an instance is alone in the cluster, elections for roles that it holds do not set
             * timeouts or try to reach other instances.
             */

            // Given
            ElectionContext context            = mock(typeof(ElectionContext));
            ClusterContext  clusterContextMock = mock(typeof(ClusterContext));

            when(clusterContextMock.GetLog(ArgumentMatchers.any())).thenReturn(NullLog.Instance);
            MessageHolder holder = mock(typeof(MessageHolder));

            // These mean the election can proceed normally, by us
            when(context.ElectionOk()).thenReturn(true);
            when(context.InCluster).thenReturn(true);
            when(context.Elector).thenReturn(true);

            // Like it says on the box, we are the only instance
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.cluster.InstanceId myInstanceId = new org.neo4j.cluster.InstanceId(1);
            InstanceId myInstanceId = new InstanceId(1);
            IDictionary <InstanceId, URI> members = new Dictionary <InstanceId, URI>();

            members[myInstanceId] = URI.create("ha://me");
            when(context.Members).thenReturn(members);

            // Any role would do, just make sure we have it
            const string role = "master";
            ElectionContext_VoteRequest voteRequest = new ElectionContext_VoteRequest(role, 13);

            when(context.PossibleRoles).thenReturn(Collections.singletonList(new ElectionRole(role)));
            when(context.GetElected(role)).thenReturn(myInstanceId);
            when(context.VoteRequestForRole(new ElectionRole(role))).thenReturn(voteRequest);

            // Required for logging
            when(context.GetLog(Mockito.any())).thenReturn(NullLog.Instance);

            // When
            election.handle(context, Message.@internal(performRoleElections), holder);

            // Then
            // Make sure that we asked ourselves to vote for that role and that no timer was set
            verify(holder, times(1)).offer(ArgumentMatchers.argThat(new MessageArgumentMatcher <ElectionMessage>()
                                                                    .onMessageType(ElectionMessage.Vote).withPayload(voteRequest)));
            verify(context, never()).setTimeout(ArgumentMatchers.any(), ArgumentMatchers.any());
        }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void voteFromPreviousSuccessfulElectionMustNotBeCounted()
        public virtual void VoteFromPreviousSuccessfulElectionMustNotBeCounted()
        {
            // Given
            const string     coordinatorRole  = "coordinator";
            HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext));

            when(heartbeatContext.Failed).thenReturn(Collections.emptySet());

            Config config = mock(typeof(Config));

            when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10);

            ElectionContext context = (new MultiPaxosContext(new InstanceId(1), Iterables.iterable(new ElectionRole(coordinatorRole)), mock(typeof(ClusterConfiguration)), mock(typeof(Executor)), NullLogProvider.Instance, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config)).ElectionContext;

            // When
            ElectionContext_VoteRequest voteRequestBefore = context.VoteRequestForRole(new ElectionRole(coordinatorRole));

            context.ForgetElection(coordinatorRole);

            // Then
            assertFalse(context.Voted(coordinatorRole, new InstanceId(2), null, voteRequestBefore.Version - 1));
        }