Search in sources :

Example 6 with EzySimpleSessionTokenGenerator

use of com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator in project ezyfox-server by youngmonkeys.

the class EzySimpleWsHandlerGroupTest method test.

@SuppressWarnings("rawtypes")
@Test
public void test() throws Exception {
    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(true);
    EzySimpleServer server = new EzySimpleServer();
    server.setSettings(settings);
    server.setSessionManager(sessionManager);
    EzyServerControllers controllers = mock(EzyServerControllers.class);
    server.setControllers(controllers);
    EzyInterceptor interceptor = mock(EzyInterceptor.class);
    when(controllers.getInterceptor(EzyCommand.PING)).thenReturn(interceptor);
    EzyController controller = mock(EzyController.class);
    when(controllers.getController(EzyCommand.PING)).thenReturn(controller);
    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);
    EzyNioSession session = (EzyNioSession) sessionManager.provideSession(channel);
    ExEzyByteToObjectDecoder decoder = new ExEzyByteToObjectDecoder();
    ExecutorService statsThreadPool = EzyExecutors.newFixedThreadPool(1, "stats");
    EzySocketStreamQueue streamQueue = new EzyBlockingSocketStreamQueue();
    EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
    EzyHandlerGroupBuilderFactory handlerGroupBuilderFactory = EzyHandlerGroupBuilderFactoryImpl.builder().statistics(statistics).serverContext(serverContext).statsThreadPool(statsThreadPool).streamQueue(streamQueue).codecFactory(new ExCodecFactory()).sessionTicketsRequestQueues(sessionTicketsRequestQueues).socketSessionTicketsQueue(socketSessionTicketsQueue).webSocketSessionTicketsQueue(webSocketSessionTicketsQueue).build();
    EzySimpleWsHandlerGroup group = (EzySimpleWsHandlerGroup) handlerGroupBuilderFactory.newBuilder(channel, EzyConnectionType.WEBSOCKET).build();
    group.fireBytesReceived("hello");
    group.fireBytesReceived(new byte[] { 127, 2, 3, 4, 5, 6 }, 0, 5);
    ((EzyAbstractSession) session).setStreamingEnable(true);
    group.fireBytesReceived(new byte[] { 127, 2, 3, 4, 5, 6 }, 0, 5);
    EzySimplePacket packet = new EzySimplePacket();
    packet.setBinary(false);
    packet.setData("world".getBytes());
    packet.setTransportType(EzyTransportType.TCP);
    ByteBuffer writeBuffer = ByteBuffer.allocate(1024);
    group.firePacketSend(packet, writeBuffer);
    group.sendPacketNow(packet);
    group.fireChannelRead(EzyCommand.PING, EzyEntityArrays.newArray(EzyCommand.PING.getId(), EzyEntityFactory.EMPTY_ARRAY));
    EzyInterceptor streamInterceptor = mock(EzyInterceptor.class);
    when(controllers.getStreamingInterceptor()).thenReturn(streamInterceptor);
    EzyStreamingController streamController = mock(EzyStreamingController.class);
    when(controllers.getStreamingController()).thenReturn(streamController);
    group.fireStreamBytesReceived(new byte[] { 0, 1, 2 });
    EzyPacket droppedPacket = mock(EzyPacket.class);
    when(droppedPacket.getSize()).thenReturn(12);
    group.addDroppedPacket(droppedPacket);
    EzyPacket failedPacket = mock(EzyPacket.class);
    when(failedPacket.getData()).thenReturn(new byte[] { 1, 2, 3 });
    when(failedPacket.isBinary()).thenReturn(false);
    when(channel.write(any(ByteBuffer.class), anyBoolean())).thenThrow(new IllegalStateException("maintain"));
    group.firePacketSend(failedPacket, writeBuffer);
    MethodInvoker.create().object(group).method("executeHandleReceivedBytes").param("hello").invoke();
    MethodInvoker.create().object(group).method("executeHandleReceivedBytes").param("hello".getBytes()).invoke();
    group.fireChannelInactive();
    Thread.sleep(2000);
    group.destroy();
    group.destroy();
    EzySocketStreamQueue streamQueue1 = mock(EzySocketStreamQueue.class);
    when(streamQueue1.add(any())).thenThrow(new IllegalStateException("queue full"));
    group = (EzySimpleWsHandlerGroup) handlerGroupBuilderFactory.newBuilder(channel, EzyConnectionType.WEBSOCKET).session(session).decoder(decoder).serverContext(serverContext).statsThreadPool(statsThreadPool).streamQueue(streamQueue1).sessionTicketsRequestQueues(sessionTicketsRequestQueues).build();
    group.fireBytesReceived(new byte[] { 127, 2, 3, 4, 5, 6 }, 0, 5);
}
Also used : 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) EzyInterceptor(com.tvd12.ezyfoxserver.interceptor.EzyInterceptor) EzyStreamingController(com.tvd12.ezyfoxserver.controller.EzyStreamingController) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) EzySimpleWsHandlerGroup(com.tvd12.ezyfoxserver.nio.websocket.EzySimpleWsHandlerGroup) EzyController(com.tvd12.ezyfoxserver.controller.EzyController) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleStreamingSetting(com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyServerControllers(com.tvd12.ezyfoxserver.wrapper.EzyServerControllers) EzyNioSession(com.tvd12.ezyfoxserver.nio.entity.EzyNioSession) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) ByteBuffer(java.nio.ByteBuffer) ExecutorService(java.util.concurrent.ExecutorService) EzySimpleStatistics(com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics) EzySimpleSessionTokenGenerator(com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 7 with EzySimpleSessionTokenGenerator

use of com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator in project ezyfox-server by youngmonkeys.

the class EzyWsHandlerTest method test.

@Test
public void test() throws Exception {
    EzySimpleSessionManagementSetting sessionManagementSetting = new EzySimpleSessionManagementSetting();
    EzyNioSessionManager sessionManager = (EzyNioSessionManager) EzyNioSessionManagerImpl.builder().maxRequestPerSecond(new EzySimpleSessionManagementSetting.EzySimpleMaxRequestPerSecond()).tokenGenerator(new EzySimpleSessionTokenGenerator()).build();
    EzyCodecFactory codecFactory = mock(EzyCodecFactory.class);
    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();
    EzyHandlerGroupManager handlerGroupManager = EzyHandlerGroupManagerImpl.builder().handlerGroupBuilderFactory(handlerGroupBuilderFactory).build();
    EzySocketDataReceiver socketDataReceiver = EzySocketDataReceiver.builder().threadPoolSize(1).handlerGroupManager(handlerGroupManager).build();
    EzyWsHandler handler = EzyWsHandler.builder().sessionManagementSetting(sessionManagementSetting).sessionManager(sessionManager).handlerGroupManager(handlerGroupManager).socketDataReceiver(socketDataReceiver).build();
    Session session = mock(Session.class);
    handler.onConnect(session);
    handler.onMessage(session, "hello");
    handler.onMessage(session, "hello".getBytes(), 0, 5);
    handler.onError(session, new TimeoutException("timeout"));
    handler.onError(session, new IllegalStateException("maintain"));
    handler.onClose(session, 39999, "test");
    handler.onClose(session, 3000, "test");
    Session session2 = mock(Session.class);
    handler.onMessage(session2, "hello");
    handler.onMessage(session2, "hello".getBytes(), 0, 5);
    handler.onError(session2, new TimeoutException("timeout"));
    handler.onError(session2, new IllegalStateException("maintain"));
    handler.onClose(session2, 39999, "test");
    handler.onClose(session2, 3000, "test");
}
Also used : 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) TimeoutException(java.util.concurrent.TimeoutException) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleStreamingSetting(com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting) EzyNioSessionManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyNioSessionManager) EzyWsHandler(com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandler) EzyCodecFactory(com.tvd12.ezyfoxserver.codec.EzyCodecFactory) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) EzyHandlerGroupManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager) EzySocketDataReceiver(com.tvd12.ezyfoxserver.nio.socket.EzySocketDataReceiver) ExecutorService(java.util.concurrent.ExecutorService) EzySimpleStatistics(com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics) EzySimpleSessionTokenGenerator(com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator) EzyNioSession(com.tvd12.ezyfoxserver.nio.entity.EzyNioSession) Session(org.eclipse.jetty.websocket.api.Session) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 8 with EzySimpleSessionTokenGenerator

