Search in sources :

Example 6 with EzyNioHandlerGroup

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();
}
Also used : EzyChannel(com.tvd12.ezyfoxserver.socket.EzyChannel) InetSocketAddress(java.net.InetSocketAddress) EzyNioSession(com.tvd12.ezyfoxserver.nio.entity.EzyNioSession) ByteBuffer(java.nio.ByteBuffer) EzySimpleSession(com.tvd12.ezyfoxserver.nio.entity.EzySimpleSession) EzyUdpReceivedPacket(com.tvd12.ezyfoxserver.socket.EzyUdpReceivedPacket) EzySimpleNioUdpDataHandler(com.tvd12.ezyfoxserver.nio.handler.EzySimpleNioUdpDataHandler) EzySimpleUdpReceivedPacket(com.tvd12.ezyfoxserver.socket.EzySimpleUdpReceivedPacket) EzyHandlerGroupManager(com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager) EzyNioHandlerGroup(com.tvd12.ezyfoxserver.nio.handler.EzyNioHandlerGroup) Test(org.testng.annotations.Test)

Aggregations

EzyNioHandlerGroup (com.tvd12.ezyfoxserver.nio.handler.EzyNioHandlerGroup)6 EzyHandlerGroupManager (com.tvd12.ezyfoxserver.nio.wrapper.EzyHandlerGroupManager)4 Test (org.testng.annotations.Test)4 EzyNioSession (com.tvd12.ezyfoxserver.nio.entity.EzyNioSession)3 SocketChannel (java.nio.channels.SocketChannel)3 EzyMessage (com.tvd12.ezyfox.codec.EzyMessage)2 EzySocketDataReceiver (com.tvd12.ezyfoxserver.nio.socket.EzySocketDataReceiver)2 EzyChannel (com.tvd12.ezyfoxserver.socket.EzyChannel)2 EzySimpleSession (com.tvd12.ezyfoxserver.nio.entity.EzySimpleSession)1 EzySimpleNioUdpDataHandler (com.tvd12.ezyfoxserver.nio.handler.EzySimpleNioUdpDataHandler)1 EzyNioSocketAcceptor (com.tvd12.ezyfoxserver.nio.socket.EzyNioSocketAcceptor)1 EzySimpleUdpReceivedPacket (com.tvd12.ezyfoxserver.socket.EzySimpleUdpReceivedPacket)1 EzyUdpReceivedPacket (com.tvd12.ezyfoxserver.socket.EzyUdpReceivedPacket)1 BaseTest (com.tvd12.test.base.BaseTest)1 InetSocketAddress (java.net.InetSocketAddress)1 ByteBuffer (java.nio.ByteBuffer)1 SelectionKey (java.nio.channels.SelectionKey)1 Selector (java.nio.channels.Selector)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1 AbstractSelector (java.nio.channels.spi.AbstractSelector)1