Search in sources :

Example 1 with EzyNonBlockingRequestQueue

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

the class EzyAbstractSessionFactory method initSession.

protected void initSession(EzyAbstractSession session) {
    session.setId(counter.incrementAndGet());
    session.setCreationTime(System.currentTimeMillis());
    session.setPacketQueue(new EzyNonBlockingPacketQueue());
    session.setSystemRequestQueue(new EzyNonBlockingRequestQueue());
    session.setExtensionRequestQueue(new EzyNonBlockingRequestQueue());
    session.setRequestFrameInSecond(new EzyRequestFrameSecond(maxRequestPerSecond.getValue()));
}
Also used : EzyNonBlockingRequestQueue(com.tvd12.ezyfoxserver.socket.EzyNonBlockingRequestQueue) EzyNonBlockingPacketQueue(com.tvd12.ezyfoxserver.socket.EzyNonBlockingPacketQueue) EzyRequestFrameSecond(com.tvd12.ezyfoxserver.statistics.EzyRequestFrameSecond)

Example 2 with EzyNonBlockingRequestQueue

use of com.tvd12.ezyfoxserver.socket.EzyNonBlockingRequestQueue 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 EzyNonBlockingRequestQueue

use of com.tvd12.ezyfoxserver.socket.EzyNonBlockingRequestQueue 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 EzyNonBlockingRequestQueue

use of com.tvd12.ezyfoxserver.socket.EzyNonBlockingRequestQueue 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 EzyNonBlockingRequestQueue

use of com.tvd12.ezyfoxserver.socket.EzyNonBlockingRequestQueue 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)6 EzyArray (com.tvd12.ezyfox.entity.EzyArray)4 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)4 EzyNonBlockingRequestQueue (com.tvd12.ezyfoxserver.socket.EzyNonBlockingRequestQueue)3 EzySocketRequest (com.tvd12.ezyfoxserver.socket.EzySocketRequest)2 BaseTest (com.tvd12.test.base.BaseTest)2 EzyNonBlockingPacketQueue (com.tvd12.ezyfoxserver.socket.EzyNonBlockingPacketQueue)1 EzyRequestFrameSecond (com.tvd12.ezyfoxserver.statistics.EzyRequestFrameSecond)1