Search in sources :

Example 1 with SimpleHttpResponseHandler

use of com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler in project databus by linkedin.

the class DummyHttpRequestHandler method setupClient.

private void setupClient() {
    _clientBootstrap = new ClientBootstrap(new DefaultLocalClientChannelFactory());
    _clientBootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline clientPipeline = pipeline();
            clientPipeline.addLast("client logger 1", new LoggingHandler("client logger 1", InternalLogLevel.DEBUG, true));
            clientPipeline.addLast("codec", new HttpClientCodec());
            clientPipeline.addLast("aggregator", new FooterAwareHttpChunkAggregator(1000000));
            _responseHandler = new SimpleHttpResponseHandler();
            clientPipeline.addLast("handler", _responseHandler);
            clientPipeline.addLast("client logger 5", new LoggingHandler("client logger 5", InternalLogLevel.DEBUG, true));
            return clientPipeline;
        }
    });
}
Also used : LoggingHandler(org.jboss.netty.handler.logging.LoggingHandler) SimpleHttpResponseHandler(com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) FooterAwareHttpChunkAggregator(com.linkedin.databus.core.test.netty.FooterAwareHttpChunkAggregator) DefaultLocalClientChannelFactory(org.jboss.netty.channel.local.DefaultLocalClientChannelFactory) HttpClientCodec(org.jboss.netty.handler.codec.http.HttpClientCodec) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 2 with SimpleHttpResponseHandler

use of com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler in project databus by linkedin.

the class TestRelayCommandsLocal method testNoDataStreamCommand.

@Test
public void testNoDataStreamCommand() throws Exception {
    LOG.debug("\n\nstarting testNoDataStreamCommand()\n");
    HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/stream?sources=100&size=1000&output=json&checkPoint={\"windowScn\":-1,\"windowOffset\":-1}");
    SimpleTestHttpClient httpClient = SimpleTestHttpClient.createLocal(TimeoutPolicy.ALL_TIMEOUTS);
    SimpleHttpResponseHandler respHandler = httpClient.sendRequest(_serverAddress, httpRequest);
    assertTrue("failed to get a response", respHandler.awaitResponseUninterruptedly(1, TimeUnit.SECONDS));
    assertEquals("expected to get empty response", 0, respHandler.getReceivedBytes().length);
    HttpResponse respObj = respHandler.getResponse();
    assertNull("/stream returned unexpected error", respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
    assertNull("/stream returned unexpected error with cause", respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CAUSE_CLASS_HEADER));
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) SimpleHttpResponseHandler(com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) SimpleTestHttpClient(com.linkedin.databus.core.test.netty.SimpleTestHttpClient) Test(org.testng.annotations.Test)

Example 3 with SimpleHttpResponseHandler

use of com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler in project databus by linkedin.

the class TestRelayCommandsLocal method testSourcesTrackingCommand.

@Test
public void testSourcesTrackingCommand() throws Exception {
    LOG.debug("\n\nstarting testSourcesTrackingCommand()\n");
    HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/sources");
    httpRequest.setHeader(DatabusHttpHeaders.DBUS_CLIENT_HOST_HDR, "localhost");
    httpRequest.setHeader(DatabusHttpHeaders.DBUS_CLIENT_SERVICE_HDR, "unittestclient");
    SimpleTestHttpClient httpClient = SimpleTestHttpClient.createLocal(TimeoutPolicy.ALL_TIMEOUTS);
    SimpleHttpResponseHandler respHandler = httpClient.sendRequest(_serverAddress, httpRequest);
    assertTrue("failed to get a response", respHandler.awaitResponseUninterruptedly(1, TimeUnit.SECONDS));
    ByteArrayInputStream in = new ByteArrayInputStream(respHandler.getReceivedBytes());
    ObjectMapper objMapper = new ObjectMapper();
    List<IdNamePair> res = objMapper.readValue(in, new TypeReference<List<IdNamePair>>() {
    });
    assertNotNull("no result", res);
    if (LOG.isDebugEnabled()) {
        LOG.debug("/sources response:" + new String(respHandler.getReceivedBytes()));
    }
    HashSet<IdNamePair> origSet = new HashSet<IdNamePair>(_staticConfig.getSourceIds());
    HashSet<IdNamePair> resSet = new HashSet<IdNamePair>(res);
    Assert.assertEquals(origSet, resSet);
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) SimpleHttpResponseHandler(com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) SimpleTestHttpClient(com.linkedin.databus.core.test.netty.SimpleTestHttpClient) IdNamePair(com.linkedin.databus.core.util.IdNamePair) List(java.util.List) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 4 with SimpleHttpResponseHandler

