use of io.vertx.core.spi.observability.HttpRequest in project vert.x by eclipse.
the class HttpTracerTestBase method testHttpClientRequest.
private void testHttpClientRequest(RequestOptions request, String expectedOperation) throws Exception {
String key = TestUtils.randomAlphaString(10);
Object val = new Object();
AtomicInteger seq = new AtomicInteger();
tracer = new VertxTracer() {
@Override
public Object sendRequest(Context context, SpanKind kind, TracingPolicy policy, Object request, String operation, BiConsumer headers, TagExtractor tagExtractor) {
assertSame(val, context.getLocal(key));
assertTrue(seq.compareAndSet(0, 1));
headers.accept("header-key", "header-value");
assertNotNull(request);
assertTrue(request instanceof HttpRequest);
assertEquals(expectedOperation, operation);
return request;
}
@Override
public void receiveResponse(Context context, Object response, Object payload, Throwable failure, TagExtractor tagExtractor) {
assertSame(val, context.getLocal(key));
assertTrue(context.removeLocal(key));
assertNotNull(response);
assertTrue(response instanceof HttpResponse);
assertNull(failure);
assertTrue(seq.compareAndSet(1, 2));
}
};
CountDownLatch latch = new CountDownLatch(1);
server.requestHandler(req -> {
assertEquals("header-value", req.getHeader("header-key"));
req.response().end();
}).listen(8080, "localhost", onSuccess(v -> {
latch.countDown();
}));
awaitLatch(latch);
Context ctx = vertx.getOrCreateContext();
ctx.runOnContext(v1 -> {
ConcurrentMap<Object, Object> tracerMap = ((ContextInternal) ctx).localContextData();
tracerMap.put(key, val);
client.request(request, onSuccess(req -> {
req.send(onSuccess(resp -> {
resp.endHandler(v2 -> {
// Updates are done on the HTTP client context, so we need to run task on this context
// to avoid data race
ctx.runOnContext(v -> {
assertNull(tracerMap.get(key));
testComplete();
});
});
}));
}));
});
await();
}
Aggregations