use of org.eclipse.hono.client.registry.TenantClient in project hono by eclipse.
the class AbstractProtocolAdapterApplication method prometheusResourceLimitChecks.
/**
* Creates resource limit checks based on data retrieved from a Prometheus server
* via its HTTP API.
*
* @param config The configuration properties.
* @param tenantClient The client to use for retrieving tenant configuration data.
* @throws NullPointerException if any of the parameters are {@code null}-
* @return The checks.
*/
protected ResourceLimitChecks prometheusResourceLimitChecks(final PrometheusBasedResourceLimitChecksConfig config, final TenantClient tenantClient) {
Objects.requireNonNull(config);
Objects.requireNonNull(tenantClient);
if (config.isHostConfigured()) {
final WebClientOptions webClientOptions = new WebClientOptions();
webClientOptions.setConnectTimeout(config.getConnectTimeout());
webClientOptions.setDefaultHost(config.getHost());
webClientOptions.setDefaultPort(config.getPort());
webClientOptions.setTrustOptions(config.getTrustOptions());
webClientOptions.setKeyCertOptions(config.getKeyCertOptions());
webClientOptions.setSsl(config.isTlsEnabled());
final var webClient = WebClient.create(vertx, webClientOptions);
final var cacheTimeout = Duration.ofSeconds(config.getCacheTimeout());
final Caffeine<Object, Object> builder = Caffeine.newBuilder().executor(Executors.newSingleThreadExecutor(r -> {
final var t = new Thread(r);
t.setDaemon(true);
return t;
})).initialCapacity(config.getCacheMinSize()).maximumSize(config.getCacheMaxSize()).expireAfterWrite(cacheTimeout).refreshAfterWrite(cacheTimeout.dividedBy(2));
return new PrometheusBasedResourceLimitChecks(builder.buildAsync(new ConnectedDevicesAsyncCacheLoader(webClient, config, tracer)), builder.buildAsync(new ConnectionDurationAsyncCacheLoader(webClient, config, tracer)), builder.buildAsync(new DataVolumeAsyncCacheLoader(webClient, config, tracer)), tenantClient, tracer);
} else {
return new NoopResourceLimitChecks();
}
}
use of org.eclipse.hono.client.registry.TenantClient in project hono by eclipse.
the class KafkaBasedInternalCommandConsumerTest method setUp.
/**
* Sets up fixture.
*/
@BeforeEach
public void setUp() {
final Admin kafkaAdminClient = mock(Admin.class);
@SuppressWarnings("unchecked") final KafkaConsumer<String, Buffer> kafkaConsumer = mock(KafkaConsumer.class);
final String adapterInstanceId = "adapterInstanceId";
final Span span = TracingMockSupport.mockSpan();
final Tracer tracer = TracingMockSupport.mockTracer(span);
context = VertxMockSupport.mockContext(mock(Vertx.class));
commandHandlers = new CommandHandlers();
tenantClient = mock(TenantClient.class);
doAnswer(invocation -> {
final String tenantId = invocation.getArgument(0);
return Future.succeededFuture(TenantObject.from(tenantId));
}).when(tenantClient).get(anyString(), any());
commandResponseSender = mock(CommandResponseSender.class);
when(commandResponseSender.sendCommandResponse(any(TenantObject.class), any(RegistrationAssertion.class), any(CommandResponse.class), any())).thenReturn(Future.succeededFuture());
internalCommandConsumer = new KafkaBasedInternalCommandConsumer(context, kafkaAdminClient, kafkaConsumer, "testClientId", tenantClient, commandResponseSender, adapterInstanceId, commandHandlers, tracer);
}
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);
}
use of org.eclipse.hono.client.registry.TenantClient in project hono by eclipse.
the class PrometheusBasedResourceLimitChecksTest method setup.
/**
* Sets up the fixture.
*/
@SuppressWarnings("unchecked")
@BeforeEach
public void setup() {
connectionCountCache = mock(AsyncLoadingCache.class);
when(connectionCountCache.get(any(LimitedResourceKey.class))).thenAnswer(i -> {
final var count = new CompletableFuture<Long>();
count.complete(10L);
return count;
});
connectionDurationCache = mock(AsyncLoadingCache.class);
when(connectionDurationCache.get(any(LimitedResourceKey.class))).then(invocation -> {
final var count = new CompletableFuture<Long>();
count.complete(10L);
return count;
});
dataVolumeCache = mock(AsyncLoadingCache.class);
when(dataVolumeCache.get(any(LimitedResourceKey.class))).then(invocation -> {
final var count = new CompletableFuture<Long>();
count.complete(10L);
return count;
});
span = TracingMockSupport.mockSpan();
tracer = TracingMockSupport.mockTracer(span);
tenantClient = mock(TenantClient.class);
when(tenantClient.get(anyString(), any())).thenAnswer(i -> {
final String tenantId = i.getArgument(0);
final var result = TenantObject.from(tenantId);
return Future.succeededFuture(result);
});
limitChecksImpl = new PrometheusBasedResourceLimitChecks(connectionCountCache, connectionDurationCache, dataVolumeCache, tenantClient, tracer);
}
use of org.eclipse.hono.client.registry.TenantClient 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