AbstractProtocolAdapterBase extends AbstractServiceBase<T> { protected Future<Void> checkConnectionDurationLimit(final TenantObject tenantConfig, final SpanContext spanContext) { Objects.requireNonNull(tenantConfig); return resourceLimitChecks.isConnectionDurationLimitReached(tenantConfig, spanContext) .recover(t -> Future.succeededFuture(Boolean.FALSE)) .compose(isExceeded -> { if (isExceeded) { return Future.failedFuture(new ConnectionDurationExceededException(tenantConfig.getTenantId(), null, null)); } else { return Future.succeededFuture(); } }); }  @Autowired @Override void setConfig(final T configuration); @Qualifier(TenantConstants.TENANT_ENDPOINT) @Autowired final void setTenantClientFactory(final TenantClientFactory factory); final TenantClientFactory getTenantClientFactory(); @Qualifier(DeviceConnectionConstants.DEVICE_CONNECTION_ENDPOINT) @Autowired final void setDeviceConnectionClientFactory(final BasicDeviceConnectionClientFactory factory); @Deprecated(forRemoval = true) final DeviceConnectionClientFactory getDeviceConnectionClientFactory(); @Qualifier(Constants.QUALIFIER_MESSAGING) @Autowired final void setDownstreamSenderFactory(final DownstreamSenderFactory factory); final DownstreamSenderFactory getDownstreamSenderFactory(); @Qualifier(RegistrationConstants.REGISTRATION_ENDPOINT) @Autowired final void setRegistrationClientFactory(final RegistrationClientFactory factory); final RegistrationClientFactory getRegistrationClientFactory(); @Qualifier(CredentialsConstants.CREDENTIALS_ENDPOINT) @Autowired final void setCredentialsClientFactory(final CredentialsClientFactory factory); final CredentialsClientFactory getCredentialsClientFactory(); @Autowired(required = false) void setConnectionEventProducer(final ConnectionEventProducer connectionEventProducer); ConnectionEventProducer getConnectionEventProducer(); @Autowired final void setCommandConsumerFactory(final ProtocolAdapterCommandConsumerFactory factory); final ProtocolAdapterCommandConsumerFactory getCommandConsumerFactory(); @Autowired final void setCommandTargetMapper(final CommandTargetMapper commandTargetMapper); @Autowired(required = false) final void setResourceLimitChecks(final ResourceLimitChecks resourceLimitChecks); final void setConnectionLimitManager(final ConnectionLimitManager connectionLimitManager); @Override void registerReadinessChecks(final HealthCheckHandler handler); @Override void registerLivenessChecks(final HealthCheckHandler handler); static ErrorCondition getErrorCondition(final Throwable t); static ConnectionAttemptOutcome getOutcome(final Throwable e);  }
@Test public void testCheckConnectionDurationLimit(final VertxTestContext ctx) { final TenantObject tenant = TenantObject.from("tenant", Boolean.TRUE); final ResourceLimitChecks checks = mock(ResourceLimitChecks.class); when(checks.isConnectionDurationLimitReached(any(TenantObject.class), any(SpanContext.class))) .thenReturn(Future.succeededFuture(Boolean.TRUE)); adapter.setResourceLimitChecks(checks); adapter.checkConnectionDurationLimit(tenant, mock(SpanContext.class)) .onComplete(ctx.failing(t -> { ctx.verify(() -> assertThat(t, instanceOf(ConnectionDurationExceededException.class))); ctx.completeNow(); })); }