Skip to content

Commit a65647f

Browse files
DEVX-786 don't retry delete requests on concurrent modification (#1062)
* don't retry delete requests on concurrent modification * spotless: Fix code style * spotless: add commit to blame ignore revs file --------- Co-authored-by: ct-sdks[bot] <153784748+ct-sdks[bot]@users.noreply.github.com>
1 parent ff0fd0d commit a65647f

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

.git-blame-ignore-revs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ c4e2bf407aa0b7a3d34605134791013ba8a2d376
2626
f00f4fe6ed5e22cdd2e3f68370c2da96e6bbc8e7
2727
899ed51a7b6607161fcda5c1000115a076cc4fe7
2828
53b9d9cc4fc4091b89f84effb6e526371d3bae68
29+
4822581aeff072b7649c7aec56a13a95bd58c249

commercetools/commercetools-sdk-java-api/src/integrationTest/java/commercetools/ConcurrentModificationTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,36 @@ public void concurrentModMiddleware() {
242242
});
243243
}
244244

245+
@Test
246+
public void concurrentModMiddlewareDelete() {
247+
String projectKey = CommercetoolsTestUtils.getProjectKey();
248+
249+
ProjectApiRoot projectApiRoot = ApiRootBuilder.of()
250+
.defaultClient(ClientCredentials.of()
251+
.withClientId(CommercetoolsTestUtils.getClientId())
252+
.withClientSecret(CommercetoolsTestUtils.getClientSecret())
253+
.build(),
254+
ServiceRegion.GCP_EUROPE_WEST1)
255+
.addConcurrentModificationMiddleware(3)
256+
.build(projectKey);
257+
258+
CartsFixtures.withUpdateableCart(cart -> {
259+
260+
final ApiHttpResponse<Cart> deCart = projectApiRoot.carts()
261+
.withId(cart.getId())
262+
.post(CartUpdateBuilder.of()
263+
.version(cart.getVersion())
264+
.actions(CartSetCountryActionBuilder.of().country("DE").build())
265+
.build())
266+
.executeBlocking();
267+
268+
Assertions.assertThatExceptionOfType(ConcurrentModificationException.class)
269+
.isThrownBy(() -> projectApiRoot.carts().delete(cart).executeBlocking());
270+
271+
return deCart.getBody();
272+
});
273+
}
274+
245275
@Test
246276
public void testInfoLoggerException() {
247277

commercetools/commercetools-sdk-java-api/src/main/java/com/commercetools/api/client/ConcurrentModificationMiddlewareImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ public ConcurrentModificationMiddlewareImpl(final int maxRetries, final long del
6565
.withMaxRetries(maxRetries)
6666
.onRetry(this::logEventFailure)
6767
.handle(ConcurrentModificationException.class)
68+
.abortIf((result, exception) -> {
69+
if (exception instanceof ConcurrentModificationException
70+
&& ((ConcurrentModificationException) exception).getRequest() != null) {
71+
return ((ConcurrentModificationException) exception).getRequest()
72+
.getMethod() == ApiHttpMethod.DELETE;
73+
}
74+
return false;
75+
})
6876
.build();
6977
this.executor = Failsafe.with(retryPolicy);
7078
}

0 commit comments

Comments
 (0)