@Test public void validateConnectionTest() throws Exception { TestUtils.assertException(IllegalArgumentException.class, () -> serverSecurityService.validateConnection(null).get(), null); SSLSession sslSession = Mockito.mock(SSLSession.class); serverSecurityService.validateConnection(sslSession, (r, e) -> { Assert.assertNull("result not null", r); Assert.assertNull("exception not null", e); }); serverSecurityService.close(); ThrowingConsumer<ExecutionException> errorAction = e -> { Assert.assertTrue("Exception should have been an instance of RestServiceException", e.getCause() instanceof RestServiceException); RestServiceException re = (RestServiceException) e.getCause(); Assert.assertEquals("Unexpected RestServerErrorCode (Future)", RestServiceErrorCode.ServiceUnavailable, re.getErrorCode()); }; TestUtils.assertException(ExecutionException.class, () -> serverSecurityService.validateConnection(sslSession).get(), errorAction); }
@Override public void validateConnection(SSLSession sslSession, Callback<Void> callback) { Exception exception = null; serverMetrics.securityServiceValidateConnectionRate.mark(); if (!isOpen) { exception = new RestServiceException("ServerSecurityService is closed", RestServiceErrorCode.ServiceUnavailable); } else if (sslSession == null) { throw new IllegalArgumentException("sslSession is null"); } callback.onCompletion(null, exception); }
AmbryServerSecurityService implements ServerSecurityService { @Override public void validateConnection(SSLSession sslSession, Callback<Void> callback) { Exception exception = null; serverMetrics.securityServiceValidateConnectionRate.mark(); if (!isOpen) { exception = new RestServiceException("ServerSecurityService is closed", RestServiceErrorCode.ServiceUnavailable); } else if (sslSession == null) { throw new IllegalArgumentException("sslSession is null"); } callback.onCompletion(null, exception); } }
AmbryServerSecurityService implements ServerSecurityService { @Override public void validateConnection(SSLSession sslSession, Callback<Void> callback) { Exception exception = null; serverMetrics.securityServiceValidateConnectionRate.mark(); if (!isOpen) { exception = new RestServiceException("ServerSecurityService is closed", RestServiceErrorCode.ServiceUnavailable); } else if (sslSession == null) { throw new IllegalArgumentException("sslSession is null"); } callback.onCompletion(null, exception); } AmbryServerSecurityService(ServerConfig serverConfig, ServerMetrics serverMetrics); }
AmbryServerSecurityService implements ServerSecurityService { @Override public void validateConnection(SSLSession sslSession, Callback<Void> callback) { Exception exception = null; serverMetrics.securityServiceValidateConnectionRate.mark(); if (!isOpen) { exception = new RestServiceException("ServerSecurityService is closed", RestServiceErrorCode.ServiceUnavailable); } else if (sslSession == null) { throw new IllegalArgumentException("sslSession is null"); } callback.onCompletion(null, exception); } AmbryServerSecurityService(ServerConfig serverConfig, ServerMetrics serverMetrics); @Override void validateConnection(SSLSession sslSession, Callback<Void> callback); @Override void validateRequest(RestRequest restRequest, Callback<Void> callback); @Override void close(); }
AmbryServerSecurityService implements ServerSecurityService { @Override public void validateConnection(SSLSession sslSession, Callback<Void> callback) { Exception exception = null; serverMetrics.securityServiceValidateConnectionRate.mark(); if (!isOpen) { exception = new RestServiceException("ServerSecurityService is closed", RestServiceErrorCode.ServiceUnavailable); } else if (sslSession == null) { throw new IllegalArgumentException("sslSession is null"); } callback.onCompletion(null, exception); } AmbryServerSecurityService(ServerConfig serverConfig, ServerMetrics serverMetrics); @Override void validateConnection(SSLSession sslSession, Callback<Void> callback); @Override void validateRequest(RestRequest restRequest, Callback<Void> callback); @Override void close();  }