Search in sources :

Example 31 with EzySession

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

the class EzySessionTicketsRequestQueues method addRequest.

public boolean addRequest(EzySocketRequest request) {
    EzyRequestQueue queue;
    EzySessionTicketsQueue ticketsQueue;
    EzySession session = request.getSession();
    if (request.isSystemRequest()) {
        ticketsQueue = systemQueue;
        queue = session.getSystemRequestQueue();
    } else {
        ticketsQueue = extensionQueue;
        queue = session.getExtensionRequestQueue();
    }
    boolean success;
    // noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (queue) {
        boolean empty = queue.isEmpty();
        success = queue.add(request);
        if (empty && success) {
            ticketsQueue.add(session);
        }
    }
    return success;
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession)

Example 32 with EzySession

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

the class EzySocketDisconnectionHandler method processDisconnection.

private void processDisconnection(EzySocketDisconnection disconnection) {
    try {
        EzySession session = disconnection.getSession();
        EzyConstant disconnectReason = disconnection.getDisconnectReason();
        EzySocketDataHandlerGroup handlerGroup = removeDataHandlerGroup(session);
        if (handlerGroup != null) {
            handlerGroup.fireChannelInactive(disconnectReason);
        } else {
            logger.warn("has no handler group with session: {}, ignore disconnection: {}", session, disconnection);
        }
    } finally {
        disconnection.release();
    }
}
Also used : EzyConstant(com.tvd12.ezyfox.constant.EzyConstant) EzySession(com.tvd12.ezyfoxserver.entity.EzySession)

Example 33 with EzySession

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

the class EzySimpleDataHandlerTest method dataReceivedValidateSessionInActive.

@Test
public void dataReceivedValidateSessionInActive() {
    // given
    MyTestDataHandler sut = createHandler();
    EzySession session = FieldUtil.getFieldValue(sut, "session");
    session.setActivated(false);
    EzyArray msg = EzyEntityFactory.newArray();
    // when
    sut.dataReceived(EzyCommand.APP_ACCESS, msg);
    // then
    Asserts.assertFalse(session.isActivated());
}
Also used : EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 34 with EzySession

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

the class EzySimpleDataHandlerTest method processMaxRequestPerSecondDisconnect.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void processMaxRequestPerSecondDisconnect() {
    // given
    EzySession session = spy(EzyAbstractSession.class);
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyServer server = mock(EzyServer.class);
    EzySessionManager sessionManager = mock(EzySessionManager.class);
    when(server.getSessionManager()).thenReturn(sessionManager);
    when(serverContext.getServer()).thenReturn(server);
    EzySessionManagementSetting sessionManagementSetting = mock(EzySessionManagementSetting.class);
    EzySessionManagementSetting.EzyMaxRequestPerSecond maxRequestPerSecond = mock(EzySessionManagementSetting.EzyMaxRequestPerSecond.class);
    when(maxRequestPerSecond.getAction()).thenReturn(EzyMaxRequestPerSecondAction.DISCONNECT_SESSION);
    when(sessionManagementSetting.getSessionMaxRequestPerSecond()).thenReturn(maxRequestPerSecond);
    EzySettings settings = mock(EzySettings.class);
    when(server.getSettings()).thenReturn(settings);
    when(settings.getSessionManagement()).thenReturn(sessionManagementSetting);
    EzyLoggerSetting loggerSetting = mock(EzyLoggerSetting.class);
    EzyLoggerSetting.EzyIgnoredCommandsSetting ignoredCommandsSetting = mock(EzyLoggerSetting.EzyIgnoredCommandsSetting.class);
    when(ignoredCommandsSetting.getCommands()).thenReturn(Collections.emptySet());
    when(loggerSetting.getIgnoredCommands()).thenReturn(ignoredCommandsSetting);
    when(settings.getLogger()).thenReturn(loggerSetting);
    MyTestDataHandler sut = new MyTestDataHandler(serverContext, session);
    // when
    sut.processMaxRequestPerSecond();
    // then
    verify(sessionManager, times(1)).removeSession(session, EzyDisconnectReason.MAX_REQUEST_PER_SECOND);
}
Also used : EzySessionManagementSetting(com.tvd12.ezyfoxserver.setting.EzySessionManagementSetting) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyLoggerSetting(com.tvd12.ezyfoxserver.setting.EzyLoggerSetting) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyServer(com.tvd12.ezyfoxserver.EzyServer) EzySettings(com.tvd12.ezyfoxserver.setting.EzySettings) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 35 with EzySession

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

the class EzyLoginControllerTest method maximumSession1Test.

@Test(expectedExceptions = EzyLoginErrorException.class)
public void maximumSession1Test() {
    EzySimpleServerContext ctx = (EzySimpleServerContext) newServerContext();
    EzySimpleServer server = (EzySimpleServer) ctx.getServer();
    EzyZoneContext zoneContext = ctx.getZoneContext("example");
    EzyZoneSetting zoneSetting = zoneContext.getZone().getSetting();
    EzySimpleUserManagementSetting userManagementSetting = (EzySimpleUserManagementSetting) zoneSetting.getUserManagement();
    userManagementSetting.setMaxSessionPerUser(0);
    server.setResponseApi(mock(EzyResponseApi.class));
    EzySession session = newSession();
    session.setToken("abcdef");
    EzyArray data = newLoginData();
    data.set(1, "");
    EzyLoginController controller = new EzyLoginController();
    EzySimpleLoginRequest request = new EzySimpleLoginRequest();
    request.deserializeParams(data);
    request.setSession(session);
    controller.handle(ctx, request);
}
Also used : EzySimpleUserManagementSetting(com.tvd12.ezyfoxserver.setting.EzySimpleUserManagementSetting) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyZoneSetting(com.tvd12.ezyfoxserver.setting.EzyZoneSetting) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimpleLoginRequest(com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyLoginController(com.tvd12.ezyfoxserver.controller.EzyLoginController) 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