Search in sources :

Example 71 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class HelloController2 method greet.

@EzyDoHandle("Hello")
public void greet(GreetRequest request, EzyUser user, EzySession session) {
    GreetResponse response = new GreetResponse("Hello " + request.getWho() + "!");
    System.out.println("HelloController::Big/Hello response: " + response);
}
Also used : GreetResponse(com.tvd12.ezyfoxserver.support.test.data.GreetResponse) EzyDoHandle(com.tvd12.ezyfox.core.annotation.EzyDoHandle)

Example 72 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class EzyBlockingSessionTicketsQueueTest method takeInactiveSession.

@Test
public void takeInactiveSession() throws Exception {
    // given
    EzyBlockingSessionTicketsQueue sut = new EzyBlockingSessionTicketsQueue();
    MySession session = new MySession();
    session.setActivated(false);
    sut.add(session);
    Thread newThread = new Thread(() -> {
        // when
        EzySession takeSession;
        try {
            takeSession = sut.take();
        } catch (InterruptedException e) {
            return;
        }
        // then
        Asserts.assertEquals(session, takeSession);
    });
    newThread.start();
    Thread.sleep(300L);
    newThread.interrupt();
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyBlockingSessionTicketsQueue(com.tvd12.ezyfoxserver.socket.EzyBlockingSessionTicketsQueue) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 73 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession 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)

Example 74 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class EzySessionTicketsRequestQueuesTest method addSystemRequestWithEmptyQueue.

@Test
public void addSystemRequestWithEmptyQueue() {
    // 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(true);
    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)

Example 75 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class EzySocketDisconnectionHandlerTest method processDisconnectionQueueExceptionCaseTest.

@Test
public void processDisconnectionQueueExceptionCaseTest() {
    EzySocketDisconnectionHandler handler = new EzySocketDisconnectionHandler();
    EzySocketDisconnectionQueue disconnectionQueue = new EzyBlockingSocketDisconnectionQueue();
    EzySocketDataHandlerGroupRemover dataHandlerGroupRemover = mock(EzySocketDataHandlerGroupRemover.class);
    when(dataHandlerGroupRemover.removeHandlerGroup(any(EzySession.class))).thenThrow(new IllegalArgumentException());
    EzySession session = spy(EzyAbstractSession.class);
    EzySocketDisconnection disconnection = new EzySimpleSocketDisconnection(session);
    disconnectionQueue.add(disconnection);
    handler.setDisconnectionQueue(disconnectionQueue);
    handler.setDataHandlerGroupRemover(dataHandlerGroupRemover);
    handler.handleEvent();
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Aggregations

EzySession (com.tvd12.ezyfoxserver.entity.EzySession)112 Test (org.testng.annotations.Test)92 EzyArray (com.tvd12.ezyfox.entity.EzyArray)33 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)26 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)25 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)25 BaseTest (com.tvd12.test.base.BaseTest)25 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)15 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)14 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)13 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)13 EzySimpleLoginRequest (com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest)13 EzyLoginController (com.tvd12.ezyfoxserver.controller.EzyLoginController)12 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)11 EzySendResponseImpl (com.tvd12.ezyfoxserver.command.impl.EzySendResponseImpl)8 EzyHandshakeController (com.tvd12.ezyfoxserver.controller.EzyHandshakeController)8 EzyHandshakeParams (com.tvd12.ezyfoxserver.request.EzyHandshakeParams)8 EzySimpleResponse (com.tvd12.ezyfoxserver.response.EzySimpleResponse)8 GreetResponse (com.tvd12.ezyfoxserver.support.test.data.GreetResponse)8 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)8