use of com.tvd12.ezyfoxserver.nio.handler.EzyNioHandlerGroup 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();
}
Aggregations