Search in sources :

Example 21 with EzyHandlerGroupManager

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

the class EzySocketDataReceiverTest method udpReceiveButHandlerGroupNullTest.

@Test
public void udpReceiveButHandlerGroupNullTest() throws Exception {
    // given
    EzyHandlerGroupManager handlerGroupManager = mock(EzyHandlerGroupManager.class);
    EzySocketDataReceiver sut = EzySocketDataReceiver.builder().handlerGroupManager(handlerGroupManager).threadPoolSize(1).build();
    SocketChannel channel = mock(SocketChannel.class);
    EzyMessage message = mock(EzyMessage.class);
    // when
    sut.udpReceive(channel, message);
    Thread.sleep(120);
    // then
    verify(handlerGroupManager, times(1)).getHandlerGroup(channel);
    sut.destroy();
}
Also used : SocketChannel(java.nio.channels.SocketChannel) EzyHandlerGroupManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager) EzySocketDataReceiver(com.tvd12.ezyfoxserver.nio.socket.EzySocketDataReceiver) EzyMessage(com.tvd12.ezyfox.codec.EzyMessage) Test(org.testng.annotations.Test)

Example 22 with EzyHandlerGroupManager

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

the class EzySocketDataReceiverTest method udpReceiveTest.

@Test
public void udpReceiveTest() throws Exception {
    // given
    EzyHandlerGroupManager handlerGroupManager = mock(EzyHandlerGroupManager.class);
    EzySocketDataReceiver sut = EzySocketDataReceiver.builder().handlerGroupManager(handlerGroupManager).threadPoolSize(1).build();
    SocketChannel channel = mock(SocketChannel.class);
    EzyMessage message = mock(EzyMessage.class);
    EzyNioHandlerGroup handlerGroup = mock(EzyNioHandlerGroup.class);
    when(handlerGroupManager.getHandlerGroup(channel)).thenReturn(handlerGroup);
    // when
    sut.udpReceive(channel, message);
    Thread.sleep(120);
    // then
    verify(handlerGroupManager, times(1)).getHandlerGroup(channel);
    verify(handlerGroup, times(1)).fireMessageReceived(message);
    sut.destroy();
}
Also used : SocketChannel(java.nio.channels.SocketChannel) EzyHandlerGroupManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager) EzySocketDataReceiver(com.tvd12.ezyfoxserver.nio.socket.EzySocketDataReceiver) EzyMessage(com.tvd12.ezyfox.codec.EzyMessage) EzyNioHandlerGroup(com.tvd12.ezyfoxserver.nio.handler.EzyNioHandlerGroup) Test(org.testng.annotations.Test)

Example 23 with EzyHandlerGroupManager

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

the class EzySocketDataReceiverTest method processReadBytesHandlerGroupIsNull.

@Test
public void processReadBytesHandlerGroupIsNull() 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("processReadBytes").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 24 with EzyHandlerGroupManager

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

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

the class EzyHandlerGroupManagerImplTest method unmapHandlerGroupNullAddress.

@Test
public void unmapHandlerGroupNullAddress() {
    // given
    EzyHandlerGroupManager sut = newHandlerGroupManager();
    // when
    // then
    sut.unmapHandlerGroup(null);
}
Also used : EzyHandlerGroupManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager) 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