|
@@ -83,18 +83,18 @@ public class EventHandlerTests extends ESTestCase {
|
|
|
}
|
|
|
|
|
|
public void testActiveNonServerAddsOP_CONNECTAndOP_READInterest() throws IOException {
|
|
|
- SocketChannelContext context = mock(SocketChannelContext.class);
|
|
|
- when(context.getSelectionKey()).thenReturn(new TestSelectionKey(0));
|
|
|
- handler.handleActive(context);
|
|
|
- assertEquals(SelectionKey.OP_READ | SelectionKey.OP_CONNECT, context.getSelectionKey().interestOps());
|
|
|
+ SocketChannelContext mockContext = mock(SocketChannelContext.class);
|
|
|
+ when(mockContext.getSelectionKey()).thenReturn(new TestSelectionKey(0));
|
|
|
+ handler.handleActive(mockContext);
|
|
|
+ assertEquals(SelectionKey.OP_READ | SelectionKey.OP_CONNECT, mockContext.getSelectionKey().interestOps());
|
|
|
}
|
|
|
|
|
|
public void testHandleServerActiveSetsOP_ACCEPTInterest() throws IOException {
|
|
|
- ServerChannelContext serverContext = mock(ServerChannelContext.class);
|
|
|
- when(serverContext.getSelectionKey()).thenReturn(new TestSelectionKey(0));
|
|
|
- handler.handleActive(serverContext);
|
|
|
+ ServerChannelContext mockServerContext = mock(ServerChannelContext.class);
|
|
|
+ when(mockServerContext.getSelectionKey()).thenReturn(new TestSelectionKey(0));
|
|
|
+ handler.handleActive(mockServerContext);
|
|
|
|
|
|
- assertEquals(SelectionKey.OP_ACCEPT, serverContext.getSelectionKey().interestOps());
|
|
|
+ assertEquals(SelectionKey.OP_ACCEPT, mockServerContext.getSelectionKey().interestOps());
|
|
|
}
|
|
|
|
|
|
public void testHandleAcceptAccept() throws IOException {
|
|
@@ -146,9 +146,9 @@ public class EventHandlerTests extends ESTestCase {
|
|
|
}
|
|
|
|
|
|
public void testHandleReadDelegatesToContext() throws IOException {
|
|
|
- SocketChannelContext context = mock(SocketChannelContext.class);
|
|
|
- handler.handleRead(context);
|
|
|
- verify(context).read();
|
|
|
+ SocketChannelContext mockContext = mock(SocketChannelContext.class);
|
|
|
+ handler.handleRead(mockContext);
|
|
|
+ verify(mockContext).read();
|
|
|
}
|
|
|
|
|
|
public void testReadExceptionCallsExceptionHandler() {
|
|
@@ -165,53 +165,53 @@ public class EventHandlerTests extends ESTestCase {
|
|
|
|
|
|
public void testPostHandlingCallWillCloseTheChannelIfReady() throws IOException {
|
|
|
NioSocketChannel channel = mock(NioSocketChannel.class);
|
|
|
- SocketChannelContext context = mock(SocketChannelContext.class);
|
|
|
+ SocketChannelContext mockContext = mock(SocketChannelContext.class);
|
|
|
|
|
|
- when(channel.getContext()).thenReturn(context);
|
|
|
- when(context.selectorShouldClose()).thenReturn(true);
|
|
|
- handler.postHandling(context);
|
|
|
+ when(channel.getContext()).thenReturn(mockContext);
|
|
|
+ when(mockContext.selectorShouldClose()).thenReturn(true);
|
|
|
+ handler.postHandling(mockContext);
|
|
|
|
|
|
- verify(context).closeFromSelector();
|
|
|
+ verify(mockContext).closeFromSelector();
|
|
|
}
|
|
|
|
|
|
public void testPostHandlingCallWillNotCloseTheChannelIfNotReady() throws IOException {
|
|
|
- SocketChannelContext context = mock(SocketChannelContext.class);
|
|
|
- when(context.getSelectionKey()).thenReturn(new TestSelectionKey(SelectionKey.OP_READ | SelectionKey.OP_WRITE));
|
|
|
- when(context.selectorShouldClose()).thenReturn(false);
|
|
|
+ SocketChannelContext mockContext = mock(SocketChannelContext.class);
|
|
|
+ when(mockContext.getSelectionKey()).thenReturn(new TestSelectionKey(SelectionKey.OP_READ | SelectionKey.OP_WRITE));
|
|
|
+ when(mockContext.selectorShouldClose()).thenReturn(false);
|
|
|
|
|
|
NioSocketChannel channel = mock(NioSocketChannel.class);
|
|
|
- when(channel.getContext()).thenReturn(context);
|
|
|
+ when(channel.getContext()).thenReturn(mockContext);
|
|
|
|
|
|
- handler.postHandling(context);
|
|
|
+ handler.postHandling(mockContext);
|
|
|
|
|
|
- verify(context, times(0)).closeFromSelector();
|
|
|
+ verify(mockContext, times(0)).closeFromSelector();
|
|
|
}
|
|
|
|
|
|
public void testPostHandlingWillAddWriteIfNecessary() throws IOException {
|
|
|
TestSelectionKey selectionKey = new TestSelectionKey(SelectionKey.OP_READ);
|
|
|
- SocketChannelContext context = mock(SocketChannelContext.class);
|
|
|
- when(context.getSelectionKey()).thenReturn(selectionKey);
|
|
|
- when(context.readyForFlush()).thenReturn(true);
|
|
|
+ SocketChannelContext mockContext = mock(SocketChannelContext.class);
|
|
|
+ when(mockContext.getSelectionKey()).thenReturn(selectionKey);
|
|
|
+ when(mockContext.readyForFlush()).thenReturn(true);
|
|
|
|
|
|
NioSocketChannel channel = mock(NioSocketChannel.class);
|
|
|
- when(channel.getContext()).thenReturn(context);
|
|
|
+ when(channel.getContext()).thenReturn(mockContext);
|
|
|
|
|
|
assertEquals(SelectionKey.OP_READ, selectionKey.interestOps());
|
|
|
- handler.postHandling(context);
|
|
|
+ handler.postHandling(mockContext);
|
|
|
assertEquals(SelectionKey.OP_READ | SelectionKey.OP_WRITE, selectionKey.interestOps());
|
|
|
}
|
|
|
|
|
|
public void testPostHandlingWillRemoveWriteIfNecessary() throws IOException {
|
|
|
TestSelectionKey key = new TestSelectionKey(SelectionKey.OP_READ | SelectionKey.OP_WRITE);
|
|
|
- SocketChannelContext context = mock(SocketChannelContext.class);
|
|
|
- when(context.getSelectionKey()).thenReturn(key);
|
|
|
- when(context.readyForFlush()).thenReturn(false);
|
|
|
+ SocketChannelContext mockContext = mock(SocketChannelContext.class);
|
|
|
+ when(mockContext.getSelectionKey()).thenReturn(key);
|
|
|
+ when(mockContext.readyForFlush()).thenReturn(false);
|
|
|
|
|
|
NioSocketChannel channel = mock(NioSocketChannel.class);
|
|
|
- when(channel.getContext()).thenReturn(context);
|
|
|
+ when(channel.getContext()).thenReturn(mockContext);
|
|
|
|
|
|
assertEquals(SelectionKey.OP_READ | SelectionKey.OP_WRITE, key.interestOps());
|
|
|
- handler.postHandling(context);
|
|
|
+ handler.postHandling(mockContext);
|
|
|
assertEquals(SelectionKey.OP_READ, key.interestOps());
|
|
|
}
|
|
|
|