From a6785726bcabd91eaf854a26506f6acad9a4ed4e Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Mon, 4 Nov 2024 21:47:42 +0100 Subject: [PATCH] add test for timeout configuration --- .../java/commercetools/TimeoutTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/commercetools/commercetools-sdk-java-api/src/integrationTest/java/commercetools/TimeoutTest.java b/commercetools/commercetools-sdk-java-api/src/integrationTest/java/commercetools/TimeoutTest.java index 4bd62c8d032..86996387f3b 100644 --- a/commercetools/commercetools-sdk-java-api/src/integrationTest/java/commercetools/TimeoutTest.java +++ b/commercetools/commercetools-sdk-java-api/src/integrationTest/java/commercetools/TimeoutTest.java @@ -58,4 +58,39 @@ public void timeoutWithRetry() { .getBody(); }); } + + @Test + public void timeoutWithRetryTimeout() { + String projectKey = CommercetoolsTestUtils.getProjectKey(); + + ProjectApiRoot b = ApiRootBuilder.of() + .defaultClient(ClientCredentials.of() + .withClientId(CommercetoolsTestUtils.getClientId()) + .withClientSecret(CommercetoolsTestUtils.getClientSecret()) + .build(), + ServiceRegion.GCP_EUROPE_WEST1) + .withTelemetryMiddleware((request, next) -> next.apply(request).thenApply((response) -> { + try { + Thread.sleep(15000); // ensure timeout + } + catch (InterruptedException e) { + throw new RuntimeException(e); + } + return response; + })) + .withPolicies(policyBuilder -> policyBuilder.withTimeout(Duration.ofSeconds(7)) + .withRetry(builder -> builder.maxRetries(3) + .statusCodes(singletonList(HttpStatusCode.NOT_FOUND_404)) + .failures(singletonList(TimeoutExceededException.class))) + .withTimeout(Duration.ofSeconds(3))) + .build(projectKey); + + Assertions.assertThatExceptionOfType(TimeoutExceededException.class).isThrownBy(() -> { + Category category = b.categories() + .withId("fdbaf4ea-fbc9-4fea-bac4-1d7e6c1995b3") + .get() + .executeBlocking() + .getBody(); + }); + } }