use of org.eclipse.hono.commandrouter.CommandRouterMetrics in project hono by eclipse.
the class KafkaBasedCommandConsumerFactoryImplIT method getKafkaBasedCommandConsumerFactory.
private KafkaBasedCommandConsumerFactoryImpl getKafkaBasedCommandConsumerFactory(final Supplier<Future<Void>> targetAdapterInstanceGetterCompletionFutureSupplier, final String tenantToHandleCommandsFor) {
final KafkaProducerFactory<String, Buffer> producerFactory = CachingKafkaProducerFactory.sharedFactory(vertx);
final TenantClient tenantClient = getTenantClient();
final CommandTargetMapper commandTargetMapper = new CommandTargetMapper() {
@Override
public Future<JsonObject> getTargetGatewayAndAdapterInstance(final String tenantId, final String deviceId, final SpanContext context) {
final JsonObject jsonObject = new JsonObject();
jsonObject.put(DeviceConnectionConstants.FIELD_ADAPTER_INSTANCE_ID, adapterInstanceId);
jsonObject.put(DeviceConnectionConstants.FIELD_PAYLOAD_DEVICE_ID, deviceId);
if (!tenantId.equals(tenantToHandleCommandsFor)) {
return Future.failedFuture("ignoring command for other tenant " + tenantId);
}
if (targetAdapterInstanceGetterCompletionFutureSupplier == null) {
return Future.succeededFuture(jsonObject);
}
return targetAdapterInstanceGetterCompletionFutureSupplier.get().map(jsonObject);
}
};
final Span span = TracingMockSupport.mockSpan();
final Tracer tracer = TracingMockSupport.mockTracer(span);
final MessagingKafkaConsumerConfigProperties kafkaConsumerConfig = new MessagingKafkaConsumerConfigProperties();
kafkaConsumerConfig.setConsumerConfig(Map.of(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, IntegrationTestSupport.DOWNSTREAM_BOOTSTRAP_SERVERS));
final CommandRouterMetrics metrics = mock(CommandRouterMetrics.class);
when(metrics.startTimer()).thenReturn(Timer.start());
final var kafkaBasedCommandConsumerFactoryImpl = new KafkaBasedCommandConsumerFactoryImpl(vertx, tenantClient, commandTargetMapper, producerFactory, IntegrationTestSupport.getKafkaProducerConfig(), IntegrationTestSupport.getKafkaProducerConfig(), kafkaConsumerConfig, metrics, NoopKafkaClientMetricsSupport.INSTANCE, tracer, null);
kafkaBasedCommandConsumerFactoryImpl.setGroupId(commandRouterGroupId);
componentsToStopAfterTest.add(kafkaBasedCommandConsumerFactoryImpl);
return kafkaBasedCommandConsumerFactoryImpl;
}
use of org.eclipse.hono.commandrouter.CommandRouterMetrics in project hono by eclipse.
the class ProtonBasedMappingAndDelegatingCommandHandlerTest method setUp.
/**
* Sets up fixture.
*/
@BeforeEach
public void setUp() {
final Vertx vertx = mock(Vertx.class);
final Context context = VertxMockSupport.mockContext(vertx);
when(vertx.getOrCreateContext()).thenReturn(context);
doAnswer(invocation -> {
final Handler<Void> handler = invocation.getArgument(1);
handler.handle(null);
return null;
}).when(vertx).setTimer(anyLong(), VertxMockSupport.anyHandler());
final EventBus eventBus = mock(EventBus.class);
when(vertx.eventBus()).thenReturn(eventBus);
final ClientConfigProperties props = new ClientConfigProperties();
props.setSendMessageTimeout(0);
final HonoConnection connection = mockHonoConnection(vertx, props);
when(connection.isConnected(anyLong())).thenReturn(Future.succeededFuture());
sender = mockProtonSender();
when(connection.createSender(anyString(), any(), any())).thenReturn(Future.succeededFuture(sender));
tenantId = UUID.randomUUID().toString();
tenantClient = mock(TenantClient.class);
when(tenantClient.get(eq(tenantId), any())).thenReturn(Future.succeededFuture(TenantObject.from(tenantId)));
commandTargetMapper = mock(CommandTargetMapper.class);
final CommandRouterMetrics metrics = mock(CommandRouterMetrics.class);
when(metrics.startTimer()).thenReturn(Timer.start());
mappingAndDelegatingCommandHandler = new ProtonBasedMappingAndDelegatingCommandHandler(tenantClient, connection, commandTargetMapper, metrics);
}
use of org.eclipse.hono.commandrouter.CommandRouterMetrics 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);
}
Aggregations