Search in sources :

Example 1 with Take

use of io.atomix.core.queue.impl.WorkQueueOperations.Take 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());
}
Also used : Add(io.atomix.core.queue.impl.WorkQueueOperations.Add) Buffer(io.atomix.storage.buffer.Buffer) HeapBuffer(io.atomix.storage.buffer.HeapBuffer) Take(io.atomix.core.queue.impl.WorkQueueOperations.Take) Task(io.atomix.core.queue.Task) ServiceContext(io.atomix.primitive.service.ServiceContext) WorkQueueService(io.atomix.core.queue.impl.WorkQueueService) Session(io.atomix.primitive.session.Session) Test(org.junit.Test)

Aggregations

Task (io.atomix.core.queue.Task)1 Add (io.atomix.core.queue.impl.WorkQueueOperations.Add)1 Take (io.atomix.core.queue.impl.WorkQueueOperations.Take)1 WorkQueueService (io.atomix.core.queue.impl.WorkQueueService)1 ServiceContext (io.atomix.primitive.service.ServiceContext)1 Session (io.atomix.primitive.session.Session)1 Buffer (io.atomix.storage.buffer.Buffer)1 HeapBuffer (io.atomix.storage.buffer.HeapBuffer)1 Test (org.junit.Test)1