Search in sources :

Example 6 with SimpleTestHttpClient

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

the class TestRelayCommandsLocal method doTestSources2Command.

private void doTestSources2Command() throws Exception {
    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) List(java.util.List) IdNamePair(com.linkedin.databus.core.util.IdNamePair) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) HashSet(java.util.HashSet)

Example 7 with SimpleTestHttpClient

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

the class TestRelayCommandsLocal method prepareTestOneDataStreamCommand.

private void prepareTestOneDataStreamCommand() throws Exception {
    //generate an event
    HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/genDataEvents/start?src_ids=100&fromScn=10&eventsPerSec=1&duration=10");
    SimpleTestHttpClient httpClient = SimpleTestHttpClient.createLocal(TimeoutPolicy.ALL_TIMEOUTS);
    SimpleHttpResponseHandler respHandler = httpClient.sendRequest(_serverAddress, httpRequest);
    assertTrue("failed to get a response", respHandler.awaitResponseUninterruptedly(1, TimeUnit.SECONDS));
    String respString = new String(respHandler.getReceivedBytes());
    LOG.debug("Response string:" + respString);
    ByteArrayInputStream in = new ByteArrayInputStream(respHandler.getReceivedBytes());
    ObjectMapper objMapper = new ObjectMapper();
    Map<String, String> genRes = objMapper.readValue(in, new TypeReference<Map<String, String>>() {
    });
    HttpResponse respObj = respHandler.getResponse();
    assertNull("/genDataEvents returned unexpected error", respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
    assertEquals("event-generation failed to start", "true", genRes.get("genDataEventsStarted"));
    try {
        Thread.sleep(2000);
    } catch (InterruptedException ie) {
    }
}
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) 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 8 with SimpleTestHttpClient

use of com.linkedin.databus.core.test.netty.SimpleTestHttpClient 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 9 with SimpleTestHttpClient

use of com.linkedin.databus.core.test.netty.SimpleTestHttpClient 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 10 with SimpleTestHttpClient

use of com.linkedin.databus.core.test.netty.SimpleTestHttpClient 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)

Aggregations

SimpleHttpResponseHandler (com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler)12 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 InvalidRequestParamValueException (com.linkedin.databus2.core.container.request.InvalidRequestParamValueException)1 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)1 TypeReference (org.codehaus.jackson.type.TypeReference)1