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:22:54 UTC
[flink] branch release-1.15 updated: [FLINK-29198][test] Fail after maximum RetryOnException
This is an automated email from the ASF dual-hosted git repository.
mapohl pushed a commit to branch release-1.15
in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/release-1.15 by this push:
new b68f37cad6d [FLINK-29198][test] Fail after maximum RetryOnException
b68f37cad6d is described below
commit b68f37cad6dc5207692badfe970ae803143054f4
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 | 45 ++++++++++++++++++++++
.../junit/RetryOnFailureExtensionTest.java | 2 +-
3 files changed, 56 insertions(+), 2 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 2065e3ee8d5..6e99a59295b 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,11 +19,18 @@
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 java.util.stream.Stream;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
/** Tests for the RetryOnException annotation. */
@@ -80,4 +87,42 @@ public 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 13675d44115..1504a66ac7f 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)
public class RetryOnFailureExtensionTest {