use of org.neo4j.causalclustering.core.consensus.ReplicatedString in project neo4j by neo4j.
the class FollowerTest method shouldTruncateIfTermDoesNotMatch.
@Test
public void shouldTruncateIfTermDoesNotMatch() throws Exception {
// given
RaftLog entryLog = new InMemoryRaftLog();
entryLog.append(new RaftLogEntry(0, new RaftTestGroup(0)));
int term = 1;
RaftState state = raftState().myself(myself).entryLog(entryLog).term(term).build();
Follower follower = new Follower();
state.update(follower.handle(new AppendEntries.Request(member1, 1, 0, 0, new RaftLogEntry[] { new RaftLogEntry(2, ContentGenerator.content()) }, 0), state, log()));
RaftLogEntry[] entries = { new RaftLogEntry(1, new ReplicatedString("commit this!")) };
Outcome outcome = follower.handle(new AppendEntries.Request(member1, 1, 0, 0, entries, 0), state, log());
state.update(outcome);
// then
assertEquals(1, state.entryLog().appendIndex());
assertEquals(1, state.entryLog().readEntryTerm(1));
}
use of org.neo4j.causalclustering.core.consensus.ReplicatedString in project neo4j by neo4j.
the class ConcurrentStressIT method read.
private void read(RaftLog raftLog) {
try (RaftLogCursor cursor = raftLog.getEntryCursor(0)) {
while (cursor.next()) {
RaftLogEntry entry = cursor.get();
ReplicatedString content = (ReplicatedString) entry.content();
assertEquals(stringForIndex(cursor.index()), content.value());
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.neo4j.causalclustering.core.consensus.ReplicatedString in project neo4j by neo4j.
the class NewEntry method advance.
@Override
public ClusterState advance(ClusterState previous) throws IOException {
ClusterState newClusterState = new ClusterState(previous);
Queue<RaftMessages.RaftMessage> newQueue = new LinkedList<>(previous.queues.get(member));
newQueue.offer(new RaftMessages.NewEntry.Request(member, new ReplicatedString("content")));
newClusterState.queues.put(member, newQueue);
return newClusterState;
}
use of org.neo4j.causalclustering.core.consensus.ReplicatedString in project neo4j by neo4j.
the class ConcurrentStressIT method write.
private void write(RaftLog raftLog) {
long index = raftLog.appendIndex();
long term = (index + 1) * 3;
try {
String data = stringForIndex(index + 1);
raftLog.append(new RaftLogEntry(term, new ReplicatedString(data)));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.neo4j.causalclustering.core.consensus.ReplicatedString in project neo4j by neo4j.
the class BatchingMessageHandlerTest method shouldBatchRequests.
@Test
public void shouldBatchRequests() throws Exception {
// given
BatchingMessageHandler batchHandler = new BatchingMessageHandler(raftStateMachine, QUEUE_SIZE, MAX_BATCH, NullLogProvider.getInstance());
ReplicatedString contentA = new ReplicatedString("A");
ReplicatedString contentB = new ReplicatedString("B");
RaftMessages.NewEntry.Request messageA = new RaftMessages.NewEntry.Request(null, contentA);
RaftMessages.NewEntry.Request messageB = new RaftMessages.NewEntry.Request(null, contentB);
batchHandler.handle(new RaftMessages.ClusterIdAwareMessage(localClusterId, messageA));
batchHandler.handle(new RaftMessages.ClusterIdAwareMessage(localClusterId, messageB));
verifyZeroInteractions(raftStateMachine);
// when
batchHandler.run();
// then
RaftMessages.NewEntry.BatchRequest batchRequest = new RaftMessages.NewEntry.BatchRequest(2);
batchRequest.add(contentA);
batchRequest.add(contentB);
verify(raftStateMachine).handle(new RaftMessages.ClusterIdAwareMessage(localClusterId, batchRequest));
}
Aggregations