AbstractServiceBase extends ConfigurationSupportingVerticle<T> implements HealthCheckProvider { protected final Future<Void> checkPortConfiguration() { if (vertx != null) { log.info("Vertx native support: {}", vertx.isNativeTransportEnabled()); } final Promise<Void> result = Promise.promise(); if (getConfig().getKeyCertOptions() == null) { if (getConfig().getPort() >= 0) { log.warn("Secure port number configured, but the certificate setup is not correct. No secure port will be opened - please check your configuration!"); } if (!getConfig().isInsecurePortEnabled()) { log.error("configuration must have at least one of key & certificate or insecure port set to start up"); result.fail("no ports configured"); } else { result.complete(); } } else if (getConfig().isInsecurePortEnabled()) { if (getConfig().getPort(getPortDefaultValue()) == getConfig().getInsecurePort(getInsecurePortDefaultValue())) { log.error("secure and insecure ports must be configured to bind to different port numbers"); result.fail("secure and insecure ports configured to bind to same port number"); } else { result.complete(); } } else { result.complete(); } return result.future(); }  @Autowired(required = false) final void setTracer(final Tracer opentracingTracer); @Autowired(required = false) void setHealthCheckServer(final HealthCheckServer healthCheckServer); @Override final void start(final Promise<Void> startPromise); @Override final void stop(final Promise<Void> stopPromise); @Override void registerReadinessChecks(final HealthCheckHandler handler); @Override void registerLivenessChecks(final HealthCheckHandler handler); abstract int getPortDefaultValue(); abstract int getInsecurePortDefaultValue(); final int getPort(); final int getInsecurePort(); final String getBindAddress(); final String getInsecurePortBindAddress();  }
@Test public void checkNoPortsSet() { final ServiceConfigProperties configProperties = new ServiceConfigProperties(); final AbstractServiceBase<ServiceConfigProperties> server = createService(configProperties); final Future<Void> portConfigurationTracker = server.checkPortConfiguration(); assertTrue(portConfigurationTracker.failed()); }
@Test public void checkBothPortsSetToSame() { final ServiceConfigProperties configProperties = new ServiceConfigProperties(); configProperties.setInsecurePortEnabled(true); configProperties.setKeyStorePath(PREFIX_KEY_PATH + "/authServerKeyStore.p12"); configProperties.setInsecurePort(8888); configProperties.setPort(8888); final AbstractServiceBase<ServiceConfigProperties> server = createService(configProperties); final Future<Void> portConfigurationTracker = server.checkPortConfiguration(); assertTrue(portConfigurationTracker.failed()); }