Search in sources :

Example 66 with Request

use of org.asynchttpclient.Request in project druid by druid-io.

the class ParametrizedUriEmitterTest method testEmitterWithFeedUriExtractor.

@Test
public void testEmitterWithFeedUriExtractor() throws Exception {
    Emitter emitter = parametrizedEmmiter("http://example.com/{feed}");
    final List<UnitEvent> events = Arrays.asList(new UnitEvent("test", 1), new UnitEvent("test", 2));
    httpClient.setGoHandler(new GoHandler() {

        @Override
        public ListenableFuture<Response> go(Request request) throws JsonProcessingException {
            Assert.assertEquals("http://example.com/test", request.getUrl());
            Assert.assertEquals(StringUtils.format("[%s,%s]\n", JSON_MAPPER.writeValueAsString(events.get(0)), JSON_MAPPER.writeValueAsString(events.get(1))), StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString());
            return GoHandlers.immediateFuture(EmitterTest.okResponse());
        }
    }.times(1));
    for (UnitEvent event : events) {
        emitter.emit(event);
    }
    emitter.flush();
    Assert.assertTrue(httpClient.succeeded());
}
Also used : Response(org.asynchttpclient.Response) UnitEvent(org.apache.druid.java.util.emitter.service.UnitEvent) Request(org.asynchttpclient.Request) Test(org.junit.Test)

Example 67 with Request

use of org.asynchttpclient.Request in project druid by druid-io.

the class ParametrizedUriEmitterTest method testEmitterWithParametrizedUriExtractor.

@Test
public void testEmitterWithParametrizedUriExtractor() throws Exception {
    Emitter emitter = parametrizedEmmiter("http://example.com/{key1}/{key2}");
    final List<UnitEvent> events = Arrays.asList(new UnitEvent("test", 1, ImmutableMap.of("key1", "val1", "key2", "val2")), new UnitEvent("test", 2, ImmutableMap.of("key1", "val1", "key2", "val2")));
    httpClient.setGoHandler(new GoHandler() {

        @Override
        protected ListenableFuture<Response> go(Request request) throws JsonProcessingException {
            Assert.assertEquals("http://example.com/val1/val2", request.getUrl());
            Assert.assertEquals(StringUtils.format("[%s,%s]\n", JSON_MAPPER.writeValueAsString(events.get(0)), JSON_MAPPER.writeValueAsString(events.get(1))), StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString());
            return GoHandlers.immediateFuture(EmitterTest.okResponse());
        }
    }.times(1));
    for (UnitEvent event : events) {
        emitter.emit(event);
    }
    emitter.flush();
    Assert.assertTrue(httpClient.succeeded());
}
Also used : Response(org.asynchttpclient.Response) UnitEvent(org.apache.druid.java.util.emitter.service.UnitEvent) Request(org.asynchttpclient.Request) Test(org.junit.Test)

Aggregations

Request (org.asynchttpclient.Request)67 Test (org.testng.annotations.Test)32 Response (org.asynchttpclient.Response)31 AsyncHttpClient (org.asynchttpclient.AsyncHttpClient)18 RequestBuilder (org.asynchttpclient.RequestBuilder)17 Test (org.junit.Test)16 UnitEvent (org.apache.druid.java.util.emitter.service.UnitEvent)10 HttpRequest (io.netty.handler.codec.http.HttpRequest)8 AbstractBasicTest (org.asynchttpclient.AbstractBasicTest)8 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)7 DefaultAsyncHttpClientConfig (org.asynchttpclient.DefaultAsyncHttpClientConfig)6 ListenableFuture (org.asynchttpclient.ListenableFuture)6 Uri (org.asynchttpclient.uri.Uri)5 Realm (org.asynchttpclient.Realm)4 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)3 HttpResponse (io.netty.handler.codec.http.HttpResponse)3 HashMap (java.util.HashMap)3 ExecutionException (java.util.concurrent.ExecutionException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3