Search in sources :

Example 71 with DefaultHttpRequest

use of org.jboss.netty.handler.codec.http.DefaultHttpRequest in project databus by linkedin.

the class TestRelayCommandsLocal method testRegisterCommandOneSource.

@Test
public void testRegisterCommandOneSource() throws Exception {
    LOG.debug("\n\nstarting testRegisterCommandOneSource()\n");
    // /register?sources=2
    HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/register?sources=3002");
    SimpleTestHttpClient httpClient = SimpleTestHttpClient.createLocal(TimeoutPolicy.ALL_TIMEOUTS);
    SimpleHttpResponseHandler respHandler = httpClient.sendRequest(_serverAddress, httpRequest);
    assertTrue("failed to get a response", respHandler.awaitResponseUninterruptedly(1, TimeUnit.SECONDS));
    byte[] respBytes = respHandler.getReceivedBytes();
    if (LOG.isDebugEnabled()) {
        LOG.debug("/register response:" + new String(respBytes));
    }
    ByteArrayInputStream in = new ByteArrayInputStream(respBytes);
    ObjectMapper objMapper = new ObjectMapper();
    List<RegisterResponseEntry> res = objMapper.readValue(in, new TypeReference<List<RegisterResponseEntry>>() {
    });
    assertNotNull("no result", res);
    assertEquals("expected one source", 1, res.size());
    assertEquals("expected correct source id", 3002, res.get(0).getId());
    Schema resSchema = Schema.parse(res.get(0).getSchema());
    assertEquals("expected correct source schema", "test3.source2_v1", resSchema.getFullName());
}
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) Schema(org.apache.avro.Schema) VersionedSchema(com.linkedin.databus2.schemas.VersionedSchema) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) RegisterResponseEntry(com.linkedin.databus2.core.container.request.RegisterResponseEntry) SimpleTestHttpClient(com.linkedin.databus.core.test.netty.SimpleTestHttpClient) List(java.util.List) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.testng.annotations.Test)

Example 72 with DefaultHttpRequest

use of org.jboss.netty.handler.codec.http.DefaultHttpRequest in project databus by linkedin.

the class TestRelayCommandsLocal method doTestRegisterCommandTwoSources.

private void doTestRegisterCommandTwoSources() throws Exception {
    ObjectMapper objMapper = new ObjectMapper();
    // /register?sources=1,2
    SimpleTestHttpClient httpClient = SimpleTestHttpClient.createLocal(TimeoutPolicy.ALL_TIMEOUTS);
    HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/register?sources=4001,4002");
    SimpleHttpResponseHandler respHandler = httpClient.sendRequest(_serverAddress, httpRequest);
    assertTrue("failed to get a response", respHandler.awaitResponseUninterruptedly(1, TimeUnit.SECONDS));
    ByteArrayInputStream in = new ByteArrayInputStream(respHandler.getReceivedBytes());
    List<RegisterResponseEntry> res = objMapper.readValue(in, new TypeReference<List<RegisterResponseEntry>>() {
    });
    assertNotNull("no result", res);
    if (LOG.isDebugEnabled()) {
        LOG.debug("/register response:" + new String(respHandler.getReceivedBytes()));
    }
    assertEquals("expected two sources", 2, res.size());
    assertEquals("expected correct source id", 4001, res.get(0).getId());
    Schema resSchema = Schema.parse(res.get(0).getSchema());
    assertEquals("expected correct source schema", "test4.source1_v1", resSchema.getFullName());
    assertEquals("expected correct source id", 4002, res.get(1).getId());
    resSchema = Schema.parse(res.get(1).getSchema());
    assertEquals("expected correct source schema", "test4.source2_v1", resSchema.getFullName());
}
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) Schema(org.apache.avro.Schema) VersionedSchema(com.linkedin.databus2.schemas.VersionedSchema) RegisterResponseEntry(com.linkedin.databus2.core.container.request.RegisterResponseEntry) SimpleTestHttpClient(com.linkedin.databus.core.test.netty.SimpleTestHttpClient) List(java.util.List) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 73 with DefaultHttpRequest

use of org.jboss.netty.handler.codec.http.DefaultHttpRequest in project databus by linkedin.

the class TestRelayCommandsLocal method testRegisterCommandThreeSources.

