Search in sources :

Example 11 with EzySimpleServerContext

use of com.tvd12.ezyfoxserver.context.EzySimpleServerContext in project ezyfox-server by youngmonkeys.

the class EzyLoginControllerTest method test2.

@Test(expectedExceptions = { EzyLoginErrorException.class })
public void test2() {
    EzySimpleServerContext ctx = (EzySimpleServerContext) newServerContext();
    EzySimpleServer server = (EzySimpleServer) ctx.getServer();
    server.setResponseApi(mock(EzyResponseApi.class));
    EzySession session = newSession();
    session.setToken("abcdef");
    EzyArray data = newLoginData();
    EzyLoginController controller = new EzyLoginController() {

        @Override
        protected void firePluginEvent(EzyZoneContext zoneContext, EzyUserLoginEvent event) {
            throw new EzyLoginErrorException();
        }
    };
    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) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyLoginErrorException(com.tvd12.ezyfoxserver.exception.EzyLoginErrorException) EzySimpleLoginRequest(com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest) EzyUserLoginEvent(com.tvd12.ezyfoxserver.event.EzyUserLoginEvent) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyLoginController(com.tvd12.ezyfoxserver.controller.EzyLoginController) Test(org.testng.annotations.Test)

Example 12 with EzySimpleServerContext

use of com.tvd12.ezyfoxserver.context.EzySimpleServerContext 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 13 with EzySimpleServerContext

use of com.tvd12.ezyfoxserver.context.EzySimpleServerContext in project ezyfox-server by youngmonkeys.

the class EzySimplePluginEntryTest method test2.

