Search in sources :

Example 1 with EzySimpleSocketRequest

use of com.tvd12.ezyfoxserver.socket.EzySimpleSocketRequest 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 2 with EzySimpleSocketRequest

use of com.tvd12.ezyfoxserver.socket.EzySimpleSocketRequest 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 3 with EzySimpleSocketRequest

use of com.tvd12.ezyfoxserver.socket.EzySimpleSocketRequest 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 4 with EzySimpleSocketRequest

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

Example 5 with EzySimpleSocketRequest

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

the class EzySessionTicketsRequestQueuesTest method addSystemRequest.

@Test
public void addSystemRequest() {
    // given
    EzySession session = mock(EzySession.class);
    EzyArray data = EzyEntityArrays.newArray(EzyCommand.APP_ACCESS.getId(), EzyEmptyObject.getInstance());
    EzySocketRequest socketRequest = new EzySimpleSocketRequest(session, data);
    EzyRequestQueue queue = mock(EzyRequestQueue.class);
    when(queue.isEmpty()).thenReturn(false);
    when(queue.add(socketRequest)).thenReturn(false);
    when(session.getSystemRequestQueue()).thenReturn(queue);
    EzySessionTicketsRequestQueues sut = new EzySessionTicketsRequestQueues();
    // when
    boolean result = sut.addRequest(socketRequest);
    // then
    Asserts.assertFalse(result);
    Asserts.assertTrue(sut.getSystemQueue().isEmpty());
}
Also used : EzySocketRequest(com.tvd12.ezyfoxserver.socket.EzySocketRequest) EzySessionTicketsRequestQueues(com.tvd12.ezyfoxserver.socket.EzySessionTicketsRequestQueues) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimpleSocketRequest(com.tvd12.ezyfoxserver.socket.EzySimpleSocketRequest) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyRequestQueue(com.tvd12.ezyfoxserver.socket.EzyRequestQueue) Test(org.testng.annotations.Test)

Aggregations

EzyArray (com.tvd12.ezyfox.entity.EzyArray)7 Test (org.testng.annotations.Test)7 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)6 EzySimpleSocketRequest (com.tvd12.ezyfoxserver.socket.EzySimpleSocketRequest)3 EzyRequestQueue (com.tvd12.ezyfoxserver.socket.EzyRequestQueue)2 EzySessionTicketsRequestQueues (com.tvd12.ezyfoxserver.socket.EzySessionTicketsRequestQueues)2 EzySocketRequest (com.tvd12.ezyfoxserver.socket.EzySocketRequest)2 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)1 BaseTest (com.tvd12.test.base.BaseTest)1