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());
}
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());
}
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());
}
Aggregations