Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void delayedVoteFromPreviousElectionMustNotCauseCurrentElectionToComplete() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void DelayedVoteFromPreviousElectionMustNotCauseCurrentElectionToComplete()
        {
            // Given
            ElectionContext context = mock(typeof(ElectionContext));
            MessageHolder   holder  = mock(typeof(MessageHolder));

            when(context.GetLog(Mockito.any())).thenReturn(NullLog.Instance);

            const string role = "master";
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.cluster.InstanceId voter = new org.neo4j.cluster.InstanceId(2);
            InstanceId voter = new InstanceId(2);

            ElectionCredentials       voteCredentialComparable = mock(typeof(ElectionCredentials));
            Message <ElectionMessage> vote = Message.@internal(voted, new ElectionMessage.VersionedVotedData(role, voter, voteCredentialComparable, 4));

            when(context.Voted(role, voter, voteCredentialComparable, 4)).thenReturn(false);

            // When
            election.handle(context, vote, holder);

            verify(context).getLog(ArgumentMatchers.any());
            verify(context).voted(role, voter, voteCredentialComparable, 4);

            // Then
            verifyNoMoreInteractions(context, holder);
        }
Пример #2
0
        public override bool Voted(string role, InstanceId suggestedNode, ElectionCredentials suggestionCredentials, long electionVersion)
        {
            if (!IsElectionProcessInProgress(role) || (electionVersion != -1 && electionVersion < _clusterContext.LastElectorVersion))
            {
                return(false);
            }
            IDictionary <InstanceId, Vote> votes = _elections[role].Votes;

            votes[suggestedNode] = new Vote(suggestedNode, suggestionCredentials);
            return(true);
        }
Пример #3
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);
        }
Пример #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void electionCompletingMakesItBeForgotten() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ElectionCompletingMakesItBeForgotten()
        {
            // Given
            string              coordinatorRole          = "coordinator";
            InstanceId          votingInstance           = new InstanceId(2);
            ElectionCredentials voteCredentialComparable = mock(typeof(ElectionCredentials));

            ElectionContext context = mock(typeof(ElectionContext));

            when(context.GetLog(Mockito.any())).thenReturn(NullLog.Instance);
            when(context.NeededVoteCount).thenReturn(3);
            when(context.GetVoteCount(coordinatorRole)).thenReturn(3);
            when(context.Voted(coordinatorRole, votingInstance, voteCredentialComparable, 4)).thenReturn(true);
            MessageHolder holder = mock(typeof(MessageHolder));

            Message <ElectionMessage> vote = Message.to(ElectionMessage.Voted, URI.create("cluster://elector"), new ElectionMessage.VersionedVotedData(coordinatorRole, votingInstance, voteCredentialComparable, 4));

            // When
            election.handle(context, vote, holder);

            // Then
            verify(context, times(1)).forgetElection(coordinatorRole);
        }
Пример #5
0
 public override int CompareTo(ElectionCredentials o)
 {
     return(-1);
 }
Пример #6
0
 public override int CompareTo(ElectionCredentials o)
 {
     return(o is IntegerElectionCredentials?Integer.compare(_credential, (( IntegerElectionCredentials )o)._credential) : 0);
 }
Пример #7
0
 public override int CompareTo(ElectionCredentials o)
 {
     // Alphabetically lower URI means higher prio
     return(-_credentials.ToString().CompareTo(((ServerIdElectionCredentials)o)._credentials.ToString()));
 }