use of io.atomix.primitive.service.impl.DefaultBackupInput in project atomix by atomix.
the class DefaultAtomicDocumentTreeServiceTest method testSnapshot.
@Test
public void testSnapshot() throws Exception {
DefaultDocumentTreeService service = new DefaultDocumentTreeService();
service.set(DocumentPath.from("/foo"), "Hello world!".getBytes());
Buffer buffer = HeapBuffer.allocate();
service.backup(new DefaultBackupOutput(buffer, service.serializer()));
service = new DefaultDocumentTreeService();
service.restore(new DefaultBackupInput(buffer.flip(), service.serializer()));
Versioned<byte[]> value = service.get(DocumentPath.from("/foo"));
assertNotNull(value);
assertArrayEquals("Hello world!".getBytes(), value.value());
}
use of io.atomix.primitive.service.impl.DefaultBackupInput in project atomix by atomix.
the class DefaultWorkQueueServiceTest method testSnapshot.
@Test
public void testSnapshot() throws Exception {
ServiceContext context = mock(ServiceContext.class);
when(context.serviceType()).thenReturn(WorkQueueType.instance());
when(context.serviceName()).thenReturn("test");
when(context.serviceId()).thenReturn(PrimitiveId.from(1));
Session session = mock(Session.class);
when(session.sessionId()).thenReturn(SessionId.from(1));
when(context.currentSession()).thenReturn(session);
DefaultWorkQueueService service = new DefaultWorkQueueService();
service.init(context);
service.register(session);
service.add(Arrays.asList("Hello world!".getBytes()));
Buffer buffer = HeapBuffer.allocate();
service.backup(new DefaultBackupOutput(buffer, service.serializer()));
service = new DefaultWorkQueueService();
service.init(context);
service.register(session);
service.restore(new DefaultBackupInput(buffer.flip(), service.serializer()));
Collection<Task<byte[]>> value = service.take(1);
assertNotNull(value);
assertEquals(1, value.size());
assertArrayEquals("Hello world!".getBytes(), value.iterator().next().payload());
}
use of io.atomix.primitive.service.impl.DefaultBackupInput in project atomix by atomix.
the class DefaultDistributedSetServiceTest method testSnapshot.
@Test
@SuppressWarnings("unchecked")
public void testSnapshot() throws Exception {
ServiceContext context = mock(ServiceContext.class);
when(context.serviceType()).thenReturn(DistributedSetType.instance());
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));
DefaultDistributedSetService service = new DefaultDistributedSetService();
service.init(context);
service.add("foo");
Buffer buffer = HeapBuffer.allocate();
service.backup(new DefaultBackupOutput(buffer, service.serializer()));
service = new DefaultDistributedSetService();
service.restore(new DefaultBackupInput(buffer.flip(), service.serializer()));
assertTrue(service.contains("foo"));
}
use of io.atomix.primitive.service.impl.DefaultBackupInput in project atomix by atomix.
the class DefaultDistributedMultisetServiceTest method testSnapshot.
@Test
@SuppressWarnings("unchecked")
public void testSnapshot() throws Exception {
ServiceContext context = mock(ServiceContext.class);
when(context.serviceType()).thenReturn(DistributedSetType.instance());
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));
DefaultDistributedMultisetService service = new DefaultDistributedMultisetService();
service.init(context);
service.add("foo");
Buffer buffer = HeapBuffer.allocate();
service.backup(new DefaultBackupOutput(buffer, service.serializer()));
service = new DefaultDistributedMultisetService();
service.restore(new DefaultBackupInput(buffer.flip(), service.serializer()));
assertTrue(service.contains("foo"));
}
use of io.atomix.primitive.service.impl.DefaultBackupInput in project atomix by atomix.
the class DefaultAtomicLockServiceTest method testSnapshot.
@Test
public void testSnapshot() throws Exception {
ServiceContext context = mock(ServiceContext.class);
when(context.serviceType()).thenReturn(LeaderElectionType.instance());
when(context.serviceName()).thenReturn("test");
when(context.serviceId()).thenReturn(PrimitiveId.from(1));
when(context.wallClock()).thenReturn(new WallClock());
when(context.currentOperation()).thenReturn(OperationType.COMMAND);
Session session = mock(Session.class);
when(session.sessionId()).thenReturn(SessionId.from(1));
when(context.currentSession()).thenReturn(session);
DefaultAtomicLockService service = new DefaultAtomicLockService();
service.init(context);
service.register(session);
service.tick(new WallClockTimestamp());
Buffer buffer = HeapBuffer.allocate();
service.backup(new DefaultBackupOutput(buffer, service.serializer()));
service = new DefaultAtomicLockService();
service.init(context);
service.register(session);
service.tick(new WallClockTimestamp());
service.restore(new DefaultBackupInput(buffer.flip(), service.serializer()));
service.lock(1);
service.lock(2, 1000);
buffer = HeapBuffer.allocate();
service.backup(new DefaultBackupOutput(buffer, service.serializer()));
service = new DefaultAtomicLockService();
service.init(context);
service.register(session);
service.tick(new WallClockTimestamp());
service.restore(new DefaultBackupInput(buffer.flip(), service.serializer()));
assertTrue(service.isLocked(service.lock.index));
assertTrue(!service.queue.isEmpty());
assertTrue(!service.timers.isEmpty());
}
Aggregations