[flink] 01/03: [hotfix] Migrate DefaultSchedulerTest to Junit5 and AssertJ.
This is an automated email from the ASF dual-hosted git repository. zhuzh pushed a commit to branch release-1.17 in repository https://gitbox.apache.org/repos/asf/flink.git commit 6f30f5b3cde5bb2b3a20bc9699950694e84278a1 Author: JunRuiLee AuthorDate: Wed Feb 15 18:30:03 2023 +0800 [hotfix] Migrate DefaultSchedulerTest to Junit5 and AssertJ. --- .../runtime/scheduler/DefaultSchedulerTest.java| 453 ++--- .../ExceptionHistoryEntryTestingUtils.java | 90 2 files changed, 308 insertions(+), 235 deletions(-) diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/DefaultSchedulerTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/DefaultSchedulerTest.java index 59122521cb2..49ba055732b 100644 --- a/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/DefaultSchedulerTest.java +++ b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/DefaultSchedulerTest.java @@ -75,7 +75,7 @@ import org.apache.flink.runtime.metrics.MetricRegistry; import org.apache.flink.runtime.metrics.groups.JobManagerMetricGroup; import org.apache.flink.runtime.metrics.util.TestingMetricRegistry; import org.apache.flink.runtime.scheduler.adaptive.AdaptiveSchedulerTest; -import org.apache.flink.runtime.scheduler.exceptionhistory.ExceptionHistoryEntryMatcher; +import org.apache.flink.runtime.scheduler.exceptionhistory.ExceptionHistoryEntryTestingUtils; import org.apache.flink.runtime.scheduler.exceptionhistory.RootExceptionHistoryEntry; import org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID; import org.apache.flink.runtime.scheduler.strategy.PipelinedRegionSchedulingStrategy; @@ -99,16 +99,9 @@ import org.apache.flink.util.concurrent.ScheduledExecutor; import org.apache.flink.shaded.guava30.com.google.common.collect.Iterables; -import org.hamcrest.collection.IsEmptyIterable; -import org.hamcrest.collection.IsIterableContainingInOrder; -import org.hamcrest.collection.IsIterableWithSize; -import org.hamcrest.core.Is; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import java.time.Duration; @@ -141,28 +134,14 @@ import static org.apache.flink.runtime.scheduler.SchedulerTestingUtils.enableChe import static org.apache.flink.runtime.scheduler.SchedulerTestingUtils.getCheckpointCoordinator; import static org.apache.flink.util.ExceptionUtils.findThrowable; import static org.apache.flink.util.ExceptionUtils.findThrowableWithMessage; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** Tests for {@link DefaultScheduler}. */ public class DefaultSchedulerTest extends TestLogger { private static final int TIMEOUT_MS = 1000; -@ClassRule public static final TemporaryFolder TEMPORARY_FOLDER = new TemporaryFolder(); - private final ManuallyTriggeredScheduledExecutor taskRestartExecutor = new ManuallyTriggeredScheduledExecutor(); @@ -188,8 +167,8 @@ public class DefaultSchedulerTest extends TestLogger { private Time timeout; -@Before -public void setUp() throws Exception { +@BeforeEach +void setUp() { executor = Executors.newSingleThreadExecutor(); scheduledExecutorService = new DirectScheduledExecutorService(); @@ -211,8 +190,8 @@ public class DefaultSchedulerTest extends TestLogger { timeout = Time.seconds(60); } -@After -public void tearDown() throws Exception { +@AfterEach +void tearDown() { if (scheduledExecutorService != null) { ExecutorUtils.gracefulShutdown( TIMEOUT_MS, TimeUnit.MILLISECONDS, scheduledExecutorService); @@ -224,7 +203,7 @@ public class DefaultSchedulerTest extends TestLogger { } @Test -public void startScheduling() { +void startScheduling() { final JobGraph jobGraph = singleNonParallelJobVertexJobGraph(); final JobVertex onlyJobVertex = getOnlyJobVertex(jobGraph); @@ -234,11 +213,11 @@ public class
[flink] 01/03: [hotfix] Migrate DefaultSchedulerTest to Junit5 and AssertJ.
This is an automated email from the ASF dual-hosted git repository. zhuzh pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/flink.git commit 0351f88cea26dc57ca7aeb78564a8e2acffc505a Author: JunRuiLee AuthorDate: Wed Feb 15 18:30:03 2023 +0800 [hotfix] Migrate DefaultSchedulerTest to Junit5 and AssertJ. --- .../runtime/scheduler/DefaultSchedulerTest.java| 453 ++--- .../ExceptionHistoryEntryTestingUtils.java | 90 2 files changed, 308 insertions(+), 235 deletions(-) diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/DefaultSchedulerTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/DefaultSchedulerTest.java index 59122521cb2..49ba055732b 100644 --- a/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/DefaultSchedulerTest.java +++ b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/DefaultSchedulerTest.java @@ -75,7 +75,7 @@ import org.apache.flink.runtime.metrics.MetricRegistry; import org.apache.flink.runtime.metrics.groups.JobManagerMetricGroup; import org.apache.flink.runtime.metrics.util.TestingMetricRegistry; import org.apache.flink.runtime.scheduler.adaptive.AdaptiveSchedulerTest; -import org.apache.flink.runtime.scheduler.exceptionhistory.ExceptionHistoryEntryMatcher; +import org.apache.flink.runtime.scheduler.exceptionhistory.ExceptionHistoryEntryTestingUtils; import org.apache.flink.runtime.scheduler.exceptionhistory.RootExceptionHistoryEntry; import org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID; import org.apache.flink.runtime.scheduler.strategy.PipelinedRegionSchedulingStrategy; @@ -99,16 +99,9 @@ import org.apache.flink.util.concurrent.ScheduledExecutor; import org.apache.flink.shaded.guava30.com.google.common.collect.Iterables; -import org.hamcrest.collection.IsEmptyIterable; -import org.hamcrest.collection.IsIterableContainingInOrder; -import org.hamcrest.collection.IsIterableWithSize; -import org.hamcrest.core.Is; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import java.time.Duration; @@ -141,28 +134,14 @@ import static org.apache.flink.runtime.scheduler.SchedulerTestingUtils.enableChe import static org.apache.flink.runtime.scheduler.SchedulerTestingUtils.getCheckpointCoordinator; import static org.apache.flink.util.ExceptionUtils.findThrowable; import static org.apache.flink.util.ExceptionUtils.findThrowableWithMessage; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** Tests for {@link DefaultScheduler}. */ public class DefaultSchedulerTest extends TestLogger { private static final int TIMEOUT_MS = 1000; -@ClassRule public static final TemporaryFolder TEMPORARY_FOLDER = new TemporaryFolder(); - private final ManuallyTriggeredScheduledExecutor taskRestartExecutor = new ManuallyTriggeredScheduledExecutor(); @@ -188,8 +167,8 @@ public class DefaultSchedulerTest extends TestLogger { private Time timeout; -@Before -public void setUp() throws Exception { +@BeforeEach +void setUp() { executor = Executors.newSingleThreadExecutor(); scheduledExecutorService = new DirectScheduledExecutorService(); @@ -211,8 +190,8 @@ public class DefaultSchedulerTest extends TestLogger { timeout = Time.seconds(60); } -@After -public void tearDown() throws Exception { +@AfterEach +void tearDown() { if (scheduledExecutorService != null) { ExecutorUtils.gracefulShutdown( TIMEOUT_MS, TimeUnit.MILLISECONDS, scheduledExecutorService); @@ -224,7 +203,7 @@ public class DefaultSchedulerTest extends TestLogger { } @Test -public void startScheduling() { +void startScheduling() { final JobGraph jobGraph = singleNonParallelJobVertexJobGraph(); final JobVertex onlyJobVertex = getOnlyJobVertex(jobGraph); @@ -234,11 +213,11 @@ public class