use of io.opentracing.Tracer in project hono by eclipse.
the class ProtonBasedDownstreamSenderTest method setUp.
/**
* Sets up the fixture.
*/
@BeforeEach
public void setUp() {
span = NoopSpan.INSTANCE;
final Tracer tracer = NoopTracerFactory.create();
final Vertx vertx = mock(Vertx.class);
when(vertx.eventBus()).thenReturn(mock(EventBus.class));
connection = AmqpClientUnitTestHelper.mockHonoConnection(vertx, new ClientConfigProperties(), tracer);
when(connection.isConnected()).thenReturn(Future.succeededFuture());
when(connection.isConnected(anyLong())).thenReturn(Future.succeededFuture());
protonSender = AmqpClientUnitTestHelper.mockProtonSender();
when(connection.createSender(anyString(), any(), any())).thenReturn(Future.succeededFuture(protonSender));
sender = new ProtonBasedDownstreamSender(connection, SendMessageSampler.Factory.noop(), true, false);
}
use of io.opentracing.Tracer in project hono by eclipse.
the class AbstractKafkaBasedDownstreamSenderTest method testThatNotificationConsumerIsRegistered.
/**
* Verifies that the sender registers itself for notifications of the type {@link TenantChangeNotification}.
*/
@Test
public void testThatNotificationConsumerIsRegistered() {
final EventBus eventBus = mock(EventBus.class);
when(vertxMock.eventBus()).thenReturn(eventBus);
final Span span = TracingMockSupport.mockSpan();
final Tracer tracer = TracingMockSupport.mockTracer(span);
final var mockProducer = KafkaClientUnitTestHelper.newMockProducer(true);
final var factory = CachingKafkaProducerFactory.testFactory(vertxMock, (n, c) -> KafkaClientUnitTestHelper.newKafkaProducer(mockProducer));
@SuppressWarnings("unused") final var sender = new AbstractKafkaBasedDownstreamSender(vertxMock, factory, PRODUCER_NAME, config, true, tracer) {
@Override
protected HonoTopic.Type getTopicType() {
return HonoTopic.Type.EVENT;
}
};
verify(eventBus).consumer(eq(NotificationEventBusSupport.getEventBusAddress(TenantChangeNotification.TYPE)), VertxMockSupport.anyHandler());
verifyNoMoreInteractions(eventBus);
}
use of io.opentracing.Tracer in project hono by eclipse.
the class KafkaBasedTelemetrySenderTest method testThatConstructorThrowsOnMissingParameter.
/**
* Verifies that the constructor throws an NPE if a parameter is {@code null}.
*/
@Test
public void testThatConstructorThrowsOnMissingParameter() {
final MockProducer<String, Buffer> mockProducer = KafkaClientUnitTestHelper.newMockProducer(true);
final CachingKafkaProducerFactory<String, Buffer> factory = CachingKafkaProducerFactory.testFactory(vertxMock, (n, c) -> KafkaClientUnitTestHelper.newKafkaProducer(mockProducer));
final Tracer tracer = NoopTracerFactory.create();
assertThrows(NullPointerException.class, () -> new KafkaBasedTelemetrySender(null, factory, kafkaProducerConfig, true, tracer));
assertThrows(NullPointerException.class, () -> new KafkaBasedTelemetrySender(vertxMock, null, kafkaProducerConfig, true, tracer));
assertThrows(NullPointerException.class, () -> new KafkaBasedTelemetrySender(vertxMock, factory, null, true, tracer));
assertThrows(NullPointerException.class, () -> new KafkaBasedTelemetrySender(vertxMock, factory, kafkaProducerConfig, true, null));
}
use of io.opentracing.Tracer in project hono by eclipse.
the class KafkaBasedTelemetrySenderTest method testSendTelemetryCreatesCorrectRecord.
/**
* Verifies that the Kafka record is created as expected when sending telemetry data.
*
* @param qos The quality of service used for sending the message.
* @param expectedTtl The ttl expected in the message.
* @param ctx The vert.x test context.
*/
@ParameterizedTest
@CsvSource(value = { "AT_MOST_ONCE,10000", "AT_LEAST_ONCE,60000" })
public void testSendTelemetryCreatesCorrectRecord(final QoS qos, final long expectedTtl, final VertxTestContext ctx) {
// GIVEN a telemetry sender
final String payload = "the-payload";
final String contentType = "text/plain";
final Map<String, Object> properties = Map.of("foo", "bar");
final var spanFinished = ctx.checkpoint();
final var messageHasHeaders = ctx.checkpoint();
final var span = TracingMockSupport.mockSpan();
doAnswer(invocation -> {
spanFinished.flag();
return null;
}).when(span).finish();
final var tracer = TracingMockSupport.mockTracer(span);
final var mockProducer = KafkaClientUnitTestHelper.newMockProducer(true);
final var factory = CachingKafkaProducerFactory.testFactory(vertxMock, (n, c) -> KafkaClientUnitTestHelper.newKafkaProducer(mockProducer));
final var sender = new KafkaBasedTelemetrySender(vertxMock, factory, kafkaProducerConfig, true, tracer);
tenant.setResourceLimits(new ResourceLimits().setMaxTtlTelemetryQoS0(10L).setMaxTtlTelemetryQoS1(60L));
// WHEN sending telemetry data
sender.sendTelemetry(tenant, device, qos, contentType, Buffer.buffer(payload), properties, null).onComplete(ctx.succeeding(t -> {
ctx.verify(() -> {
// THEN the producer record is created from the given values...
final var producerRecord = mockProducer.history().get(0);
assertThat(producerRecord.key()).isEqualTo(device.getDeviceId());
assertThat(producerRecord.topic()).isEqualTo(new HonoTopic(HonoTopic.Type.TELEMETRY, tenant.getTenantId()).toString());
assertThat(producerRecord.value().toString()).isEqualTo(payload);
KafkaClientUnitTestHelper.assertUniqueHeaderWithExpectedValue(producerRecord.headers(), "foo", "bar");
KafkaClientUnitTestHelper.assertUniqueHeaderWithExpectedValue(producerRecord.headers(), MessageHelper.SYS_HEADER_PROPERTY_TTL, expectedTtl);
// ...AND contains the standard headers
KafkaClientUnitTestHelper.assertStandardHeaders(producerRecord, device.getDeviceId(), contentType, qos.ordinal());
});
messageHasHeaders.flag();
}));
}
use of io.opentracing.Tracer in project hono by eclipse.
the class ClasspathSchemaCreator method runScript.
private Future<Void> runScript(final JdbcProperties jdbcProperties, final String script, final SpanContext ctx) {
final JDBCClient jdbcClient = JdbcProperties.dataSource(vertx, jdbcProperties);
final Promise<Void> clientCloseTracker = Promise.promise();
SQL.runTransactionally(jdbcClient, tracer, ctx, (connection, context) -> {
final var expanded = Statement.statement(script).expand();
log.debug("Creating database schema in [{}] with script: {}", jdbcProperties.getUrl(), expanded);
return expanded.query(jdbcClient).recover(SQL::translateException);
}).onComplete(ar -> jdbcClient.close(clientCloseTracker));
return clientCloseTracker.future();
}
Aggregations