use of org.neo4j.causalclustering.core.consensus.RaftMessages.RaftMessage in project neo4j by neo4j.
the class FollowerTest method followerReceivingHeartbeatIndicatingClusterIsAheadShouldElicitAppendResponse.
@Test
public void followerReceivingHeartbeatIndicatingClusterIsAheadShouldElicitAppendResponse() throws Exception {
// given
int term = 1;
int followerAppendIndex = 9;
RaftLog entryLog = new InMemoryRaftLog();
entryLog.append(new RaftLogEntry(0, new RaftTestGroup(0)));
RaftState state = raftState().myself(myself).term(term).build();
Follower follower = new Follower();
appendSomeEntriesToLog(state, follower, followerAppendIndex - 1, term, 1);
AppendEntries.Request heartbeat = appendEntriesRequest().from(member1).leaderTerm(term).prevLogIndex(// leader has appended 2 ahead from this follower
followerAppendIndex + 2).prevLogTerm(// in the same term
term).build();
Outcome outcome = follower.handle(heartbeat, state, log());
assertEquals(1, outcome.getOutgoingMessages().size());
RaftMessage outgoing = outcome.getOutgoingMessages().iterator().next().message();
assertEquals(RaftMessages.Type.APPEND_ENTRIES_RESPONSE, outgoing.type());
RaftMessages.AppendEntries.Response response = (AppendEntries.Response) outgoing;
assertFalse(response.success());
}
use of org.neo4j.causalclustering.core.consensus.RaftMessages.RaftMessage in project neo4j by neo4j.
the class BatchingMessageHandler method collateAndHandleBatch.
private void collateAndHandleBatch(List<RaftMessages.ClusterIdAwareMessage> batch) {
RaftMessages.NewEntry.BatchRequest batchRequest = null;
ClusterId clusterId = batch.get(0).clusterId();
for (RaftMessages.ClusterIdAwareMessage clusterIdAwareMessage : batch) {
if (batchRequest != null && !clusterIdAwareMessage.clusterId().equals(clusterId)) {
handler.handle(new RaftMessages.ClusterIdAwareMessage(clusterId, batchRequest));
batchRequest = null;
}
clusterId = clusterIdAwareMessage.clusterId();
RaftMessage message = clusterIdAwareMessage.message();
if (message instanceof RaftMessages.NewEntry.Request) {
RaftMessages.NewEntry.Request newEntryRequest = (RaftMessages.NewEntry.Request) message;
if (batchRequest == null) {
batchRequest = new RaftMessages.NewEntry.BatchRequest(batch.size());
}
batchRequest.add(newEntryRequest.content());
} else {
handler.handle(clusterIdAwareMessage);
}
}
if (batchRequest != null) {
handler.handle(new RaftMessages.ClusterIdAwareMessage(clusterId, batchRequest));
}
}
Aggregations