Search in sources :

Example 81 with Tracer

use of io.opentracing.Tracer in project hono by eclipse.

the class KafkaBasedInternalCommandConsumerTest method setUp.

/**
 * Sets up fixture.
 */
@BeforeEach
public void setUp() {
    final Admin kafkaAdminClient = mock(Admin.class);
    @SuppressWarnings("unchecked") final KafkaConsumer<String, Buffer> kafkaConsumer = mock(KafkaConsumer.class);
    final String adapterInstanceId = "adapterInstanceId";
    final Span span = TracingMockSupport.mockSpan();
    final Tracer tracer = TracingMockSupport.mockTracer(span);
    context = VertxMockSupport.mockContext(mock(Vertx.class));
    commandHandlers = new CommandHandlers();
    tenantClient = mock(TenantClient.class);
    doAnswer(invocation -> {
        final String tenantId = invocation.getArgument(0);
        return Future.succeededFuture(TenantObject.from(tenantId));
    }).when(tenantClient).get(anyString(), any());
    commandResponseSender = mock(CommandResponseSender.class);
    when(commandResponseSender.sendCommandResponse(any(TenantObject.class), any(RegistrationAssertion.class), any(CommandResponse.class), any())).thenReturn(Future.succeededFuture());
    internalCommandConsumer = new KafkaBasedInternalCommandConsumer(context, kafkaAdminClient, kafkaConsumer, "testClientId", tenantClient, commandResponseSender, adapterInstanceId, commandHandlers, tracer);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) CommandHandlers(org.eclipse.hono.client.command.CommandHandlers) Tracer(io.opentracing.Tracer) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CommandResponse(org.eclipse.hono.client.command.CommandResponse) Admin(org.apache.kafka.clients.admin.Admin) Span(io.opentracing.Span) TenantObject(org.eclipse.hono.util.TenantObject) RegistrationAssertion(org.eclipse.hono.util.RegistrationAssertion) CommandResponseSender(org.eclipse.hono.client.command.CommandResponseSender) TenantClient(org.eclipse.hono.client.registry.TenantClient) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 82 with Tracer

use of io.opentracing.Tracer in project hono by eclipse.

the class MessageAnnotationsInjectExtractAdapterTest method testJaegerTracerCanUseAdapter.

/**
 * Verifies that the Jaeger tracer implementation can successfully use the adapter to inject and extract
 * a SpanContext.
 */
@Test
public void testJaegerTracerCanUseAdapter() {
    final Configuration config = new Configuration("test");
    final Tracer tracer = config.getTracer();
    final Span span = tracer.buildSpan("do").start();
    final Message message = ProtonHelper.message();
    final MessageAnnotationsInjectAdapter injectAdapter = new MessageAnnotationsInjectAdapter(message, propertiesMapName);
    tracer.inject(span.context(), Format.Builtin.TEXT_MAP, injectAdapter);
    final SpanContext context = tracer.extract(Format.Builtin.TEXT_MAP, new MessageAnnotationsExtractAdapter(message, propertiesMapName));
    assertThat(context.toSpanId()).isEqualTo(span.context().toSpanId());
}
Also used : SpanContext(io.opentracing.SpanContext) Configuration(io.jaegertracing.Configuration) Message(org.apache.qpid.proton.message.Message) Tracer(io.opentracing.Tracer) Span(io.opentracing.Span) Test(org.junit.jupiter.api.Test)

Example 83 with Tracer

use of io.opentracing.Tracer in project hono by eclipse.

the class JsonObjectInjectExtractAdapterTest method testJaegerTracerCanUseAdapter.

/**
 * Verifies that the Jaeger tracer implementation can successfully use the adapter to inject and extract
 * a SpanContext.
 */
@Test
public void testJaegerTracerCanUseAdapter() {
    final Configuration config = new Configuration("test");
    final Tracer tracer = config.getTracer();
    final Span span = tracer.buildSpan("do").start();
    final JsonObject jsonObject = new JsonObject();
    final JsonObjectInjectAdapter injectAdapter = new JsonObjectInjectAdapter(jsonObject);
    tracer.inject(span.context(), Format.Builtin.TEXT_MAP, injectAdapter);
    final SpanContext context = tracer.extract(Format.Builtin.TEXT_MAP, new JsonObjectExtractAdapter(jsonObject));
    assertThat(context.toSpanId()).isEqualTo(span.context().toSpanId());
}
Also used : SpanContext(io.opentracing.SpanContext) Configuration(io.jaegertracing.Configuration) Tracer(io.opentracing.Tracer) JsonObject(io.vertx.core.json.JsonObject) Span(io.opentracing.Span) Test(org.junit.jupiter.api.Test)

Example 84 with Tracer

use of io.opentracing.Tracer in project hono by eclipse.

the class MultiMapInjectExtractAdapterTest method testJaegerTracerCanUseAdapter.

/**
 * Verifies that the Jaeger tracer implementation can successfully use the adapter to inject and extract
 * a SpanContext.
 */
