Search in sources :

Example 6 with EzyStatistics

use of com.tvd12.ezyfoxserver.statistics.EzyStatistics in project ezyfox-server by youngmonkeys.

the class EzyNioSocketAcceptorTest method newHandlerGroupManager.

private EzyHandlerGroupManager newHandlerGroupManager() {
    EzyNioSessionManager sessionManager = (EzyNioSessionManager) EzyNioSessionManagerImpl.builder().maxRequestPerSecond(new EzySimpleSessionManagementSetting.EzySimpleMaxRequestPerSecond()).tokenGenerator(new EzySimpleSessionTokenGenerator()).build();
    ExEzyByteToObjectDecoder decoder = new ExEzyByteToObjectDecoder();
    EzyCodecFactory codecFactory = mock(EzyCodecFactory.class);
    when(codecFactory.newDecoder(any())).thenReturn(decoder);
    ExecutorService statsThreadPool = EzyExecutors.newSingleThreadExecutor("stats");
    EzySocketStreamQueue streamQueue = new EzyBlockingSocketStreamQueue();
    EzySocketDisconnectionQueue disconnectionQueue = new EzyBlockingSocketDisconnectionQueue();
    EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
    EzySimpleSettings settings = new EzySimpleSettings();
    EzySimpleStreamingSetting streaming = settings.getStreaming();
    streaming.setEnable(true);
    EzySimpleServer server = new EzySimpleServer();
    server.setSettings(settings);
    server.setSessionManager(sessionManager);
    EzySimpleServerContext serverContext = new EzySimpleServerContext();
    serverContext.setServer(server);
    serverContext.init();
    EzySessionTicketsQueue socketSessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
    EzySessionTicketsQueue webSocketSessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
    EzyStatistics statistics = new EzySimpleStatistics();
    EzyHandlerGroupBuilderFactory handlerGroupBuilderFactory = EzyHandlerGroupBuilderFactoryImpl.builder().statistics(statistics).statsThreadPool(statsThreadPool).streamQueue(streamQueue).disconnectionQueue(disconnectionQueue).codecFactory(codecFactory).serverContext(serverContext).socketSessionTicketsQueue(socketSessionTicketsQueue).webSocketSessionTicketsQueue(webSocketSessionTicketsQueue).sessionTicketsRequestQueues(sessionTicketsRequestQueues).build();
    return EzyHandlerGroupManagerImpl.builder().handlerGroupBuilderFactory(handlerGroupBuilderFactory).build();
}
Also used : EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyHandlerGroupBuilderFactory(com.tvd12.ezyfoxserver.nio.factory.EzyHandlerGroupBuilderFactory) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzySimpleStreamingSetting(com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting) EzyStatistics(com.tvd12.ezyfoxserver.statistics.EzyStatistics) EzyNioSessionManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyNioSessionManager) EzyCodecFactory(com.tvd12.ezyfoxserver.codec.EzyCodecFactory) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) ExecutorService(java.util.concurrent.ExecutorService) EzySimpleStatistics(com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics) EzySimpleSessionTokenGenerator(com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator)

Example 7 with EzyStatistics

use of com.tvd12.ezyfoxserver.statistics.EzyStatistics in project ezyfox-server by youngmonkeys.

the class EzySimpleWsHandlerGroupTest method newHandlerGroup.

