use of com.tvd12.ezyfoxserver.socket.EzySimpleUdpReceivedPacket 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();
}
use of com.tvd12.ezyfoxserver.socket.EzySimpleUdpReceivedPacket in project ezyfox-server by youngmonkeys.
the class EzySimpleNioUdpDataHandlerTest method testExceptionCase.
@Test
public void testExceptionCase() 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;
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);
when(handlerGroupManager.getHandlerGroup(packet.getAddress())).thenThrow(new IllegalArgumentException("test"));
handler.setHandlerGroupManager(handlerGroupManager);
handler.fireUdpPacketReceived(packet);
Thread.sleep(200);
handler.destroy();
}
use of com.tvd12.ezyfoxserver.socket.EzySimpleUdpReceivedPacket in project ezyfox-server by youngmonkeys.
the class EzySimpleUdpReceivedPacketTest method test.
@Test
public void test() {
DatagramChannel channel = null;
try {
channel = DatagramChannel.open();
} catch (Exception e) {
e.printStackTrace();
}
InetSocketAddress address = new InetSocketAddress(12345);
byte[] bytes = new byte[] { 1, 2, 3 };
EzySimpleUdpReceivedPacket packet = new EzySimpleUdpReceivedPacket(channel, address, bytes);
assert packet.getAddress() != null;
assert packet.getBytes() != null;
System.out.println(packet.getChannel());
packet.release();
}
use of com.tvd12.ezyfoxserver.socket.EzySimpleUdpReceivedPacket in project ezyfox-server by youngmonkeys.
the class EzySimpleNioUdpDataHandlerTest method testNotHandshakeCase.
@Test
public void testNotHandshakeCase() 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;
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);
EzyNioHandlerGroup handlerGroup = mock(EzyNioHandlerGroup.class);
when(handlerGroupManager.getHandlerGroup(packet.getAddress())).thenReturn(handlerGroup);
EzyNioSession session = new EzySimpleSession();
session.setToken(sessionToken);
EzyChannel channel = mock(EzyChannel.class);
when(channel.getClientAddress()).thenReturn(new InetSocketAddress(12345));
session.setChannel(channel);
when(handlerGroup.getSession()).thenReturn(session);
handler.setHandlerGroupManager(handlerGroupManager);
handler.fireUdpPacketReceived(packet);
Thread.sleep(200);
handler.destroy();
}
use of com.tvd12.ezyfoxserver.socket.EzySimpleUdpReceivedPacket in project ezyfox-server by youngmonkeys.
the class EzySimpleNioUdpDataHandlerTest method testInvalidMessageCase.
@Test
public void testInvalidMessageCase() throws Exception {
EzySimpleNioUdpDataHandler handler = new EzySimpleNioUdpDataHandler(1);
byte[] bytes = new byte[] { 1, 2, 3 };
EzyUdpReceivedPacket packet = new EzySimpleUdpReceivedPacket(DatagramChannel.open(), new InetSocketAddress(12345), bytes);
handler.fireUdpPacketReceived(packet);
Thread.sleep(200);
handler.destroy();
}
Aggregations