use of com.tvd12.ezyfoxserver.codec.EzyCodecFactory in project ezyfox-server by youngmonkeys.
the class EzySimpleCodecFactoryTest method test.
@Test
public void test() {
EzySimpleSocketSetting socketSetting = new EzySimpleSocketSetting();
socketSetting.setActive(false);
EzySimpleWebSocketSetting webSocketSetting = new EzySimpleWebSocketSetting();
webSocketSetting.setActive(false);
EzyCodecFactory factory = EzySimpleCodecFactory.builder().socketSetting(socketSetting).websocketSetting(webSocketSetting).build();
assert factory.newEncoder(EzyConnectionType.SOCKET) == null;
assert factory.newEncoder(EzyConnectionType.WEBSOCKET) == null;
assert factory.newDecoder(EzyConnectionType.SOCKET) == null;
assert factory.newDecoder(EzyConnectionType.WEBSOCKET) == null;
socketSetting.setActive(true);
socketSetting.setCodecCreator(ExBytesCodecCreator.class.getName());
webSocketSetting.setActive(true);
webSocketSetting.setCodecCreator(ExStringCodecCreator.class.getName());
factory = EzySimpleCodecFactory.builder().socketSetting(socketSetting).websocketSetting(webSocketSetting).build();
assert factory.newEncoder(EzyConnectionType.SOCKET) != null;
assert factory.newEncoder(EzyConnectionType.WEBSOCKET) != null;
assert factory.newDecoder(EzyConnectionType.SOCKET) != null;
assert factory.newDecoder(EzyConnectionType.WEBSOCKET) != null;
}
use of com.tvd12.ezyfoxserver.codec.EzyCodecFactory in project ezyfox-server by youngmonkeys.
the class EzyProxyResponseApiTest method test.
@Test
public void test() throws Exception {
EzyCodecFactory codecFactory = mock(EzyCodecFactory.class);
EzyProxyResponseApi api = new EzyProxyResponseApi(codecFactory);
EzyPackage pack = mock(EzyPackage.class);
api.response(pack);
EzyObjectToByteEncoder byteEncoder = mock(EzyObjectToByteEncoder.class);
EzyObjectToStringEncoder stringEncoder = mock(EzyObjectToStringEncoder.class);
when(codecFactory.newEncoder(EzyConnectionType.SOCKET)).thenReturn(byteEncoder);
when(codecFactory.newEncoder(EzyConnectionType.WEBSOCKET)).thenReturn(stringEncoder);
api = new EzyProxyResponseApi(codecFactory);
api.response(pack);
api.response(pack, true);
EzyImmediateDeliver immediateDeliver = mock(EzyImmediateDeliver.class);
EzyAbstractSession session = spy(EzyAbstractSession.class);
session.setImmediateDeliver(immediateDeliver);
when(pack.getRecipients(any(EzyConstant.class))).thenReturn(Lists.newArrayList(session));
api.response(pack);
api.response(pack, true);
}
use of com.tvd12.ezyfoxserver.codec.EzyCodecFactory in project ezyfox-server by youngmonkeys.
the class EzySimpleNioHandlerGroupTest method newHandlerGroup.
@SuppressWarnings("rawtypes")
private EzySimpleNioHandlerGroup 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);
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.SOCKET);
EzySimpleSession session = mock(EzySimpleSession.class);
when(session.getChannel()).thenReturn(channel);
ExecutorService statsThreadPool = EzyExecutors.newFixedThreadPool(1, "stats");
EzySessionTicketsRequestQueues sessionTicketsRequestQueues = new EzySessionTicketsRequestQueues();
SelectionKey selectionKey = mock(SelectionKey.class);
when(selectionKey.isValid()).thenReturn(true);
when(session.getProperty(EzyNioSession.SELECTION_KEY)).thenReturn(selectionKey);
EzyCodecFactory codecFactory = mock(EzyCodecFactory.class);
EzyByteToObjectDecoder decoder = mock(EzyByteToObjectDecoder.class);
when(codecFactory.newDecoder(any())).thenReturn(decoder);
EzyHandlerGroupBuilderFactory handlerGroupBuilderFactory = EzyHandlerGroupBuilderFactoryImpl.builder().statistics(statistics).serverContext(serverContext).statsThreadPool(statsThreadPool).codecFactory(codecFactory).sessionTicketsRequestQueues(sessionTicketsRequestQueues).socketSessionTicketsQueue(socketSessionTicketsQueue).webSocketSessionTicketsQueue(webSocketSessionTicketsQueue).build();
return (EzySimpleNioHandlerGroup) handlerGroupBuilderFactory.newBuilder(channel, EzyConnectionType.SOCKET).session(session).decoder(decoder).serverContext(serverContext).statsThreadPool(statsThreadPool).sessionTicketsRequestQueues(sessionTicketsRequestQueues).build();
}
use of com.tvd12.ezyfoxserver.codec.EzyCodecFactory in project ezyfox-server by youngmonkeys.
the class EzyNioServerBootstrapBuilderImpl method newServerBootstrap.
@Override
protected EzyServerBootstrap newServerBootstrap() {
ExecutorService statsThreadPool = newStatsThreadPool();
EzyCodecFactory codecFactory = newCodecFactory();
EzyStreamingApi streamingApi = newStreamingApi();
EzyResponseApi responseApi = newResponseApi(codecFactory);
EzySocketStreamQueue streamQueue = newStreamQueue();
EzySessionTicketsQueue socketSessionTicketsQueue = newSocketSessionTicketsQueue();
EzySessionTicketsQueue websocketSessionTicketsQueue = newWebSocketSessionTicketsQueue();
EzySocketDisconnectionQueue socketDisconnectionQueue = newSocketDisconnectionQueue();
EzySessionTicketsRequestQueues sessionTicketsRequestQueues = newSessionTicketsRequestQueues();
EzyHandlerGroupBuilderFactory handlerGroupBuilderFactory = newHandlerGroupBuilderFactory(statsThreadPool, codecFactory, streamQueue, socketDisconnectionQueue, socketSessionTicketsQueue, websocketSessionTicketsQueue, sessionTicketsRequestQueues);
EzyHandlerGroupManager handlerGroupManager = newHandlerGroupManager(handlerGroupBuilderFactory);
EzySocketDataReceiver socketDataReceiver = newSocketDataReceiver(handlerGroupManager);
EzyNioServerBootstrap bootstrap = new EzyNioServerBootstrap();
bootstrap.setResponseApi(responseApi);
bootstrap.setStreamingApi(streamingApi);
bootstrap.setStreamQueue(streamQueue);
bootstrap.setSocketDataReceiver(socketDataReceiver);
bootstrap.setHandlerGroupManager(handlerGroupManager);
bootstrap.setSocketDisconnectionQueue(socketDisconnectionQueue);
bootstrap.setSocketSessionTicketsQueue(socketSessionTicketsQueue);
bootstrap.setWebsocketSessionTicketsQueue(websocketSessionTicketsQueue);
bootstrap.setSocketSessionTicketsRequestQueues(sessionTicketsRequestQueues);
bootstrap.setSslContext(newSslContext(getWebsocketSetting().getSslConfig()));
return bootstrap;
}
Aggregations