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();
}
}
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();
}
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());
}
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());
}
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());
}
Aggregations