Skip to content

Commit

Permalink
[FLINK-27740][test] Revert JUnit5 migration for RetryOnFailureTest
Browse files Browse the repository at this point in the history
It's actually meant to test the JUnit4 RetryRule feature. The corresponding JUnit5 Extension is tested in `RetryOnFailureExtensionTest`.
  • Loading branch information
RyanSkraba authored and XComp committed Nov 4, 2022
1 parent 7339690 commit 0e27854
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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++;
Expand All @@ -56,9 +55,9 @@ void testRetryOnFailure() {
}
}

@TestTemplate
@Test
@RetryOnFailure(times = NUMBER_OF_RUNS)
void testRetryOnceOnFailure() {
public void testRetryOnceOnFailure() throws Exception {
if (firstRun) {
numberOfFailedRuns++;
firstRun = false;
Expand All @@ -68,9 +67,9 @@ void testRetryOnceOnFailure() {
}
}

@TestTemplate
@Test
@RetryOnFailure(times = NUMBER_OF_RUNS)
void testDontRetryOnSuccess() {
public void testDontRetryOnSuccess() throws Exception {
numberOfSuccessfulRuns++;
}
}

0 comments on commit 0e27854

Please sign in to comment.