use of com.tvd12.ezyfoxserver.nio.handler.EzyNioUdpDataHandler in project ezyfox-server by youngmonkeys.
the class EzyNioUdpReaderTest method testClosedSelectorExceptionCase.
@Test
public void testClosedSelectorExceptionCase() 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 ClosedSelectorException());
reader.handleEvent();
}
use of com.tvd12.ezyfoxserver.nio.handler.EzyNioUdpDataHandler in project ezyfox-server by youngmonkeys.
the class EzyNioUdpReaderTest method testExceptionCase.
@Test
public void testExceptionCase() 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 IllegalStateException("test"));
reader.handleEvent();
}
Aggregations