Search in sources :

Example 1 with EzyNioDataHandler

use of com.tvd12.ezyfoxserver.nio.handler.EzyNioDataHandler in project ezyfox-server by youngmonkeys.

the class EzyAbstractHandlerGroupTest method fireExceptionCaughtException.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void fireExceptionCaughtException() throws Exception {
    // given
    ExHandlerGroup sut = newHandlerGroup();
    EzySession session = FieldUtil.getFieldValue(sut, "session");
    EzyNioDataHandler handler = FieldUtil.getFieldValue(sut, "handler");
    EzySessionManager sessionManager = FieldUtil.getFieldValue(handler, "sessionManager");
    doThrow(new RuntimeException()).when(sessionManager).removeSession(session, MAX_REQUEST_SIZE);
    EzyMaxRequestSizeException exception = new EzyMaxRequestSizeException("just test");
    // when
    sut.fireExceptionCaught(exception);
    // then
    verify(sessionManager, times(1)).removeSession(session, MAX_REQUEST_SIZE);
}
Also used : EzyNioDataHandler(com.tvd12.ezyfoxserver.nio.handler.EzyNioDataHandler) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyMaxRequestSizeException(com.tvd12.ezyfox.exception.EzyMaxRequestSizeException) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 2 with EzyNioDataHandler

use of com.tvd12.ezyfoxserver.nio.handler.EzyNioDataHandler in project ezyfox-server by youngmonkeys.

the class EzyAbstractHandlerGroupTest method fireChannelInactiveException.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void fireChannelInactiveException() throws Exception {
    // given
    ExHandlerGroup sut = newHandlerGroup();
    EzySession session = FieldUtil.getFieldValue(sut, "session");
    EzyNioDataHandler handler = FieldUtil.getFieldValue(sut, "handler");
    EzySessionManager sessionManager = FieldUtil.getFieldValue(handler, "sessionManager");
    doThrow(new RuntimeException()).when(sessionManager).clearSession(session);
    // when
    sut.fireChannelInactive(EzyDisconnectReason.ADMIN_BAN);
    // then
    verify(sessionManager, times(1)).clearSession(session);
}
Also used : EzyNioDataHandler(com.tvd12.ezyfoxserver.nio.handler.EzyNioDataHandler) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 3 with EzyNioDataHandler

use of com.tvd12.ezyfoxserver.nio.handler.EzyNioDataHandler in project ezyfox-server by youngmonkeys.

the class EzyAbstractHandlerGroupTest method hasMaxRequestPerSecondTest.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void hasMaxRequestPerSecondTest() throws Exception {
    // given
    ExHandlerGroup sut = newHandlerGroup();
    EzySession session = FieldUtil.getFieldValue(sut, "session");
    when(session.addReceivedRequests(1)).thenReturn(true);
    EzyNioDataHandler handler = FieldUtil.getFieldValue(sut, "handler");
    EzySessionManager sessionManager = FieldUtil.getFieldValue(handler, "sessionManager");
    EzySimpleMaxRequestPerSecond maxRequestPerSecond = FieldUtil.getFieldValue(handler, "maxRequestPerSecond");
    maxRequestPerSecond.setAction(EzyMaxRequestPerSecondAction.DISCONNECT_SESSION);
    EzyArray data = EzyEntityFactory.newArray();
    // when
    MethodInvoker.create().object(sut).method("handleReceivedData").param(Object.class, data).param(int.class, 100).call();
    // then
    verify(sessionManager, times(1)).removeSession(session, MAX_REQUEST_PER_SECOND);
}
Also used : EzySimpleMaxRequestPerSecond(com.tvd12.ezyfoxserver.setting.EzySimpleSessionManagementSetting.EzySimpleMaxRequestPerSecond) EzyNioDataHandler(com.tvd12.ezyfoxserver.nio.handler.EzyNioDataHandler) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Aggregations

EzySession (com.tvd12.ezyfoxserver.entity.EzySession)3 EzyNioDataHandler (com.tvd12.ezyfoxserver.nio.handler.EzyNioDataHandler)3 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)3 BaseTest (com.tvd12.test.base.BaseTest)3 Test (org.testng.annotations.Test)3 EzyArray (com.tvd12.ezyfox.entity.EzyArray)1 EzyMaxRequestSizeException (com.tvd12.ezyfox.exception.EzyMaxRequestSizeException)1 EzySimpleMaxRequestPerSecond (com.tvd12.ezyfoxserver.setting.EzySimpleSessionManagementSetting.EzySimpleMaxRequestPerSecond)1