Search in sources :

Example 6 with Session

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());
}
Also used : SessionEvent(io.atomix.primitive.session.SessionEvent) Session(io.atomix.primitive.session.Session) Test(org.junit.Test)

Example 7 with Session

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());
}
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

Session (io.atomix.primitive.session.Session)7 Test (org.junit.Test)3 ServiceContext (io.atomix.primitive.service.ServiceContext)2 Buffer (io.atomix.storage.buffer.Buffer)2 HeapBuffer (io.atomix.storage.buffer.HeapBuffer)2 Scheduled (io.atomix.utils.concurrent.Scheduled)2 Run (io.atomix.core.election.impl.LeaderElectionOperations.Run)1 LeaderElectionService (io.atomix.core.election.impl.LeaderElectionService)1 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 SessionEvent (io.atomix.primitive.session.SessionEvent)1 PrimaryBackupSession (io.atomix.protocols.backup.impl.PrimaryBackupSession)1 ExecuteOperation (io.atomix.protocols.backup.protocol.ExecuteOperation)1 WallClock (io.atomix.utils.time.WallClock)1 HashSet (java.util.HashSet)1