Search in sources :

Example 1 with EzyBlockingSocketStreamQueue

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

the class EzySocketStreamHandlerTest method test.

@Test
public void test() {
    EzySocketStreamHandler handler = new EzySocketStreamHandler();
    EzySocketDataHandlerGroupFetcher dataHandlerGroupFetcher = mock(EzySocketDataHandlerGroupFetcher.class);
    EzySocketDataHandlerGroup dataHandlerGroup = mock(EzySocketDataHandlerGroup.class);
    when(dataHandlerGroupFetcher.getDataHandlerGroup(any(EzySession.class))).thenReturn(dataHandlerGroup);
    EzySocketStreamQueue streamQueue = new EzyBlockingSocketStreamQueue();
    EzySession session = spy(EzyAbstractSession.class);
    EzySocketStream stream = new EzySimpleSocketStream(session, new byte[0]);
    streamQueue.add(stream);
    handler.setStreamQueue(streamQueue);
    handler.setDataHandlerGroupFetcher(dataHandlerGroupFetcher);
    handler.handleEvent();
    handler.destroy();
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 2 with EzyBlockingSocketStreamQueue

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

the class EzySocketStreamHandlerTest method hasNoHandlerGroupCaseTest.

@Test
public void hasNoHandlerGroupCaseTest() {
    EzySocketStreamHandler handler = new EzySocketStreamHandler();
    EzySocketDataHandlerGroupFetcher dataHandlerGroupFetcher = mock(EzySocketDataHandlerGroupFetcher.class);
    when(dataHandlerGroupFetcher.getDataHandlerGroup(any(EzySession.class))).thenReturn(null);
    EzySocketStreamQueue streamQueue = new EzyBlockingSocketStreamQueue();
    EzySession session = spy(EzyAbstractSession.class);
    EzySocketStream stream = new EzySimpleSocketStream(session, new byte[0]);
    streamQueue.add(stream);
    handler.setStreamQueue(streamQueue);
    handler.setDataHandlerGroupFetcher(dataHandlerGroupFetcher);
    handler.handleEvent();
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 3 with EzyBlockingSocketStreamQueue

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

the class EzySocketStreamHandlerTest method doProcessStreamQueueExceptionCaseTest.

@Test
public void doProcessStreamQueueExceptionCaseTest() {
    EzySocketStreamHandler handler = new EzySocketStreamHandler();
    EzySocketDataHandlerGroupFetcher dataHandlerGroupFetcher = mock(EzySocketDataHandlerGroupFetcher.class);
    when(dataHandlerGroupFetcher.getDataHandlerGroup(any(EzySession.class))).thenThrow(new IllegalArgumentException());
    EzySocketStreamQueue streamQueue = new EzyBlockingSocketStreamQueue();
    EzySession session = spy(EzyAbstractSession.class);
    EzySocketStream stream = new EzySimpleSocketStream(session, new byte[0]);
    streamQueue.add(stream);
    handler.setStreamQueue(streamQueue);
    handler.setDataHandlerGroupFetcher(dataHandlerGroupFetcher);
    handler.handleEvent();
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Test(org.testng.annotations.Test)

Example 4 with EzyBlockingSocketStreamQueue

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

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

Aggregations

EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)9 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)9 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)9 EzySimpleStreamingSetting (com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting)9 Test (org.testng.annotations.Test)9 EzyHandlerGroupBuilderFactory (com.tvd12.ezyfoxserver.nio.factory.EzyHandlerGroupBuilderFactory)8 EzySimpleSessionTokenGenerator (com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator)8 EzySimpleStatistics (com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics)8 EzyStatistics (com.tvd12.ezyfoxserver.statistics.EzyStatistics)8 ExecutorService (java.util.concurrent.ExecutorService)8 EzyCodecFactory (com.tvd12.ezyfoxserver.codec.EzyCodecFactory)5 EzyNioSessionManager (com.tvd12.ezyfoxserver.nio.wrapper.EzyNioSessionManager)5 BaseTest (com.tvd12.test.base.BaseTest)5 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)4 EzySimpleSessionManagementSetting (com.tvd12.ezyfoxserver.setting.EzySimpleSessionManagementSetting)4 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)3 EzyNioSession (com.tvd12.ezyfoxserver.nio.entity.EzyNioSession)3 EzyHandlerGroupManager (com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager)3 EzyServerControllers (com.tvd12.ezyfoxserver.wrapper.EzyServerControllers)3 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)3