@SuppressWarnings("rawtypes")
private EzySimpleWsHandlerGroup newHandlerGroup(boolean streamEnable) throws IOException {
    EzySessionTicketsQueue socketSessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
    EzySessionTicketsQueue webSocketSessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
    EzySessionManager sessionManager = EzyNioSessionManagerImpl.builder().maxRequestPerSecond(new EzySimpleSessionManagementSetting.EzySimpleMaxRequestPerSecond()).tokenGenerator(new EzySimpleSessionTokenGenerator()).build();
    EzyStatistics statistics = new EzySimpleStatistics();
    EzySimpleSettings settings = new EzySimpleSettings();
    EzySimpleStreamingSetting streaming = settings.getStreaming();
    streaming.setEnable(streamEnable);
    EzySimpleServer server = new EzySimpleServer();
    server.setSettings(settings);
    server.setSessionManager(sessionManager);
    EzyServerControllers controllers = mock(EzyServerControllers.class);
    server.setControllers(controllers);
    EzySimpleConfig config = new EzySimpleConfig();
    server.setConfig(config);
    EzySimpleServerContext serverContext = new EzySimpleServerContext();
    serverContext.setServer(server);
    serverContext.init();
    EzyChannel channel = mock(EzyChannel.class);
    when(channel.isConnected()).thenReturn(true);
    when(channel.getConnection()).thenReturn(SocketChannel.open());
    when(channel.getConnectionType()).thenReturn(EzyConnectionType.WEBSOCKET);
    ExecutorService statsThreadPool = EzyExecutors.newFixedThreadPool(1, "stats");
    EzySocketStreamQueue streamQueue = new EzyBlockingSocketStreamQueue();
    EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
    EzySimpleSession session = mock(EzySimpleSession.class);
    when(session.getChannel()).thenReturn(channel);
    EzyHandlerGroupBuilderFactory handlerGroupBuilderFactory = EzyHandlerGroupBuilderFactoryImpl.builder().statistics(statistics).serverContext(serverContext).statsThreadPool(statsThreadPool).streamQueue(streamQueue).codecFactory(new ExCodecFactory()).sessionTicketsRequestQueues(sessionTicketsRequestQueues).socketSessionTicketsQueue(socketSessionTicketsQueue).webSocketSessionTicketsQueue(webSocketSessionTicketsQueue).build();
    return (EzySimpleWsHandlerGroup) handlerGroupBuilderFactory.newBuilder(channel, EzyConnectionType.WEBSOCKET).session(session).build();
}
Also used : EzySimpleConfig(com.tvd12.ezyfoxserver.config.EzySimpleConfig) EzySimpleWsHandlerGroup(com.tvd12.ezyfoxserver.nio.websocket.EzySimpleWsHandlerGroup) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleSessionManagementSetting(com.tvd12.ezyfoxserver.setting.EzySimpleSessionManagementSetting) EzyHandlerGroupBuilderFactory(com.tvd12.ezyfoxserver.nio.factory.EzyHandlerGroupBuilderFactory) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzyStatistics(com.tvd12.ezyfoxserver.statistics.EzyStatistics) EzySimpleStreamingSetting(com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyServerControllers(com.tvd12.ezyfoxserver.wrapper.EzyServerControllers) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) EzySimpleSession(com.tvd12.ezyfoxserver.nio.entity.EzySimpleSession) ExecutorService(java.util.concurrent.ExecutorService) EzySimpleStatistics(com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics) EzySimpleSessionTokenGenerator(com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator)

Example 8 with EzyStatistics

use of com.tvd12.ezyfoxserver.statistics.EzyStatistics in project ezyfox-server by youngmonkeys.

the class EzyHandlerGroupManagerImplTest method newHandlerGroupManager.

