use of io.atomix.core.queue.impl.WorkQueueOperations.Add in project atomix by atomix.
the class WorkQueueServiceTest method testSnapshot.
@Test
public void testSnapshot() throws Exception {
ServiceContext context = mock(ServiceContext.class);
when(context.serviceType()).thenReturn(PrimitiveTypes.workQueue());
when(context.serviceName()).thenReturn("test");
when(context.serviceId()).thenReturn(PrimitiveId.from(1));
Session session = mock(Session.class);
when(session.sessionId()).thenReturn(SessionId.from(1));
WorkQueueService service = new WorkQueueService();
service.init(context);
service.add(new DefaultCommit<>(2, ADD, new Add(Arrays.asList("Hello world!".getBytes())), session, System.currentTimeMillis()));
Buffer buffer = HeapBuffer.allocate();
service.backup(buffer);
service = new WorkQueueService();
service.init(context);
service.restore(buffer.flip());
Collection<Task<byte[]>> value = service.take(new DefaultCommit<>(2, TAKE, new Take(1), session, System.currentTimeMillis()));
assertNotNull(value);
assertEquals(1, value.size());
assertArrayEquals("Hello world!".getBytes(), value.iterator().next().payload());
}
Aggregations