use of io.atomix.protocols.raft.session.RaftSessionRegistry in project atomix by atomix.
the class RaftSessionsTest method testSessions.
@Test
public void testSessions() throws Exception {
RaftSessionRegistry sessionManager = new RaftSessionRegistry();
RaftSessions sessions = new RaftSessions(PrimitiveId.from(1), sessionManager);
TestSessionListener listener = new TestSessionListener();
sessions.addListener(listener);
RaftSession session1 = createSession(1);
sessionManager.addSession(session1);
assertNull(sessions.getSession(1));
sessions.openSession(session1);
assertNotNull(sessions.getSession(1));
assertEquals(session1.getState(), State.OPEN);
assertTrue(listener.eventReceived());
assertTrue(listener.isOpened());
sessions.closeSession(session1);
assertEquals(session1.getState(), State.CLOSED);
assertTrue(listener.eventReceived());
assertTrue(listener.isClosed());
RaftSession session2 = createSession(2);
sessions.openSession(session2);
assertEquals(session2.getState(), State.OPEN);
assertTrue(listener.eventReceived());
assertTrue(listener.isOpened());
sessions.expireSession(session2);
assertEquals(session2.getState(), State.EXPIRED);
assertTrue(listener.eventReceived());
assertTrue(listener.isExpired());
}
Aggregations