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

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

commit c3f9142303a953f5048ed037c9efa417bacd94e5
Author: Weijie Guo <[email protected]>
AuthorDate: Mon Mar 13 22:51:41 2023 +0800

    [hotfix] Let ThreadInfoRequestCoordinatorTest more comply with the 
specifications of Junit and AssertJ.
---
 .../ThreadInfoRequestCoordinatorTest.java          | 45 +++++++++-------------
 1 file changed, 18 insertions(+), 27 deletions(-)

diff --git 
a/flink-runtime/src/test/java/org/apache/flink/runtime/webmonitor/threadinfo/ThreadInfoRequestCoordinatorTest.java
 
b/flink-runtime/src/test/java/org/apache/flink/runtime/webmonitor/threadinfo/ThreadInfoRequestCoordinatorTest.java
index f937ccd1c5d..f483de63822 100644
--- 
a/flink-runtime/src/test/java/org/apache/flink/runtime/webmonitor/threadinfo/ThreadInfoRequestCoordinatorTest.java
+++ 
b/flink-runtime/src/test/java/org/apache/flink/runtime/webmonitor/threadinfo/ThreadInfoRequestCoordinatorTest.java
@@ -24,8 +24,6 @@ import org.apache.flink.runtime.messages.ThreadInfoSample;
 import org.apache.flink.runtime.taskexecutor.IdleTestTask;
 import org.apache.flink.runtime.taskexecutor.TaskExecutorThreadInfoGateway;
 import org.apache.flink.runtime.util.JvmUtils;
-import org.apache.flink.util.ExceptionUtils;
-import org.apache.flink.util.TestLogger;
 
 import org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableSet;
 
@@ -52,13 +50,14 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.stream.Collectors;
 
+import static org.apache.flink.core.testutils.FlinkAssertions.anyCauseMatches;
 import static 
org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.createExecutionAttemptId;
 import static 
org.apache.flink.runtime.taskexecutor.IdleTestTask.executeWithTerminationGuarantee;
-import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
-import static org.assertj.core.api.Fail.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 /** Tests for the {@link ThreadInfoRequestCoordinator}. */
-public class ThreadInfoRequestCoordinatorTest extends TestLogger {
+class ThreadInfoRequestCoordinatorTest {
 
     private static final Duration REQUEST_TIMEOUT = Duration.ofMillis(100);
     private static final String REQUEST_TIMEOUT_MESSAGE = "Request timeout.";
@@ -71,34 +70,34 @@ public class ThreadInfoRequestCoordinatorTest extends 
TestLogger {
     private ThreadInfoRequestCoordinator coordinator;
 
     @BeforeAll
-    public static void setUp() throws Exception {
+    static void setUp() throws Exception {
         executorService = new ScheduledThreadPoolExecutor(1);
     }
 
     @AfterAll
-    public static void tearDown() throws Exception {
+    static void tearDown() throws Exception {
         if (executorService != null) {
             executorService.shutdown();
         }
     }
 
     @BeforeEach
-    public void initCoordinator() throws Exception {
+    void initCoordinator() {
         coordinator = new ThreadInfoRequestCoordinator(executorService, 
REQUEST_TIMEOUT);
     }
 
     @AfterEach
-    public void shutdownCoordinator() throws Exception {
+    void shutdownCoordinator() {
         if (coordinator != null) {
             // verify no more pending request
-            assertThat(coordinator.getNumberOfPendingRequests()).isEqualTo(0);
+            assertThat(coordinator.getNumberOfPendingRequests()).isZero();
             coordinator.shutDown();
         }
     }
 
     /** Tests successful thread info stats request. */
     @Test
-    public void testSuccessfulThreadInfoRequest() throws Exception {
+    void testSuccessfulThreadInfoRequest() throws Exception {
         Map<ImmutableSet<ExecutionAttemptID>, 
CompletableFuture<TaskExecutorThreadInfoGateway>>
                 executionWithGateways =
                         createMockSubtaskWithGateways(
@@ -127,7 +126,7 @@ public class ThreadInfoRequestCoordinatorTest extends 
TestLogger {
 
     /** Tests that failed thread info request to one of the tasks fails the 
future. */
     @Test
-    public void testThreadInfoRequestWithException() throws Exception {
+    void testThreadInfoRequestWithException() throws Exception {
         Map<ImmutableSet<ExecutionAttemptID>, 
CompletableFuture<TaskExecutorThreadInfoGateway>>
                 executionWithGateways =
                         createMockSubtaskWithGateways(
@@ -140,17 +139,14 @@ public class ThreadInfoRequestCoordinatorTest extends 
TestLogger {
                         DEFAULT_DELAY_BETWEEN_SAMPLES,
                         DEFAULT_MAX_STACK_TRACE_DEPTH);
 
-        try {
-            requestFuture.get();
-            fail("Exception expected.");
-        } catch (ExecutionException e) {
-            assertThat(e.getCause()).isInstanceOf(RuntimeException.class);
-        }
+        assertThatThrownBy(requestFuture::get, "The request must be failed.")
+                .isInstanceOf(ExecutionException.class)
+                .hasCauseInstanceOf(RuntimeException.class);
     }
 
     /** Tests that thread info stats request times out if not finished in 
time. */
     @Test
-    public void testThreadInfoRequestTimeout() throws Exception {
+    void testThreadInfoRequestTimeout() throws Exception {
         Map<ImmutableSet<ExecutionAttemptID>, 
CompletableFuture<TaskExecutorThreadInfoGateway>>
                 executionWithGateways =
                         createMockSubtaskWithGateways(
@@ -164,13 +160,8 @@ public class ThreadInfoRequestCoordinatorTest extends 
TestLogger {
                         DEFAULT_MAX_STACK_TRACE_DEPTH);
 
         try {
-            requestFuture.get();
-            fail("Exception expected.");
-        } catch (ExecutionException e) {
-            assertThat(
-                            ExceptionUtils.findThrowableWithMessage(e, 
REQUEST_TIMEOUT_MESSAGE)
-                                    .isPresent())
-                    .isTrue();
+            assertThatThrownBy(requestFuture::get, "The request must be 
failed.")
+                    .satisfies(anyCauseMatches(REQUEST_TIMEOUT_MESSAGE));
         } finally {
             coordinator.shutDown();
         }
@@ -178,7 +169,7 @@ public class ThreadInfoRequestCoordinatorTest extends 
TestLogger {
 
     /** Tests that shutdown fails all pending requests and future request 
triggers. */
     @Test
-    public void testShutDown() throws Exception {
+    void testShutDown() throws Exception {
         Map<ImmutableSet<ExecutionAttemptID>, 
CompletableFuture<TaskExecutorThreadInfoGateway>>
                 executionWithGateways =
                         createMockSubtaskWithGateways(

Reply via email to