This is an automated email from the ASF dual-hosted git repository.

He-Pin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko.git


The following commit(s) were added to refs/heads/main by this push:
     new fd478baa90 test: add Java test for retry short-circuit with Predicate2 
(#3435)
fd478baa90 is described below

commit fd478baa903d2ad8e3501bd5d381b88a96d47a32
Author: He-Pin(kerr) <[email protected]>
AuthorDate: Sat Aug 15 18:13:32 2026 +0800

    test: add Java test for retry short-circuit with Predicate2 (#3435)
    
    Motivation:
    The Java DSL Patterns.retry with Predicate2 (shouldRetry) has been
    available since 1.1.0 but lacks a directional test exercising the
    short-circuit behavior from Java. The Scala DSL has coverage in
    RetrySpec but the Java path is untested.
    
    Modification:
    Add testShortCircuitRetry to PatternsTest.java that verifies:
    - Retry continues when predicate returns true (IllegalStateException)
    - Retry stops immediately when predicate returns false 
(IllegalArgumentException)
    - Exactly 3 attempts are made (2 retriable + 1 non-retriable)
    
    Result:
    Java DSL retry short-circuit behavior is now covered by a directional
    test that would fail if the Predicate2 wiring were broken.
    
    Tests:
    - sbt "actor-tests / Test / testOnly org.apache.pekko.pattern.PatternsTest"
    
    References:
    Refs akka/akka-core#32035
---
 .../org/apache/pekko/pattern/PatternsTest.java     | 32 ++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git 
a/actor-tests/src/test/java/org/apache/pekko/pattern/PatternsTest.java 
b/actor-tests/src/test/java/org/apache/pekko/pattern/PatternsTest.java
index 258f83bfca..a89d08262a 100644
--- a/actor-tests/src/test/java/org/apache/pekko/pattern/PatternsTest.java
+++ b/actor-tests/src/test/java/org/apache/pekko/pattern/PatternsTest.java
@@ -338,6 +338,38 @@ public class PatternsTest {
     assertEquals(expected, actual);
   }
 
+  @Test
+  public void testShortCircuitRetry() throws Exception {
+    AtomicInteger failureCounter = new AtomicInteger();
+
+    final CompletableFuture<Object> ise = new CompletableFuture<>();
+    final CompletableFuture<Object> iae = new CompletableFuture<>();
+    ise.completeExceptionally(new IllegalStateException());
+    iae.completeExceptionally(new IllegalArgumentException());
+
+    CompletionStage<Object> retriedAttempts =
+        Patterns.retry(
+            () -> {
+              if ((failureCounter.getAndIncrement() % 3) < 2) {
+                return ise;
+              } else {
+                return iae;
+              }
+            },
+            (result, ex) -> !(ex instanceof IllegalArgumentException),
+            10,
+            ec);
+
+    try {
+      retriedAttempts.toCompletableFuture().get(3, SECONDS);
+      throw new AssertionError("future should have failed!");
+    } catch (java.util.concurrent.ExecutionException e) {
+      assertEquals(IllegalArgumentException.class, e.getCause().getClass());
+    }
+
+    assertEquals(3, failureCounter.get());
+  }
+
   @Test
   public void testAfterFailedCallable() throws Exception {
     Callable<CompletionStage<String>> failedCallable =


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to