Search in sources :

Example 1 with InitializeEntry

use of io.atomix.protocols.raft.storage.log.entry.InitializeEntry in project atomix by atomix.

the class AbstractLogTest method testResetTruncateZero.

@Test
public void testResetTruncateZero() throws Exception {
    RaftLog log = createLog();
    RaftLogWriter writer = log.writer();
    RaftLogReader reader = log.openReader(1, RaftLogReader.Mode.ALL);
    assertEquals(0, writer.getLastIndex());
    writer.reset(1);
    assertEquals(0, writer.getLastIndex());
    writer.append(new InitializeEntry(1, System.currentTimeMillis()));
    assertEquals(1, writer.getLastIndex());
    assertEquals(1, writer.getLastEntry().index());
    assertTrue(reader.hasNext());
    assertEquals(1, reader.next().index());
    writer.truncate(0);
    assertEquals(0, writer.getLastIndex());
    assertNull(writer.getLastEntry());
    writer.append(new InitializeEntry(1, System.currentTimeMillis()));
    assertEquals(1, writer.getLastIndex());
    assertEquals(1, writer.getLastEntry().index());
    assertTrue(reader.hasNext());
    assertEquals(1, reader.next().index());
}
Also used : InitializeEntry(io.atomix.protocols.raft.storage.log.entry.InitializeEntry) Test(org.junit.Test)

Example 2 with InitializeEntry

use of io.atomix.protocols.raft.storage.log.entry.InitializeEntry in project atomix by atomix.

the class RaftServiceManagerTest method testInstallSnapshotOnApply.

@Test
public void testInstallSnapshotOnApply() throws Exception {
    RaftLogWriter writer = raft.getLogWriter();
    writer.append(new InitializeEntry(1, System.currentTimeMillis()));
    writer.append(new OpenSessionEntry(1, System.currentTimeMillis(), "test-1", "test", "test", null, ReadConsistency.LINEARIZABLE, 100, 1000));
    writer.commit(2);
    RaftServiceManager manager = raft.getServiceManager();
    manager.apply(2).join();
    Snapshot snapshot = manager.snapshot();
    assertEquals(2, snapshot.index());
    assertTrue(snapshotTaken.get());
    snapshot.complete();
    assertEquals(2, raft.getSnapshotStore().getCurrentSnapshot().index());
    writer.append(new CommandEntry(1, System.currentTimeMillis(), 2, 1, new PrimitiveOperation(RUN, new byte[0])));
    writer.commit(3);
    manager.apply(3).join();
    assertTrue(snapshotInstalled.get());
}
Also used : PrimitiveOperation(io.atomix.primitive.operation.PrimitiveOperation) Snapshot(io.atomix.protocols.raft.storage.snapshot.Snapshot) CommandEntry(io.atomix.protocols.raft.storage.log.entry.CommandEntry) OpenSessionEntry(io.atomix.protocols.raft.storage.log.entry.OpenSessionEntry) InitializeEntry(io.atomix.protocols.raft.storage.log.entry.InitializeEntry) RaftLogWriter(io.atomix.protocols.raft.storage.log.RaftLogWriter) Test(org.junit.Test)

Example 3 with InitializeEntry

use of io.atomix.protocols.raft.storage.log.entry.InitializeEntry in project atomix by atomix.

the class RaftServiceManagerTest method testSnapshotTakeInstall.

@Test
public void testSnapshotTakeInstall() throws Exception {
    RaftLogWriter writer = raft.getLogWriter();
    writer.append(new InitializeEntry(1, System.currentTimeMillis()));
    writer.append(new OpenSessionEntry(1, System.currentTimeMillis(), "test-1", "test", "test", null, ReadConsistency.LINEARIZABLE, 100, 1000));
    writer.commit(2);
    RaftServiceManager manager = raft.getServiceManager();
    manager.apply(2).join();
    Snapshot snapshot = manager.snapshot();
    assertEquals(2, snapshot.index());
    assertTrue(snapshotTaken.get());
    snapshot = snapshot.complete();
    assertEquals(2, raft.getSnapshotStore().getCurrentSnapshot().index());
    manager.install(snapshot);
    assertTrue(snapshotInstalled.get());
}
Also used : Snapshot(io.atomix.protocols.raft.storage.snapshot.Snapshot) OpenSessionEntry(io.atomix.protocols.raft.storage.log.entry.OpenSessionEntry) InitializeEntry(io.atomix.protocols.raft.storage.log.entry.InitializeEntry) RaftLogWriter(io.atomix.protocols.raft.storage.log.RaftLogWriter) Test(org.junit.Test)

Aggregations

InitializeEntry (io.atomix.protocols.raft.storage.log.entry.InitializeEntry)3 Test (org.junit.Test)3 RaftLogWriter (io.atomix.protocols.raft.storage.log.RaftLogWriter)2 OpenSessionEntry (io.atomix.protocols.raft.storage.log.entry.OpenSessionEntry)2 Snapshot (io.atomix.protocols.raft.storage.snapshot.Snapshot)2 PrimitiveOperation (io.atomix.primitive.operation.PrimitiveOperation)1 CommandEntry (io.atomix.protocols.raft.storage.log.entry.CommandEntry)1