use of io.atomix.storage.buffer.Buffer in project atomix by atomix.
the class AtomicCounterServiceTest method testSnapshot.
@Test
public void testSnapshot() throws Exception {
AtomicCounterService service = new AtomicCounterService();
service.set(new DefaultCommit<>(2, SET, new Set(1L), mock(Session.class), System.currentTimeMillis()));
Buffer buffer = HeapBuffer.allocate();
service.backup(buffer);
service = new AtomicCounterService();
service.restore(buffer.flip());
long value = service.get(new DefaultCommit<>(2, GET, null, mock(Session.class), System.currentTimeMillis()));
assertEquals(1, value);
}
use of io.atomix.storage.buffer.Buffer in project atomix by atomix.
the class FileSnapshot method openReader.
@Override
public synchronized SnapshotReader openReader() {
checkState(file.file().exists(), "missing snapshot file: %s", file.file());
Buffer buffer = FileBuffer.allocate(file.file(), SnapshotDescriptor.BYTES);
SnapshotDescriptor descriptor = new SnapshotDescriptor(buffer);
int length = buffer.position(SnapshotDescriptor.BYTES).readInt();
return openReader(new SnapshotReader(buffer.mark().limit(SnapshotDescriptor.BYTES + Integer.BYTES + length), this), descriptor);
}
Aggregations