use of com.tvd12.ezyfoxserver.api.EzyResponseApi in project ezyfox-server by youngmonkeys.
the class EzySendResponseImplTest method responseOneSuccessButIsPong.
@Test
public void responseOneSuccessButIsPong() throws Exception {
// given
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.PONG);
EzySession recipient = spy(EzyAbstractSession.class);
// when
cmd.execute(response, recipient, 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 responseOneSuccessButNotDebug.
@Test
public void responseOneSuccessButNotDebug() throws Exception {
// given
EzySimpleSettings settings = new EzySimpleSettings();
settings.setDebug(false);
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);
// when
cmd.execute(response, recipient, 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 responseOneExceptionCase.
@Test
public void responseOneExceptionCase() throws Exception {
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);
cmd.execute(response, recipient, false, false, EzyTransportType.TCP);
}
use of com.tvd12.ezyfoxserver.api.EzyResponseApi in project ezyfox-server by youngmonkeys.
the class EzySendResponseImpl method execute.
@Override
public void execute(EzyResponse response, Collection<EzySession> recipients, boolean encrypted, boolean immediate, EzyTransportType transportType) {
boolean success = false;
EzyResponseApi responseApi = server.getResponseApi();
EzyArray data = response.serialize();
EzySimplePackage pack = newPackage(data, encrypted, transportType);
pack.addRecipients(recipients);
try {
responseApi.response(pack, immediate);
success = true;
} catch (Exception e) {
logger.error("send data: {}, to client: {} error", pack.getData(), getRecipientsNames(recipients), e);
} finally {
pack.release();
}
boolean debug = server.getSettings().isDebug();
if (debug && success && !ignoredLogCommands.contains(response.getCommand())) {
logger.debug("send to: {} data: {}", getRecipientsNames(recipients), data);
}
}
use of com.tvd12.ezyfoxserver.api.EzyResponseApi in project ezyfox-server by youngmonkeys.
the class EzySimpleNioUdpDataHandlerTest method test.
@SuppressWarnings("rawtypes")
@Test
public void test() throws Exception {
String sessionToken = "12345678";
long sessionId = 12345L;
EzySimpleNioUdpDataHandler handler = new EzySimpleNioUdpDataHandler(1);
int tokenSize = sessionToken.length();
int messageSize = 0;
// sessionIdSize
messageSize += 8;
// tokenLengthSize
messageSize += 2;
// messageSize
messageSize += tokenSize;
ByteBuffer buffer = ByteBuffer.allocate(1 + 2 + messageSize);
byte header = 0;
header |= 1 << 5;
buffer.put(header);
buffer.putShort((short) messageSize);
buffer.putLong(sessionId);
buffer.putShort((short) tokenSize);
buffer.put(sessionToken.getBytes());
buffer.flip();
byte[] bytes = EzyByteBuffers.getBytes(buffer);
EzyUdpReceivedPacket packet = new EzySimpleUdpReceivedPacket(DatagramChannel.open(), new InetSocketAddress(12345), bytes);
EzyHandlerGroupManager handlerGroupManager = mock(EzyHandlerGroupManager.class);
EzySessionManager sessionManager = mock(EzySessionManager.class);
EzySession session = spy(EzyAbstractSession.class);
session.setToken(sessionToken);
when(sessionManager.getSession(sessionId)).thenReturn(session);
EzyResponseApi responseApi = mock(EzyResponseApi.class);
EzyDatagramChannelPool channelPool = new EzyDatagramChannelPool(1);
handler.setHandlerGroupManager(handlerGroupManager);
handler.setSessionManager(sessionManager);
handler.setResponseApi(responseApi);
handler.setDatagramChannelPool(channelPool);
handler.fireUdpPacketReceived(packet);
Thread.sleep(200);
handler.destroy();
}
Aggregations