use of io.atomix.primitive.session.Session in project atomix by atomix.
the class SessionEventTest method testRaftSessionEvent.
@Test
public void testRaftSessionEvent() throws Exception {
Session session = mock(Session.class);
long timestamp = System.currentTimeMillis();
SessionEvent event = new SessionEvent(SessionEvent.Type.OPEN, session, timestamp);
assertEquals(SessionEvent.Type.OPEN, event.type());
assertEquals(session, event.subject());
assertEquals(timestamp, event.time());
}
use of io.atomix.primitive.session.Session 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