You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ma...@apache.org on 2022/11/04 13:21:39 UTC

[flink] branch master updated (cf3158b21bf -> b9c5799927b)

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

mapohl pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git


    from cf3158b21bf Revert "[FLINK-29862] Upgrade to flink-shaded 16.0"
     new 73396900103 [FLINK-29198][test] Fail after maximum RetryOnException
     new 0e27854c277 [FLINK-27740][test] Revert JUnit5 migration for RetryOnFailureTest
     new b9c5799927b [hotfix][test] Clarify javadoc exceptions

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../retry/strategy/RetryOnExceptionStrategy.java   | 11 ++++-
 .../extensions/retry/strategy/RetryStrategy.java   |  8 ++-
 .../junit/RetryOnExceptionExtensionTest.java       | 57 +++++++++++++++++++---
 .../testutils/junit/RetryOnExceptionTest.java      | 35 +++++++------
 .../junit/RetryOnFailureExtensionTest.java         |  2 +-
 .../flink/testutils/junit/RetryOnFailureTest.java  | 31 ++++++------
 6 files changed, 101 insertions(+), 43 deletions(-)


[flink] 02/03: [FLINK-27740][test] Revert JUnit5 migration for RetryOnFailureTest

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mapohl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git

commit 0e27854c27707d440977efab90d59f5a8da2ae1e
Author: Ryan Skraba <rs...@apache.org>
AuthorDate: Fri Oct 21 17:32:01 2022 +0200

    [FLINK-27740][test] Revert JUnit5 migration for RetryOnFailureTest
    
    It's actually meant to test the JUnit4 RetryRule feature. The corresponding JUnit5 Extension is tested in `RetryOnFailureExtensionTest`.
---
 .../testutils/junit/RetryOnExceptionTest.java      | 35 +++++++++++-----------
 .../flink/testutils/junit/RetryOnFailureTest.java  | 31 ++++++++++---------
 2 files changed, 32 insertions(+), 34 deletions(-)

diff --git a/flink-test-utils-parent/flink-test-utils-junit/src/test/java/org/apache/flink/testutils/junit/RetryOnExceptionTest.java b/flink-test-utils-parent/flink-test-utils-junit/src/test/java/org/apache/flink/testutils/junit/RetryOnExceptionTest.java
index 1aa104aa9b2..0f32b54d71d 100644
--- a/flink-test-utils-parent/flink-test-utils-junit/src/test/java/org/apache/flink/testutils/junit/RetryOnExceptionTest.java
+++ b/flink-test-utils-parent/flink-test-utils-junit/src/test/java/org/apache/flink/testutils/junit/RetryOnExceptionTest.java
@@ -18,17 +18,16 @@
 
 package org.apache.flink.testutils.junit;
 
