Search in sources :

Example 1 with ReplicatedString

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));
}
Also used : RaftTestGroup(org.neo4j.causalclustering.core.consensus.membership.RaftTestGroup) RaftState(org.neo4j.causalclustering.core.consensus.state.RaftState) TestMessageBuilders.appendEntriesRequest(org.neo4j.causalclustering.core.consensus.TestMessageBuilders.appendEntriesRequest) AppendEntries(org.neo4j.causalclustering.core.consensus.RaftMessages.AppendEntries) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) ReplicatedString(org.neo4j.causalclustering.core.consensus.ReplicatedString) InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) Outcome(org.neo4j.causalclustering.core.consensus.outcome.Outcome) InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) RaftLog(org.neo4j.causalclustering.core.consensus.log.RaftLog) Test(org.junit.Test)

Example 2 with ReplicatedString

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);
    }
}
Also used : ReplicatedString(org.neo4j.causalclustering.core.consensus.ReplicatedString) IOException(java.io.IOException)

Example 3 with ReplicatedString

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;
}
Also used : ClusterState(org.neo4j.causalclustering.core.consensus.explorer.ClusterState) ReplicatedString(org.neo4j.causalclustering.core.consensus.ReplicatedString) LinkedList(java.util.LinkedList)

Example 4 with ReplicatedString

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);
    }
}
Also used : ReplicatedString(org.neo4j.causalclustering.core.consensus.ReplicatedString) ReplicatedString(org.neo4j.causalclustering.core.consensus.ReplicatedString) IOException(java.io.IOException)

Example 5 with ReplicatedString

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

Aggregations

ReplicatedString (org.neo4j.causalclustering.core.consensus.ReplicatedString)8 Test (org.junit.Test)5 AppendEntries (org.neo4j.causalclustering.core.consensus.RaftMessages.AppendEntries)3 InMemoryRaftLog (org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog)3 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)3 Outcome (org.neo4j.causalclustering.core.consensus.outcome.Outcome)3 RaftState (org.neo4j.causalclustering.core.consensus.state.RaftState)3 IOException (java.io.IOException)2 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)2 ReadableRaftState (org.neo4j.causalclustering.core.consensus.state.ReadableRaftState)2 LinkedList (java.util.LinkedList)1 TestMessageBuilders.appendEntriesRequest (org.neo4j.causalclustering.core.consensus.TestMessageBuilders.appendEntriesRequest)1 ClusterState (org.neo4j.causalclustering.core.consensus.explorer.ClusterState)1 RaftLog (org.neo4j.causalclustering.core.consensus.log.RaftLog)1 RaftTestGroup (org.neo4j.causalclustering.core.consensus.membership.RaftTestGroup)1