示例#1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testElectionVersionIsUpdatedOnElectionFromSelfAndProperlyIgnoredIfOld()
        public virtual void TestElectionVersionIsUpdatedOnElectionFromSelfAndProperlyIgnoredIfOld()
        {
            const string coordinatorRole = "coordinator";
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.cluster.InstanceId me = new org.neo4j.cluster.InstanceId(1);
            InstanceId me = new InstanceId(1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.cluster.InstanceId winner = new org.neo4j.cluster.InstanceId(2);
            InstanceId       winner           = new InstanceId(2);
            HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext));

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

            Config config = mock(typeof(Config));

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

            MultiPaxosContext multiPaxosContext = new MultiPaxosContext(me, Iterables.iterable(new ElectionRole(coordinatorRole)), mock(typeof(ClusterConfiguration)), ThreadStart.run, NullLogProvider.Instance, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config);
            ClusterContext    context           = multiPaxosContext.ClusterContext;
            ElectionContext   electionContext   = multiPaxosContext.ElectionContext;

            ClusterListener listener = mock(typeof(ClusterListener));

            context.AddClusterListener(listener);

            electionContext.ForgetElection(coordinatorRole);
            long expectedVersion = electionContext.NewConfigurationStateChange().Version;

            context.Elected(coordinatorRole, winner, me, expectedVersion);
            assertEquals(1, expectedVersion);
            verify(listener, times(1)).elected(coordinatorRole, winner, null);

            electionContext.ForgetElection(coordinatorRole);
            expectedVersion = electionContext.NewConfigurationStateChange().Version;
            context.Elected(coordinatorRole, winner, me, expectedVersion);
            assertEquals(2, expectedVersion);
            verify(listener, times(2)).elected(coordinatorRole, winner, null);

            context.Elected(coordinatorRole, winner, me, expectedVersion - 1);
            verifyNoMoreInteractions(listener);
        }
示例#2
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);
        }
示例#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));
        }