use of com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandler in project ezyfox-server by youngmonkeys.
the class EzyWebSocketServerCreatorTest method createManagementTest.
@Test
public void createManagementTest() {
// given
EzyWebSocketServerCreator creator = new EzyWebSocketServerCreator();
EzySimpleWebSocketSetting webSocketSetting = new EzySimpleWebSocketSetting();
webSocketSetting.setManagementEnable(true);
creator.setting(webSocketSetting);
// when
creator.create();
// then
EzyWsHandler wsHandler = MethodInvoker.create().object(creator).method("newWsHandler").invoke(EzyWsHandler.class);
WebSocketCreator webSocketCreator = MethodInvoker.create().object(creator).method("newWebSocketCreator").param(EzyWsHandler.class, wsHandler).invoke(WebSocketCreator.class);
webSocketCreator.createWebSocket(null, null);
}
use of com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandler in project ezyfox-server by youngmonkeys.
the class EzyWebSocketServerCreator method create.
public Server create() {
ContextHandler wsContextHandler = new ContextHandler("/ws");
wsContextHandler.setAllowNullPathInfo(true);
EzyWsHandler wsHandler = newWsHandler();
wsContextHandler.setHandler(newWebSocketHandler(wsHandler));
QueuedThreadPool threadPool = new QueuedThreadPool(16, 8);
threadPool.setName("ezyfox-ws-handler");
Server server = new Server(threadPool);
ContextHandlerCollection contextHandlers = new ContextHandlerCollection();
contextHandlers.addHandler(wsContextHandler);
if (setting.isManagementEnable()) {
contextHandlers.addHandler(managementHandler());
}
server.setHandler(contextHandlers);
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setSecureScheme("https");
httpConfig.setSecurePort(setting.getSslPort());
ServerConnector wsConnector = new ServerConnector(server);
wsConnector.setPort(setting.getPort());
wsConnector.setHost(setting.getAddress());
server.addConnector(wsConnector);
configServer(server, httpConfig, wsConnector);
return server;
}
use of com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandler in project ezyfox-server by youngmonkeys.
the class EzyWsHandlerTest method setChannelClosedWithChannelNull.
@Test
public void setChannelClosedWithChannelNull() {
// given
EzyNioSessionManager sessionManager = mock(EzyNioSessionManager.class);
EzyWsHandler sut = EzyWsHandler.builder().sessionManager(sessionManager).build();
Session connection = mock(Session.class);
EzyNioSession session = mock(EzyNioSession.class);
when(sessionManager.getSession(connection)).thenReturn(session);
// when
MethodInvoker.create().object(sut).method("setChannelClosed").param(Session.class, connection).call();
// then
verify(sessionManager, times(1)).getSession(connection);
verify(session, times(1)).getChannel();
}
use of com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandler in project ezyfox-server by youngmonkeys.
the class EzyWebSocketSecureServerCreatorTest method test.
@Test
public void test() throws Exception {
SSLContext sslContext = SSLContext.getDefault();
EzySimpleWebSocketSetting webSocketSetting = new EzySimpleWebSocketSetting();
EzyWebSocketSecureServerCreator creator = new EzyWebSocketSecureServerCreator(sslContext);
creator.setting(webSocketSetting);
creator.create();
EzyWsHandler wsHandler = MethodInvoker.create().object(creator).method("newWsHandler").invoke(EzyWsHandler.class);
WebSocketCreator webSocketCreator = MethodInvoker.create().object(creator).method("newWebSocketCreator").param(EzyWsHandler.class, wsHandler).invoke(WebSocketCreator.class);
webSocketCreator.createWebSocket(null, null);
}
use of com.tvd12.ezyfoxserver.nio.websocket.EzyWsHandler 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");
}
Aggregations