Search in sources :

Example 16 with Buffer

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);
}
Also used : Buffer(io.atomix.storage.buffer.Buffer) HeapBuffer(io.atomix.storage.buffer.HeapBuffer) Set(io.atomix.core.counter.impl.AtomicCounterOperations.Set) AtomicCounterService(io.atomix.core.counter.impl.AtomicCounterService) Test(org.junit.Test)

Example 17 with Buffer

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);
}
Also used : Buffer(io.atomix.storage.buffer.Buffer) FileBuffer(io.atomix.storage.buffer.FileBuffer)

Aggregations

Buffer (io.atomix.storage.buffer.Buffer)17 HeapBuffer (io.atomix.storage.buffer.HeapBuffer)14 FileBuffer (io.atomix.storage.buffer.FileBuffer)9 Test (org.junit.Test)8 MappedBuffer (io.atomix.storage.buffer.MappedBuffer)6 File (java.io.File)6 ServiceContext (io.atomix.primitive.service.ServiceContext)2 Session (io.atomix.primitive.session.Session)2 Set (io.atomix.core.counter.impl.AtomicCounterOperations.Set)1 AtomicCounterService (io.atomix.core.counter.impl.AtomicCounterService)1 Run (io.atomix.core.election.impl.LeaderElectionOperations.Run)1 LeaderElectionService (io.atomix.core.election.impl.LeaderElectionService)1 Get (io.atomix.core.map.impl.AtomicCounterMapOperations.Get)1 Put (io.atomix.core.map.impl.AtomicCounterMapOperations.Put)1 AtomicCounterMapService (io.atomix.core.map.impl.AtomicCounterMapService)1 Get (io.atomix.core.map.impl.ConsistentMapOperations.Get)1 Put (io.atomix.core.map.impl.ConsistentMapOperations.Put)1 Get (io.atomix.core.multimap.impl.ConsistentSetMultimapOperations.Get)1 Put (io.atomix.core.multimap.impl.ConsistentSetMultimapOperations.Put)1 ConsistentSetMultimapService (io.atomix.core.multimap.impl.ConsistentSetMultimapService)1