use of org.neo4j.causalclustering.core.consensus.ReplicatedString in project neo4j by neo4j.
the class BatchingMessageHandlerTest method shouldBatchNewEntriesAndHandleOtherMessagesSingularly.
@Test
public void shouldBatchNewEntriesAndHandleOtherMessagesSingularly() throws Exception {
// given
BatchingMessageHandler batchHandler = new BatchingMessageHandler(raftStateMachine, QUEUE_SIZE, MAX_BATCH, NullLogProvider.getInstance());
ReplicatedString contentA = new ReplicatedString("A");
ReplicatedString contentC = new ReplicatedString("C");
RaftMessages.ClusterIdAwareMessage messageA = new RaftMessages.ClusterIdAwareMessage(localClusterId, new RaftMessages.NewEntry.Request(null, contentA));
RaftMessages.ClusterIdAwareMessage messageB = new RaftMessages.ClusterIdAwareMessage(localClusterId, new RaftMessages.Heartbeat(null, 0, 0, 0));
RaftMessages.ClusterIdAwareMessage messageC = new RaftMessages.ClusterIdAwareMessage(localClusterId, new RaftMessages.NewEntry.Request(null, contentC));
RaftMessages.ClusterIdAwareMessage messageD = new RaftMessages.ClusterIdAwareMessage(localClusterId, new RaftMessages.Heartbeat(null, 1, 1, 1));
batchHandler.handle(messageA);
batchHandler.handle(messageB);
batchHandler.handle(messageC);
batchHandler.handle(messageD);
verifyZeroInteractions(raftStateMachine);
// when
batchHandler.run();
// then
RaftMessages.NewEntry.BatchRequest batchRequest = new RaftMessages.NewEntry.BatchRequest(2);
batchRequest.add(contentA);
batchRequest.add(contentC);
verify(raftStateMachine).handle(new RaftMessages.ClusterIdAwareMessage(localClusterId, batchRequest));
verify(raftStateMachine).handle(messageB);
verify(raftStateMachine).handle(messageD);
}
use of org.neo4j.causalclustering.core.consensus.ReplicatedString in project neo4j by neo4j.
the class LeaderTest method leaderShouldCommitOnMajorityResponse.
@Test
public void leaderShouldCommitOnMajorityResponse() throws Exception {
// 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 RaftMessages.AppendEntries.Response(member1, 0, true, 0, 0), state, log());
// then
assertEquals(0L, outcome.getCommitIndex());
assertEquals(0L, outcome.getLeaderCommit());
}
use of org.neo4j.causalclustering.core.consensus.ReplicatedString in project neo4j by neo4j.
the class LeaderTest method leaderShouldCommitAllPreviouslyAppendedEntriesWhenCommittingLaterEntryInSameTerm.
// TODO move this someplace else, since log no longer holds the commit
@Test
public void leaderShouldCommitAllPreviouslyAppendedEntriesWhenCommittingLaterEntryInSameTerm() throws Exception {
// 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 AppendEntries.Response(member1, 0, true, 2, 2), state, log());
state.update(outcome);
// then
assertEquals(2, state.commitIndex());
}
Aggregations