Search in sources :

Example 1 with TenantClient

use of org.eclipse.hono.client.registry.TenantClient 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 TenantClient

use of org.eclipse.hono.client.registry.TenantClient 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 TenantClient

use of org.eclipse.hono.client.registry.TenantClient in project hono by eclipse.

the class Application method commandRouterService.

private CommandRouterService commandRouterService() {
    final DeviceRegistrationClient registrationClient = registrationClient();
    final TenantClient tenantClient = tenantClient();
    final CommandTargetMapper commandTargetMapper = CommandTargetMapper.create(registrationClient, deviceConnectionInfo, tracer);
    return new CommandRouterServiceImpl(amqpServerProperties, registrationClient, tenantClient, deviceConnectionInfo, commandConsumerFactoryProvider(tenantClient, commandTargetMapper), adapterInstanceStatusService, tracer);
}
Also used : CommandTargetMapper(org.eclipse.hono.commandrouter.CommandTargetMapper) ProtonBasedDeviceRegistrationClient(org.eclipse.hono.client.registry.amqp.ProtonBasedDeviceRegistrationClient) DeviceRegistrationClient(org.eclipse.hono.client.registry.DeviceRegistrationClient) TenantClient(org.eclipse.hono.client.registry.TenantClient) ProtonBasedTenantClient(org.eclipse.hono.client.registry.amqp.ProtonBasedTenantClient) CommandRouterServiceImpl(org.eclipse.hono.commandrouter.impl.CommandRouterServiceImpl)

Example 4 with TenantClient

use of org.eclipse.hono.client.registry.TenantClient in project hono by eclipse.

the class ProtocolAdapterMockSupport method createTenantClientMock.

private TenantClient createTenantClientMock() {
    final TenantClient client = mock(TenantClient.class);
    when(client.start()).thenReturn(Future.succeededFuture());
    when(client.stop()).thenReturn(Future.succeededFuture());
    return client;
}
Also used : TenantClient(org.eclipse.hono.client.registry.TenantClient)

Example 5 with TenantClient

use of org.eclipse.hono.client.registry.TenantClient in project hono by eclipse.

the class AbstractProtocolAdapterBaseTest method setup.

/**
 * Sets up the fixture.
 */
@BeforeEach
public void setup() {
    tenantClient = mock(TenantClient.class);
    when(tenantClient.start()).thenReturn(Future.succeededFuture());
    registrationClient = mock(DeviceRegistrationClient.class);
    when(registrationClient.start()).thenReturn(Future.succeededFuture());
    credentialsClient = mock(CredentialsClient.class);
    when(credentialsClient.start()).thenReturn(Future.succeededFuture());
    amqpTelemetrySender = mockMessagingClient(TelemetrySender.class, MessagingType.amqp);
    when(amqpTelemetrySender.start()).thenReturn(Future.succeededFuture());
    kafkaTelemetrySender = mockMessagingClient(TelemetrySender.class, MessagingType.kafka);
    when(kafkaTelemetrySender.start()).thenReturn(Future.succeededFuture());
    amqpEventSender = mockMessagingClient(EventSender.class, MessagingType.amqp);
    when(amqpEventSender.start()).thenReturn(Future.succeededFuture());
    kafkaEventSender = mockMessagingClient(EventSender.class, MessagingType.kafka);
    when(kafkaEventSender.start()).thenReturn(Future.succeededFuture());
    commandConsumerFactory = mock(CommandConsumerFactory.class);
    when(commandConsumerFactory.start()).thenReturn(Future.succeededFuture());
    amqpCommandResponseSender = mockMessagingClient(CommandResponseSender.class, MessagingType.amqp);
    when(amqpCommandResponseSender.start()).thenReturn(Future.succeededFuture());
    kafkaCommandResponseSender = mockMessagingClient(CommandResponseSender.class, MessagingType.kafka);
    when(kafkaCommandResponseSender.start()).thenReturn(Future.succeededFuture());
    final var telemetrySenderProvider = new MessagingClientProvider<TelemetrySender>().setClient(amqpTelemetrySender).setClient(kafkaTelemetrySender);
    final var eventSenderProvider = new MessagingClientProvider<EventSender>().setClient(amqpEventSender).setClient(kafkaEventSender);
    final var commandResponseSenderProvider = new MessagingClientProvider<CommandResponseSender>().setClient(amqpCommandResponseSender).setClient(kafkaCommandResponseSender);
    messagingClientProviders = new MessagingClientProviders(telemetrySenderProvider, eventSenderProvider, commandResponseSenderProvider);
    commandRouterClient = mock(CommandRouterClient.class);
    when(commandRouterClient.start()).thenReturn(Future.succeededFuture());
    properties = new ProtocolAdapterProperties();
    adapter = newProtocolAdapter(properties, ADAPTER_NAME);
    setCollaborators(adapter);
    vertx = mock(Vertx.class);
    VertxMockSupport.runTimersImmediately(vertx);
    context = mock(Context.class);
    adapter.init(vertx, context);
}
Also used : Context(io.vertx.core.Context) VertxTestContext(io.vertx.junit5.VertxTestContext) TelemetryExecutionContext(org.eclipse.hono.util.TelemetryExecutionContext) SpanContext(io.opentracing.SpanContext) CommandRouterClient(org.eclipse.hono.client.command.CommandRouterClient) ProtocolAdapterProperties(org.eclipse.hono.config.ProtocolAdapterProperties) CommandConsumerFactory(org.eclipse.hono.client.command.CommandConsumerFactory) DeviceRegistrationClient(org.eclipse.hono.client.registry.DeviceRegistrationClient) Vertx(io.vertx.core.Vertx) CredentialsClient(org.eclipse.hono.client.registry.CredentialsClient) MessagingClientProvider(org.eclipse.hono.client.util.MessagingClientProvider) CommandResponseSender(org.eclipse.hono.client.command.CommandResponseSender) TenantClient(org.eclipse.hono.client.registry.TenantClient) EventSender(org.eclipse.hono.client.telemetry.EventSender) TelemetrySender(org.eclipse.hono.client.telemetry.TelemetrySender) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

TenantClient (org.eclipse.hono.client.registry.TenantClient)10 Tracer (io.opentracing.Tracer)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Span (io.opentracing.Span)3 SpanContext (io.opentracing.SpanContext)3 Context (io.vertx.core.Context)3 Vertx (io.vertx.core.Vertx)3 Buffer (io.vertx.core.buffer.Buffer)3 CommandResponseSender (org.eclipse.hono.client.command.CommandResponseSender)3 DeviceRegistrationClient (org.eclipse.hono.client.registry.DeviceRegistrationClient)3 CommandTargetMapper (org.eclipse.hono.commandrouter.CommandTargetMapper)3 TenantObject (org.eclipse.hono.util.TenantObject)3 Future (io.vertx.core.Future)2 JsonObject (io.vertx.core.json.JsonObject)2 VertxTestContext (io.vertx.junit5.VertxTestContext)2 List (java.util.List)2 Objects (java.util.Objects)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CommandRouterClient (org.eclipse.hono.client.command.CommandRouterClient)2 KafkaBasedCommandResponseSender (org.eclipse.hono.client.command.kafka.KafkaBasedCommandResponseSender)2