use of io.opentracing.Tracer in project hono by eclipse.
the class CacheBasedDeviceConnectionInfoTest method testGetCommandHandlingAdapterInstancesWithTerminatedAdapterInstance.
/**
* Verifies that the <em>getCommandHandlingAdapterInstances</em> operation fails
* if the adapter instance mapping entry is associated with a terminated adapter.
*
* @param ctx The vert.x context.
*/
@Test
public void testGetCommandHandlingAdapterInstancesWithTerminatedAdapterInstance(final VertxTestContext ctx) {
final AdapterInstanceStatusProvider statusProvider = mock(AdapterInstanceStatusProvider.class);
info = new CacheBasedDeviceConnectionInfo(cache, tracer, statusProvider);
final String deviceId = "testDevice";
final String adapterInstance = "adapterInstance";
when(cache.get(anyString())).thenReturn(Future.succeededFuture(adapterInstance));
when(statusProvider.getStatus(adapterInstance)).thenReturn(AdapterInstanceStatus.DEAD);
when(cache.remove(anyString(), anyString())).thenReturn(Future.succeededFuture(Boolean.TRUE));
info.getCommandHandlingAdapterInstances(Constants.DEFAULT_TENANT, deviceId, Set.of(), span).onComplete(ctx.failing(t -> {
ctx.verify(() -> {
verify(cache).get(CacheBasedDeviceConnectionInfo.getAdapterInstanceEntryKey(Constants.DEFAULT_TENANT, deviceId));
assertThat(t).isInstanceOf(ClientErrorException.class);
assertThat(((ClientErrorException) t).getErrorCode()).isEqualTo(HttpURLConnection.HTTP_NOT_FOUND);
// verify mapping entry for terminated adapter instance has been removed
verify(cache).remove(CacheBasedDeviceConnectionInfo.getAdapterInstanceEntryKey(Constants.DEFAULT_TENANT, deviceId), adapterInstance);
});
ctx.completeNow();
}));
}
use of io.opentracing.Tracer in project hono by eclipse.
the class ProtonBasedTenantClientTest 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 KafkaBasedEventSenderTest method testThatSendEventThrowsOnMissingMandatoryParameter.
/**
* Verifies that
* {@link KafkaBasedEventSender#sendEvent(TenantObject, RegistrationAssertion, String, Buffer, Map, io.opentracing.SpanContext)}
* throws a nullpointer exception if a mandatory parameter is {@code null}.
*/
@Test
public void testThatSendEventThrowsOnMissingMandatoryParameter() {
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();
final KafkaBasedEventSender sender = new KafkaBasedEventSender(vertxMock, factory, kafkaProducerConfig, true, tracer);
assertThrows(NullPointerException.class, () -> sender.sendEvent(null, device, "the-content-type", null, null, null));
assertThrows(NullPointerException.class, () -> sender.sendEvent(tenant, null, "the-content-type", null, null, null));
}
use of io.opentracing.Tracer in project hono by eclipse.
the class KafkaBasedEventSenderTest method testSendEventCreatesCorrectRecord.
/**
* Verifies that the Kafka record is created as expected.
*
* @param ctx The vert.x test context.
*/
@Test
public void testSendEventCreatesCorrectRecord(final VertxTestContext ctx) {
// GIVEN a sender
final String contentType = "text/plain";
final String payload = "the-payload";
final Map<String, Object> properties = Map.of("foo", "bar", MessageHelper.SYS_HEADER_PROPERTY_TTL, 5);
final var span = TracingMockSupport.mockSpan();
final var tracer = TracingMockSupport.mockTracer(span);
final var mockProducer = KafkaClientUnitTestHelper.newMockProducer(true);
final var factory = newProducerFactory(mockProducer);
final var sender = new KafkaBasedEventSender(vertxMock, factory, kafkaProducerConfig, true, tracer);
// WHEN sending a message
sender.sendEvent(tenant, device, 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.EVENT, tenant.getTenantId()).toString());
assertThat(producerRecord.value().toString()).isEqualTo(payload);
KafkaClientUnitTestHelper.assertUniqueHeaderWithExpectedValue(producerRecord.headers(), "foo", "bar");
KafkaClientUnitTestHelper.assertUniqueHeaderWithExpectedValue(producerRecord.headers(), MessageHelper.SYS_HEADER_PROPERTY_TTL, 5000L);
// ...AND contains the standard headers
KafkaClientUnitTestHelper.assertStandardHeaders(producerRecord, device.getDeviceId(), contentType, QoS.AT_LEAST_ONCE.ordinal());
verify(span).finish();
});
ctx.completeNow();
}));
}
use of io.opentracing.Tracer in project hono by eclipse.
the class KafkaBasedEventSenderTest method testThatConstructorThrowsOnMissingParameter.
/**
* Verifies that the constructor throws a nullpointer exception 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 KafkaBasedEventSender(null, factory, kafkaProducerConfig, true, tracer));
assertThrows(NullPointerException.class, () -> new KafkaBasedEventSender(vertxMock, null, kafkaProducerConfig, true, tracer));
assertThrows(NullPointerException.class, () -> new KafkaBasedEventSender(vertxMock, factory, null, true, tracer));
assertThrows(NullPointerException.class, () -> new KafkaBasedEventSender(vertxMock, factory, kafkaProducerConfig, true, null));
}
Aggregations