-import org.apache.flink.testutils.junit.extensions.retry.RetryExtension;
-
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.TestTemplate;
-import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.AfterClass;
+import org.junit.Rule;
+import org.junit.Test;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-/** Tests for the RetryOnException annotation. */
-@ExtendWith(RetryExtension.class)
-class RetryOnExceptionTest {
+/** Tests for the {@link RetryOnException} annotation on JUnit4 {@link RetryRule}. */
+public class RetryOnExceptionTest {
+
+    @Rule public RetryRule retryRule = new RetryRule();
 
     private static final int NUMBER_OF_RUNS = 3;
 
@@ -40,41 +39,41 @@ class RetryOnExceptionTest {
 
     private static int runsForPassAfterOneFailure = 0;
 
-    @AfterAll
+    @AfterClass
     public static void verify() {
         assertThat(runsForTestWithMatchingException).isEqualTo(NUMBER_OF_RUNS + 1);
         assertThat(runsForTestWithSubclassException).isEqualTo(NUMBER_OF_RUNS + 1);
-        assertThat(runsForSuccessfulTest).isEqualTo(1);
+        assertThat(runsForSuccessfulTest).isOne();
         assertThat(runsForPassAfterOneFailure).isEqualTo(2);
     }
 
-    @TestTemplate
+    @Test
     @RetryOnException(times = NUMBER_OF_RUNS, exception = IllegalArgumentException.class)
-    void testSuccessfulTest() {
+    public void testSuccessfulTest() {
         runsForSuccessfulTest++;
     }
 
-    @TestTemplate
+    @Test
     @RetryOnException(times = NUMBER_OF_RUNS, exception = IllegalArgumentException.class)
-    void testMatchingException() {
+    public void testMatchingException() {
         runsForTestWithMatchingException++;
         if (runsForTestWithMatchingException <= NUMBER_OF_RUNS) {
             throw new IllegalArgumentException();
         }
     }
 
-    @TestTemplate
+    @Test
     @RetryOnException(times = NUMBER_OF_RUNS, exception = RuntimeException.class)
-    void testSubclassException() {
+    public void testSubclassException() {
         runsForTestWithSubclassException++;
         if (runsForTestWithSubclassException <= NUMBER_OF_RUNS) {
             throw new IllegalArgumentException();
         }
     }
 
-    @TestTemplate
+    @Test
     @RetryOnException(times = NUMBER_OF_RUNS, exception = IllegalArgumentException.class)
-    void testPassAfterOneFailure() {
+    public void testPassAfterOneFailure() {
         runsForPassAfterOneFailure++;
         if (runsForPassAfterOneFailure == 1) {
             throw new IllegalArgumentException();
diff --git a/flink-test-utils-parent/flink-test-utils-junit/src/test/java/org/apache/flink/testutils/junit/RetryOnFailureTest.java b/flink-test-utils-parent/flink-test-utils-junit/src/test/java/org/apache/flink/testutils/junit/RetryOnFailureTest.java
index d0b551ccbb7..3fdf9c0cda2 100644
--- a/flink-test-utils-parent/flink-test-utils-junit/src/test/java/org/apache/flink/testutils/junit/RetryOnFailureTest.java
+++ b/flink-test-utils-parent/flink-test-utils-junit/src/test/java/org/apache/flink/testutils/junit/RetryOnFailureTest.java
@@ -18,17 +18,16 @@
 
 package org.apache.flink.testutils.junit;
 
-import org.apache.flink.testutils.junit.extensions.retry.RetryExtension;
-
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.TestTemplate;
-import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.AfterClass;
+import org.junit.Rule;
+import org.junit.Test;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-/** Tests for the RetryOnFailure annotation. */
-@ExtendWith(RetryExtension.class)
-class RetryOnFailureTest {
+/** Tests for the {@link RetryOnFailure} annotation on JUnit4 {@link RetryRule}. */
+public class RetryOnFailureTest {
+
+    @Rule public RetryRule retryRule = new RetryRule();
 
     private static final int NUMBER_OF_RUNS = 5;
 
@@ -38,15 +37,15 @@ class RetryOnFailureTest {
 
     private static boolean firstRun = true;
 
-    @AfterAll
-    static void verify() {
+    @AfterClass
+    public static void verify() throws Exception {
         assertThat(numberOfFailedRuns).isEqualTo(NUMBER_OF_RUNS + 1);
         assertThat(numberOfSuccessfulRuns).isEqualTo(3);
     }
 
-    @TestTemplate
+    @Test
     @RetryOnFailure(times = NUMBER_OF_RUNS)
-    void testRetryOnFailure() {
+    public void testRetryOnFailure() throws Exception {
         // All but the (expected) last run should be successful
         if (numberOfFailedRuns < NUMBER_OF_RUNS) {
             numberOfFailedRuns++;
@@ -56,9 +55,9 @@ class RetryOnFailureTest {
         }
     }
 
-    @TestTemplate
+    @Test
     @RetryOnFailure(times = NUMBER_OF_RUNS)
-    void testRetryOnceOnFailure() {
+    public void testRetryOnceOnFailure() throws Exception {
         if (firstRun) {
             numberOfFailedRuns++;
             firstRun = false;
@@ -68,9 +67,9 @@ class RetryOnFailureTest {
         }
     }
 
-    @TestTemplate
+    @Test
     @RetryOnFailure(times = NUMBER_OF_RUNS)
-    void testDontRetryOnSuccess() {
+    public void testDontRetryOnSuccess() throws Exception {
         numberOfSuccessfulRuns++;
     }
 }


[flink] 03/03: [hotfix][test] Clarify javadoc exceptions

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mapohl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git

commit b9c5799927b13e70b01e14faa0e467eb6d0a3edc
Author: Ryan Skraba <rs...@apache.org>
AuthorDate: Wed Oct 19 17:55:56 2022 +0200

    [hotfix][test] Clarify javadoc exceptions
---
 .../testutils/junit/extensions/retry/strategy/RetryStrategy.java  | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/testutils/junit/extensions/retry/strategy/RetryStrategy.java b/flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/testutils/junit/extensions/retry/strategy/RetryStrategy.java
index f6f9adc020a..fa893cb7387 100644
--- a/flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/testutils/junit/extensions/retry/strategy/RetryStrategy.java
+++ b/flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/testutils/junit/extensions/retry/strategy/RetryStrategy.java
@@ -27,11 +27,17 @@ public interface RetryStrategy {
     void stopFollowingAttempts();
 
     /**
-     * Handle the exception after the test execution.
+     * Handle an exception that occurred during the annotated test attempt.
+     *
+     * <p>This method can swallow the exception to pass the test.
      *
      * @param testName the test name
      * @param attemptIndex test attempt index that starts from 1
      * @param throwable the throwable that the test case throws
+     * @throws org.opentest4j.TestAbortedException When handling a test attempt failure, throwing
+     *     this exception indicates another attempt should be made.
+     * @throws Throwable Propagating the original exception, or throwing any other exception
+     *     indicates that the test has definitively failed and no further attempts should be made.
      */
     void handleException(String testName, int attemptIndex, Throwable throwable) throws Throwable;
 }


[flink] 01/03: [FLINK-29198][test] Fail after maximum RetryOnException

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mapohl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git

commit 733969001036b1263bd798433e229816acff1658
Author: Ryan Skraba <rs...@apache.org>
AuthorDate: Fri Oct 21 17:31:27 2022 +0200

    [FLINK-29198][test] Fail after maximum RetryOnException
    
    Co-authored-by: Sergey Nuyanzin <se...@aiven.io>
---
 .../retry/strategy/RetryOnExceptionStrategy.java   | 11 ++++-
 .../junit/RetryOnExceptionExtensionTest.java       | 57 +++++++++++++++++++---
 .../junit/RetryOnFailureExtensionTest.java         |  2 +-
 3 files changed, 62 insertions(+), 8 deletions(-)

diff --git a/flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/testutils/junit/extensions/retry/strategy/RetryOnExceptionStrategy.java b/flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/testutils/junit/extensions/retry/strategy/RetryOnExceptionStrategy.java
index 68dc1ec512d..4c829afa564 100644
--- a/flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/testutils/junit/extensions/retry/strategy/RetryOnExceptionStrategy.java
+++ b/flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/testutils/junit/extensions/retry/strategy/RetryOnExceptionStrategy.java
@@ -22,7 +22,10 @@ import org.opentest4j.TestAbortedException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/** Retry strategy that retry fixed times, and will not fail with some kind of exception. */
+/**
+ * A retry strategy that will ignore a specific type of exception and retry a test if it occurs, up
+ * to a fixed number of times.
+ */
 public class RetryOnExceptionStrategy extends AbstractRetryStrategy {
     private static final Logger LOG = LoggerFactory.getLogger(RetryOnExceptionStrategy.class);
 
@@ -37,6 +40,12 @@ public class RetryOnExceptionStrategy extends AbstractRetryStrategy {
     @Override
     public void handleException(String testName, int attemptIndex, Throwable throwable)
             throws Throwable {
+        // Failed when reach the total retry times
+        if (attemptIndex >= totalTimes) {
+            LOG.error("Test Failed at the last retry.", throwable);
+            throw throwable;
+        }
+
         if (repeatableException.isAssignableFrom(throwable.getClass())) {
             // continue retrying when get some repeatable exceptions
             String retryMsg =
diff --git a/flink-test-utils-parent/flink-test-utils-junit/src/test/java/org/apache/flink/testutils/junit/RetryOnExceptionExtensionTest.java b/flink-test-utils-parent/flink-test-utils-junit/src/test/java/org/apache/flink/testutils/junit/RetryOnExceptionExtensionTest.java
index 980b7eeaad0..d1186a489f5 100644
--- a/flink-test-utils-parent/flink-test-utils-junit/src/test/java/org/apache/flink/testutils/junit/RetryOnExceptionExtensionTest.java
+++ b/flink-test-utils-parent/flink-test-utils-junit/src/test/java/org/apache/flink/testutils/junit/RetryOnExceptionExtensionTest.java
@@ -19,14 +19,21 @@
 package org.apache.flink.testutils.junit;
 
 import org.apache.flink.testutils.junit.extensions.retry.RetryExtension;
+import org.apache.flink.testutils.junit.extensions.retry.strategy.RetryOnExceptionStrategy;
 
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.TestTemplate;
 import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.opentest4j.TestAbortedException;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import java.util.stream.Stream;
 
-/** Tests for the RetryOnException annotation. */
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/** Tests for the {@link RetryOnException} annotation on JUnit5 {@link RetryExtension}. */
 @ExtendWith(RetryExtension.class)
 class RetryOnExceptionExtensionTest {
 
@@ -42,10 +49,10 @@ class RetryOnExceptionExtensionTest {
 
     @AfterAll
     static void verify() {
-        assertEquals(NUMBER_OF_RUNS + 1, runsForTestWithMatchingException);
-        assertEquals(NUMBER_OF_RUNS + 1, runsForTestWithSubclassException);
-        assertEquals(1, runsForSuccessfulTest);
-        assertEquals(2, runsForPassAfterOneFailure);
+        assertThat(runsForTestWithMatchingException).isEqualTo(NUMBER_OF_RUNS + 1);
+        assertThat(runsForTestWithSubclassException).isEqualTo(NUMBER_OF_RUNS + 1);
+        assertThat(runsForSuccessfulTest).isOne();
+        assertThat(runsForPassAfterOneFailure).isEqualTo(2);
     }
 
     @TestTemplate
@@ -80,4 +87,42 @@ class RetryOnExceptionExtensionTest {
             throw new IllegalArgumentException();
         }
     }
+
+    @ParameterizedTest(name = "Retrying with {0}")
+    @MethodSource("retryTestProvider")
+    void testRetryFailsWithExpectedExceptionAfterNumberOfRetries(
+            final Throwable expectedException) {
+        final int numberOfRetries = 1;
+        RetryOnExceptionStrategy retryOnExceptionStrategy =
+                new RetryOnExceptionStrategy(numberOfRetries, expectedException.getClass());
+        // All attempts that permit a retry should be a TestAbortedException.  When retries are no
+        // longer permitted, the handled exception should be propagated.
+        for (int j = 0; j <= numberOfRetries; j++) {
+            final int attemptIndex = j;
+            assertThatThrownBy(
+                            () ->
+                                    retryOnExceptionStrategy.handleException(
+                                            "Any test name", attemptIndex, expectedException))
+                    .isInstanceOf(
+                            j == numberOfRetries
+                                    ? expectedException.getClass()
+                                    : TestAbortedException.class);
+        }
+    }
+
+    static class RetryTestError extends Error {}
+
+    static class RetryTestException extends Exception {}
+
+    static class RetryTestRuntimeException extends RuntimeException {}
+
+    static class RetryTestThrowable extends Throwable {}
+
+    static Stream<Throwable> retryTestProvider() {
+        return Stream.of(
+                new RetryTestError(),
+                new RetryTestException(),
+                new RetryTestRuntimeException(),
+                new RetryTestThrowable());
+    }
 }
diff --git a/flink-test-utils-parent/flink-test-utils-junit/src/test/java/org/apache/flink/testutils/junit/RetryOnFailureExtensionTest.java b/flink-test-utils-parent/flink-test-utils-junit/src/test/java/org/apache/flink/testutils/junit/RetryOnFailureExtensionTest.java
index 8cb146e3f50..703c035ca00 100644
--- a/flink-test-utils-parent/flink-test-utils-junit/src/test/java/org/apache/flink/testutils/junit/RetryOnFailureExtensionTest.java
+++ b/flink-test-utils-parent/flink-test-utils-junit/src/test/java/org/apache/flink/testutils/junit/RetryOnFailureExtensionTest.java
@@ -26,7 +26,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
-/** Tests for the RetryOnFailure annotation. */
+/** Tests for the {@link RetryOnFailure} annotation on JUnit5 {@link RetryExtension}. */
 @ExtendWith(RetryExtension.class)
 class RetryOnFailureExtensionTest {