Search in sources :

Example 1 with CommandRouterMetrics

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;
}
Also used : Buffer(io.vertx.core.buffer.Buffer) KafkaBasedCommandConsumerFactoryImpl(org.eclipse.hono.commandrouter.impl.kafka.KafkaBasedCommandConsumerFactoryImpl) SpanContext(io.opentracing.SpanContext) Tracer(io.opentracing.Tracer) JsonObject(io.vertx.core.json.JsonObject) Span(io.opentracing.Span) MessagingKafkaConsumerConfigProperties(org.eclipse.hono.client.kafka.consumer.MessagingKafkaConsumerConfigProperties) CommandRouterMetrics(org.eclipse.hono.commandrouter.CommandRouterMetrics) CommandTargetMapper(org.eclipse.hono.commandrouter.CommandTargetMapper) TenantClient(org.eclipse.hono.client.registry.TenantClient)

Example 2 with CommandRouterMetrics

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);
}
Also used : Context(io.vertx.core.Context) CommandRouterMetrics(org.eclipse.hono.commandrouter.CommandRouterMetrics) CommandTargetMapper(org.eclipse.hono.commandrouter.CommandTargetMapper) HonoConnection(org.eclipse.hono.client.HonoConnection) TenantClient(org.eclipse.hono.client.registry.TenantClient) ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties) EventBus(io.vertx.core.eventbus.EventBus) Vertx(io.vertx.core.Vertx) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with CommandRouterMetrics

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);
}
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

TenantClient (org.eclipse.hono.client.registry.TenantClient)3 CommandRouterMetrics (org.eclipse.hono.commandrouter.CommandRouterMetrics)3 CommandTargetMapper (org.eclipse.hono.commandrouter.CommandTargetMapper)3 Tracer (io.opentracing.Tracer)2 Context (io.vertx.core.Context)2 Vertx (io.vertx.core.Vertx)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Span (io.opentracing.Span)1 SpanContext (io.opentracing.SpanContext)1 Buffer (io.vertx.core.buffer.Buffer)1 EventBus (io.vertx.core.eventbus.EventBus)1 JsonObject (io.vertx.core.json.JsonObject)1 VertxTestContext (io.vertx.junit5.VertxTestContext)1 HonoConnection (org.eclipse.hono.client.HonoConnection)1 CommandContext (org.eclipse.hono.client.command.CommandContext)1 KafkaBasedCommandContext (org.eclipse.hono.client.command.kafka.KafkaBasedCommandContext)1 KafkaBasedCommandResponseSender (org.eclipse.hono.client.command.kafka.KafkaBasedCommandResponseSender)1 KafkaBasedInternalCommandSender (org.eclipse.hono.client.command.kafka.KafkaBasedInternalCommandSender)1 MessagingKafkaConsumerConfigProperties (org.eclipse.hono.client.kafka.consumer.MessagingKafkaConsumerConfigProperties)1 KafkaBasedCommandConsumerFactoryImpl (org.eclipse.hono.commandrouter.impl.kafka.KafkaBasedCommandConsumerFactoryImpl)1