use of io.opentracing.Tracer in project hono by eclipse.
the class ProtonBasedDeviceRegistrationClientTest method setUp.
/**
* Sets up the fixture.
*/
@SuppressWarnings("unchecked")
@BeforeEach
public void setUp() {
span = TracingMockSupport.mockSpan();
final Tracer tracer = TracingMockSupport.mockTracer(span);
eventBus = mock(EventBus.class);
vertx = mock(Vertx.class);
when(vertx.eventBus()).thenReturn(eventBus);
VertxMockSupport.executeBlockingCodeImmediately(vertx);
receiver = AmqpClientUnitTestHelper.mockProtonReceiver();
sender = AmqpClientUnitTestHelper.mockProtonSender();
final RequestResponseClientConfigProperties config = new RequestResponseClientConfigProperties();
connection = AmqpClientUnitTestHelper.mockHonoConnection(vertx, config, tracer);
when(connection.connect()).thenReturn(Future.succeededFuture());
when(connection.isConnected(anyLong())).thenReturn(Future.succeededFuture());
when(connection.createReceiver(anyString(), any(ProtonQoS.class), any(ProtonMessageHandler.class), VertxMockSupport.anyHandler())).thenReturn(Future.succeededFuture(receiver));
when(connection.createSender(anyString(), any(ProtonQoS.class), VertxMockSupport.anyHandler())).thenReturn(Future.succeededFuture(sender));
cache = mock(Cache.class);
when(cache.asMap()).thenReturn(cacheBackingMap);
}
use of io.opentracing.Tracer in project hono by eclipse.
the class ProtonBasedCredentialsClientTest method setUp.
/**
* Sets up the fixture.
*/
@SuppressWarnings("unchecked")
@BeforeEach
public void setUp() {
span = TracingMockSupport.mockSpan();
final Tracer tracer = TracingMockSupport.mockTracer(span);
eventBus = mock(EventBus.class);
vertx = mock(Vertx.class);
when(vertx.eventBus()).thenReturn(eventBus);
VertxMockSupport.executeBlockingCodeImmediately(vertx);
receiver = AmqpClientUnitTestHelper.mockProtonReceiver();
sender = AmqpClientUnitTestHelper.mockProtonSender();
final RequestResponseClientConfigProperties config = new RequestResponseClientConfigProperties();
connection = AmqpClientUnitTestHelper.mockHonoConnection(vertx, config, tracer);
when(connection.connect()).thenReturn(Future.succeededFuture());
when(connection.isConnected(anyLong())).thenReturn(Future.succeededFuture());
when(connection.createReceiver(anyString(), any(ProtonQoS.class), any(ProtonMessageHandler.class), VertxMockSupport.anyHandler())).thenReturn(Future.succeededFuture(receiver));
when(connection.createSender(anyString(), any(ProtonQoS.class), VertxMockSupport.anyHandler())).thenReturn(Future.succeededFuture(sender));
cache = mock(Cache.class);
when(cache.asMap()).thenReturn(cacheBackingMap);
}
use of io.opentracing.Tracer in project hono by eclipse.
the class KafkaBasedMappingAndDelegatingCommandHandler method mapAndDelegateIncomingCommandMessage.
/**
* Delegates an incoming command to the protocol adapter instance that the target
* device is connected to.
* <p>
* Determines the target gateway (if applicable) and protocol adapter instance for an incoming command
* and delegates the command to the resulting protocol adapter instance.
*
* @param consumerRecord The consumer record corresponding to the command.
* @return A future indicating the outcome of the operation.
* @throws NullPointerException if any of the parameters is {@code null}.
*/
public Future<Void> mapAndDelegateIncomingCommandMessage(final KafkaConsumerRecord<String, Buffer> consumerRecord) {
Objects.requireNonNull(consumerRecord);
final Timer.Sample timer = getMetrics().startTimer();
final KafkaBasedCommand command;
try {
command = KafkaBasedCommand.from(consumerRecord);
} catch (final IllegalArgumentException exception) {
log.debug("command record is invalid", exception);
return Future.failedFuture("command record is invalid");
}
final SpanContext spanContext = KafkaTracingHelper.extractSpanContext(tracer, consumerRecord);
final Span currentSpan = createSpan(command.getTenant(), command.getDeviceId(), spanContext);
KafkaTracingHelper.setRecordTags(currentSpan, consumerRecord);
final KafkaBasedCommandContext commandContext = new KafkaBasedCommandContext(command, kafkaBasedCommandResponseSender, currentSpan);
command.logToSpan(currentSpan);
if (!command.isValid()) {
log.debug("received invalid command record [{}]", command);
return tenantClient.get(command.getTenant(), currentSpan.context()).compose(tenantConfig -> {
commandContext.put(CommandContext.KEY_TENANT_CONFIG, tenantConfig);
return Future.failedFuture("command is invalid");
}).onComplete(ar -> {
commandContext.reject("malformed command message");
reportInvalidCommand(commandContext, timer);
}).mapEmpty();
}
log.trace("received valid command record [{}]", command);
commandQueue.add(commandContext);
final Promise<Void> resultPromise = Promise.promise();
final long timerId = vertx.setTimer(PROCESSING_TIMEOUT.toMillis(), tid -> {
if (commandQueue.remove(commandContext) || !commandContext.isCompleted()) {
log.info("command processing timed out after {}s [{}]", PROCESSING_TIMEOUT.toSeconds(), commandContext.getCommand());
TracingHelper.logError(commandContext.getTracingSpan(), String.format("command processing timed out after %ds", PROCESSING_TIMEOUT.toSeconds()));
final ServerErrorException error = new ServerErrorException(HttpURLConnection.HTTP_UNAVAILABLE, "command processing timed out");
commandContext.release(error);
resultPromise.tryFail(error);
}
});
mapAndDelegateIncomingCommand(commandContext, timer).onComplete(ar -> {
vertx.cancelTimer(timerId);
if (ar.failed()) {
commandQueue.remove(commandContext);
}
Futures.tryHandleResult(resultPromise, ar);
});
return resultPromise.future();
}
use of io.opentracing.Tracer in project cxf by apache.
the class OpenTracingTracingTest method testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleClients.
@Test
public void testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleClients() throws Exception {
final WebClient client = createWebClient("/bookstore/books", new OpenTracingClientProvider(tracer));
// The intention is to make a calls one after another, not in parallel, to ensure the
// thread have trace contexts cleared out.
IntStream.range(0, 4).mapToObj(index -> client.get()).forEach(r -> assertEquals(Status.OK.getStatusCode(), r.getStatus()));
assertEquals(REPORTER.getSpans().toString(), 12, REPORTER.getSpans().size());
IntStream.range(0, 4).map(index -> index * 3).forEach(index -> {
assertThat(REPORTER.getSpans().get(index).getOperationName(), equalTo("Get Books"));
assertThat(REPORTER.getSpans().get(index + 1).getOperationName(), equalTo("GET /bookstore/books"));
assertThat(REPORTER.getSpans().get(index + 2).getOperationName(), equalTo("GET " + client.getCurrentURI()));
});
}
use of io.opentracing.Tracer in project cxf by apache.
the class OpenTracingTracingTest method testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleAsyncClients.
@Test
public void testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleAsyncClients() throws Exception {
final WebClient client = createWebClient("/bookstore/books", new OpenTracingClientProvider(tracer));
// The intention is to make a calls one after another, not in parallel, to ensure the
// thread have trace contexts cleared out.
IntStream.range(0, 4).mapToObj(index -> client.async().get()).map(this::get).forEach(r -> assertEquals(Status.OK.getStatusCode(), r.getStatus()));
assertThat(REPORTER.getSpans().size(), equalTo(12));
IntStream.range(0, 4).map(index -> index * 3).forEach(index -> {
assertThat(REPORTER.getSpans().get(index).getOperationName(), equalTo("Get Books"));
assertThat(REPORTER.getSpans().get(index + 1).getOperationName(), equalTo("GET /bookstore/books"));
assertThat(REPORTER.getSpans().get(index + 2).getOperationName(), equalTo("GET " + client.getCurrentURI()));
});
}
Aggregations