private RaftMembershipManager RaftMembershipManager(InMemoryRaftLog log) { RaftMembershipManager raftMembershipManager = new RaftMembershipManager(null, INSTANCE, log, Instance, 3, 1000, Clocks.fakeClock(), 1000, new InMemoryStateStorage <RaftMembershipState>((new Marshal()).startState())); raftMembershipManager.RecoverFromIndexSupplier = () => 0; return(raftMembershipManager); }
private RaftLog BootstrappedLog() { InMemoryRaftLog raftLog = new InMemoryRaftLog(); raftLog.Append(new RaftLogEntry(0, content())); return(raftLog); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldSendCompactionInfoIfFailureWithNoEarlierEntries() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldSendCompactionInfoIfFailureWithNoEarlierEntries() { // given Leader leader = new Leader(); long term = 1; long leaderPrevIndex = 3; long followerIndex = leaderPrevIndex - 1; InMemoryRaftLog raftLog = new InMemoryRaftLog(); raftLog.Skip(leaderPrevIndex, term); RaftState state = raftState().term(term).entryLog(raftLog).build(); Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response incomingResponse = appendEntriesResponse().failure().term(term).appendIndex(followerIndex).from(_member1).build(); // when Outcome outcome = leader.Handle(incomingResponse, state, Log()); // then Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage outgoingMessage = messageFor(outcome, _member1); assertThat(outgoingMessage, instanceOf(typeof(Org.Neo4j.causalclustering.core.consensus.RaftMessages_LogCompactionInfo))); Org.Neo4j.causalclustering.core.consensus.RaftMessages_LogCompactionInfo typedOutgoingMessage = (Org.Neo4j.causalclustering.core.consensus.RaftMessages_LogCompactionInfo)outgoingMessage; assertThat(typedOutgoingMessage.PrevIndex(), equalTo(leaderPrevIndex)); }
// TODO: rethink this test, it does too much //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void leaderShouldSpawnMismatchCommandOnFailure() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void LeaderShouldSpawnMismatchCommandOnFailure() { // given /* * A leader who * - has an append index of 100 * - knows about instance 2 * - assumes that instance 2 is fully caught up */ Leader leader = new Leader(); MemberId instance2 = member(2); FollowerState instance2State = CreateArtificialFollowerState(100); ReadableRaftState state = mock(typeof(ReadableRaftState)); FollowerStates <MemberId> followerState = new FollowerStates <MemberId>(); followerState = new FollowerStates <MemberId>(followerState, instance2, instance2State); RaftLog log = new InMemoryRaftLog(); for (int i = 0; i <= 100; i++) { log.Append(new RaftLogEntry(0, valueOf(i))); } when(state.CommitIndex()).thenReturn(-1L); when(state.EntryLog()).thenReturn(log); when(state.FollowerStates()).thenReturn(followerState); when(state.Term()).thenReturn(4L); // both leader and follower are in the same term // when // that leader is asked to handle a response from that follower that says that the follower is still missing // things Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response response = appendEntriesResponse().failure().appendIndex(0).matchIndex(-1).term(4).from(instance2).build(); Outcome outcome = leader.Handle(response, state, mock(typeof(Log))); // then int mismatchCount = 0; foreach (ShipCommand shipCommand in outcome.ShipCommands) { if (shipCommand is ShipCommand.Mismatch) { mismatchCount++; } } assertThat(mismatchCount, greaterThan(0)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldGeneratePruneCommandsOnRequest() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldGeneratePruneCommandsOnRequest() { // given InMemoryRaftLog raftLog = new InMemoryRaftLog(); RaftState state = raftState().myself(_myself).entryLog(raftLog).build(); // when Org.Neo4j.causalclustering.core.consensus.RaftMessages_PruneRequest pruneRequest = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_PruneRequest(1000); Outcome outcome = Role.handler.handle(pruneRequest, state, Log()); // then assertThat(outcome.LogCommands, hasItem(new PruneLogCommand(1000))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotResultInCommitIfReferringToFutureEntries() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotResultInCommitIfReferringToFutureEntries() { InMemoryRaftLog raftLog = new InMemoryRaftLog(); RaftState state = raftState().myself(_myself).entryLog(raftLog).build(); long leaderTerm = state.Term() + LeaderTermDifference; raftLog.Append(new RaftLogEntry(leaderTerm, content())); Org.Neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat heartbeat = heartbeat().from(_leader).commitIndex(raftLog.AppendIndex() + 1).commitIndexTerm(leaderTerm).leaderTerm(leaderTerm).build(); Outcome outcome = Role.handler.handle(heartbeat, state, Log()); assertThat(outcome.LogCommands, empty()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAcceptContinuousEntries() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldAcceptContinuousEntries() { InMemoryRaftLog raftLog = new InMemoryRaftLog(); RaftState state = raftState().myself(_myself).entryLog(raftLog).build(); long leaderTerm = state.Term() + LeaderTermDifference; raftLog.Append(new RaftLogEntry(leaderTerm, content())); // when Outcome outcome = Role.handler.handle(appendEntriesRequest().from(_leader).leaderTerm(leaderTerm).prevLogIndex(raftLog.AppendIndex()).prevLogTerm(leaderTerm).logEntry(new RaftLogEntry(leaderTerm, content())).build(), state, Log()); // then assertTrue((( RaftMessages_AppendEntries_Response )messageFor(outcome, _leader)).success()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void membershipManagerShouldUseLatestAppendedMembershipSetEntries() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void MembershipManagerShouldUseLatestAppendedMembershipSetEntries() { // given //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog log = new org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog(); InMemoryRaftLog log = new InMemoryRaftLog(); RaftMembershipManager membershipManager = LifeRule.add(RaftMembershipManager(log)); // when membershipManager.processLog(0, asList(new AppendLogEntry(0, new RaftLogEntry(0, new RaftTestGroup(1, 2, 3, 4))), new AppendLogEntry(1, new RaftLogEntry(0, new RaftTestGroup(1, 2, 3, 5))) )); // then assertEquals((new RaftTestGroup(1, 2, 3, 5)).Members, membershipManager.VotingMembers()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCommitEntry() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldCommitEntry() { // given InMemoryRaftLog raftLog = new InMemoryRaftLog(); RaftState state = raftState().entryLog(raftLog).myself(_myself).build(); long leaderTerm = state.Term() + LeaderTermDifference; raftLog.Append(new RaftLogEntry(leaderTerm, content())); // when Outcome outcome = Role.handler.handle(appendEntriesRequest().from(_leader).leaderTerm(leaderTerm).prevLogIndex(raftLog.AppendIndex()).prevLogTerm(leaderTerm).leaderCommit(0).build(), state, Log()); // then assertTrue((( RaftMessages_AppendEntries_Response )messageFor(outcome, _leader)).success()); assertThat(outcome.CommitIndex, Matchers.equalTo(0L)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotCommitAheadOfMatchingHistory() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotCommitAheadOfMatchingHistory() { // given InMemoryRaftLog raftLog = new InMemoryRaftLog(); RaftState state = raftState().entryLog(raftLog).myself(_myself).build(); long leaderTerm = state.Term() + LeaderTermDifference; RaftLogEntry previouslyAppendedEntry = new RaftLogEntry(leaderTerm, content()); raftLog.Append(previouslyAppendedEntry); // when Outcome outcome = Role.handler.handle(appendEntriesRequest().from(_leader).leaderTerm(leaderTerm).prevLogIndex(raftLog.AppendIndex() + 1).prevLogTerm(leaderTerm).leaderCommit(0).build(), state, Log()); // then assertFalse((( RaftMessages_AppendEntries_Response )messageFor(outcome, _leader)).success()); assertThat(outcome.LogCommands, empty()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void leaderShouldCommitOnMajorityResponse() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void LeaderShouldCommitOnMajorityResponse() { // given InMemoryRaftLog raftLog = new InMemoryRaftLog(); raftLog.Append(new RaftLogEntry(0, new ReplicatedString("lalalala"))); RaftState state = raftState().votingMembers(_member1, _member2).term(0).lastLogIndexBeforeWeBecameLeader(-1).leader(_myself).leaderCommit(-1).entryLog(raftLog).messagesSentToFollower(_member1, raftLog.AppendIndex() + 1).messagesSentToFollower(_member2, raftLog.AppendIndex() + 1).build(); Leader leader = new Leader(); // when a single instance responds (plus self == 2 out of 3 instances) Outcome outcome = leader.Handle(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response(_member1, 0, true, 0, 0), state, Log()); // then assertEquals(0L, outcome.CommitIndex); assertEquals(0L, outcome.LeaderCommit); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldTruncateOnReceiptOfConflictingEntry() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldTruncateOnReceiptOfConflictingEntry() { // given InMemoryRaftLog raftLog = new InMemoryRaftLog(); RaftState state = raftState().myself(_myself).term(5).entryLog(raftLog).build(); long leaderTerm = state.Term() + LeaderTermDifference; raftLog.Append(new RaftLogEntry(state.Term() - 1, content())); raftLog.Append(new RaftLogEntry(state.Term() - 1, content())); // when long previousIndex = raftLog.AppendIndex() - 1; Outcome outcome = Role.handler.handle(appendEntriesRequest().from(_leader).leaderTerm(leaderTerm).prevLogIndex(previousIndex).prevLogTerm(raftLog.ReadEntryTerm(previousIndex)).logEntry(new RaftLogEntry(leaderTerm, content())).build(), state, Log()); // then assertTrue((( RaftMessages_AppendEntries_Response )messageFor(outcome, _leader)).success()); assertThat(outcome.LogCommands, hasItem(new TruncateLogCommand(1))); }
// TODO move this someplace else, since log no longer holds the commit //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void leaderShouldCommitAllPreviouslyAppendedEntriesWhenCommittingLaterEntryInSameTerm() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void LeaderShouldCommitAllPreviouslyAppendedEntriesWhenCommittingLaterEntryInSameTerm() { // given InMemoryRaftLog raftLog = new InMemoryRaftLog(); raftLog.Append(new RaftLogEntry(0, new ReplicatedString("first!"))); raftLog.Append(new RaftLogEntry(0, new ReplicatedString("second"))); raftLog.Append(new RaftLogEntry(0, new ReplicatedString("third"))); RaftState state = raftState().votingMembers(_myself, _member1, _member2).term(0).entryLog(raftLog).messagesSentToFollower(_member1, raftLog.AppendIndex() + 1).messagesSentToFollower(_member2, raftLog.AppendIndex() + 1).build(); Leader leader = new Leader(); // when Outcome outcome = leader.Handle(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response(_member1, 0, true, 2, 2), state, Log()); state.Update(outcome); // then assertEquals(2, state.CommitIndex()); }
internal Fixture(ISet <MemberId> memberIds, TestNetwork net, long electionTimeout, long heartbeatInterval) { this.Net = net; foreach (MemberId member in memberIds) { TestNetwork.Inbound inbound = new TestNetwork.Inbound(net, member); TestNetwork.Outbound outbound = new TestNetwork.Outbound(net, member); _members.Add(member); TimerService timerService = CreateTimerService(); BootstrapWaiter waiter = new BootstrapWaiter(); _bootstrapWaiters.Add(waiter); InMemoryRaftLog raftLog = new InMemoryRaftLog(); RaftMachine raftMachine = (new RaftMachineBuilder(member, memberIds.Count, RaftTestMemberSetBuilder.INSTANCE)).electionTimeout(electionTimeout).heartbeatInterval(heartbeatInterval).inbound(inbound).outbound(outbound).timerService(timerService).raftLog(raftLog).commitListener(waiter).build(); Rafts.Add(new RaftFixture(this, raftMachine, raftLog)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void membershipManagerShouldRevertToEarlierAppendedMembershipSetAfterTruncationCausesLossOfLastAppended() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void MembershipManagerShouldRevertToEarlierAppendedMembershipSetAfterTruncationCausesLossOfLastAppended() { // given //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog raftLog = new org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog(); InMemoryRaftLog raftLog = new InMemoryRaftLog(); RaftMembershipManager membershipManager = LifeRule.add(RaftMembershipManager(raftLog)); // when IList <RaftLogCommand> logCommands = asList(new AppendLogEntry(0, new RaftLogEntry(0, new RaftTestGroup(1, 2, 3, 4))), new AppendLogEntry(1, new RaftLogEntry(0, new RaftTestGroup(1, 2, 3, 5))), new AppendLogEntry(2, new RaftLogEntry(0, new RaftTestGroup(1, 2, 3, 6))), new TruncateLogCommand(2) ); foreach (RaftLogCommand logCommand in logCommands) { logCommand.ApplyTo(raftLog, _log); } membershipManager.ProcessLog(0, logCommands); // then assertEquals((new RaftTestGroup(1, 2, 3, 5)).Members, membershipManager.VotingMembers()); }
internal RaftFixture(Fixture outerInstance, RaftMachine raftMachine, InMemoryRaftLog raftLog) { this._outerInstance = outerInstance; this.RaftMachineConflict = raftMachine; this.RaftLogConflict = raftLog; }