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);
}
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);
}
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);
}
Aggregations