Search in sources :

Example 1 with EzySessionTicketsRequestQueues

use of com.tvd12.ezyfoxserver.socket.EzySessionTicketsRequestQueues 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());
}
Also used : EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 2 with EzySessionTicketsRequestQueues

use of com.tvd12.ezyfoxserver.socket.EzySessionTicketsRequestQueues in project ezyfox-server by youngmonkeys.

the class EzySocketRequestHandlerTest method test.

@Test
public void test() {
    ExEzySocketRequestHandler handler = new ExEzySocketRequestHandler();
    EzySocketDataHandlerGroupFetcher dataHandlerGroupFetcher = mock(EzySocketDataHandlerGroupFetcher.class);
    EzySocketDataHandlerGroup handlerGroup = mock(EzySocketDataHandlerGroup.class);
    when(dataHandlerGroupFetcher.getDataHandlerGroup(any(EzySession.class))).thenReturn(handlerGroup);
    EzySession session = spy(EzyAbstractSession.class);
    session.setActivated(true);
    EzyRequestQueue requestQueue = new EzyNonBlockingRequestQueue();
    when(session.getExtensionRequestQueue()).thenReturn(requestQueue);
    EzyArray array = EzyEntityFactory.newArrayBuilder().append(10).build();
    EzySocketRequest request = new EzySimpleSocketRequest(session, array);
    EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
    handler.setSessionTicketsQueue(sessionTicketsRequestQueues.getExtensionQueue());
    sessionTicketsRequestQueues.addRequest(request);
    handler.setDataHandlerGroupFetcher(dataHandlerGroupFetcher);
    handler.handleEvent();
    handler.destroy();
}
Also used : EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 3 with EzySessionTicketsRequestQueues

use of com.tvd12.ezyfoxserver.socket.EzySessionTicketsRequestQueues in project ezyfox-server by youngmonkeys.

the class EzySocketRequestHandlerTest method processRequestQueue0RemainTest.

@Test
public void processRequestQueue0RemainTest() {
    // given
    ExEzySocketRequestHandler handler = new ExEzySocketRequestHandler();
    EzySocketDataHandlerGroup handlerGroup = mock(EzySocketDataHandlerGroup.class);
    EzySocketDataHandlerGroupFetcher dataHandlerGroupFetcher = mock(EzySocketDataHandlerGroupFetcher.class);
    when(dataHandlerGroupFetcher.getDataHandlerGroup(any(EzySession.class))).thenReturn(handlerGroup);
    EzySession session = spy(EzyAbstractSession.class);
    when(session.isActivated()).thenReturn(Boolean.TRUE);
    EzyRequestQueue requestQueue = new EzyNonBlockingRequestQueue();
    when(session.getExtensionRequestQueue()).thenReturn(requestQueue);
    EzyArray array = EzyEntityFactory.newArrayBuilder().append(10).build();
    EzySocketRequest request = new EzySimpleSocketRequest(session, array);
    EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
    handler.setSessionTicketsQueue(sessionTicketsRequestQueues.getExtensionQueue());
    sessionTicketsRequestQueues.addRequest(request);
    sessionTicketsRequestQueues.addRequest(request);
    handler.setDataHandlerGroupFetcher(dataHandlerGroupFetcher);
    // when
    handler.handleEvent();
    // then
    Asserts.assertEquals(sessionTicketsRequestQueues.getExtensionQueue().size(), 1);
}
Also used : EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 4 with EzySessionTicketsRequestQueues

use of com.tvd12.ezyfoxserver.socket.EzySessionTicketsRequestQueues in project ezyfox-server by youngmonkeys.

the class EzySocketRequestHandlerTest method handleGroupNullCaseTest.

@Test
public void handleGroupNullCaseTest() {
    ExEzySocketRequestHandler handler = new ExEzySocketRequestHandler();
    EzySocketDataHandlerGroupFetcher dataHandlerGroupFetcher = mock(EzySocketDataHandlerGroupFetcher.class);
    when(dataHandlerGroupFetcher.getDataHandlerGroup(any(EzySession.class))).thenReturn(null);
    EzySession session = spy(EzyAbstractSession.class);
    when(session.isActivated()).thenReturn(Boolean.TRUE);
    EzyRequestQueue requestQueue = new EzyNonBlockingRequestQueue();
    when(session.getExtensionRequestQueue()).thenReturn(requestQueue);
    EzyArray array = EzyEntityFactory.newArrayBuilder().append(10).build();
    EzySocketRequest request = new EzySimpleSocketRequest(session, array);
    EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
    handler.setSessionTicketsQueue(sessionTicketsRequestQueues.getExtensionQueue());
    sessionTicketsRequestQueues.addRequest(request);
    handler.setDataHandlerGroupFetcher(dataHandlerGroupFetcher);
    handler.handleEvent();
}
Also used : EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 5 with EzySessionTicketsRequestQueues

use of com.tvd12.ezyfoxserver.socket.EzySessionTicketsRequestQueues in project ezyfox-server by youngmonkeys.

the class EzySocketRequestHandlerTest method processRequestQueue0ExceptionCaseTest.

@Test
public void processRequestQueue0ExceptionCaseTest() {
    ExEzySocketRequestHandler handler = new ExEzySocketRequestHandler();
    EzySocketDataHandlerGroupFetcher dataHandlerGroupFetcher = mock(EzySocketDataHandlerGroupFetcher.class);
    when(dataHandlerGroupFetcher.getDataHandlerGroup(any(EzySession.class))).thenThrow(new IllegalArgumentException());
    EzySession session = spy(EzyAbstractSession.class);
    when(session.isActivated()).thenReturn(Boolean.TRUE);
    EzyRequestQueue requestQueue = new EzyNonBlockingRequestQueue();
    when(session.getExtensionRequestQueue()).thenReturn(requestQueue);
    EzyArray array = EzyEntityFactory.newArrayBuilder().append(10).build();
    EzySocketRequest request = new EzySimpleSocketRequest(session, array);
    EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
    handler.setSessionTicketsQueue(sessionTicketsRequestQueues.getExtensionQueue());
    sessionTicketsRequestQueues.addRequest(request);
    handler.setDataHandlerGroupFetcher(dataHandlerGroupFetcher);
    handler.handleEvent();
}
Also used : EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)15 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)14 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)14 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)14 EzySimpleStreamingSetting (com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting)14 ExecutorService (java.util.concurrent.ExecutorService)14 EzySimpleStatistics (com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics)13 EzyStatistics (com.tvd12.ezyfoxserver.statistics.EzyStatistics)13 EzyHandlerGroupBuilderFactory (com.tvd12.ezyfoxserver.nio.factory.EzyHandlerGroupBuilderFactory)12 EzySimpleSessionTokenGenerator (com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator)12 BaseTest (com.tvd12.test.base.BaseTest)9 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)8 EzySimpleSessionManagementSetting (com.tvd12.ezyfoxserver.setting.EzySimpleSessionManagementSetting)8 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)8 EzyArray (com.tvd12.ezyfox.entity.EzyArray)7 EzyCodecFactory (com.tvd12.ezyfoxserver.codec.EzyCodecFactory)7 EzyNioSession (com.tvd12.ezyfoxserver.nio.entity.EzyNioSession)6 ByteBuffer (java.nio.ByteBuffer)6 EzyNioSessionManager (com.tvd12.ezyfoxserver.nio.wrapper.EzyNioSessionManager)5 EzySimpleNioHandlerGroup (com.tvd12.ezyfoxserver.nio.handler.EzySimpleNioHandlerGroup)4