use of com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator in project ezyfox-server by youngmonkeys.

the class EzyHandlerGroupManagerImplTest method test.

@Test
public void test() {
    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();
    EzyHandlerGroupManager handlerGroupManager = EzyHandlerGroupManagerImpl.builder().handlerGroupBuilderFactory(handlerGroupBuilderFactory).build();
    handlerGroupManager.removeHandlerGroup(null);
    EzySession session1 = mock(EzyAbstractSession.class);
    handlerGroupManager.removeHandlerGroup(session1);
    EzySession session2 = mock(EzyAbstractSession.class);
    EzyChannel channel2 = mock(EzyChannel.class);
    when(session2.getChannel()).thenReturn(channel2);
    handlerGroupManager.removeHandlerGroup(session2);
    EzyChannel channel3 = mock(EzyChannel.class);
    Session connection3 = mock(Session.class);
    when(channel3.getConnection()).thenReturn(connection3);
    EzyHandlerGroup handlerGroup3 = handlerGroupManager.newHandlerGroup(channel3, EzyConnectionType.WEBSOCKET);
    EzySession session3 = mock(EzyAbstractSession.class);
    when(session3.getChannel()).thenReturn(channel3);
    assert handlerGroupManager.getDataHandlerGroup(null) == null;
    assert handlerGroupManager.getDataHandlerGroup(session1) == null;
    assert handlerGroupManager.getDataHandlerGroup(session2) == null;
    assert handlerGroupManager.getWriterGroup(session3) == handlerGroup3;
    InetSocketAddress udpAddress = new InetSocketAddress("127.0.0.1", 12345);
    handlerGroupManager.mapSocketChannel(udpAddress, session3);
    assert handlerGroupManager.getSocketChannel(udpAddress) != null;
    handlerGroupManager.unmapHandlerGroup(udpAddress);
    handlerGroupManager.removeHandlerGroup(session3);
    handlerGroupManager.destroy();
}
Also used : EzyHandlerGroupBuilderFactory(com.tvd12.ezyfoxserver.nio.factory.EzyHandlerGroupBuilderFactory) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) InetSocketAddress(java.net.InetSocketAddress) EzyStatistics(com.tvd12.ezyfoxserver.statistics.EzyStatistics) EzyHandlerGroup(com.tvd12.ezyfoxserver.nio.handler.EzyHandlerGroup) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleStreamingSetting(com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting) EzyNioSessionManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyNioSessionManager) EzyCodecFactory(com.tvd12.ezyfoxserver.codec.EzyCodecFactory) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyHandlerGroupManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager) ExecutorService(java.util.concurrent.ExecutorService) EzySimpleStatistics(com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics) EzySimpleSessionTokenGenerator(com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Session(org.eclipse.jetty.websocket.api.Session) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 9 with EzySimpleSessionTokenGenerator

use of com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator in project ezyfox-server by youngmonkeys.

the class V121SessionManagerTest method inspectTest.

@Test
public void inspectTest() throws Exception {
    // given
    EzySocketDisconnectionQueue disconnectionQueue = new EzyBlockingSocketDisconnectionQueue();
    SessionManager sut = (SessionManager) new SessionManager.Builder().validationInterval(100).validationDelay(100).objectFactory(() -> new Session(disconnectionQueue)).tokenGenerator(new EzySimpleSessionTokenGenerator()).build();
    EzyChannel channel1 = mock(EzyChannel.class);
    when(channel1.getConnection()).thenReturn(new Object());
    EzyChannel channel2 = mock(EzyChannel.class);
    when(channel2.getConnection()).thenReturn(new Object());
    EzyChannel channel3 = mock(EzyChannel.class);
    when(channel3.getConnection()).thenReturn(new Object());
    Session session1 = sut.provideSession(channel1);
    session1.setLoggedIn(true);
    session1.setLastReadTime(System.currentTimeMillis());
    Session session2 = sut.provideSession(channel2);
    session2.setLoggedIn(true);
    session2.setLastReadTime(System.currentTimeMillis());
    Session session3 = sut.provideSession(channel3);
    session3.setLoggedIn(true);
    session3.setLastReadTime(System.currentTimeMillis());
    Thread[] threads = new Thread[10];
    for (int i = 0; i < threads.length; ++i) {
        threads[i] = new Thread(() -> {
            long start = System.currentTimeMillis();
            long elapsedTime = 0;
            while (elapsedTime < 100) {
                EzyChannel channel = mock(EzyChannel.class);
                when(channel.getConnection()).thenReturn(new Object());
                sut.provideSession(channel);
                elapsedTime = System.currentTimeMillis() - start;
            }
        });
    }
    Thread disconnectionThread = new Thread(() -> {
        while (true) {
            try {
                EzySocketDisconnection item = disconnectionQueue.take();
                sut.clearSession((Session) item.getSession());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    disconnectionThread.start();
    // when
    sut.start();
    for (Thread thread : threads) {
        thread.start();
    }
    Thread.sleep(1000);
    disconnectionThread.interrupt();
    // then
    Asserts.assertEquals(3, sut.getAllSessionCount());
    sut.destroy();
}
Also used : EzySocketDisconnection(com.tvd12.ezyfoxserver.socket.EzySocketDisconnection) EzyChannel(com.tvd12.ezyfoxserver.socket.EzyChannel) EzySimpleSessionManager(com.tvd12.ezyfoxserver.wrapper.EzySimpleSessionManager) EzyBlockingSocketDisconnectionQueue(com.tvd12.ezyfoxserver.socket.EzyBlockingSocketDisconnectionQueue) EzySimpleSessionTokenGenerator(com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator) EzySocketDisconnectionQueue(com.tvd12.ezyfoxserver.socket.EzySocketDisconnectionQueue) EzyAbstractSession(com.tvd12.ezyfoxserver.entity.EzyAbstractSession) Test(org.testng.annotations.Test)

Example 10 with EzySimpleSessionTokenGenerator

use of com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator in project ezyfox-server by youngmonkeys.

the class EzyAbstractHandlerGroupTest method test.

@SuppressWarnings("rawtypes")
@Test
public void test() throws Exception {
    EzyStatistics statistics = new EzySimpleStatistics();
    EzySimpleSettings settings = new EzySimpleSettings();
    EzySimpleStreamingSetting streaming = settings.getStreaming();
    streaming.setEnable(true);
    EzySimpleServer server = new EzySimpleServer();
    server.setSettings(settings);
    EzySimpleServerContext serverContext = new EzySimpleServerContext();
    serverContext.setServer(server);
    serverContext.init();
    EzySessionManager sessionManager = EzyNioSessionManagerImpl.builder().maxRequestPerSecond(new EzySimpleSessionManagementSetting.EzySimpleMaxRequestPerSecond()).tokenGenerator(new EzySimpleSessionTokenGenerator()).build();
    EzyChannel channel = mock(EzyChannel.class);
    when(channel.isConnected()).thenReturn(true);
    when(channel.getConnection()).thenReturn(SocketChannel.open());
    when(channel.getConnectionType()).thenReturn(EzyConnectionType.SOCKET);
    EzyNioSession session = (EzyNioSession) sessionManager.provideSession(channel);
    ExEzyByteToObjectDecoder decoder = new ExEzyByteToObjectDecoder();
    ExecutorService statsThreadPool = EzyExecutors.newFixedThreadPool(1, "stats");
    EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
    when(channel.write(any(ByteBuffer.class), anyBoolean())).thenReturn(123456);
    ExHandlerGroup group = (ExHandlerGroup) new ExHandlerGroup.Builder().session(session).decoder(decoder).sessionCount(new AtomicInteger()).networkStats((EzyNetworkStats) statistics.getSocketStats().getNetworkStats()).sessionStats((EzySessionStats) statistics.getSocketStats().getSessionStats()).serverContext(serverContext).statsThreadPool(statsThreadPool).sessionTicketsRequestQueues(sessionTicketsRequestQueues).build();
    EzyChannel channelX = mock(EzyChannel.class);
    MethodInvoker.create().object(group).method("canWriteBytes").param(EzyChannel.class, null).invoke();
    MethodInvoker.create().object(group).method("canWriteBytes").param(EzyChannel.class, channelX).invoke();
    sessionTicketsRequestQueues = mock(EzySessionTicketsRequestQueues.class);
    when(sessionTicketsRequestQueues.addRequest(any())).thenReturn(false);
    group = (ExHandlerGroup) new ExHandlerGroup.Builder().session(session).decoder(decoder).sessionCount(new AtomicInteger()).networkStats((EzyNetworkStats) statistics.getSocketStats().getNetworkStats()).sessionStats((EzySessionStats) statistics.getSocketStats().getSessionStats()).serverContext(serverContext).statsThreadPool(statsThreadPool).sessionTicketsRequestQueues(sessionTicketsRequestQueues).build();
    MethodInvoker.create().object(group).method("handleReceivedData").param(Object.class, EzyEntityFactory.newArrayBuilder().append(EzyCommand.PING.getId()).append(EzyEntityFactory.EMPTY_OBJECT).build()).param(int.class, 100).invoke();
    ((EzyDatagramChannelPoolAware) session).setDatagramChannelPool(new EzyDatagramChannelPool(1));
    ((EzyUdpClientAddressAware) session).setUdpClientAddress(new InetSocketAddress("127.0.0.1", 12348));
    EzyPacket packet = mock(EzyPacket.class);
    when(packet.getData()).thenReturn(new byte[] { 1, 2, 3 });
    ByteBuffer buffer = ByteBuffer.allocate(100);
    MethodInvoker.create().object(group).method("executeSendingPacket").param(EzyPacket.class, packet).param(Object.class, buffer).invoke();
    MethodInvoker.create().object(group).method("executeSendingPacket").param(EzyPacket.class, packet).param(Object.class, new Object()).invoke();
    Asserts.assertNotNull(group.getSession());
}
Also used : EzySimpleSessionManagementSetting(com.tvd12.ezyfoxserver.setting.EzySimpleSessionManagementSetting) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) InetSocketAddress(java.net.InetSocketAddress) EzyStatistics(com.tvd12.ezyfoxserver.statistics.EzyStatistics) EzyNetworkStats(com.tvd12.ezyfoxserver.statistics.EzyNetworkStats) EzySimpleMaxRequestPerSecond(com.tvd12.ezyfoxserver.setting.EzySimpleSessionManagementSetting.EzySimpleMaxRequestPerSecond) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleStreamingSetting(com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzyNioSession(com.tvd12.ezyfoxserver.nio.entity.EzyNioSession) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) ByteBuffer(java.nio.ByteBuffer) EzySessionStats(com.tvd12.ezyfoxserver.statistics.EzySessionStats) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) EzySimpleStatistics(com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics) EzySimpleSessionTokenGenerator(com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator) ExEzyByteToObjectDecoder(com.tvd12.ezyfoxserver.nio.testing.handler.EzySimpleNioHandlerGroupTest.ExEzyByteToObjectDecoder) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Aggregations

EzySimpleSessionTokenGenerator (com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator)15 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)13 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)13 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)13 EzySimpleStreamingSetting (com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting)12 EzySimpleStatistics (com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics)12 EzyStatistics (com.tvd12.ezyfoxserver.statistics.EzyStatistics)12 ExecutorService (java.util.concurrent.ExecutorService)12 EzyHandlerGroupBuilderFactory (com.tvd12.ezyfoxserver.nio.factory.EzyHandlerGroupBuilderFactory)11 EzySimpleSessionManagementSetting (com.tvd12.ezyfoxserver.setting.EzySimpleSessionManagementSetting)9 Test (org.testng.annotations.Test)9 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)8 BaseTest (com.tvd12.test.base.BaseTest)8 EzyNioSession (com.tvd12.ezyfoxserver.nio.entity.EzyNioSession)7 EzyCodecFactory (com.tvd12.ezyfoxserver.codec.EzyCodecFactory)6 EzySimpleNioHandlerGroup (com.tvd12.ezyfoxserver.nio.handler.EzySimpleNioHandlerGroup)5 EzyNioSessionManager (com.tvd12.ezyfoxserver.nio.wrapper.EzyNioSessionManager)5 ByteBuffer (java.nio.ByteBuffer)5 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)4 EzySimpleSession (com.tvd12.ezyfoxserver.nio.entity.EzySimpleSession)2