Search in sources :

Example 6 with WallClockTimestamp

use of io.atomix.utils.time.WallClockTimestamp in project atomix by atomix.

the class FileSnapshotStoreTest method testPersistLoadSnapshot.

/**
 * Tests persisting and loading snapshots.
 */
@Test
public void testPersistLoadSnapshot() {
    SnapshotStore store = createSnapshotStore();
    Snapshot snapshot = store.newTemporarySnapshot(2, new WallClockTimestamp());
    try (SnapshotWriter writer = snapshot.openWriter()) {
        writer.writeLong(10);
    }
    snapshot = snapshot.persist();
    assertNull(store.getSnapshot(2));
    snapshot.complete();
    assertNotNull(store.getSnapshot(2));
    try (SnapshotReader reader = snapshot.openReader()) {
        assertEquals(reader.readLong(), 10);
    }
    store.close();
    store = createSnapshotStore();
    assertNotNull(store.getSnapshot(2));
    assertEquals(store.getSnapshot(2).index(), 2);
    snapshot = store.getSnapshot(2);
    try (SnapshotReader reader = snapshot.openReader()) {
        assertEquals(reader.readLong(), 10);
    }
}
Also used : WallClockTimestamp(io.atomix.utils.time.WallClockTimestamp) Test(org.junit.Test)

Aggregations

WallClockTimestamp (io.atomix.utils.time.WallClockTimestamp)6 Test (org.junit.Test)5 DefaultServiceExecutor (io.atomix.primitive.service.impl.DefaultServiceExecutor)1 RaftException (io.atomix.protocols.raft.RaftException)1 RaftServiceContext (io.atomix.protocols.raft.service.RaftServiceContext)1 Snapshot (io.atomix.protocols.raft.storage.snapshot.Snapshot)1 SnapshotWriter (io.atomix.protocols.raft.storage.snapshot.SnapshotWriter)1 HashSet (java.util.HashSet)1