@Test
public void testJaegerTracerCanUseAdapter() {
    final Configuration config = new Configuration("test");
    final Tracer tracer = config.getTracer();
    final Span span = tracer.buildSpan("do").start();
    final MultiMap multiMap = MultiMap.caseInsensitiveMultiMap();
    final MultiMapInjectAdapter injectAdapter = new MultiMapInjectAdapter(multiMap);
    tracer.inject(span.context(), Format.Builtin.TEXT_MAP, injectAdapter);
    final SpanContext context = tracer.extract(Format.Builtin.TEXT_MAP, new MultiMapExtractAdapter(multiMap));
    assertThat(context.toSpanId()).isEqualTo(span.context().toSpanId());
}
Also used : MultiMap(io.vertx.core.MultiMap) SpanContext(io.opentracing.SpanContext) Configuration(io.jaegertracing.Configuration) Tracer(io.opentracing.Tracer) Span(io.opentracing.Span) Test(org.junit.jupiter.api.Test)

Example 85 with Tracer

use of io.opentracing.Tracer in project hono by eclipse.

the class KafkaBasedMappingAndDelegatingCommandHandlerTest method setUp.

/**
 * Sets up fixture.
 */
@BeforeEach
public void setUp() {
    tenantId = UUID.randomUUID().toString();
    deviceId = UUID.randomUUID().toString();
    adapterInstanceId = UUID.randomUUID().toString();
    final TenantClient tenantClient = mock(TenantClient.class);
    when(tenantClient.get(eq(tenantId), any())).thenReturn(Future.succeededFuture(TenantObject.from(tenantId)));
    commandTargetMapper = mock(CommandTargetMapper.class);
    when(commandTargetMapper.getTargetGatewayAndAdapterInstance(eq(tenantId), eq(deviceId), any())).thenReturn(Future.succeededFuture(createTargetAdapterInstanceJson(deviceId, adapterInstanceId)));
    internalCommandSender = mock(KafkaBasedInternalCommandSender.class);
    when(internalCommandSender.sendCommand(any(CommandContext.class), anyString())).thenReturn(Future.succeededFuture());
    final KafkaBasedCommandResponseSender kafkaBasedCommandResponseSender = mock(KafkaBasedCommandResponseSender.class);
    vertx = mock(Vertx.class);
    final Context context = VertxMockSupport.mockContext(vertx);
    final KafkaCommandProcessingQueue commandQueue = new KafkaCommandProcessingQueue(context);
    final CommandRouterMetrics metrics = mock(CommandRouterMetrics.class);
    when(metrics.startTimer()).thenReturn(Timer.start());
    final Tracer tracer = TracingMockSupport.mockTracer(TracingMockSupport.mockSpan());
    cmdHandler = new KafkaBasedMappingAndDelegatingCommandHandler(vertx, tenantClient, commandQueue, commandTargetMapper, internalCommandSender, kafkaBasedCommandResponseSender, metrics, tracer);
}
Also used : Context(io.vertx.core.Context) CommandContext(org.eclipse.hono.client.command.CommandContext) VertxTestContext(io.vertx.junit5.VertxTestContext) KafkaBasedCommandContext(org.eclipse.hono.client.command.kafka.KafkaBasedCommandContext) CommandRouterMetrics(org.eclipse.hono.commandrouter.CommandRouterMetrics) CommandTargetMapper(org.eclipse.hono.commandrouter.CommandTargetMapper) KafkaBasedCommandResponseSender(org.eclipse.hono.client.command.kafka.KafkaBasedCommandResponseSender) CommandContext(org.eclipse.hono.client.command.CommandContext) KafkaBasedCommandContext(org.eclipse.hono.client.command.kafka.KafkaBasedCommandContext) Tracer(io.opentracing.Tracer) TenantClient(org.eclipse.hono.client.registry.TenantClient) Vertx(io.vertx.core.Vertx) KafkaBasedInternalCommandSender(org.eclipse.hono.client.command.kafka.KafkaBasedInternalCommandSender) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Tracer (io.opentracing.Tracer)104 Span (io.opentracing.Span)49 SpanContext (io.opentracing.SpanContext)30 Map (java.util.Map)21 Vertx (io.vertx.core.Vertx)19 HashMap (java.util.HashMap)19 Test (org.junit.Test)19 BeforeEach (org.junit.jupiter.api.BeforeEach)19 Test (org.junit.jupiter.api.Test)19 Future (io.vertx.core.Future)18 Buffer (io.vertx.core.buffer.Buffer)16 HttpURLConnection (java.net.HttpURLConnection)14 EventBus (io.vertx.core.eventbus.EventBus)13 JsonObject (io.vertx.core.json.JsonObject)12 Objects (java.util.Objects)12 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 Tags (io.opentracing.tag.Tags)9 Scope (io.opentracing.Scope)8 GlobalTracer (io.opentracing.util.GlobalTracer)8