Esempio n. 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testElectionVersionIsResetWhenElectorChangesFromMeToOther()
        public virtual void TestElectionVersionIsResetWhenElectorChangesFromMeToOther()
        {
            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);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.cluster.InstanceId elector = new org.neo4j.cluster.InstanceId(2);
            InstanceId       elector          = 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.LastElectorVersion = 5;
            context.LastElector        = me;
            context.AddClusterListener(listener);

            long expectedVersion = electionContext.NewConfigurationStateChange().Version;

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

            context.Elected(coordinatorRole, winner, elector, 2);
            verify(listener, times(2)).elected(coordinatorRole, winner, null);

            context.Elected(coordinatorRole, winner, elector, 3);
            verify(listener, times(3)).elected(coordinatorRole, winner, null);

            context.Elected(coordinatorRole, winner, elector, 2);
            verifyNoMoreInteractions(listener);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        /*
         * This assumes an instance leaves the cluster normally and then rejoins, without any elections in between. The
         * expected result is that it will succeed in sending election results.
         */
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void electorLeavingAndRejoiningWithNoElectionsInBetweenMustStillHaveElectionsGoThrough()
        public virtual void ElectorLeavingAndRejoiningWithNoElectionsInBetweenMustStillHaveElectionsGoThrough()
        {
            // Given
            const string role1           = "coordinator1";
            InstanceId   me              = new InstanceId(1);
            InstanceId   leavingInstance = 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(leavingInstance);
            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);

            ClusterContext clusterContext = context.ClusterContext;

            clusterContext.LastElector        = leavingInstance;
            clusterContext.LastElectorVersion = 8;

            // When the elector leaves the cluster
            clusterContext.Left(leavingInstance);

            // 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
            // We don't need to join, election results do not check for elector membership
            clusterContext.Elected(role1, forQuorum, leavingInstance, 9);

            // Then the result is actually respected
            assertEquals(clusterContext.LastElector, leavingInstance);
            assertEquals(clusterContext.LastElectorVersion, 9);
        }