public EzyHandlerGroupManager newHandlerGroupManager() {
    EzyNioSessionManager sessionManager = (EzyNioSessionManager) EzyNioSessionManagerImpl.builder().maxRequestPerSecond(new EzySimpleSessionManagementSetting.EzySimpleMaxRequestPerSecond()).tokenGenerator(new EzySimpleSessionTokenGenerator()).build();
    ExEzyByteToObjectDecoder decoder = new ExEzyByteToObjectDecoder();
    EzyCodecFactory codecFactory = mock(EzyCodecFactory.class);
    when(codecFactory.newDecoder(any())).thenReturn(decoder);
    ExecutorService statsThreadPool = EzyExecutors.newSingleThreadExecutor("stats");
    EzySocketStreamQueue streamQueue = new EzyBlockingSocketStreamQueue();
    EzySocketDisconnectionQueue disconnectionQueue = new EzyBlockingSocketDisconnectionQueue();
    EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
    EzySimpleSettings settings = new EzySimpleSettings();
    EzySimpleStreamingSetting streaming = settings.getStreaming();
    streaming.setEnable(true);
    EzySimpleServer server = new EzySimpleServer();
    server.setSettings(settings);
    server.setSessionManager(sessionManager);
    EzySimpleServerContext serverContext = new EzySimpleServerContext();
    serverContext.setServer(server);
    serverContext.init();
    EzySessionTicketsQueue socketSessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
    EzySessionTicketsQueue webSocketSessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
    EzyStatistics statistics = new EzySimpleStatistics();
    EzyHandlerGroupBuilderFactory handlerGroupBuilderFactory = EzyHandlerGroupBuilderFactoryImpl.builder().statistics(statistics).statsThreadPool(statsThreadPool).streamQueue(streamQueue).disconnectionQueue(disconnectionQueue).codecFactory(codecFactory).serverContext(serverContext).socketSessionTicketsQueue(socketSessionTicketsQueue).webSocketSessionTicketsQueue(webSocketSessionTicketsQueue).socketSessionTicketsQueue(webSocketSessionTicketsQueue).sessionTicketsRequestQueues(sessionTicketsRequestQueues).build();
    return EzyHandlerGroupManagerImpl.builder().handlerGroupBuilderFactory(handlerGroupBuilderFactory).build();
}
Also used : EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyHandlerGroupBuilderFactory(com.tvd12.ezyfoxserver.nio.factory.EzyHandlerGroupBuilderFactory) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzySimpleStreamingSetting(com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting) EzyStatistics(com.tvd12.ezyfoxserver.statistics.EzyStatistics) EzyNioSessionManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyNioSessionManager) EzyCodecFactory(com.tvd12.ezyfoxserver.codec.EzyCodecFactory) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) ExecutorService(java.util.concurrent.ExecutorService) EzySimpleStatistics(com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics) EzySimpleSessionTokenGenerator(com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator)

Example 9 with EzyStatistics

use of com.tvd12.ezyfoxserver.statistics.EzyStatistics in project ezyfox-server by youngmonkeys.

the class EzyLoginControllerTest method testExceptionCase.

@SuppressWarnings("rawtypes")
@Test(expectedExceptions = IllegalStateException.class)
public void testExceptionCase() {
    EzyServerContext ctx = mock(EzyServerContext.class);
    doThrow(new IllegalStateException("server maintain")).when(ctx).send(any(EzyResponse.class), any(EzySession.class), any(boolean.class));
    EzyStatistics userStats = new EzySimpleStatistics();
    EzySimpleServer server = new EzySimpleServer();
    server.setStatistics(userStats);
    when(ctx.getServer()).thenReturn(server);
    server.setResponseApi(mock(EzyResponseApi.class));
    EzySessionManager sessionManager = mock(EzySessionManager.class);
    server.setSessionManager(sessionManager);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(ctx.getZoneContext("example")).thenReturn(zoneContext);
    EzySimpleZone zone = new EzySimpleZone();
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    zone.setSetting(zoneSetting);
    when(zoneContext.getZone()).thenReturn(zone);
    EzyZoneUserManager zoneUserManager = EzyZoneUserManagerImpl.builder().maxUsers(1).build();
    zone.setUserManager(zoneUserManager);
    EzySession session = newSession();
    session.setToken("abcdef");
    EzyArray data = newLoginData();
    EzyLoginController controller = new EzyLoginController() {

        @Override
        protected void responseLoginError(EzyServerContext ctx, EzySession session, EzyILoginError error) {
        }
    };
    EzySimpleLoginRequest request = new EzySimpleLoginRequest();
    request.deserializeParams(data);
    request.setSession(session);
    controller.handle(ctx, request);
}
Also used : EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyStatistics(com.tvd12.ezyfoxserver.statistics.EzyStatistics) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzyLoginController(com.tvd12.ezyfoxserver.controller.EzyLoginController) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimpleLoginRequest(com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest) EzyILoginError(com.tvd12.ezyfoxserver.constant.EzyILoginError) EzySimpleStatistics(com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) Test(org.testng.annotations.Test)

