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