//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void candidateShouldWinElectionAndBecomeLeader() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void CandidateShouldWinElectionAndBecomeLeader() { // given FakeClock fakeClock = Clocks.fakeClock(); TimerService timeouts = new OnDemandTimerService(fakeClock); RaftMachine raft = (new RaftMachineBuilder(_myself, 3, RaftTestMemberSetBuilder.INSTANCE)).outbound(_outbound).timerService(timeouts).clock(fakeClock).build(); raft.InstallCoreState(new RaftCoreState(new MembershipEntry(0, asSet(_myself, _member1, _member2)))); raft.PostRecoveryActions(); timeouts.Invoke(RaftMachine.Timeouts.ELECTION); // when raft.Handle(voteResponse().from(_member1).term(1).grant().build()); raft.Handle(voteResponse().from(_member2).term(1).grant().build()); // then assertEquals(1, raft.Term()); assertEquals(LEADER, raft.CurrentRole()); /* * We require atLeast here because RaftMachine has its own scheduled service, which can spuriously wake up and * send empty entries. These are fine and have no bearing on the correctness of this test, but can cause it * fail if we expect exactly 2 of these messages */ verify(_outbound, atLeast(1)).send(eq(_member1), isA(typeof(Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request))); verify(_outbound, atLeast(1)).send(eq(_member2), isA(typeof(Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void candidateShouldLoseElectionAndRemainCandidate() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void CandidateShouldLoseElectionAndRemainCandidate() { // Note the etcd implementation seems to diverge from the paper here, since the paper suggests that it should // remain as a candidate // given FakeClock fakeClock = Clocks.fakeClock(); TimerService timeouts = new OnDemandTimerService(fakeClock); RaftMachine raft = (new RaftMachineBuilder(_myself, 3, RaftTestMemberSetBuilder.INSTANCE)).outbound(_outbound).timerService(timeouts).clock(fakeClock).build(); raft.InstallCoreState(new RaftCoreState(new MembershipEntry(0, asSet(_myself, _member1, _member2)))); raft.PostRecoveryActions(); timeouts.Invoke(RaftMachine.Timeouts.ELECTION); // when raft.Handle(voteResponse().from(_member1).term(1).deny().build()); raft.Handle(voteResponse().from(_member2).term(1).deny().build()); // then assertEquals(1, raft.Term()); assertEquals(CANDIDATE, raft.CurrentRole()); verify(_outbound, never()).send(eq(_member1), isA(typeof(Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request))); verify(_outbound, never()).send(eq(_member2), isA(typeof(Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void candidateShouldVoteForTheSameCandidateInTheSameTerm() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void CandidateShouldVoteForTheSameCandidateInTheSameTerm() { // given FakeClock fakeClock = Clocks.fakeClock(); TimerService timeouts = new OnDemandTimerService(fakeClock); RaftMachine raft = (new RaftMachineBuilder(_myself, 3, RaftTestMemberSetBuilder.INSTANCE)).outbound(_outbound).timerService(timeouts).clock(fakeClock).build(); raft.InstallCoreState(new RaftCoreState(new MembershipEntry(0, asSet(_myself, _member1, _member2)))); // when raft.Handle(voteRequest().from(_member1).candidate(_member1).term(1).build()); raft.Handle(voteRequest().from(_member1).candidate(_member1).term(1).build()); // then verify(_outbound, times(2)).send(_member1, voteResponse().term(1).grant().build()); }