@Override public void close() { delegate.close(); }
@Override public void close() { delegate.close(); }
@Override public void close() { delegate.close(); }
@Override public void close() { delegate.close(); }
@Override public void close() { delegate.close(); }
@Override public void close() { delegate.close(); }
@Override public void close() { delegate.close(); }
public void close() { underlying.close(); }
@Override public SphereClient get() { SphereClient sphereClient = SphereClient.of(sphereClientConfig, httpClient, sphereAccessTokenSupplier); logger.info("Provide SphereClient"); applicationLifecycle.addStopHook(() -> { sphereClient.close(); return completedFuture(null); }); return sphereClient; }
@Override public void cancel() { if (subscriptionIsCanceled()) { noOp(); } else { executor.shutdownNow(); executor = null; subscriber = null; sphereClient.close(); sphereClient = null; seedQuery = null; lastId = null; } }
private void expectExceptionAndClose(final SphereClient client, final Class<InvalidTokenException> exceptionClass, final CompletionStage<PagedQueryResult<Category>> stage) throws Throwable { thrown.expect(exceptionClass); try { stage.toCompletableFuture().join(); } catch (final CompletionException e) { client.close(); throw e.getCause(); } }
@Test public void autoLoadHttpClientWithoutExplicitSpecification() { if (!"false".equals(System.getenv("JVM_SDK_IT_SSL_VALIDATION"))) { final SphereClientFactory sphereClientFactory = SphereClientFactory.of(); final SphereClient client = sphereClientFactory.createClient(getSphereClientConfig()); final PagedQueryResult<Category> queryResult = client.execute(CategoryQuery.of()).toCompletableFuture().join(); assertThat(queryResult).isNotNull(); client.close(); } }
@Test public void clientAlreadyClosed() throws Exception { if (!"false".equals(System.getenv("JVM_SDK_IT_SSL_VALIDATION"))) { try (final SphereClient client = SphereClientFactory.of().createClient(getSphereClientConfig())) { client.close(); assertThatThrownBy(() -> client.execute(ProjectGet.of())) .isInstanceOf(IllegalStateException.class); } } }
/** * This is a test if no threads are blocking the the termination of the application. Needs to be executed on the ci server. * In case it has a leak, it just hangs. * This is necessary, since a unit test cannot cover this termination problem. * @param args unused command line parameters */ public static void main(String[] args) throws InterruptedException, ExecutionException, TimeoutException { final SphereClient client = SphereClientFactory.of() .createClient(SphereClientConfig.ofEnvironmentVariables("JVM_SDK_IT")); final CompletionStage<PagedQueryResult<ProductProjection>> stage = client.execute(ProductProjectionQuery.ofStaged()); stage.toCompletableFuture().get(10, TimeUnit.SECONDS); client.close(); } }
@Test public void requestsArePossible() throws Exception { withCategory(client(), category -> { final CategoryQuery categoryQuery = CategoryQuery.of(); final SphereApiConfig apiConfig = SphereApiConfig.of(getSphereClientConfig().getProjectKey(), getSphereClientConfig().getApiUrl()); final SphereAuthConfig authConfig = SphereAuthConfig.of(getSphereClientConfig().getProjectKey(), getSphereClientConfig().getClientId(), getSphereClientConfig().getClientSecret(), getSphereClientConfig().getAuthUrl()); final SphereAccessTokenSupplier fixedTokenSupplier = SphereAccessTokenSupplier.ofOneTimeFetchingToken(authConfig, newHttpClient(), true); final SphereClient oneTokenClient = SphereClient.of(apiConfig, newHttpClient(), fixedTokenSupplier); final Long actual = oneTokenClient.execute(categoryQuery).toCompletableFuture().join().getTotal(); assertThat(actual).isGreaterThanOrEqualTo(1); oneTokenClient.close(); }); } }