use of com.tvd12.ezyfoxserver.api.EzyResponseApi in project ezyfox-server by youngmonkeys.
the class EzySendResponseImplTest method responseOneSuccessCaseTest.
@Test
public void responseOneSuccessCaseTest() {
EzySimpleSettings settings = new EzySimpleSettings();
settings.setDebug(true);
EzyResponseApi responseApi = spy(EzyAbstractResponseApi.class);
EzySimpleServer server = new EzySimpleServer();
server.setResponseApi(responseApi);
server.setSettings(settings);
EzySendResponseImpl cmd = new EzySendResponseImpl(server);
EzyResponse response = new EzySimpleResponse(EzyCommand.APP_REQUEST);
EzySession recipient = spy(EzyAbstractSession.class);
cmd.execute(response, recipient, false, false, EzyTransportType.TCP);
}
use of com.tvd12.ezyfoxserver.api.EzyResponseApi in project ezyfox-server by youngmonkeys.
the class EzySendResponseImplTest method responseMultiSuccessCaseButNotDebug.
@Test
public void responseMultiSuccessCaseButNotDebug() throws Exception {
// when
EzySimpleSettings settings = new EzySimpleSettings();
settings.setDebug(false);
EzyResponseApi responseApi = mock(EzyResponseApi.class);
EzySimpleServer server = new EzySimpleServer();
server.setResponseApi(responseApi);
server.setSettings(settings);
EzySendResponseImpl cmd = new EzySendResponseImpl(server);
EzyResponse response = new EzySimpleResponse(EzyCommand.APP_REQUEST);
EzySession recipient = spy(EzyAbstractSession.class);
List<EzySession> recipients = Collections.singletonList(recipient);
// when
cmd.execute(response, recipients, false, false, EzyTransportType.TCP);
// then
verify(responseApi, times(1)).response(any(EzyPackage.class), anyBoolean());
}
use of com.tvd12.ezyfoxserver.api.EzyResponseApi in project ezyfox-server by youngmonkeys.
the class EzySendResponseImplTest method responseMultiErrorTest.
@Test
public void responseMultiErrorTest() throws Exception {
// given
EzySimpleSettings settings = new EzySimpleSettings();
settings.setDebug(true);
EzyResponseApi responseApi = mock(EzyResponseApi.class);
doThrow(new IllegalArgumentException()).when(responseApi).response(any(EzyPackage.class), anyBoolean());
EzySimpleServer server = new EzySimpleServer();
server.setResponseApi(responseApi);
server.setSettings(settings);
EzySendResponseImpl cmd = new EzySendResponseImpl(server);
EzyResponse response = new EzySimpleResponse(EzyCommand.APP_REQUEST);
EzySession recipient = spy(EzyAbstractSession.class);
List<EzySession> recipients = Collections.singletonList(recipient);
// when
cmd.execute(response, recipients, false, false, EzyTransportType.TCP);
// then
verify(responseApi, times(1)).response(any(EzyPackage.class), anyBoolean());
}
use of com.tvd12.ezyfoxserver.api.EzyResponseApi in project ezyfox-server by youngmonkeys.
the class EzyAbstractHandlerGroupTest method newHandlerGroup.
@SuppressWarnings("rawtypes")
private ExHandlerGroup newHandlerGroup() throws Exception {
EzyStatistics statistics = new EzySimpleStatistics();
EzySimpleSettings settings = new EzySimpleSettings();
EzySimpleStreamingSetting streaming = settings.getStreaming();
streaming.setEnable(true);
EzySimpleServer server = new EzySimpleServer();
server.setSettings(settings);
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);
EzySessionManager sessionManager = mock(EzySessionManager.class);
server.setSessionManager(sessionManager);
EzyResponseApi responseApi = mock(EzyResponseApi.class);
server.setResponseApi(responseApi);
ExEzyByteToObjectDecoder decoder = new ExEzyByteToObjectDecoder();
ExecutorService statsThreadPool = EzyExecutors.newFixedThreadPool(1, "stats");
EzySessionTicketsRequestQueues sessionTicketsRequestQueues = mock(EzySessionTicketsRequestQueues.class);
when(channel.write(any(ByteBuffer.class), anyBoolean())).thenReturn(123456);
return (ExHandlerGroup) new ExHandlerGroup.Builder().session(session).decoder(decoder).sessionCount(new AtomicInteger()).networkStats((EzyNetworkStats) statistics.getSocketStats().getNetworkStats()).sessionStats((EzySessionStats) statistics.getSocketStats().getSessionStats()).serverContext(serverContext).statsThreadPool(statsThreadPool).sessionTicketsRequestQueues(sessionTicketsRequestQueues).build();
}
use of com.tvd12.ezyfoxserver.api.EzyResponseApi 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