use of com.tvd12.ezyfoxserver.testing.MyTestSessionManager 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();
}
use of com.tvd12.ezyfoxserver.testing.MyTestSessionManager in project ezyfox-server by youngmonkeys.
the class EzySimpleSessionManagerTest method test1.
@Test
public void test1() {
MyTestSessionManager manager = (MyTestSessionManager) new MyTestSessionManager.Builder().tokenGenerator(() -> UUID.randomUUID().toString()).build();
MyTestSession session = manager.provideSession(EzyConnectionType.SOCKET);
session.setLoggedIn(true);
manager.addLoggedInSession(session);
MyTestSession session2 = manager.provideSession(EzyConnectionType.SOCKET);
assert session.getId() != session2.getId();
assertEquals(manager.getAllSessions(), Lists.newArrayList(session, session2));
}
use of com.tvd12.ezyfoxserver.testing.MyTestSessionManager in project ezyfox-server by youngmonkeys.
the class EzySimpleSessionManagerTest method isUnloggedInSessionFalseTest.
@Test
public void isUnloggedInSessionFalseTest() {
// given
MyTestSessionManager manager = new MyTestSessionManager.Builder().build();
EzySession session = mock(EzySession.class);
when(session.isLoggedIn()).thenReturn(false);
when(session.isActivated()).thenReturn(true);
when(session.getMaxWaitingTime()).thenReturn(1000L);
when(session.getCreationTime()).thenReturn(System.currentTimeMillis() - 100L);
// when
Boolean result = MethodInvoker.create().object(manager).method("isUnloggedInSession").param(EzySession.class, session).invoke(Boolean.class);
// then
Asserts.assertFalse(result);
}
use of com.tvd12.ezyfoxserver.testing.MyTestSessionManager in project ezyfox-server by youngmonkeys.
the class EzySimpleSessionManagerTest method checkMaxSessionsTest.
@Test
public void checkMaxSessionsTest() {
// given
MyTestSessionManager manager = (MyTestSessionManager) new MyTestSessionManager.Builder().maxSessions(0).build();
// when
Throwable e = Asserts.assertThrows(() -> manager.provideSession(EzyConnectionType.SOCKET));
// then
Asserts.assertEquals(EzyMaxSessionException.class, e.getClass());
}
use of com.tvd12.ezyfoxserver.testing.MyTestSessionManager in project ezyfox-server by youngmonkeys.
the class EzySimpleSessionManagerTest method clearNullSessionTest.
@Test
public void clearNullSessionTest() {
// given
MyTestSessionManager manager = new MyTestSessionManager.Builder().build();
// when
// then
manager.clearSession(null);
}
Aggregations