Search in sources :

Example 61 with Request

use of org.asynchttpclient.Request in project pinpoint by naver.

the class ExecuteInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        // Do not log result
        logger.afterInterceptor(target, args);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    final Request httpRequest = getHttpRequest(args);
    if (httpRequest == null) {
        return;
    }
    try {
        final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        // Accessing httpRequest here not BEFORE() because it can cause side effect.
        this.clientRequestRecorder.record(recorder, httpRequest, throwable);
        this.cookieRecorder.record(recorder, httpRequest, throwable);
        this.entityRecorder.record(recorder, httpRequest, throwable);
        recorder.recordApi(descriptor);
        recorder.recordException(throwable);
    } finally {
        trace.traceBlockEnd();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) Request(org.asynchttpclient.Request)

Example 62 with Request

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

the class HttpPostEmitterStressTest method testLargeEventsQueueLimit.

@Test
public void testLargeEventsQueueLimit() throws IOException {
    HttpEmitterConfig config = new HttpEmitterConfig.Builder("http://foo.bar").setFlushMillis(100).setFlushCount(4).setBatchingStrategy(BatchingStrategy.ONLY_EVENTS).setMaxBatchSize(1024 * 1024).setBatchQueueSizeLimit(10).build();
    final HttpPostEmitter emitter = new HttpPostEmitter(config, httpClient, new ObjectMapper());
    emitter.start();
    httpClient.setGoHandler(new GoHandler() {

        @Override
        protected <X extends Exception> ListenableFuture<Response> go(Request request) throws X {
            return GoHandlers.immediateFuture(EmitterTest.BAD_RESPONSE);
        }
    });
    char[] chars = new char[600000];
    Arrays.fill(chars, '*');
    String bigString = new String(chars);
    Event bigEvent = ServiceMetricEvent.builder().setFeed("bigEvents").setDimension("test", bigString).build("metric", 10).build("qwerty", "asdfgh");
    for (int i = 0; i < 1000; i++) {
        emitter.emit(bigEvent);
        Assert.assertTrue(emitter.getLargeEventsToEmit() <= 11);
    }
    emitter.flush();
}
Also used : Request(org.asynchttpclient.Request) ListenableFuture(org.asynchttpclient.ListenableFuture) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 63 with Request

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

the class EmitterTest method testTimeBasedEmission.

@Test
public void testTimeBasedEmission() throws Exception {
    final int timeBetweenEmissions = 100;
    emitter = timeBasedEmitter(timeBetweenEmissions);
    final CountDownLatch latch = new CountDownLatch(1);
    httpClient.setGoHandler(new GoHandler() {

        @Override
        protected ListenableFuture<Response> go(Request request) {
            latch.countDown();
            return GoHandlers.immediateFuture(okResponse());
        }
    }.times(1));
    long emitTime = System.currentTimeMillis();
    emitter.emit(new UnitEvent("test", 1));
    latch.await();
    long timeWaited = System.currentTimeMillis() - emitTime;
    Assert.assertTrue(StringUtils.format("timeWaited[%s] !< %s", timeWaited, timeBetweenEmissions * 2), timeWaited < timeBetweenEmissions * 2);
    waitForEmission(emitter, 1);
    final CountDownLatch thisLatch = new CountDownLatch(1);
    httpClient.setGoHandler(new GoHandler() {

        @Override
        protected ListenableFuture<Response> go(Request request) {
            thisLatch.countDown();
            return GoHandlers.immediateFuture(okResponse());
        }
    }.times(1));
    emitTime = System.currentTimeMillis();
    emitter.emit(new UnitEvent("test", 2));
    thisLatch.await();
    timeWaited = System.currentTimeMillis() - emitTime;
    Assert.assertTrue(StringUtils.format("timeWaited[%s] !< %s", timeWaited, timeBetweenEmissions * 2), timeWaited < timeBetweenEmissions * 2);
    waitForEmission(emitter, 2);
    closeNoFlush(emitter);
    Assert.assertTrue("httpClient.succeeded()", httpClient.succeeded());
}
Also used : Response(org.asynchttpclient.Response) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) Request(org.asynchttpclient.Request) UnitEvent(org.apache.druid.java.util.emitter.service.UnitEvent) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 64 with Request

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

the class EmitterTest method testSanity.

@Test
public void testSanity() throws Exception {
    final List<UnitEvent> events = Arrays.asList(new UnitEvent("test", 1), new UnitEvent("test", 2));
    emitter = sizeBasedEmitter(2);
    httpClient.setGoHandler(new GoHandler() {

        @Override
        protected ListenableFuture<Response> go(Request request) throws JsonProcessingException {
            Assert.assertEquals(TARGET_URL, request.getUrl());
            Assert.assertEquals("application/json", request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE));
            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(okResponse());
        }
    }.times(1));
    for (UnitEvent event : events) {
        emitter.emit(event);
    }
    waitForEmission(emitter, 1);
    closeNoFlush(emitter);
    Assert.assertTrue(httpClient.succeeded());
}
Also used : Response(org.asynchttpclient.Response) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) UnitEvent(org.apache.druid.java.util.emitter.service.UnitEvent) Request(org.asynchttpclient.Request) Test(org.junit.Test)

Example 65 with Request

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

the class EmitterTest method testGzipContentEncoding.

@Test
public void testGzipContentEncoding() throws Exception {
    final List<UnitEvent> events = Arrays.asList(new UnitEvent("plain-text", 1), new UnitEvent("plain-text", 2));
    emitter = sizeBasedEmitterWithContentEncoding(2, ContentEncoding.GZIP);
    httpClient.setGoHandler(new GoHandler() {

        @Override
        protected ListenableFuture<Response> go(Request request) throws IOException {
            Assert.assertEquals(TARGET_URL, request.getUrl());
            Assert.assertEquals("application/json", request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE));
            Assert.assertEquals(HttpHeaders.Values.GZIP, request.getHeaders().get(HttpHeaders.Names.CONTENT_ENCODING));
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ByteBuffer data = request.getByteBufferData().slice();
            byte[] dataArray = new byte[data.remaining()];
            data.get(dataArray);
            CompressionUtils.gunzip(new ByteArrayInputStream(dataArray), baos);
            Assert.assertEquals(StringUtils.format("[%s,%s]\n", JSON_MAPPER.writeValueAsString(events.get(0)), JSON_MAPPER.writeValueAsString(events.get(1))), baos.toString(StandardCharsets.UTF_8.name()));
            return GoHandlers.immediateFuture(okResponse());
        }
    }.times(1));
    for (UnitEvent event : events) {
        emitter.emit(event);
    }
    waitForEmission(emitter, 1);
    closeNoFlush(emitter);
    Assert.assertTrue(httpClient.succeeded());
}
Also used : Response(org.asynchttpclient.Response) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) UnitEvent(org.apache.druid.java.util.emitter.service.UnitEvent) Request(org.asynchttpclient.Request) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuffer(java.nio.ByteBuffer) 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