@Test
public void testRegisterCommandThreeSources() throws Exception {
    LOG.debug("\n\nstarting testRegisterCommandThreeSources()\n");
    // /register?sources=1,2,3
    SimpleTestHttpClient httpClient = SimpleTestHttpClient.createLocal(TimeoutPolicy.ALL_TIMEOUTS);
    HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/register?sources=5001,5002,5003");
    SimpleHttpResponseHandler respHandler = httpClient.sendRequest(_serverAddress, httpRequest);
    assertTrue("failed to get a response", respHandler.awaitResponseUninterruptedly(1, TimeUnit.SECONDS));
    if (LOG.isDebugEnabled()) {
        LOG.debug("/register response:" + new String(respHandler.getReceivedBytes()));
    }
    HttpResponse respObj = respHandler.getResponse();
    // Note that v3 client code doesn't currently (May 2013) support "sources" param for "/register".
    assertNotNull("exception class header not present", respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
    assertEquals("exception class name mismatch", InvalidRequestParamValueException.class.getName(), respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_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) InvalidRequestParamValueException(com.linkedin.databus2.core.container.request.InvalidRequestParamValueException) Test(org.testng.annotations.Test)

Example 74 with DefaultHttpRequest

use of org.jboss.netty.handler.codec.http.DefaultHttpRequest in project databus by linkedin.

the class TestRelayCommandsLocal method testRegisterV4CommandHappyPath.

@Test
public void testRegisterV4CommandHappyPath() throws Exception {
    LOG.debug("\n\nstarting testRegisterV4CommandHappyPath()\n");
    // /register?protocolVersion=4
    HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/register?sources=4002&" + DatabusHttpHeaders.PROTOCOL_VERSION_PARAM + "=4");
    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("/register v4 returned unexpected error: " + respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER), respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
    String registerResponseProtocolVersionStr = respObj.getHeader(DatabusHttpHeaders.DBUS_CLIENT_RELAY_PROTOCOL_VERSION_HDR);
    assertNotNull("/register protocol-version response header not present", registerResponseProtocolVersionStr);
    assertEquals("client-relay protocol response version mismatch", "4", registerResponseProtocolVersionStr);
    byte[] respBytes = respHandler.getReceivedBytes();
    if (LOG.isDebugEnabled()) {
        LOG.debug("/register response: " + new String(respBytes));
    }
    ByteArrayInputStream in = new ByteArrayInputStream(respBytes);
    ObjectMapper objMapper = new ObjectMapper();
    Map<String, List<Object>> resMap = objMapper.readValue(in, new TypeReference<Map<String, List<Object>>>() {
    });
    assertNotNull("no result", resMap);
    List<Object> sourceSchemasObjectsList = resMap.get(RegisterResponseEntry.SOURCE_SCHEMAS_KEY);
    assertNotNull("missing required sourceSchemas key in response", sourceSchemasObjectsList);
    assertEquals("expected one source schema", 1, sourceSchemasObjectsList.size());
    // ObjectMapper encodes plain Object as LinkedHashMap with (apparently) String keys and
    // either String or Integer values (currently).  We must construct RegisterResponseEntry
    // manually.
    assertTrue("sourceSchemas deserialization error: 'Object' type = " + sourceSchemasObjectsList.get(0).getClass().getName() + ", not LinkedHashMap", sourceSchemasObjectsList.get(0) instanceof LinkedHashMap);
    // just obj
    @SuppressWarnings("unchecked") LinkedHashMap<String, Object> obj = (LinkedHashMap<String, Object>) sourceSchemasObjectsList.get(0);
    assertTrue("sourceSchemas deserialization error: missing \"id\" key", obj.containsKey("id"));
    assertTrue("sourceSchemas deserialization error: missing \"version\" key", obj.containsKey("version"));
    assertTrue("sourceSchemas deserialization error: missing \"schema\" key", obj.containsKey("schema"));
    assertTrue("obj.get(\"id\") type = " + obj.get("id").getClass().getName() + ", not Integer", obj.get("id") instanceof Integer);
    assertTrue("obj.get(\"version\") type = " + obj.get("version").getClass().getName() + ", not Integer", obj.get("version") instanceof Integer);
    RegisterResponseEntry rre = new RegisterResponseEntry((Integer) obj.get("id"), ((Integer) obj.get("version")).shortValue(), (String) obj.get("schema"));
    assertEquals("unexpected source id", 4002, rre.getId());
    Schema resSchema = Schema.parse(rre.getSchema());
    assertEquals("unexpected source-schema name for source id 4002", "test4.source2_v1", resSchema.getFullName());
    // There's no guarantee of a metadataSchemas entry in general, but we pre-stuffed our
    // VersionedSchemaSetBackedRegistryService with one in the test's constructor, so we
    // expect the relay to hand it back to us.  Or else.
    /* disabled for now since simplistic relay implementation has been disabled; reenable/update/modify as part of DDSDBUS-2093/2096 (TODO)
    List<Object> metadataSchemasObjectsList = resMap.get(RegisterResponseMetadataEntry.METADATA_SCHEMAS_KEY);
    assertNotNull("missing expected metadataSchemas key in response", metadataSchemasObjectsList);
    assertEquals("expected one metadata schema", 1, metadataSchemasObjectsList.size());

    // As above, we must construct RegisterResponseMetadataEntry manually.
    assertTrue("metadataSchemas deserialization error: 'Object' type = " +
               metadataSchemasObjectsList.get(0).getClass().getName() + ", not LinkedHashMap",
               metadataSchemasObjectsList.get(0) instanceof LinkedHashMap);
    @SuppressWarnings("unchecked") // just obj2
    LinkedHashMap<String, Object> obj2 = (LinkedHashMap<String, Object>)metadataSchemasObjectsList.get(0);
    assertTrue("metadataSchemas deserialization error: missing \"version\" key", obj2.containsKey("version"));
    assertTrue("metadataSchemas deserialization error: missing \"schema\" key", obj2.containsKey("schema"));

    assertTrue("obj2.get(\"version\") type = " + obj2.get("version").getClass().getName() + ", not Integer",
               obj2.get("version") instanceof Integer);
    RegisterResponseMetadataEntry rrme = new RegisterResponseMetadataEntry(((Integer)obj2.get("version")).shortValue(),
                                                                          (String)obj2.get("schema"));
    assertEquals("unexpected metadata version", 1, rrme.getVersion());
    resSchema = Schema.parse(rrme.getSchema());
    assertEquals("unexpected metadata schema name", "test_namespace.metadata", resSchema.getFullName());
 */
    LOG.debug("\n\ndone with testRegisterV4CommandHappyPath()\n");
}
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) Schema(org.apache.avro.Schema) VersionedSchema(com.linkedin.databus2.schemas.VersionedSchema) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) LinkedHashMap(java.util.LinkedHashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) RegisterResponseEntry(com.linkedin.databus2.core.container.request.RegisterResponseEntry) SimpleTestHttpClient(com.linkedin.databus.core.test.netty.SimpleTestHttpClient) List(java.util.List) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.testng.annotations.Test)

