Search in sources :

Example 16 with RaftSession

use of io.atomix.protocols.raft.session.RaftSession in project atomix by atomix.

the class RaftSessions method openSession.

/**
 * Adds a session to the sessions list.
 *
 * @param session The session to add.
 */
void openSession(RaftSession session) {
    final RaftSession singletonSession = sessionManager.addSession(session);
    singletonSession.open();
    listeners.forEach(l -> l.onOpen(singletonSession));
}
Also used : RaftSession(io.atomix.protocols.raft.session.RaftSession)

Example 17 with RaftSession

use of io.atomix.protocols.raft.session.RaftSession 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());
}
Also used : RaftSession(io.atomix.protocols.raft.session.RaftSession) RaftSessionRegistry(io.atomix.protocols.raft.session.RaftSessionRegistry) Test(org.junit.Test)

Aggregations

RaftSession (io.atomix.protocols.raft.session.RaftSession)17 RaftServiceContext (io.atomix.protocols.raft.service.RaftServiceContext)3 PrimitiveType (io.atomix.primitive.PrimitiveType)2 SessionId (io.atomix.primitive.session.SessionId)2 QueryEntry (io.atomix.protocols.raft.storage.log.entry.QueryEntry)2 Indexed (io.atomix.storage.journal.Indexed)2 NodeId (io.atomix.cluster.NodeId)1 SessionMetadata (io.atomix.primitive.session.SessionMetadata)1 ReadConsistency (io.atomix.protocols.raft.ReadConsistency)1 OperationResult (io.atomix.protocols.raft.impl.OperationResult)1 PendingCommand (io.atomix.protocols.raft.impl.PendingCommand)1 RaftContext (io.atomix.protocols.raft.impl.RaftContext)1 RaftServiceManager (io.atomix.protocols.raft.impl.RaftServiceManager)1 CommandResponse (io.atomix.protocols.raft.protocol.CommandResponse)1 QueryResponse (io.atomix.protocols.raft.protocol.QueryResponse)1 RaftServerProtocol (io.atomix.protocols.raft.protocol.RaftServerProtocol)1 TestPrimitiveType (io.atomix.protocols.raft.proxy.impl.TestPrimitiveType)1 RaftSessionRegistry (io.atomix.protocols.raft.session.RaftSessionRegistry)1 ThreadContext (io.atomix.utils.concurrent.ThreadContext)1 ThreadContextFactory (io.atomix.utils.concurrent.ThreadContextFactory)1