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();
}
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();
}
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);
}
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");
}
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);
}
Aggregations