Example 75 with DefaultHttpRequest

use of org.jboss.netty.handler.codec.http.DefaultHttpRequest in project databus by linkedin.

the class TestRelayCommandsLocal method doTestOneDataClientVerStreamCommand.

/** Validates the version checks in the stream calls. */
private void doTestOneDataClientVerStreamCommand(int ver, boolean expectFail) throws Exception {
    //try to read it
    Checkpoint cp = Checkpoint.createFlexibleCheckpoint();
    String maxev = "&" + DatabusHttpHeaders.MAX_EVENT_VERSION + "=" + ver;
    // protocol version 2 (versions >= 3 use "subs=")
    String streamRequest = "/stream?sources=100&size=100000&output=json&checkPoint=" + cp.toString() + maxev;
    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();
    if (expectFail) {
        assertNotNull("/stream failed to return expected error", respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
    } else {
        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)

Aggregations

DefaultHttpRequest (org.jboss.netty.handler.codec.http.DefaultHttpRequest)128 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)101 Test (org.junit.Test)53 Channel (org.jboss.netty.channel.Channel)37 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)33 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)25 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)24 Test (org.testng.annotations.Test)23 HttpMethod (org.jboss.netty.handler.codec.http.HttpMethod)21 ChannelFuture (org.jboss.netty.channel.ChannelFuture)19 SimpleHttpResponseHandler (com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler)12 SimpleTestHttpClient (com.linkedin.databus.core.test.netty.SimpleTestHttpClient)12 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)11 InetSocketAddress (java.net.InetSocketAddress)11 Logger (org.apache.log4j.Logger)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)10 SucceededChannelFuture (org.jboss.netty.channel.SucceededChannelFuture)10 InvocationOnMock (org.mockito.invocation.InvocationOnMock)10 SocketAddress (java.net.SocketAddress)9