use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzyAbstractHandlerGroupTest method handleReceivedDataNotSuccess.
@Test
public void handleReceivedDataNotSuccess() throws Exception {
// given
ExHandlerGroup sut = newHandlerGroup();
EzySession session = FieldUtil.getFieldValue(sut, "session");
when(session.addReceivedRequests(1)).thenReturn(false);
when(session.isActivated()).thenReturn(true);
EzySessionTicketsRequestQueues sessionTicketsRequestQueues = FieldUtil.getFieldValue(sut, "sessionTicketsRequestQueues");
EzyArray data = EzyEntityFactory.newArrayBuilder().append(EzyCommand.APP_ACCESS.getId()).append(EzyEntityFactory.newArray()).build();
// when
MethodInvoker.create().object(sut).method("handleReceivedData").param(Object.class, data).param(int.class, 100).call();
// then
verify(sessionTicketsRequestQueues, times(1)).addRequest(any());
}
use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzyAbstractHandlerGroupTest method executeSendingPacketCanNotWriteBytes.
@Test
public void executeSendingPacketCanNotWriteBytes() throws Exception {
// given
ExHandlerGroup sut = newHandlerGroup();
EzyPacket packet = mock(EzyPacket.class);
ByteBuffer writeBuffer = ByteBuffer.wrap(new byte[0]);
// when
MethodInvoker.create().object(sut).method("executeSendingPacket").param(EzyPacket.class, packet).param(Object.class, writeBuffer).call();
// then
EzySession session = FieldUtil.getFieldValue(sut, "session");
verify(session, times(3)).getChannel();
}
use of com.tvd12.ezyfoxserver.entity.EzySession 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.entity.EzySession in project ezyfox-server by youngmonkeys.
the class EzySimpleNioHandlerGroupTest method handleReceivedMessageHeaderIsNotRawBytes.
@Test
public void handleReceivedMessageHeaderIsNotRawBytes() throws Exception {
// given
EzySimpleNioHandlerGroup sut = newHandlerGroup();
EzyMessage message = mock(EzyMessage.class);
EzyMessageHeader header = mock(EzyMessageHeader.class);
when(message.getHeader()).thenReturn(header);
// when
MethodInvoker.create().object(sut).method("handleReceivedMessage").param(EzyMessage.class, message).call();
// then
verify(header, times(1)).isRawBytes();
EzySimpleMessageDataDecoder decoder = FieldUtil.getFieldValue(sut, "decoder");
EzyByteToObjectDecoder d = FieldUtil.getFieldValue(decoder, "decoder");
EzySession session = FieldUtil.getFieldValue(sut, "session");
verify(d, times(1)).decode(message, session.getSessionKey());
}
use of com.tvd12.ezyfoxserver.entity.EzySession 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);
}
Aggregations