Example 10 with EzyStatistics

use of com.tvd12.ezyfoxserver.statistics.EzyStatistics in project ezyfox-server by youngmonkeys.

the class EzyLoginProcessorTest method processUserSessionsButNotAllowToChangeSession.

@SuppressWarnings("rawtypes")
@Test
public void processUserSessionsButNotAllowToChangeSession() {
    // given
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    zoneSetting.getUserManagement().setMaxSessionPerUser(1);
    zoneSetting.getUserManagement().setAllowChangeSession(false);
    EzySimpleZone zone = new EzySimpleZone();
    zone.setSetting(zoneSetting);
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    when(zoneContext.getZone()).thenReturn(zone);
    EzySimpleServer server = new EzySimpleServer();
    EzySessionManager sessionManager = mock(EzySessionManager.class);
    server.setSessionManager(sessionManager);
    EzyZoneUserManager userManager = EzyZoneUserManagerImpl.builder().build();
    EzyUser user = mock(EzyUser.class);
    when(user.getName()).thenReturn("monkey");
    when(user.getSessionCount()).thenReturn(1);
    userManager.addUser(user);
    zone.setUserManager(userManager);
    EzyStatistics statistics = mock(EzyStatistics.class);
    EzyUserStatistics userStatistics = mock(EzyUserStatistics.class);
    when(statistics.getUserStats()).thenReturn(userStatistics);
    server.setStatistics(statistics);
    EzyServerContext serverContext = mock(EzyServerContext.class);
    when(serverContext.getServer()).thenReturn(server);
    EzyLoginProcessor sut = new EzyLoginProcessor(serverContext);
    EzySessionDelegate sessionDelegate = mock(EzySessionDelegate.class);
    EzyAbstractSession session = spy(EzyAbstractSession.class);
    session.setDelegate(sessionDelegate);
    EzyUserLoginEvent event = mock(EzyUserLoginEvent.class);
    when(event.getUsername()).thenReturn("monkey");
    when(event.getSession()).thenReturn(session);
    // when
    Throwable e = Asserts.assertThrows(() -> sut.apply(zoneContext, event));
    // then
    Asserts.assertEquals(EzyLoginErrorException.class, e.getClass());
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyStatistics(com.tvd12.ezyfoxserver.statistics.EzyStatistics) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyUserLoginEvent(com.tvd12.ezyfoxserver.event.EzyUserLoginEvent) EzyUserStatistics(com.tvd12.ezyfoxserver.statistics.EzyUserStatistics) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzySessionDelegate(com.tvd12.ezyfoxserver.delegate.EzySessionDelegate) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) EzyLoginProcessor(com.tvd12.ezyfoxserver.controller.EzyLoginProcessor) Test(org.testng.annotations.Test)

Aggregations

EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)22 EzyStatistics (com.tvd12.ezyfoxserver.statistics.EzyStatistics)22 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)17 Test (org.testng.annotations.Test)16 EzySimpleStatistics (com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics)15 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)13 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)13 EzySimpleStreamingSetting (com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting)13 ExecutorService (java.util.concurrent.ExecutorService)13 EzySimpleSessionTokenGenerator (com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator)12 EzyHandlerGroupBuilderFactory (com.tvd12.ezyfoxserver.nio.factory.EzyHandlerGroupBuilderFactory)11 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)9 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)9 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)9 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)9 EzySimpleZoneSetting (com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting)9 EzySimpleSessionManagementSetting (com.tvd12.ezyfoxserver.setting.EzySimpleSessionManagementSetting)8 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)8 EzyLoginProcessor (com.tvd12.ezyfoxserver.controller.EzyLoginProcessor)7 EzyUserLoginEvent (com.tvd12.ezyfoxserver.event.EzyUserLoginEvent)7