use of io.atomix.storage.buffer.Buffer in project atomix by atomix.
the class FileSnapshot method openWriter.
@Override
public synchronized SnapshotWriter openWriter() {
checkWriter();
Buffer buffer = FileBuffer.allocate(file.file(), SnapshotDescriptor.BYTES);
descriptor.copyTo(buffer);
int length = buffer.position(SnapshotDescriptor.BYTES).readInt();
return openWriter(new SnapshotWriter(buffer.skip(length).mark(), this), descriptor);
}
use of io.atomix.storage.buffer.Buffer in project atomix by atomix.
the class LeaderElectionServiceTest method testSnapshot.
@Test
public void testSnapshot() throws Exception {
ServiceContext context = mock(ServiceContext.class);
when(context.serviceType()).thenReturn(PrimitiveTypes.leaderElection());
when(context.serviceName()).thenReturn("test");
when(context.serviceId()).thenReturn(PrimitiveId.from(1));
when(context.wallClock()).thenReturn(new WallClock());
Session session = mock(Session.class);
when(session.sessionId()).thenReturn(SessionId.from(1));
LeaderElectionService service = new LeaderElectionService();
service.init(context);
byte[] id = "a".getBytes();
service.run(new DefaultCommit<>(2, RUN, new Run(id), session, System.currentTimeMillis()));
Buffer buffer = HeapBuffer.allocate();
service.backup(buffer);
service = new LeaderElectionService();
service.init(context);
service.restore(buffer.flip());
Leadership<byte[]> value = service.getLeadership();
assertNotNull(value);
assertArrayEquals(value.leader().id(), id);
}
use of io.atomix.storage.buffer.Buffer in project atomix by atomix.
the class AtomicCounterMapServiceTest method testSnapshot.
@Test
public void testSnapshot() throws Exception {
AtomicCounterMapService service = new AtomicCounterMapService();
service.put(new DefaultCommit<>(2, PUT, new Put("foo", 1), mock(Session.class), System.currentTimeMillis()));
Buffer buffer = HeapBuffer.allocate();
service.backup(buffer);
service = new AtomicCounterMapService();
service.restore(buffer.flip());
long value = service.get(new DefaultCommit<>(2, GET, new Get("foo"), mock(Session.class), System.currentTimeMillis()));
assertEquals(1, value);
}
use of io.atomix.storage.buffer.Buffer in project atomix by atomix.
the class DocumentTreeServiceTest method testSnapshot.
private void testSnapshot(Ordering ordering) throws Exception {
DocumentTreeService service = new DocumentTreeService(ordering);
service.update(new DefaultCommit<>(2, UPDATE, new Update(DocumentPath.from("root|foo"), Optional.of("Hello world!".getBytes()), Match.any(), Match.ifNull()), mock(Session.class), System.currentTimeMillis()));
Buffer buffer = HeapBuffer.allocate();
service.backup(buffer);
service = new DocumentTreeService(ordering);
service.restore(buffer.flip());
Versioned<byte[]> value = service.get(new DefaultCommit<>(2, GET, new Get(DocumentPath.from("root|foo")), mock(Session.class), System.currentTimeMillis()));
assertNotNull(value);
assertArrayEquals("Hello world!".getBytes(), value.value());
}
use of io.atomix.storage.buffer.Buffer in project atomix by atomix.
the class ConsistentMapServiceTest method testSnapshot.
@Test
@SuppressWarnings("unchecked")
public void testSnapshot() throws Exception {
ConsistentMapService service = new TestConsistentMapService();
service.put(new DefaultCommit<>(2, PUT, new Put("foo", "Hello world!".getBytes(), 1000), mock(Session.class), System.currentTimeMillis()));
Buffer buffer = HeapBuffer.allocate();
service.backup(buffer);
service = new TestConsistentMapService();
service.restore(buffer.flip());
Versioned<byte[]> value = service.get(new DefaultCommit<>(2, GET, new Get("foo"), mock(Session.class), System.currentTimeMillis()));
assertNotNull(value);
assertArrayEquals("Hello world!".getBytes(), value.value());
assertNotNull(service.entries().get("foo").timer);
}
Aggregations