Search in sources :

Example 81 with Channel

use of org.jboss.netty.channel.Channel in project opentsdb by OpenTSDB.

the class TestPutRpc method executeHBaseErrorHandler.

@SuppressWarnings("unchecked")
@Test
public void executeHBaseErrorHandler() throws Exception {
    when(tsdb.addPoint(anyString(), anyLong(), anyLong(), (HashMap<String, String>) any())).thenReturn(Deferred.fromError(new RuntimeException("Wotcher!")));
    final PutDataPointRpc put = new PutDataPointRpc();
    final Channel chan = NettyMocks.fakeChannel();
    assertNull(put.execute(tsdb, chan, new String[] { "put", "sys.cpu.nice", "1365465600", "42", "host=web01" }).joinUninterruptibly());
    assertEquals(1, requests.get());
    assertEquals(0, invalid_values.get());
    assertEquals(1, hbase_errors.get());
    verify(chan, times(1)).write(any());
    verify(chan, times(1)).isConnected();
    verify(tsdb, times(1)).getStorageExceptionHandler();
    verify(handler, times(1)).handleError((IncomingDataPoint) any(), (Exception) any());
}
Also used : Channel(org.jboss.netty.channel.Channel) Matchers.anyString(org.mockito.Matchers.anyString) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 82 with Channel

use of org.jboss.netty.channel.Channel in project opentsdb by OpenTSDB.

the class TestPutRpc method executeHBaseErrorNotWriteable.

@SuppressWarnings("unchecked")
@Test
public void executeHBaseErrorNotWriteable() throws Exception {
    when(tsdb.addPoint(anyString(), anyLong(), anyLong(), (HashMap<String, String>) any())).thenReturn(Deferred.fromError(new RuntimeException("Wotcher!")));
    final PutDataPointRpc put = new PutDataPointRpc();
    final Channel chan = NettyMocks.fakeChannel();
    when(chan.isWritable()).thenReturn(false);
    assertNull(put.execute(tsdb, chan, new String[] { "put", "sys.cpu.nice", "1365465600", "42", "host=web01" }).joinUninterruptibly());
    assertEquals(1, requests.get());
    assertEquals(0, invalid_values.get());
    assertEquals(1, hbase_errors.get());
    assertEquals(1, writes_blocked.get());
    verify(chan, never()).write(any());
    verify(chan, times(1)).isConnected();
    verify(tsdb, times(1)).getStorageExceptionHandler();
}
Also used : Channel(org.jboss.netty.channel.Channel) Matchers.anyString(org.mockito.Matchers.anyString) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 83 with Channel

use of org.jboss.netty.channel.Channel in project opentsdb by OpenTSDB.

the class TestPutRpc method executeNullArray.

@Test(expected = NullPointerException.class)
public void executeNullArray() throws Exception {
    final PutDataPointRpc put = new PutDataPointRpc();
    final Channel chan = NettyMocks.fakeChannel();
    put.execute(tsdb, chan, null);
}
Also used : Channel(org.jboss.netty.channel.Channel) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 84 with Channel

use of org.jboss.netty.channel.Channel in project opentsdb by OpenTSDB.

the class TestRpcHandler method emptyPathIsBadRequest.

@Test
public void emptyPathIsBadRequest() throws Exception {
    final HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "");
    final Channel mockChan = handleHttpRpc(req, new Answer<ChannelFuture>() {

        public ChannelFuture answer(final InvocationOnMock args) throws Throwable {
            DefaultHttpResponse response = (DefaultHttpResponse) args.getArguments()[0];
            assertEquals(HttpResponseStatus.BAD_REQUEST, response.getStatus());
            return new SucceededChannelFuture((Channel) args.getMock());
        }
    });
    final RpcHandler rpc = new RpcHandler(tsdb, rpc_manager);
    Whitebox.invokeMethod(rpc, "handleHttpQuery", tsdb, mockChan, req);
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) ChannelFuture(org.jboss.netty.channel.ChannelFuture) SucceededChannelFuture(org.jboss.netty.channel.SucceededChannelFuture) SucceededChannelFuture(org.jboss.netty.channel.SucceededChannelFuture) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) Channel(org.jboss.netty.channel.Channel) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 85 with Channel

use of org.jboss.netty.channel.Channel in project opentsdb by OpenTSDB.

the class TestRpcHandler method createQueryInstanceEmptyRequestInvalid.

@Test(expected = BadRequestException.class)
public void createQueryInstanceEmptyRequestInvalid() throws Exception {
    final RpcHandler rpc = new RpcHandler(tsdb, rpc_manager);
    final Channel mockChan = NettyMocks.fakeChannel();
    final Method meth = Whitebox.getMethod(RpcHandler.class, "createQueryInstance", TSDB.class, HttpRequest.class, Channel.class);
    meth.invoke(rpc, tsdb, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, ""), mockChan);
}
Also used : DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) Channel(org.jboss.netty.channel.Channel) HttpMethod(org.jboss.netty.handler.codec.http.HttpMethod) Method(java.lang.reflect.Method) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Channel (org.jboss.netty.channel.Channel)187 InetSocketAddress (java.net.InetSocketAddress)57 Test (org.junit.Test)52 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)40 DefaultHttpRequest (org.jboss.netty.handler.codec.http.DefaultHttpRequest)37 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)34 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)34 SocketAddress (java.net.SocketAddress)33 ChannelFuture (org.jboss.netty.channel.ChannelFuture)33 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)30 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)27 Test (org.testng.annotations.Test)23 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)22 IOException (java.io.IOException)21 SimpleObjectCaptureHandler (com.linkedin.databus2.test.container.SimpleObjectCaptureHandler)19 Logger (org.apache.log4j.Logger)19 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)17 DefaultHttpChunk (org.jboss.netty.handler.codec.http.DefaultHttpChunk)16 HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)16 ArrayList (java.util.ArrayList)14