@Test
public void test2() throws Exception {
    EzySimpleSettings settings = new EzySimpleSettings();
    EzySimpleServer server = new EzySimpleServer();
    server.setSettings(settings);
    EzySimpleServerContext serverContext = new EzySimpleServerContext();
    serverContext.setServer(server);
    serverContext.init();
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    EzySimpleZone zone = new EzySimpleZone();
    zone.setSetting(zoneSetting);
    EzySimpleZoneContext zoneContext = new EzySimpleZoneContext();
    zoneContext.setZone(zone);
    zoneContext.init();
    zoneContext.setParent(serverContext);
    EzySimplePluginSetting pluginSetting = new EzySimplePluginSetting();
    pluginSetting.setName("test");
    EzyEventControllersSetting eventControllersSetting = new EzySimpleEventControllersSetting();
    EzyEventControllers eventControllers = EzyEventControllersImpl.create(eventControllersSetting);
    EzySimplePlugin plugin = new EzySimplePlugin();
    plugin.setSetting(pluginSetting);
    plugin.setEventControllers(eventControllers);
    ScheduledExecutorService pluginScheduledExecutorService = new EzyErrorScheduledExecutorService("not implement");
    EzySimplePluginContext pluginContext = new EzySimplePluginContext();
    pluginContext.setPlugin(plugin);
    pluginContext.setParent(zoneContext);
    pluginContext.setExecutorService(pluginScheduledExecutorService);
    pluginContext.init();
    EzySimplePluginEntry entry = new EzyPluginEntryEx2();
    entry.config(pluginContext);
    entry.start();
    entry.destroy();
}
Also used : EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyErrorScheduledExecutorService(com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzySimplePlugin(com.tvd12.ezyfoxserver.EzySimplePlugin) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzyEventControllers(com.tvd12.ezyfoxserver.wrapper.EzyEventControllers) EzySimplePluginContext(com.tvd12.ezyfoxserver.context.EzySimplePluginContext) EzySimplePluginEntry(com.tvd12.ezyfoxserver.support.entry.EzySimplePluginEntry) Test(org.testng.annotations.Test)

Example 14 with EzySimpleServerContext

use of com.tvd12.ezyfoxserver.context.EzySimpleServerContext 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 15 with EzySimpleServerContext

use of com.tvd12.ezyfoxserver.context.EzySimpleServerContext in project ezyfox-server by youngmonkeys.

the class EzyNioServerBootstrapTest method test.

@Test
public void test() throws Exception {
    SSLContext sslContext = SSLContext.getDefault();
    EzyResponseApi responseApi = mock(EzyResponseApi.class);
    EzyStreamingApi streamingApi = mock(EzyStreamingApi.class);
    EzySocketStreamQueue streamQueue = new EzyBlockingSocketStreamQueue();
    EzyHandlerGroupManager handlerGroupManager = mock(EzyHandlerGroupManager.class);
    EzySessionTicketsQueue socketSessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
    EzySessionTicketsQueue websocketSessionTicketsQueue = new EzyBlockingSessionTicketsQueue();
    EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
    EzySocketDisconnectionQueue socketDisconnectionQueue = new EzySocketDisconnectionQueue() {

        final BlockingQueue<EzySocketDisconnection> queue = new LinkedBlockingQueue<>();

        @Override
        public EzySocketDisconnection take() throws InterruptedException {
            return queue.take();
        }

        @Override
        public int size() {
            return 0;
        }

        @Override
        public void remove(EzySocketDisconnection disconnection) {
        }

        @Override
        public boolean isEmpty() {
            return false;
        }

        @Override
        public void clear() {
        }

        @Override
        public boolean add(EzySocketDisconnection disconnection) {
            return false;
        }
    };
    EzySimpleConfig config = new EzySimpleConfig();
    EzySimpleSettings settings = new EzySimpleSettings();
    EzySimpleStreamingSetting streaming = settings.getStreaming();
    streaming.setEnable(true);
    settings.getUdp().setActive(true);
    EzySimpleServer server = new EzySimpleServer();
    EzyServerControllers serverControllers = EzyServerControllersImpl.builder().build();
    server.setControllers(serverControllers);
    EzyEventControllersSetting eventControllersSetting = new EzySimpleEventControllersSetting();
    EzyEventControllers eventControllers = EzyEventControllersImpl.create(eventControllersSetting);
    server.setEventControllers(eventControllers);
    server.setConfig(config);
    server.setSettings(settings);
    EzySimpleServerContext serverContext = new EzySimpleServerContext();
    serverContext.setProperty(EzySocketUserRemovalQueue.class, new EzyBlockingSocketUserRemovalQueue());
    serverContext.setServer(server);
    serverContext.init();
    ExBootstrap localBootstrap = new ExBootstrap(new EzyBootstrap.Builder().context(serverContext));
    EzyNioServerBootstrap bootstrap = new EzyNioServerBootstrap();
    bootstrap.setContext(serverContext);
    bootstrap.setLocalBootstrap(localBootstrap);
    bootstrap.setSslContext(sslContext);
    bootstrap.setResponseApi(responseApi);
    bootstrap.setStreamingApi(streamingApi);
    bootstrap.setStreamQueue(streamQueue);
    bootstrap.setHandlerGroupManager(handlerGroupManager);
    bootstrap.setSocketSessionTicketsQueue(socketSessionTicketsQueue);
    bootstrap.setWebsocketSessionTicketsQueue(websocketSessionTicketsQueue);
    bootstrap.setSocketDisconnectionQueue(socketDisconnectionQueue);
    bootstrap.setSocketSessionTicketsRequestQueues(sessionTicketsRequestQueues);
    bootstrap.start();
    bootstrap.destroy();
    bootstrap.destroy();
}
Also used : EzyEventControllersSetting(com.tvd12.ezyfoxserver.setting.EzyEventControllersSetting) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzyStreamingApi(com.tvd12.ezyfoxserver.api.EzyStreamingApi) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) BlockingQueue(java.util.concurrent.BlockingQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) EzySimpleConfig(com.tvd12.ezyfoxserver.config.EzySimpleConfig) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleStreamingSetting(com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting) EzyServerControllers(com.tvd12.ezyfoxserver.wrapper.EzyServerControllers) SSLContext(javax.net.ssl.SSLContext) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) EzyEventControllers(com.tvd12.ezyfoxserver.wrapper.EzyEventControllers) EzyHandlerGroupManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager) EzyNioServerBootstrap(com.tvd12.ezyfoxserver.nio.EzyNioServerBootstrap) EzySimpleEventControllersSetting(com.tvd12.ezyfoxserver.setting.EzySimpleEventControllersSetting) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Aggregations

EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)41 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)39 Test (org.testng.annotations.Test)34 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)16 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)15 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)14 EzySimpleStreamingSetting (com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting)14 EzySimpleSessionTokenGenerator (com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator)13 EzySimpleStatistics (com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics)13 EzyStatistics (com.tvd12.ezyfoxserver.statistics.EzyStatistics)13 ExecutorService (java.util.concurrent.ExecutorService)13 EzyArray (com.tvd12.ezyfox.entity.EzyArray)11 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)11 EzyHandlerGroupBuilderFactory (com.tvd12.ezyfoxserver.nio.factory.EzyHandlerGroupBuilderFactory)11 EzyEventControllers (com.tvd12.ezyfoxserver.wrapper.EzyEventControllers)11 BaseTest (com.tvd12.test.base.BaseTest)11 EzyErrorScheduledExecutorService (com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService)10 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)10 EzySimpleZoneContext (com.tvd12.ezyfoxserver.context.EzySimpleZoneContext)10 EzyLoginController (com.tvd12.ezyfoxserver.controller.EzyLoginController)10