use of com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting in project ezyfox-server by youngmonkeys.
the class EzySettingsBuilderTest method test.
@Test
public void test() {
EzySimpleStreamingSetting streamingSetting = new EzySimpleStreamingSetting();
EzySimpleHttpSetting httpSetting = new EzySimpleHttpSetting();
EzySimpleSocketSetting socketSetting = new EzySocketSettingBuilder().active(true).address("1.1.1.1").codecCreator(TestCodecCreator.class).maxRequestSize(1024).port(12345).tcpNoDelay(true).writerThreadPoolSize(3).build();
EzySimpleUdpSetting udpSetting = new EzyUdpSettingBuilder().active(true).address("2.2.2.2").channelPoolSize(3).codecCreator(TestCodecCreator.class).handlerThreadPoolSize(3).maxRequestSize(2048).port(23456).build();
EzySimpleSslConfigSetting sslConfigSetting = new EzySimpleSslConfigSetting();
EzySimpleWebSocketSetting webSocketSetting = new EzyWebSocketSettingBuilder().active(true).address("1.1.1.1").codecCreator(TestCodecCreator.class).maxFrameSize(1024).port(12345).sslActive(true).sslConfig(sslConfigSetting).sslPort(23456).writerThreadPoolSize(3).build();
EzySimpleAdminsSetting adminsSetting = new EzySimpleAdminsSetting();
EzySimpleAdminSetting adminSetting = new EzyAdminSettingBuilder().accessToken("123").username("admin").password("123456").build();
EzySimpleLoggerSetting loggerSetting = new EzySimpleLoggerSetting();
EzySimpleThreadPoolSizeSetting threadPoolSizeSetting = new EzyThreadPoolSizeSettingBuilder().socketDataReceiver(1).extensionRequestHandler(2).socketDisconnectionHandler(3).socketUserRemovalHandler(4).statistics(5).streamHandler(6).systemRequestHandler(7).build();
EzySimpleMaxRequestPerSecond maxRequestPerSecond = new EzyMaxRequestPerSecondBuilder().value(15).action(EzyMaxRequestPerSecondAction.DROP_REQUEST).build();
EzySimpleSessionManagementSetting sessionManagementSetting = new EzySessionManagementSettingBuilder().sessionMaxIdleTimeInSecond(100).sessionMaxRequestPerSecond(maxRequestPerSecond).sessionMaxWaitingTimeInSecond(200).build();
EzySimpleEventControllersSetting eventControllersSetting = new EzySimpleEventControllersSetting();
EzySimpleZonesSetting zonesSetting = new EzySimpleZonesSetting();
EzySimpleZoneSetting zoneSetting = new EzyZoneSettingBuilder().name("test").build();
EzySimpleSettings settings = new EzySettingsBuilder().debug(true).nodeName("test").maxSessions(100).socket(socketSetting).udp(udpSetting).streaming(streamingSetting).http(httpSetting).websocket(webSocketSetting).admins(adminsSetting).admin(adminSetting).logger(loggerSetting).threadPoolSize(threadPoolSizeSetting).sessionManagement(sessionManagementSetting).eventControllers(eventControllersSetting).zones(zonesSetting).zone(zoneSetting).addEventController(EzyEventType.SERVER_INITIALIZING, HelloServerInitializingReadyController.class).build();
assertTrue(settings.isDebug());
assertEquals(settings.getNodeName(), "test");
assertEquals(settings.getMaxSessions(), 100);
assertEquals(settings.getStreaming(), streamingSetting);
assertEquals(settings.getHttp(), httpSetting);
socketSetting = settings.getSocket();
assertTrue(socketSetting.isActive());
assertEquals(socketSetting.getAddress(), "1.1.1.1");
assertEquals(socketSetting.getCodecCreator(), TestCodecCreator.class.getName());
assertEquals(socketSetting.getMaxRequestSize(), 1024);
assertEquals(socketSetting.getPort(), 12345);
assertTrue(socketSetting.isTcpNoDelay());
assertEquals(socketSetting.getWriterThreadPoolSize(), 3);
udpSetting = settings.getUdp();
assertTrue(udpSetting.isActive());
assertEquals(udpSetting.getAddress(), "2.2.2.2");
assertEquals(udpSetting.getCodecCreator(), TestCodecCreator.class.getName());
assertEquals(udpSetting.getMaxRequestSize(), 2048);
assertEquals(udpSetting.getPort(), 23456);
assertEquals(udpSetting.getChannelPoolSize(), 3);
assertEquals(udpSetting.getHandlerThreadPoolSize(), 3);
webSocketSetting = settings.getWebsocket();
assertTrue(webSocketSetting.isActive());
assertEquals(webSocketSetting.getAddress(), "1.1.1.1");
assertEquals(webSocketSetting.getCodecCreator(), TestCodecCreator.class.getName());
assertEquals(webSocketSetting.getMaxFrameSize(), 1024);
assertEquals(webSocketSetting.getPort(), 12345);
assertTrue(webSocketSetting.isSslActive());
assertEquals(webSocketSetting.getSslConfig(), sslConfigSetting);
assertEquals(webSocketSetting.getSslPort(), 23456);
assertEquals(webSocketSetting.getWriterThreadPoolSize(), 3);
assertEquals(settings.getAdmins(), adminsSetting);
adminSetting = (EzySimpleAdminSetting) settings.getAdmins().getAdminByName("admin");
assertEquals(adminSetting.getAccessToken(), "123");
assertEquals(adminSetting.getUsername(), "admin");
assertEquals(adminSetting.getPassword(), "123456");
assertEquals(settings.getLogger(), loggerSetting);
threadPoolSizeSetting = settings.getThreadPoolSize();
assertEquals(threadPoolSizeSetting.getSocketDataReceiver(), 1);
assertEquals(threadPoolSizeSetting.getExtensionRequestHandler(), 2);
assertEquals(threadPoolSizeSetting.getSocketDisconnectionHandler(), 3);
assertEquals(threadPoolSizeSetting.getSocketUserRemovalHandler(), 4);
assertEquals(threadPoolSizeSetting.getStatistics(), 5);
assertEquals(threadPoolSizeSetting.getStreamHandler(), 6);
assertEquals(threadPoolSizeSetting.getSystemRequestHandler(), 7);
sessionManagementSetting = settings.getSessionManagement();
assertEquals(sessionManagementSetting.getSessionMaxIdleTimeInSecond(), 100);
assertEquals(sessionManagementSetting.getSessionMaxRequestPerSecond(), maxRequestPerSecond);
assertEquals(maxRequestPerSecond.getValue(), 15);
assertEquals(maxRequestPerSecond.getAction(), EzyMaxRequestPerSecondAction.DROP_REQUEST);
assertEquals(settings.getEventControllers(), eventControllersSetting);
assertEquals(settings.getZones().getSize(), 1);
assertEquals(zonesSetting.getZoneByName("test"), zoneSetting);
}
use of com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting in project ezyfox-server by youngmonkeys.
the class EzyNioSocketAcceptorTest method newHandlerGroupManager.
private EzyHandlerGroupManager newHandlerGroupManager() {
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).sessionTicketsRequestQueues(sessionTicketsRequestQueues).build();
return EzyHandlerGroupManagerImpl.builder().handlerGroupBuilderFactory(handlerGroupBuilderFactory).build();
}
use of com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting in project ezyfox-server by youngmonkeys.
the class EzySimpleWsHandlerGroupTest method newHandlerGroup.
@SuppressWarnings("rawtypes")
private EzySimpleWsHandlerGroup newHandlerGroup(boolean streamEnable) throws IOException {
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(streamEnable);
EzySimpleServer server = new EzySimpleServer();
server.setSettings(settings);
server.setSessionManager(sessionManager);
EzyServerControllers controllers = mock(EzyServerControllers.class);
server.setControllers(controllers);
EzySimpleConfig config = new EzySimpleConfig();
server.setConfig(config);
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);
ExecutorService statsThreadPool = EzyExecutors.newFixedThreadPool(1, "stats");
EzySocketStreamQueue streamQueue = new EzyBlockingSocketStreamQueue();
EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
EzySimpleSession session = mock(EzySimpleSession.class);
when(session.getChannel()).thenReturn(channel);
EzyHandlerGroupBuilderFactory handlerGroupBuilderFactory = EzyHandlerGroupBuilderFactoryImpl.builder().statistics(statistics).serverContext(serverContext).statsThreadPool(statsThreadPool).streamQueue(streamQueue).codecFactory(new ExCodecFactory()).sessionTicketsRequestQueues(sessionTicketsRequestQueues).socketSessionTicketsQueue(socketSessionTicketsQueue).webSocketSessionTicketsQueue(webSocketSessionTicketsQueue).build();
return (EzySimpleWsHandlerGroup) handlerGroupBuilderFactory.newBuilder(channel, EzyConnectionType.WEBSOCKET).session(session).build();
}
use of com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting 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();
}
use of com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting in project ezyfox-server by youngmonkeys.
the class EzyHandlerGroupManagerImplTest method newHandlerGroupManager.
public EzyHandlerGroupManager newHandlerGroupManager() {
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();
return EzyHandlerGroupManagerImpl.builder().handlerGroupBuilderFactory(handlerGroupBuilderFactory).build();
}
Aggregations