Пример #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 shouldSendAtomicBroadcastOnJoiningAClusterWithAnEstablishedCoordinator() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSendAtomicBroadcastOnJoiningAClusterWithAnEstablishedCoordinator()
        {
            // Given
            string     winnerURI = "some://winner";
            InstanceId winner    = new InstanceId(2);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<org.neo4j.cluster.com.message.Message<?>> messages = new java.util.ArrayList<>(1);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
            IList <Message <object> > messages = new List <Message <object> >(1);
            MessageHolder             holder   = messages.add;
            ElectionCredentials       voteCredentialComparable = mock(typeof(ElectionCredentials));

            ElectionContext electionContext = mock(typeof(ElectionContext));

            when(electionContext.Voted(eq(COORDINATOR), eq(new InstanceId(1)), eq(voteCredentialComparable), anyLong())).thenReturn(true);
            when(electionContext.GetVoteCount(COORDINATOR)).thenReturn(3);
            when(electionContext.NeededVoteCount).thenReturn(3);
            when(electionContext.GetElectionWinner(COORDINATOR)).thenReturn(winner);

            when(electionContext.GetLog(any(typeof(Type)))).thenReturn(NullLog.Instance);
            VersionedConfigurationStateChange stateChange = mock(typeof(VersionedConfigurationStateChange));

            when(electionContext.NewConfigurationStateChange()).thenReturn(stateChange);

            when(electionContext.GetUriForId(winner)).thenReturn(URI.create(winnerURI));

            // When
            Message <ElectionMessage> votedMessage = Message.to(ElectionMessage.Voted, URI.create("some://instance"), new ElectionMessage.VotedData(COORDINATOR, new InstanceId(1), voteCredentialComparable));

            votedMessage.SetHeader(Message.HEADER_FROM, "some://other");

            election.handle(electionContext, votedMessage, holder);

            // Then
            assertEquals(1, messages.Count);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.cluster.com.message.Message<?> message = messages.get(0);
            Message <object> message = messages[0];

            assertEquals(AtomicBroadcastMessage.broadcast, message.MessageType);
        }