use of org.neo4j.causalclustering.core.consensus.LeaderContext in project neo4j by neo4j.
the class RaftLogShipperTest method shouldSendNextBatchAfterMatch.
@Test
public void shouldSendNextBatchAfterMatch() throws Throwable {
// given
raftLog.append(entry0);
raftLog.append(entry1);
raftLog.append(entry2);
raftLog.append(entry3);
startLogShipper();
logShipper.onMismatch(0, new LeaderContext(0, 0));
// when
outbound.clear();
logShipper.onMatch(0, new LeaderContext(0, 0));
// then
assertThat(outbound.sentTo(follower), Matchers.hasRaftLogEntries(asList(entry1, entry2, entry3)));
}
use of org.neo4j.causalclustering.core.consensus.LeaderContext in project neo4j by neo4j.
the class RaftLogShipperTest method shouldSendNewEntriesAfterMatchingLastEntry.
@Test
public void shouldSendNewEntriesAfterMatchingLastEntry() throws Throwable {
// given
raftLog.append(entry0);
startLogShipper();
logShipper.onMatch(0, new LeaderContext(0, 0));
// when
outbound.clear();
raftLog.append(entry1);
logShipper.onNewEntries(0, 0, new RaftLogEntry[] { entry1 }, new LeaderContext(0, 0));
raftLog.append(entry2);
logShipper.onNewEntries(1, 0, new RaftLogEntry[] { entry2 }, new LeaderContext(0, 0));
// then
assertThat(outbound.sentTo(follower), Matchers.hasRaftLogEntries(asList(entry1, entry2)));
}
use of org.neo4j.causalclustering.core.consensus.LeaderContext in project neo4j by neo4j.
the class RaftLogShipperTest method shouldSendPreviousEntryOnMismatch.
@Test
public void shouldSendPreviousEntryOnMismatch() throws Throwable {
// given
raftLog.append(entry0);
raftLog.append(entry1);
raftLog.append(entry2);
// ships entry2 on start
startLogShipper();
// when
outbound.clear();
logShipper.onMismatch(0, new LeaderContext(0, 0));
// then: we expect it to ship (empty) entry1 next
RaftMessages.AppendEntries.Request expected = new RaftMessages.AppendEntries.Request(leader, leaderTerm, 0, 0, RaftLogEntry.empty, leaderCommit);
assertThat(outbound.sentTo(follower), hasItem(expected));
}
use of org.neo4j.causalclustering.core.consensus.LeaderContext in project neo4j by neo4j.
the class RaftLogShipperTest method shouldKeepSendingFirstEntryAfterSeveralMismatches.
@Test
public void shouldKeepSendingFirstEntryAfterSeveralMismatches() throws Throwable {
// given
raftLog.append(entry0);
raftLog.append(entry1);
startLogShipper();
logShipper.onMismatch(0, new LeaderContext(0, 0));
logShipper.onMismatch(0, new LeaderContext(0, 0));
// when
outbound.clear();
logShipper.onMismatch(0, new LeaderContext(0, 0));
// then
RaftMessages.AppendEntries.Request expected = new RaftMessages.AppendEntries.Request(leader, leaderTerm, 0, 0, RaftLogEntry.empty, leaderCommit);
assertThat(outbound.sentTo(follower), hasItem(expected));
}
use of org.neo4j.causalclustering.core.consensus.LeaderContext in project neo4j by neo4j.
the class RaftLogShipperTest method shouldNotSendNewEntriesWhenNotMatched.
@Test
public void shouldNotSendNewEntriesWhenNotMatched() throws Throwable {
// given
raftLog.append(entry0);
startLogShipper();
// when
outbound.clear();
logShipper.onNewEntries(0, 0, new RaftLogEntry[] { entry1 }, new LeaderContext(0, 0));
logShipper.onNewEntries(1, 0, new RaftLogEntry[] { entry2 }, new LeaderContext(0, 0));
// then
assertEquals(0, outbound.sentTo(follower).size());
}
Aggregations