//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))); }
//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 shouldAcceptInitialEntryAfterBootstrap() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldAcceptInitialEntryAfterBootstrap() { RaftLog raftLog = BootstrappedLog(); RaftState state = raftState().entryLog(raftLog).myself(_myself).build(); long leaderTerm = state.Term() + LeaderTermDifference; RaftLogEntry logEntry = new RaftLogEntry(leaderTerm, content()); // when Outcome outcome = Role.handler.handle(appendEntriesRequest().from(_leader).leaderTerm(leaderTerm).prevLogIndex(0).prevLogTerm(0).logEntry(logEntry).build(), state, Log()); // then assertTrue((( RaftMessages_AppendEntries_Response )messageFor(outcome, _leader)).success()); assertThat(outcome.LogCommands, hasItem(new BatchAppendLogEntries(1, 0, new RaftLogEntry[] { logEntry }))); }
//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 shouldRejectDiscontinuousEntries() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldRejectDiscontinuousEntries() { // given RaftState state = raftState().myself(_myself).build(); long leaderTerm = state.Term() + LeaderTermDifference; // when Outcome outcome = Role.handler.handle(appendEntriesRequest().from(_leader).leaderTerm(leaderTerm).prevLogIndex(state.EntryLog().appendIndex() + 1).prevLogTerm(leaderTerm).logEntry(new RaftLogEntry(leaderTerm, content())).build(), state, Log()); // then RaftMessages_AppendEntries_Response response = ( RaftMessages_AppendEntries_Response )messageFor(outcome, _leader); assertEquals(state.EntryLog().appendIndex(), response.AppendIndex()); assertFalse(response.Success()); }
//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 leaderShouldRejectAppendEntriesResponseWithNewerTermAndBecomeAFollower() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void LeaderShouldRejectAppendEntriesResponseWithNewerTermAndBecomeAFollower() { // given RaftState state = raftState().myself(_myself).build(); Leader leader = new Leader(); // when Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response message = appendEntriesResponse().from(_member1).term(state.Term() + 1).build(); Outcome outcome = leader.Handle(message, state, Log()); // then assertEquals(0, count(outcome.OutgoingMessages)); assertEquals(FOLLOWER, outcome.Role); assertEquals(0, count(outcome.LogCommands)); assertEquals(state.Term() + 1, outcome.Term); }
//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()); }