use of com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler in project databus by linkedin.

the class TestRelayCommandsLocal method doTestOneDataStreamCommand.

private void doTestOneDataStreamCommand() throws Exception {
    // try to read it
    Checkpoint cp = Checkpoint.createFlexibleCheckpoint();
    String streamRequest = "/stream?sources=100&size=100000&output=json&checkPoint=" + cp.toString();
    HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, streamRequest);
    SimpleTestHttpClient httpClient = SimpleTestHttpClient.createLocal(TimeoutPolicy.ALL_TIMEOUTS);
    SimpleHttpResponseHandler respHandler = httpClient.sendRequest(_serverAddress, httpRequest);
    assertTrue("failed to get a response", respHandler.awaitResponseUninterruptedly(1, TimeUnit.SECONDS));
    HttpResponse respObj = respHandler.getResponse();
    assertNull("/stream returned unexpected error", respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
    if (LOG.isDebugEnabled()) {
        LOG.debug("/stream response:" + new String(respHandler.getReceivedBytes()));
    }
    ObjectMapper objMapper = new ObjectMapper();
    ByteArrayInputStream in = new ByteArrayInputStream(respHandler.getReceivedBytes());
    objMapper.readValue(in, new TypeReference<Map<String, String>>() {
    });
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) Checkpoint(com.linkedin.databus.core.Checkpoint) SimpleHttpResponseHandler(com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) SimpleTestHttpClient(com.linkedin.databus.core.test.netty.SimpleTestHttpClient) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 5 with SimpleHttpResponseHandler

use of com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler in project databus by linkedin.

the class TestRelayCommandsLocal method testSources1Command.

@Test
public void testSources1Command() throws Exception {
    LOG.debug("\n\nstarting testSources1Command()\n");
    HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/sources");
    SimpleTestHttpClient httpClient = SimpleTestHttpClient.createLocal(TimeoutPolicy.ALL_TIMEOUTS);
    SimpleHttpResponseHandler respHandler = httpClient.sendRequest(_serverAddress, httpRequest);
    assertTrue("failed to get a response", respHandler.awaitResponseUninterruptedly(1, TimeUnit.SECONDS));
    ByteArrayInputStream in = new ByteArrayInputStream(respHandler.getReceivedBytes());
    ObjectMapper objMapper = new ObjectMapper();
    List<IdNamePair> res = objMapper.readValue(in, new TypeReference<List<IdNamePair>>() {
    });
    assertNotNull("no result", res);
    if (LOG.isDebugEnabled()) {
        LOG.debug("/sources response:" + new String(respHandler.getReceivedBytes()));
    }
    HashSet<IdNamePair> origSet = new HashSet<IdNamePair>(_staticConfig.getSourceIds());
    HashSet<IdNamePair> resSet = new HashSet<IdNamePair>(res);
    Assert.assertEquals(origSet, resSet);
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) SimpleHttpResponseHandler(com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) SimpleTestHttpClient(com.linkedin.databus.core.test.netty.SimpleTestHttpClient) IdNamePair(com.linkedin.databus.core.util.IdNamePair) List(java.util.List) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

SimpleHttpResponseHandler (com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler)13 SimpleTestHttpClient (com.linkedin.databus.core.test.netty.SimpleTestHttpClient)12 DefaultHttpRequest (org.jboss.netty.handler.codec.http.DefaultHttpRequest)12 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)12 ByteArrayInputStream (java.io.ByteArrayInputStream)10 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)10 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)7 Test (org.testng.annotations.Test)7 List (java.util.List)6 RegisterResponseEntry (com.linkedin.databus2.core.container.request.RegisterResponseEntry)4 VersionedSchema (com.linkedin.databus2.schemas.VersionedSchema)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 Schema (org.apache.avro.Schema)4 IdNamePair (com.linkedin.databus.core.util.IdNamePair)3 HashSet (java.util.HashSet)3 Checkpoint (com.linkedin.databus.core.Checkpoint)2 FooterAwareHttpChunkAggregator (com.linkedin.databus.core.test.netty.FooterAwareHttpChunkAggregator)1 InvalidRequestParamValueException (com.linkedin.databus2.core.container.request.InvalidRequestParamValueException)1 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)1