Search in sources :

Example 16 with ChannelHandlerContext

use of org.jboss.netty.channel.ChannelHandlerContext in project hadoop by apache.

the class TestShuffleHandler method testSendMapCount.

@Test(timeout = 4000)
public void testSendMapCount() throws Exception {
    final List<ShuffleHandler.ReduceMapFileCount> listenerList = new ArrayList<ShuffleHandler.ReduceMapFileCount>();
    final ChannelHandlerContext mockCtx = Mockito.mock(ChannelHandlerContext.class);
    final MessageEvent mockEvt = Mockito.mock(MessageEvent.class);
    final Channel mockCh = Mockito.mock(AbstractChannel.class);
    // Mock HttpRequest and ChannelFuture
    final HttpRequest mockHttpRequest = createMockHttpRequest();
    final ChannelFuture mockFuture = createMockChannelFuture(mockCh, listenerList);
    // Mock Netty Channel Context and Channel behavior
    Mockito.doReturn(mockCh).when(mockCtx).getChannel();
    Mockito.when(mockCtx.getChannel()).thenReturn(mockCh);
    Mockito.doReturn(mockFuture).when(mockCh).write(Mockito.any(Object.class));
    Mockito.when(mockCh.write(Object.class)).thenReturn(mockFuture);
    //Mock MessageEvent behavior
    Mockito.doReturn(mockCh).when(mockEvt).getChannel();
    Mockito.when(mockEvt.getChannel()).thenReturn(mockCh);
    Mockito.doReturn(mockHttpRequest).when(mockEvt).getMessage();
    final ShuffleHandler sh = new MockShuffleHandler();
    Configuration conf = new Configuration();
    sh.init(conf);
    sh.start();
    int maxOpenFiles = conf.getInt(ShuffleHandler.SHUFFLE_MAX_SESSION_OPEN_FILES, ShuffleHandler.DEFAULT_SHUFFLE_MAX_SESSION_OPEN_FILES);
    sh.getShuffle(conf).messageReceived(mockCtx, mockEvt);
    assertTrue("Number of Open files should not exceed the configured " + "value!-Not Expected", listenerList.size() <= maxOpenFiles);
    while (!listenerList.isEmpty()) {
        listenerList.remove(0).operationComplete(mockFuture);
        assertTrue("Number of Open files should not exceed the configured " + "value!-Not Expected", listenerList.size() <= maxOpenFiles);
    }
    sh.close();
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) ChannelFuture(org.jboss.netty.channel.ChannelFuture) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) MessageEvent(org.jboss.netty.channel.MessageEvent) SocketChannel(org.jboss.netty.channel.socket.SocketChannel) Channel(org.jboss.netty.channel.Channel) AbstractChannel(org.jboss.netty.channel.AbstractChannel) ArrayList(java.util.ArrayList) ChannelHandlerContext(org.jboss.netty.channel.ChannelHandlerContext) Test(org.junit.Test)

Aggregations

ChannelHandlerContext (org.jboss.netty.channel.ChannelHandlerContext)16 Test (org.junit.Test)8 Channel (org.jboss.netty.channel.Channel)7 ArrayList (java.util.ArrayList)6 Configuration (org.apache.hadoop.conf.Configuration)6 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)6 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)6 HttpURLConnection (java.net.HttpURLConnection)5 URL (java.net.URL)5 DataOutputBuffer (org.apache.hadoop.io.DataOutputBuffer)5 AbstractChannel (org.jboss.netty.channel.AbstractChannel)5 SocketChannel (org.jboss.netty.channel.socket.SocketChannel)5 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)5 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)5 DataInputStream (java.io.DataInputStream)4 List (java.util.List)4 Map (java.util.Map)4 ShuffleHeader (org.apache.hadoop.mapreduce.task.reduce.ShuffleHeader)4 EOFException (java.io.EOFException)3 MessageEvent (org.jboss.netty.channel.MessageEvent)3