Search in sources :

Example 1 with EzyAbstractSessionDelegate

use of com.tvd12.ezyfoxserver.delegate.EzyAbstractSessionDelegate in project ezyfox-server by youngmonkeys.

the class EzySessionAdapterTest method test.

@Test
public void test() {
    EzySessionDelegate delegate = new EzyAbstractSessionDelegate() {
    };
    delegate.onSessionLoggedIn(new EzySimpleUser());
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzySessionDelegate(com.tvd12.ezyfoxserver.delegate.EzySessionDelegate) EzyAbstractSessionDelegate(com.tvd12.ezyfoxserver.delegate.EzyAbstractSessionDelegate) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 2 with EzyAbstractSessionDelegate

use of com.tvd12.ezyfoxserver.delegate.EzyAbstractSessionDelegate in project ezyfox-server by youngmonkeys.

the class EzySimpleSessionManagerTest method testNormalCase.

@Test
public void testNormalCase() throws Exception {
    MyTestSessionManager manager = (MyTestSessionManager) new MyTestSessionManager.Builder().validationDelay(5).validationInterval(5).build();
    MyTestSession session = manager.provideSession(EzyConnectionType.SOCKET);
    manager.removeSession(session);
    session = manager.provideSession(EzyConnectionType.SOCKET);
    session.setDelegate(new EzyAbstractSessionDelegate() {
    });
    manager.removeSession(session, EzyDisconnectReason.IDLE);
    manager.removeSession(null, EzyDisconnectReason.IDLE);
    session = manager.provideSession(EzyConnectionType.SOCKET);
    session.setDelegate(new EzyAbstractSessionDelegate() {
    });
    session.setLoggedIn(true);
    manager.addLoggedInSession(session);
    assertEquals(manager.getLoggedInSessions(), Lists.newArrayList(session));
    session = manager.provideSession(EzyConnectionType.SOCKET);
    session.setActivated(true);
    session.setLoggedIn(false);
    session.setCreationTime(System.currentTimeMillis() - 1000);
    session.setMaxWaitingTime(100);
    session = manager.provideSession(EzyConnectionType.SOCKET);
    session.setLoggedIn(false);
    session.setCreationTime(System.currentTimeMillis());
    session.setMaxWaitingTime(10000);
    assert manager.getAllSessionCount() == 5;
    assert manager.getAliveSessionCount() == 5;
    assert manager.getLoggedInSessionCount() == 1;
    session = manager.provideSession(EzyConnectionType.SOCKET);
    session.setActivated(true);
    session.setLoggedIn(true);
    session.setLastReadTime(0);
    session.setCreationTime(System.currentTimeMillis());
    session.setMaxWaitingTime(10000);
    try {
        manager.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
    Thread.sleep(300);
    Object connection = new Object();
    EzyChannel channel = mock(EzyChannel.class);
    when(channel.getConnection()).thenReturn(connection);
    when(channel.getConnectionType()).thenReturn(EzyConnectionType.SOCKET);
    session = manager.provideSession(channel);
    assert manager.getSession(session.getId()) == session;
    assert manager.getSession(connection) == session;
    manager.clearSession(session);
    Thread.sleep(300);
    manager.destroy();
}
Also used : EzyChannel(com.tvd12.ezyfoxserver.socket.EzyChannel) EzyAbstractSessionDelegate(com.tvd12.ezyfoxserver.delegate.EzyAbstractSessionDelegate) MyTestSessionManager(com.tvd12.ezyfoxserver.testing.MyTestSessionManager) MyTestSession(com.tvd12.ezyfoxserver.testing.MyTestSession) EzyMaxSessionException(com.tvd12.ezyfoxserver.exception.EzyMaxSessionException) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Aggregations

EzyAbstractSessionDelegate (com.tvd12.ezyfoxserver.delegate.EzyAbstractSessionDelegate)2 Test (org.testng.annotations.Test)2 EzySessionDelegate (com.tvd12.ezyfoxserver.delegate.EzySessionDelegate)1 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)1 EzyMaxSessionException (com.tvd12.ezyfoxserver.exception.EzyMaxSessionException)1 EzyChannel (com.tvd12.ezyfoxserver.socket.EzyChannel)1 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)1 MyTestSession (com.tvd12.ezyfoxserver.testing.MyTestSession)1 MyTestSessionManager (com.tvd12.ezyfoxserver.testing.MyTestSessionManager)1 BaseTest (com.tvd12.test.base.BaseTest)1