PrometheusBasedResourceLimitChecks implements ResourceLimitChecks { @Override public Future<Boolean> isConnectionDurationLimitReached( final TenantObject tenant, final SpanContext spanContext) { Objects.requireNonNull(tenant); final Span span = createSpan("verify connection duration limit", spanContext, tenant); final Map<String, Object> items = new HashMap<>(); final Promise<Boolean> result = Promise.promise(); if (tenant.getResourceLimits() == null) { items.put(Fields.EVENT, "no resource limits configured"); LOG.trace("no resource limits configured for tenant [{}]", tenant.getTenantId()); result.complete(Boolean.FALSE); } else if (tenant.getResourceLimits().getConnectionDuration() == null) { items.put(Fields.EVENT, "no connection duration limit configured"); LOG.trace("no connection duration limit configured for tenant [{}]", tenant.getTenantId()); result.complete(Boolean.FALSE); } else { checkConnectionDurationLimit(tenant, items, span, result); } return result.future() .map(b -> { items.put("limit exceeded", b); span.log(items); span.finish(); return b; }); } PrometheusBasedResourceLimitChecks(
            final WebClient webClient,
            final PrometheusBasedResourceLimitChecksConfig config,
            final AsyncCache<String, LimitedResource<Long>> connectionCountCache,
            final AsyncCache<String, LimitedResource<Duration>> connectionDurationCache,
            final AsyncCache<String, LimitedResource<Long>> dataVolumeCache);  PrometheusBasedResourceLimitChecks(
            final WebClient webClient,
            final PrometheusBasedResourceLimitChecksConfig config,
            final AsyncCache<String, LimitedResource<Long>> connectionCountCache,
            final AsyncCache<String, LimitedResource<Duration>> connectionDurationCache,
            final AsyncCache<String, LimitedResource<Long>> dataVolumeCache,
            final Tracer tracer); @Override Future<Boolean> isConnectionLimitReached(final TenantObject tenant, final SpanContext spanContext); @Override Future<Boolean> isMessageLimitReached(
            final TenantObject tenant,
            final long payloadSize,
            final SpanContext spanContext); @Override Future<Boolean> isConnectionDurationLimitReached(
            final TenantObject tenant,
            final SpanContext spanContext);  }
@SuppressWarnings("unchecked") @Test public void testConnectionDurationLimitNotExceededWhenTimeoutOccurred(final VertxTestContext ctx) { givenFailResponseWithTimeoutException(); final TenantObject tenant = TenantObject.from(Constants.DEFAULT_TENANT, true) .setResourceLimits(new ResourceLimits() .setConnectionDuration(new ConnectionDuration( Instant.parse("2019-01-03T14:30:00Z"), new ResourceLimitsPeriod(ResourceLimitsPeriod.PERIOD_MODE_DAYS).setNoOfDays(30), 10L))); limitChecksImpl.isConnectionDurationLimitReached(tenant, mock(SpanContext.class)) .onComplete(ctx.succeeding(response -> { ctx.verify(() -> { assertFalse(response); verify(request).send(any(Handler.class)); }); ctx.completeNow(); })); }