Search in sources :

Example 6 with EzyHandlerGroupManager

use of com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager in project ezyfox-server by youngmonkeys.

the class EzySocketDataReceiverTest method doWsReceiveButException.

@Test
public void doWsReceiveButException() throws Exception {
    // given
    EzyHandlerGroupManager handlerGroupManager = mock(EzyHandlerGroupManager.class);
    EzySocketDataReceiver sut = EzySocketDataReceiver.builder().handlerGroupManager(handlerGroupManager).build();
    Session session = mock(Session.class);
    String message = RandomUtil.randomShortAlphabetString();
    EzyWsHandlerGroup handlerGroup = mock(EzyWsHandlerGroup.class);
    doThrow(new RuntimeException()).when(handlerGroup).fireBytesReceived(message);
    when(handlerGroupManager.getHandlerGroup(session)).thenReturn(handlerGroup);
    // when
    MethodInvoker.create().object(sut).method("doWsReceive").param(Session.class, session).param(String.class, message).call();
    // then
    verify(handlerGroupManager, times(1)).getHandlerGroup(session);
    verify(handlerGroup, times(1)).fireBytesReceived(message);
}
Also used : EzyWsHandlerGroup(com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandlerGroup) EzyHandlerGroupManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager) EzySocketDataReceiver(com.tvd12.ezyfoxserver.nio.socket.EzySocketDataReceiver) Session(org.eclipse.jetty.websocket.api.Session) Test(org.testng.annotations.Test)

Example 7 with EzyHandlerGroupManager

use of com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager in project ezyfox-server by youngmonkeys.

the class EzySocketDataReceiverTest method doWsReceive2ButException.

@Test
public void doWsReceive2ButException() throws Exception {
    // given
    EzyHandlerGroupManager handlerGroupManager = mock(EzyHandlerGroupManager.class);
    EzySocketDataReceiver sut = EzySocketDataReceiver.builder().handlerGroupManager(handlerGroupManager).build();
    Session session = mock(Session.class);
    byte[] payload = new byte[] { 1, 2, 3 };
    EzyWsHandlerGroup handlerGroup = mock(EzyWsHandlerGroup.class);
    doThrow(new RuntimeException()).when(handlerGroup).fireBytesReceived(payload, 0, payload.length);
    when(handlerGroupManager.getHandlerGroup(session)).thenReturn(handlerGroup);
    // when
    MethodInvoker.create().object(sut).method("doWsReceive").param(Session.class, session).param(byte[].class, payload).param(int.class, 0).param(int.class, payload.length).call();
    // then
    verify(handlerGroupManager, times(1)).getHandlerGroup(session);
    verify(handlerGroup, times(1)).fireBytesReceived(payload, 0, payload.length);
}
Also used : EzyWsHandlerGroup(com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandlerGroup) EzyHandlerGroupManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager) EzySocketDataReceiver(com.tvd12.ezyfoxserver.nio.socket.EzySocketDataReceiver) Session(org.eclipse.jetty.websocket.api.Session) Test(org.testng.annotations.Test)

Example 8 with EzyHandlerGroupManager

use of com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager in project ezyfox-server by youngmonkeys.

the class EzySocketDataReceiverTest method tcpReadBytesClosedChannelException.

@Test
public void tcpReadBytesClosedChannelException() throws Exception {
    // given
    EzyHandlerGroupManager handlerGroupManager = mock(EzyHandlerGroupManager.class);
    EzySocketDataReceiver sut = EzySocketDataReceiver.builder().handlerGroupManager(handlerGroupManager).build();
    ByteBuffer buffer = ByteBuffer.wrap(new byte[] { 1, 2, 3 });
    SocketChannel channel = mock(SocketChannel.class);
    when(channel.read(buffer)).thenThrow(new ClosedChannelException());
    // when
    MethodInvoker.create().object(sut).method("tcpReadBytes").param(SocketChannel.class, channel).param(ByteBuffer.class, buffer).call();
    // then
    verify(handlerGroupManager, times(1)).getHandlerGroup(channel);
}
Also used : SocketChannel(java.nio.channels.SocketChannel) ClosedChannelException(java.nio.channels.ClosedChannelException) EzyHandlerGroupManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager) EzySocketDataReceiver(com.tvd12.ezyfoxserver.nio.socket.EzySocketDataReceiver) ByteBuffer(java.nio.ByteBuffer) Test(org.testng.annotations.Test)

Example 9 with EzyHandlerGroupManager

use of com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager in project ezyfox-server by youngmonkeys.

the class EzyHandlerGroupManagerImplTest method mapSocketChannelSessionNull.

@Test
public void mapSocketChannelSessionNull() {
    // given
    EzyHandlerGroupManager sut = newHandlerGroupManager();
    // when
    // then
    sut.mapSocketChannel(null, null);
}
Also used : EzyHandlerGroupManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 10 with EzyHandlerGroupManager

use of com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager 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

EzyHandlerGroupManager (com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager)29 Test (org.testng.annotations.Test)28 BaseTest (com.tvd12.test.base.BaseTest)14 EzySocketDataReceiver (com.tvd12.ezyfoxserver.nio.socket.EzySocketDataReceiver)13 SocketChannel (java.nio.channels.SocketChannel)13 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)9 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)9 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)9 EzyCodecFactory (com.tvd12.ezyfoxserver.codec.EzyCodecFactory)8 EzyHandlerGroupBuilderFactory (com.tvd12.ezyfoxserver.nio.factory.EzyHandlerGroupBuilderFactory)8 EzySimpleStreamingSetting (com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting)8 ExecutorService (java.util.concurrent.ExecutorService)8 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)7 EzyNioSessionManager (com.tvd12.ezyfoxserver.nio.wrapper.EzyNioSessionManager)7 EzySimpleSessionTokenGenerator (com.tvd12.ezyfoxserver.service.impl.EzySimpleSessionTokenGenerator)7 EzySimpleStatistics (com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics)7 EzyStatistics (com.tvd12.ezyfoxserver.statistics.EzyStatistics)7 InetSocketAddress (java.net.InetSocketAddress)7 ByteBuffer (java.nio.ByteBuffer)7 EzySimpleNioUdpDataHandler (com.tvd12.ezyfoxserver.nio.handler.EzySimpleNioUdpDataHandler)6