Search in sources :

Example 6 with RaftLogCursor

use of org.neo4j.causalclustering.core.consensus.log.RaftLogCursor in project neo4j by neo4j.

the class InFlightLogEntryReaderTest method startingFromIndexReturnEntries.

private void startingFromIndexReturnEntries(ReadableRaftLog raftLog, long startIndex, RaftLogEntry entry, RaftLogEntry... otherEntries) throws IOException {
    RaftLogCursor cursor = mock(RaftLogCursor.class);
    when(raftLog.getEntryCursor(startIndex)).thenReturn(cursor, (RaftLogCursor) null);
    Boolean[] bools = new Boolean[otherEntries.length + 1];
    Arrays.fill(bools, Boolean.TRUE);
    bools[otherEntries.length] = Boolean.FALSE;
    when(cursor.next()).thenReturn(true, bools);
    Long[] indexes = new Long[otherEntries.length + 1];
    for (int offset = 0; offset < indexes.length; offset++) {
        indexes[offset] = startIndex + 1 + offset;
    }
    indexes[otherEntries.length] = -1L;
    when(cursor.index()).thenReturn(startIndex, indexes);
    RaftLogEntry[] raftLogEntries = Arrays.copyOf(otherEntries, otherEntries.length + 1);
    when(cursor.get()).thenReturn(entry, raftLogEntries);
}
Also used : RaftLogCursor(org.neo4j.causalclustering.core.consensus.log.RaftLogCursor) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)

Example 7 with RaftLogCursor

use of org.neo4j.causalclustering.core.consensus.log.RaftLogCursor in project neo4j by neo4j.

the class LogPrinter method print.

public void print(PrintStream out) throws IOException {
    out.println(String.format("%1$8s %2$5s  %3$2s %4$s", "Index", "Term", "C?", "Content"));
    long index = 0L;
    try (RaftLogCursor cursor = raftLog.getEntryCursor(0)) {
        while (cursor.next()) {
            RaftLogEntry raftLogEntry = cursor.get();
            out.printf("%8d %5d %s", index, raftLogEntry.term(), raftLogEntry.content());
            index++;
        }
    }
}
Also used : RaftLogCursor(org.neo4j.causalclustering.core.consensus.log.RaftLogCursor) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)

Aggregations

RaftLogCursor (org.neo4j.causalclustering.core.consensus.log.RaftLogCursor)7 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)6 Test (org.junit.Test)4 File (java.io.File)1 NewLeaderBarrier (org.neo4j.causalclustering.core.consensus.NewLeaderBarrier)1 StoreChannel (org.neo4j.io.fs.StoreChannel)1