use of com.tvd12.ezyfoxserver.nio.handler.EzyNioUdpDataHandler in project ezyfox-server by youngmonkeys.
the class EzyUdpServerBootstrap method newUdpDataHandler.
private EzyNioUdpDataHandler newUdpDataHandler() {
int handlerThreadPoolSize = getSocketHandlerPoolSize();
EzySimpleNioUdpDataHandler handler = new EzySimpleNioUdpDataHandler(handlerThreadPoolSize);
handler.setResponseApi(getResponseApi());
handler.setDatagramChannelPool(udpChannelPool);
handler.setSessionManager(getSessionManager());
handler.setSocketDataReceiver(socketDataReceiver);
handler.setHandlerGroupManager(handlerGroupManager);
return handler;
}
use of com.tvd12.ezyfoxserver.nio.handler.EzyNioUdpDataHandler in project ezyfox-server by youngmonkeys.
the class EzyNioUdpReaderTest method testAddressNull.
@Test
public void testAddressNull() throws Exception {
EzyNioUdpReader reader = new EzyNioUdpReader(1);
Selector selector = spy(Selector.class);
when(selector.select()).thenReturn(1);
reader.setOwnSelector(selector);
EzyNioUdpDataHandler dataHandler = mock(EzyNioUdpDataHandler.class);
reader.setUdpDataHandler(dataHandler);
SelectionKey selectionKey = spy(SelectionKey.class);
when(selector.selectedKeys()).thenReturn(Sets.newHashSet(selectionKey));
when(selectionKey.isValid()).thenReturn(true);
when(selectionKey.readyOps()).thenReturn(SelectionKey.OP_READ);
MyDatagramChannel channel = mock(MyDatagramChannel.class);
when(selectionKey.channel()).thenReturn(channel);
reader.handleEvent();
}
use of com.tvd12.ezyfoxserver.nio.handler.EzyNioUdpDataHandler in project ezyfox-server by youngmonkeys.
the class EzyNioUdpReaderTest method testCancelledKeyExceptionCase.
@Test
public void testCancelledKeyExceptionCase() throws Exception {
EzyNioUdpReader reader = new EzyNioUdpReader(1);
Selector selector = spy(Selector.class);
when(selector.select()).thenReturn(1);
reader.setOwnSelector(selector);
EzyNioUdpDataHandler dataHandler = mock(EzyNioUdpDataHandler.class);
reader.setUdpDataHandler(dataHandler);
SelectionKey selectionKey = spy(SelectionKey.class);
when(selector.selectedKeys()).thenReturn(Sets.newHashSet(selectionKey));
when(selectionKey.isValid()).thenReturn(true);
when(selectionKey.readyOps()).thenReturn(SelectionKey.OP_READ);
MyDatagramChannel channel = mock(MyDatagramChannel.class);
when(selectionKey.channel()).thenReturn(channel);
when(channel.receive(any(ByteBuffer.class))).thenThrow(new CancelledKeyException());
reader.handleEvent();
}
use of com.tvd12.ezyfoxserver.nio.handler.EzyNioUdpDataHandler in project ezyfox-server by youngmonkeys.
the class EzyNioUdpReaderTest method test.
@Test
public void test() throws Exception {
EzyNioUdpReader reader = new EzyNioUdpReader(1);
Selector selector = spy(Selector.class);
when(selector.select()).thenReturn(1);
reader.setOwnSelector(selector);
EzyNioUdpDataHandler dataHandler = mock(EzyNioUdpDataHandler.class);
reader.setUdpDataHandler(dataHandler);
SelectionKey selectionKey = spy(SelectionKey.class);
when(selector.selectedKeys()).thenReturn(Sets.newHashSet(selectionKey));
when(selectionKey.isValid()).thenReturn(true);
when(selectionKey.readyOps()).thenReturn(SelectionKey.OP_READ);
MyDatagramChannel channel = mock(MyDatagramChannel.class);
when(selectionKey.channel()).thenReturn(channel);
when(channel.receive(any(ByteBuffer.class))).thenAnswer((Answer<InetSocketAddress>) invocation -> {
ByteBuffer buffer = invocation.getArgumentAt(0, ByteBuffer.class);
buffer.put((byte) 0);
return new InetSocketAddress(12346);
});
reader.handleEvent();
}
use of com.tvd12.ezyfoxserver.nio.handler.EzyNioUdpDataHandler in project ezyfox-server by youngmonkeys.
the class EzyNioUdpReaderTest method testIOExceptionCase.
@Test
public void testIOExceptionCase() throws Exception {
EzyNioUdpReader reader = new EzyNioUdpReader(1);
Selector selector = spy(Selector.class);
when(selector.select()).thenReturn(1);
reader.setOwnSelector(selector);
EzyNioUdpDataHandler dataHandler = mock(EzyNioUdpDataHandler.class);
reader.setUdpDataHandler(dataHandler);
SelectionKey selectionKey = spy(SelectionKey.class);
when(selector.selectedKeys()).thenReturn(Sets.newHashSet(selectionKey));
when(selectionKey.isValid()).thenReturn(true);
when(selectionKey.readyOps()).thenReturn(SelectionKey.OP_READ);
MyDatagramChannel channel = mock(MyDatagramChannel.class);
when(selectionKey.channel()).thenReturn(channel);
when(channel.receive(any(ByteBuffer.class))).thenThrow(new IOException("test"));
reader.handleEvent();
}
Aggregations