Search in sources :

Example 11 with EzyResponseApi

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);
}
Also used : EzySimpleResponse(com.tvd12.ezyfoxserver.response.EzySimpleResponse) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzySendResponseImpl(com.tvd12.ezyfoxserver.command.impl.EzySendResponseImpl) Test(org.testng.annotations.Test)

Example 12 with EzyResponseApi

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());
}
Also used : EzySimpleResponse(com.tvd12.ezyfoxserver.response.EzySimpleResponse) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyPackage(com.tvd12.ezyfoxserver.response.EzyPackage) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzySendResponseImpl(com.tvd12.ezyfoxserver.command.impl.EzySendResponseImpl) Test(org.testng.annotations.Test)

Example 13 with EzyResponseApi

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());
}
Also used : EzySimpleResponse(com.tvd12.ezyfoxserver.response.EzySimpleResponse) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyPackage(com.tvd12.ezyfoxserver.response.EzyPackage) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzySendResponseImpl(com.tvd12.ezyfoxserver.command.impl.EzySendResponseImpl) Test(org.testng.annotations.Test)

Example 14 with EzyResponseApi

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();
}
Also used : EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzyStatistics(com.tvd12.ezyfoxserver.statistics.EzyStatistics) EzySimpleStreamingSetting(com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting) EzySessionManager(com.tvd12.ezyfoxserver.wrapper.EzySessionManager) EzySimpleSettings(com.tvd12.ezyfoxserver.setting.EzySimpleSettings) EzySimpleSession(com.tvd12.ezyfoxserver.nio.entity.EzySimpleSession) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) ByteBuffer(java.nio.ByteBuffer) EzySessionStats(com.tvd12.ezyfoxserver.statistics.EzySessionStats) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) EzySimpleStatistics(com.tvd12.ezyfoxserver.statistics.EzySimpleStatistics) ExEzyByteToObjectDecoder(com.tvd12.ezyfoxserver.nio.testing.handler.EzySimpleNioHandlerGroupTest.ExEzyByteToObjectDecoder)

Example 15 with EzyResponseApi

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;
}
Also used : EzyHandlerGroupBuilderFactory(com.tvd12.ezyfoxserver.nio.factory.EzyHandlerGroupBuilderFactory) EzyHandlerGroupManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager) EzySocketDataReceiver(com.tvd12.ezyfoxserver.nio.socket.EzySocketDataReceiver) ExecutorService(java.util.concurrent.ExecutorService) EzyStreamingApi(com.tvd12.ezyfoxserver.api.EzyStreamingApi) EzyCodecFactory(com.tvd12.ezyfoxserver.codec.EzyCodecFactory) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzyNioServerBootstrap(com.tvd12.ezyfoxserver.nio.EzyNioServerBootstrap)

Aggregations

EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)15 Test (org.testng.annotations.Test)11 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)10 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)10 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)10 EzySendResponseImpl (com.tvd12.ezyfoxserver.command.impl.EzySendResponseImpl)8 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)8 EzySimpleResponse (com.tvd12.ezyfoxserver.response.EzySimpleResponse)8 EzyPackage (com.tvd12.ezyfoxserver.response.EzyPackage)7 EzyHandlerGroupManager (com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager)3 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)3 ByteBuffer (java.nio.ByteBuffer)3 EzyArray (com.tvd12.ezyfox.entity.EzyArray)2 EzyStreamingApi (com.tvd12.ezyfoxserver.api.EzyStreamingApi)2 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)2 EzyNioServerBootstrap (com.tvd12.ezyfoxserver.nio.EzyNioServerBootstrap)2 EzySimpleNioUdpDataHandler (com.tvd12.ezyfoxserver.nio.handler.EzySimpleNioUdpDataHandler)2 EzySimpleStreamingSetting (com.tvd12.ezyfoxserver.setting.EzySimpleStreamingSetting)2 EzySimplePackage (com.tvd12.ezyfoxserver.socket.EzySimplePackage)2 InetSocketAddress (java.net.InetSocketAddress)2