Search in sources :

Example 6 with LeaderContext

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)));
}
Also used : LeaderContext(org.neo4j.causalclustering.core.consensus.LeaderContext) Test(org.junit.Test)

Example 7 with LeaderContext

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)));
}
Also used : LeaderContext(org.neo4j.causalclustering.core.consensus.LeaderContext) Test(org.junit.Test)

Example 8 with LeaderContext

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));
}
Also used : RaftMessages(org.neo4j.causalclustering.core.consensus.RaftMessages) AppendEntries(org.neo4j.causalclustering.core.consensus.RaftMessages.AppendEntries) LeaderContext(org.neo4j.causalclustering.core.consensus.LeaderContext) Test(org.junit.Test)

Example 9 with LeaderContext

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));
}
Also used : RaftMessages(org.neo4j.causalclustering.core.consensus.RaftMessages) AppendEntries(org.neo4j.causalclustering.core.consensus.RaftMessages.AppendEntries) LeaderContext(org.neo4j.causalclustering.core.consensus.LeaderContext) Test(org.junit.Test)

Example 10 with LeaderContext

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());
}
Also used : LeaderContext(org.neo4j.causalclustering.core.consensus.LeaderContext) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 LeaderContext (org.neo4j.causalclustering.core.consensus.LeaderContext)10 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)5 AppendEntries (org.neo4j.causalclustering.core.consensus.RaftMessages.AppendEntries)5 ArrayList (java.util.ArrayList)1 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)1