You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "wangzzu (via GitHub)" <gi...@apache.org> on 2023/08/19 15:20:01 UTC

[GitHub] [flink] wangzzu opened a new pull request, #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

wangzzu opened a new pull request, #23242:
URL: https://github.com/apache/flink/pull/23242

   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   Migrate rest package related tests under flink-runtime module to junit5
   
   ## Brief change log
   
   Migrate rest package related tests under flink-runtime module to junit5
   
   ## Verifying this change
   
   This change is already covered by existing tests.
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): no 
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`:  no
     - The serializers: no
     - The runtime per-record code paths (performance sensitive): no
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
     - The S3 file system connector: no
   
   ## Documentation
   
     - Does this pull request introduce a new feature?  no
     - If yes, how is the feature documented? not documented
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] wangzzu commented on a diff in pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "wangzzu (via GitHub)" <gi...@apache.org>.
wangzzu commented on code in PR #23242:
URL: https://github.com/apache/flink/pull/23242#discussion_r1301142809


##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientTest.java:
##########
@@ -82,42 +79,39 @@ void testConnectionTimeout() throws Exception {
                             new TestMessageHeaders(),
                             EmptyMessageParameters.getInstance(),
                             EmptyRequestBody.getInstance());
-
-            FlinkAssertions.assertThatFuture(future)
+            assertThatFuture(future)
                     .eventuallyFailsWith(ExecutionException.class)
                     .withCauseInstanceOf(ConnectTimeoutException.class)
-                    .extracting(Throwable::getCause, as(InstanceOfAssertFactories.THROWABLE))
-                    .hasMessageContaining(unroutableIp);
+                    .withMessageContaining(unroutableIp);
         }
     }
 
     @Test
-    public void testInvalidVersionRejection() throws Exception {
-        try (final RestClient restClient =
-                new RestClient(new Configuration(), Executors.directExecutor())) {
-            assertThatThrownBy(
-                            () ->
-                                    restClient.sendRequest(
-                                            unroutableIp,
-                                            80,
-                                            new TestMessageHeaders(),
-                                            EmptyMessageParameters.getInstance(),
-                                            EmptyRequestBody.getInstance(),
-                                            Collections.emptyList(),
-                                            RuntimeRestAPIVersion.V0))
-                    .as("The request should have been rejected due to a version mismatch.")
-                    .isInstanceOf(IllegalArgumentException.class);
-        }
+    void testInvalidVersionRejection() throws Exception {
+        final RestClient restClient =
+                new RestClient(new Configuration(), Executors.directExecutor());

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] wangzzu commented on pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "wangzzu (via GitHub)" <gi...@apache.org>.
wangzzu commented on PR #23242:
URL: https://github.com/apache/flink/pull/23242#issuecomment-1727628727

   @Jiabao-Sun @1996fanrui do you have time to review it again?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] wangzzu commented on a diff in pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "wangzzu (via GitHub)" <gi...@apache.org>.
wangzzu commented on code in PR #23242:
URL: https://github.com/apache/flink/pull/23242#discussion_r1300073633


##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestExternalHandlersITCase.java:
##########
@@ -128,29 +124,27 @@ void teardown() throws Exception {
     void testHandlersMustBeLoaded() {
         final List<InboundChannelHandlerFactory> inboundChannelHandlerFactories =
                 serverEndpoint.getInboundChannelHandlerFactories();
-        assertEquals(inboundChannelHandlerFactories.size(), 2);
-        assertTrue(
-                inboundChannelHandlerFactories.get(0) instanceof Prio1InboundChannelHandlerFactory);
-        assertTrue(
-                inboundChannelHandlerFactories.get(1) instanceof Prio0InboundChannelHandlerFactory);
+        assertThat(inboundChannelHandlerFactories.size()).isEqualTo(2);
+        assertThat(inboundChannelHandlerFactories.get(0))
+                .isInstanceOf(Prio1InboundChannelHandlerFactory.class);
+        assertThat(inboundChannelHandlerFactories.get(1))
+                .isInstanceOf(Prio0InboundChannelHandlerFactory.class);
 
         final List<OutboundChannelHandlerFactory> outboundChannelHandlerFactories =
                 restClient.getOutboundChannelHandlerFactories();
-        assertEquals(outboundChannelHandlerFactories.size(), 2);
-        assertTrue(
-                outboundChannelHandlerFactories.get(0)
-                        instanceof Prio1OutboundChannelHandlerFactory);
-        assertTrue(
-                outboundChannelHandlerFactories.get(1)
-                        instanceof Prio0OutboundChannelHandlerFactory);
+        assertThat(outboundChannelHandlerFactories.size()).isEqualTo(2);
+        assertThat(outboundChannelHandlerFactories.get(0))
+                .isInstanceOf(Prio1OutboundChannelHandlerFactory.class);
+        assertThat(outboundChannelHandlerFactories.get(1))
+                .isInstanceOf(Prio0OutboundChannelHandlerFactory.class);
 
         try {
             final CompletableFuture<TestResponse> response =
                     sendRequestToTestHandler(new TestRequest());
             response.get();
             fail("Request must fail with 2 times redirected URL");
         } catch (Exception e) {
-            assertTrue(e.getMessage().contains(REDIRECT2_URL));
+            assertThat(e.getMessage()).contains(REDIRECT2_URL);
         }

Review Comment:
   fixed it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] wangzzu commented on a diff in pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "wangzzu (via GitHub)" <gi...@apache.org>.
wangzzu commented on code in PR #23242:
URL: https://github.com/apache/flink/pull/23242#discussion_r1300087671


##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestServerEndpointConfigurationTest.java:
##########
@@ -22,42 +22,38 @@
 import org.apache.flink.configuration.RestOptions;
 import org.apache.flink.configuration.WebOptions;
 import org.apache.flink.util.ConfigurationException;
-import org.apache.flink.util.TestLogger;
 
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
-import static org.hamcrest.CoreMatchers.containsString;
+import java.io.File;
+
+import static org.assertj.core.api.Assertions.assertThat;
 
 /** Tests for the {@link RestServerEndpointConfiguration}. */
-public class RestServerEndpointConfigurationTest extends TestLogger {
+class RestServerEndpointConfigurationTest {
 
     private static final String ADDRESS = "123.123.123.123";
     private static final String BIND_ADDRESS = "023.023.023.023";
     private static final String BIND_PORT = "7282";
     private static final int CONTENT_LENGTH = 1234;
 
-    @Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder();
-
     @Test
-    public void testBasicMapping() throws ConfigurationException {
+    void testBasicMapping(@TempDir File file) throws ConfigurationException {

Review Comment:
   fixed it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] huwh closed pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "huwh (via GitHub)" <gi...@apache.org>.
huwh closed pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module
URL: https://github.com/apache/flink/pull/23242


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] Jiabao-Sun commented on pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "Jiabao-Sun (via GitHub)" <gi...@apache.org>.
Jiabao-Sun commented on PR #23242:
URL: https://github.com/apache/flink/pull/23242#issuecomment-1686616668

   By the way, the CI looks failed.
   Please take a look as well.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] wangzzu commented on pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "wangzzu (via GitHub)" <gi...@apache.org>.
wangzzu commented on PR #23242:
URL: https://github.com/apache/flink/pull/23242#issuecomment-1727627956

   @huwh thanks for your review, i have fixed these


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] wangzzu commented on pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "wangzzu (via GitHub)" <gi...@apache.org>.
wangzzu commented on PR #23242:
URL: https://github.com/apache/flink/pull/23242#issuecomment-1704528278

   @1996fanrui @Jiabao-Sun if you have time, can you help me reveiw this again


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] Jiabao-Sun commented on a diff in pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "Jiabao-Sun (via GitHub)" <gi...@apache.org>.
Jiabao-Sun commented on code in PR #23242:
URL: https://github.com/apache/flink/pull/23242#discussion_r1299393443


##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientTest.java:
##########
@@ -87,14 +79,19 @@ public void testConnectionTimeout() throws Exception {
                             EmptyMessageParameters.getInstance(),
                             EmptyRequestBody.getInstance());
 
-            final Throwable cause = assertThrows(ExecutionException.class, future::get).getCause();
-            assertThat(cause, instanceOf(ConnectTimeoutException.class));
-            assertThat(cause.getMessage(), containsString(unroutableIp));
+            try {
+                future.get();
+                fail("Expected exception not thrown.");
+            } catch (ExecutionException e) {
+                final Throwable cause = e.getCause();
+                assertThat(cause).isInstanceOf(ConnectTimeoutException.class);
+                assertThat(cause.getMessage()).contains(unroutableIp);
+            }

Review Comment:
   ```suggestion
               assertThatFuture(future)
                       .eventuallyFailsWith(ExecutionException.class)
                       .withCauseInstanceOf(ConnectTimeoutException.class)
                       .withMessageContaining(unroutableIp);
   ```



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientTest.java:
##########
@@ -106,15 +103,15 @@ public void testInvalidVersionRejection() throws Exception {
                             EmptyRequestBody.getInstance(),
                             Collections.emptyList(),
                             RuntimeRestAPIVersion.V0);
-            Assert.fail("The request should have been rejected due to a version mismatch.");
+            fail("Expected exception not thrown.");
         } catch (IllegalArgumentException e) {

Review Comment:
   ```suggestions
     assertThatThrownBy(() ->
                       restClient.sendRequest(
                               unroutableIp,
                               80,
                               new TestMessageHeaders(),
                               EmptyMessageParameters.getInstance(),
                               EmptyRequestBody.getInstance(),
                               Collections.emptyList(),
                               RuntimeRestAPIVersion.V0))
                       .isInstanceOf(IllegalArgumentException.class);
   ```
   
   By the way, would you mind to change all this pattern of expecting an exception?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] wangzzu commented on a diff in pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "wangzzu (via GitHub)" <gi...@apache.org>.
wangzzu commented on code in PR #23242:
URL: https://github.com/apache/flink/pull/23242#discussion_r1301154971


##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/InFlightRequestTrackerTest.java:
##########
@@ -18,70 +18,65 @@
 
 package org.apache.flink.runtime.rest.handler;
 
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import java.util.concurrent.CompletableFuture;
 
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
 
 /** Tests for {@link InFlightRequestTracker}. */
-public class InFlightRequestTrackerTest {
+class InFlightRequestTrackerTest {
 
     private InFlightRequestTracker inFlightRequestTracker;
 
-    @Before
-    public void setUp() {
+    @BeforeEach
+    void setUp() {
         inFlightRequestTracker = new InFlightRequestTracker();
     }
 
     @Test
-    public void testShouldFinishAwaitAsyncImmediatelyIfNoRequests() {
-        assertTrue(inFlightRequestTracker.awaitAsync().isDone());
+    void testShouldFinishAwaitAsyncImmediatelyIfNoRequests() {
+        assertThat(inFlightRequestTracker.awaitAsync()).isDone();
     }
 
     @Test
-    public void testShouldFinishAwaitAsyncIffAllRequestsDeregistered() {
+    void testShouldFinishAwaitAsyncIffAllRequestsDeregistered() {
         inFlightRequestTracker.registerRequest();
 
         final CompletableFuture<Void> awaitFuture = inFlightRequestTracker.awaitAsync();
-        assertFalse(awaitFuture.isDone());
+        assertThat(awaitFuture).isNotDone();
 
         inFlightRequestTracker.deregisterRequest();
-        assertTrue(awaitFuture.isDone());
+        assertThat(awaitFuture).isDone();
     }
 
     @Test
-    public void testAwaitAsyncIsIdempotent() {
+    void testAwaitAsyncIsIdempotent() {
         final CompletableFuture<Void> awaitFuture = inFlightRequestTracker.awaitAsync();
-        assertTrue(awaitFuture.isDone());
-
-        assertSame(
-                "The reference to the future must not change",
-                awaitFuture,
-                inFlightRequestTracker.awaitAsync());
+        assertThat(awaitFuture).isDone();
+        assertThat(awaitFuture)
+                .as("The reference to the future must not change")
+                .isEqualTo(inFlightRequestTracker.awaitAsync());

Review Comment:
   `isCompletedWithValue` cannot be used on **Void**, `as` api does not exist, I think the current implementation is also OK



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] wangzzu commented on a diff in pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "wangzzu (via GitHub)" <gi...@apache.org>.
wangzzu commented on code in PR #23242:
URL: https://github.com/apache/flink/pull/23242#discussion_r1300071546


##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestServerEndpointITCase.java:
##########
@@ -340,60 +331,52 @@ public void testBadHandlerRequest() throws Exception {
         } catch (ExecutionException ee) {
             Throwable t = ExceptionUtils.stripExecutionException(ee);
 
-            assertTrue(t instanceof RestClientException);
+            assertThat(t instanceof RestClientException).isTrue();
 
             RestClientException rce = (RestClientException) t;
 
-            assertEquals(HttpResponseStatus.BAD_REQUEST, rce.getHttpResponseStatus());
+            assertThat(rce.getHttpResponseStatus()).isEqualTo(HttpResponseStatus.BAD_REQUEST);

Review Comment:
   @Jiabao-Sun if we use `assertThatFuture`, how can we do the test for `rce.getHttpResponseStatus()` witch is not a msg



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] huwh commented on pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "huwh (via GitHub)" <gi...@apache.org>.
huwh commented on PR #23242:
URL: https://github.com/apache/flink/pull/23242#issuecomment-1730802811

   There hasn't been a response in a while. Merging now.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] huwh commented on a diff in pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "huwh (via GitHub)" <gi...@apache.org>.
huwh commented on code in PR #23242:
URL: https://github.com/apache/flink/pull/23242#discussion_r1328092633


##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/async/CompletedOperationCacheTest.java:
##########
@@ -154,35 +149,35 @@ public void testCacheTimeoutCanBeConfigured() throws Exception {
 
         manualTicker.advanceTime(baseTimeout.multipliedBy(2).getSeconds(), TimeUnit.SECONDS);
 
-        assertTrue(completedOperationCache.get(TEST_OPERATION_KEY).isPresent());
+        assertThat(completedOperationCache.get(TEST_OPERATION_KEY)).isPresent();
     }
 
     @Test
-    public void containsReturnsFalseForUnknownOperation() {
-        assertThat(completedOperationCache.containsOperation(TEST_OPERATION_KEY), is(false));
+    void containsReturnsFalseForUnknownOperation() {
+        assertThat(completedOperationCache.containsOperation(TEST_OPERATION_KEY)).isFalse();
     }
 
     @Test
-    public void containsChecksOnoingOperations() {
+    void containsChecksOnoingOperations() {
         completedOperationCache.registerOngoingOperation(
                 TEST_OPERATION_KEY, new CompletableFuture<>());
-        assertThat(completedOperationCache.containsOperation(TEST_OPERATION_KEY), is(true));
+        assertThat(completedOperationCache.containsOperation(TEST_OPERATION_KEY)).isTrue();
     }
 
     @Test
-    public void containsChecksCompletedOperations() {
+    void containsChecksCompletedOperations() {
         completedOperationCache.registerOngoingOperation(
                 TEST_OPERATION_KEY, CompletableFuture.completedFuture(null));
-        assertThat(completedOperationCache.containsOperation(TEST_OPERATION_KEY), is(true));
+        assertThat(completedOperationCache.containsOperation(TEST_OPERATION_KEY)).isTrue();
     }
 
     @Test
-    public void containsDoesNotMarkResultAsAccessed() {
+    void containsDoesNotMarkResultAsAccessed() {
         completedOperationCache.registerOngoingOperation(
                 TEST_OPERATION_KEY, CompletableFuture.completedFuture(null));
-        assertThat(completedOperationCache.containsOperation(TEST_OPERATION_KEY), is(true));
-        assertThat(
-                completedOperationCache.closeAsync(),
-                FlinkMatchers.willNotComplete(Duration.ofMillis(10)));
+        assertThat(completedOperationCache.containsOperation(TEST_OPERATION_KEY)).isTrue();
+
+        assertThat(completedOperationCache.closeAsync())

Review Comment:
   ```suggestion
           assertThatFuture(completedOperationCache.closeAsync())
                   .willNotCompleteWithin(Duration.ofMillis(10));
   ```



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestServerEndpointITCase.java:
##########
@@ -543,21 +529,23 @@ public void testDefaultVersionRouting() throws Exception {
                         .build();
 
         try (final Response response = client.newCall(request).execute()) {
-            assertEquals(HttpResponseStatus.ACCEPTED.code(), response.code());
+            assertThat(response.code()).isEqualTo(HttpResponseStatus.ACCEPTED.code());
         }
     }
 
-    @Test
-    public void testNonSslRedirectForEnabledSsl() throws Exception {
-        Assume.assumeTrue(config.getBoolean(SecurityOptions.SSL_REST_ENABLED));
+    @TestTemplate
+    void testNonSslRedirectForEnabledSsl() throws Exception {
+        if (!config.getBoolean(SecurityOptions.SSL_REST_ENABLED)) {

Review Comment:
   ditto



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/job/metrics/AggregatingMetricsHandlerTestBase.java:
##########
@@ -185,9 +183,9 @@ public void getStores() throws Exception {
                             .sorted()
                             .collect(Collectors.toList());
 
-            assertEquals(1, sortedMetrics1.size());
+            assertThat(sortedMetrics1).hasSize(1);

Review Comment:
   ditto



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/messages/json/JobResultDeserializerTest.java:
##########
@@ -78,20 +74,19 @@ public void testInvalidType() throws Exception {
                             + "}",
                     JobResult.class);
         } catch (final JsonMappingException e) {
-            assertThat(
-                    e.getMessage(),
-                    containsString("Expected token VALUE_NUMBER_INT (was VALUE_STRING)"));
+            assertThat(e.getMessage())

Review Comment:
   ```suggestion
           assertThatThrownBy(
                           () ->
                                   objectMapper.readValue(
                                           "{\n"
                                                   + "\t\"id\": \"1bb5e8c7df49938733b7c6a73678de6a\",\n"
                                                   + "\t\"net-runtime\": \"invalid\"\n"
                                                   + "}",
                                           JobResult.class))
                   .isInstanceOf(JsonMappingException.class)
                   .hasMessageContaining("Expected token VALUE_NUMBER_INT (was VALUE_STRING)");
   ```



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/messages/json/JobResultDeserializerTest.java:
##########
@@ -78,20 +74,19 @@ public void testInvalidType() throws Exception {
                             + "}",
                     JobResult.class);
         } catch (final JsonMappingException e) {
-            assertThat(
-                    e.getMessage(),
-                    containsString("Expected token VALUE_NUMBER_INT (was VALUE_STRING)"));
+            assertThat(e.getMessage())
+                    .contains("Expected token VALUE_NUMBER_INT (was VALUE_STRING)");
         }
     }
 
     @Test
-    public void testIncompleteJobResult() throws Exception {
+    void testIncompleteJobResult() throws Exception {
         try {
             objectMapper.readValue(
                     "{\n" + "\t\"id\": \"1bb5e8c7df49938733b7c6a73678de6a\"\n" + "}",
                     JobResult.class);
         } catch (final JsonMappingException e) {
-            assertThat(e.getMessage(), containsString("Could not deserialize JobResult"));
+            assertThat(e.getMessage()).contains("Could not deserialize JobResult");

Review Comment:
   ditto



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/job/metrics/AggregatingMetricsHandlerTestBase.java:
##########
@@ -145,10 +143,10 @@ public void getStores() throws Exception {
                             .sorted()
                             .collect(Collectors.toList());
 
-            assertEquals(2, sortedMetrics1.size());
+            assertThat(sortedMetrics1).hasSize(2);

Review Comment:
   ```suggestion
               assertThat(sortedMetrics1).containsExactly("1", "3");
   ```



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/job/metrics/AggregatingMetricsHandlerTestBase.java:
##########
@@ -221,13 +219,13 @@ public void testListMetrics() throws Exception {
                         .sorted()
                         .collect(Collectors.toList());
 
-        assertEquals(2, availableMetrics.size());
-        assertEquals("abc.metric1", availableMetrics.get(0));
-        assertEquals("abc.metric2", availableMetrics.get(1));
+        assertThat(availableMetrics).hasSize(2);

Review Comment:
   ditto



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/job/metrics/AggregatingMetricsHandlerTestBase.java:
##########
@@ -196,14 +194,14 @@ public void getStores() throws Exception {
                             .sorted()
                             .collect(Collectors.toList());
 
-            assertEquals(1, sortedMetrics2.size());
+            assertThat(sortedMetrics2).hasSize(1);

Review Comment:
   ditto



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestServerEndpointITCase.java:
##########
@@ -517,20 +499,24 @@ public void testVersionSelection() throws Exception {
                         Collections.emptyList(),
                         RuntimeRestAPIVersion.V1);
 
-        try {
-            version2Response.get(5, TimeUnit.SECONDS);
-            fail();
-        } catch (ExecutionException ee) {
-            RestClientException rce = (RestClientException) ee.getCause();
-            assertEquals(HttpResponseStatus.ACCEPTED, rce.getHttpResponseStatus());
-        }
+        assertThatFuture(version2Response)
+                .failsWithin(5, TimeUnit.SECONDS)
+                .withThrowableOfType(ExecutionException.class)
+                .withCauseInstanceOf(RestClientException.class)
+                .satisfies(
+                        e ->
+                                assertThat(
+                                                ((RestClientException) e.getCause())
+                                                        .getHttpResponseStatus())
+                                        .isEqualTo(HttpResponseStatus.ACCEPTED));
     }
 
-    @Test
-    public void testDefaultVersionRouting() throws Exception {
-        Assume.assumeFalse(
-                "Ignoring SSL-enabled test to keep OkHttp usage simple.",
-                config.getBoolean(SecurityOptions.SSL_REST_ENABLED));
+    @TestTemplate
+    void testDefaultVersionRouting() throws Exception {
+        // Ignoring SSL-enabled test to keep OkHttp usage simple.
+        if (config.getBoolean(SecurityOptions.SSL_REST_ENABLED)) {

Review Comment:
   It's betther to use org.assertj.core.api.Assumptions.assumeThat



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/legacy/DefaultExecutionGraphCacheTest.java:
##########
@@ -79,20 +75,20 @@ public void testExecutionGraphCaching() throws Exception {
             CompletableFuture<ExecutionGraphInfo> executionGraphInfoFuture =
                     executionGraphCache.getExecutionGraphInfo(expectedJobId, restfulGateway);
 
-            assertEquals(expectedExecutionGraphInfo, executionGraphInfoFuture.get());
+            assertThat(executionGraphInfoFuture.get()).isEqualTo(expectedExecutionGraphInfo);

Review Comment:
   shall we change all the future related assert to `FlinkAssertions.assertThatFuture` ?



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestExternalHandlersITCase.java:
##########
@@ -128,29 +124,27 @@ void teardown() throws Exception {
     void testHandlersMustBeLoaded() {
         final List<InboundChannelHandlerFactory> inboundChannelHandlerFactories =
                 serverEndpoint.getInboundChannelHandlerFactories();
-        assertEquals(inboundChannelHandlerFactories.size(), 2);
-        assertTrue(
-                inboundChannelHandlerFactories.get(0) instanceof Prio1InboundChannelHandlerFactory);
-        assertTrue(
-                inboundChannelHandlerFactories.get(1) instanceof Prio0InboundChannelHandlerFactory);
+        assertThat(inboundChannelHandlerFactories).hasSize(2);
+        assertThat(inboundChannelHandlerFactories.get(0))
+                .isInstanceOf(Prio1InboundChannelHandlerFactory.class);
+        assertThat(inboundChannelHandlerFactories.get(1))
+                .isInstanceOf(Prio0InboundChannelHandlerFactory.class);
 
         final List<OutboundChannelHandlerFactory> outboundChannelHandlerFactories =
                 restClient.getOutboundChannelHandlerFactories();
-        assertEquals(outboundChannelHandlerFactories.size(), 2);
-        assertTrue(
-                outboundChannelHandlerFactories.get(0)
-                        instanceof Prio1OutboundChannelHandlerFactory);
-        assertTrue(
-                outboundChannelHandlerFactories.get(1)
-                        instanceof Prio0OutboundChannelHandlerFactory);
+        assertThat(outboundChannelHandlerFactories).hasSize(2);
+        assertThat(outboundChannelHandlerFactories.get(0))
+                .isInstanceOf(Prio1OutboundChannelHandlerFactory.class);
+        assertThat(outboundChannelHandlerFactories.get(1))
+                .isInstanceOf(Prio0OutboundChannelHandlerFactory.class);
 
         try {
             final CompletableFuture<TestResponse> response =
                     sendRequestToTestHandler(new TestRequest());
             response.get();
             fail("Request must fail with 2 times redirected URL");
         } catch (Exception e) {
-            assertTrue(e.getMessage().contains(REDIRECT2_URL));
+            assertThat(e.getMessage()).contains(REDIRECT2_URL);

Review Comment:
   ```suggestion
           final CompletableFuture<TestResponse> response =
                   sendRequestToTestHandler(new TestRequest());
           FlinkAssertions.assertThatFuture(response)
                   .eventuallyFailsWith(ExecutionException.class)
                   .as("Request must fail with 2 times redirected URL")
                   .withMessageContaining(REDIRECT2_URL);
   ```



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/job/metrics/AggregatingMetricsHandlerTestBase.java:
##########
@@ -157,9 +155,9 @@ public void getStores() throws Exception {
                             .sorted()
                             .collect(Collectors.toList());
 
-            assertEquals(1, sortedMetrics2.size());
+            assertThat(sortedMetrics2).hasSize(1);

Review Comment:
   ditto



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] wangzzu commented on a diff in pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "wangzzu (via GitHub)" <gi...@apache.org>.
wangzzu commented on code in PR #23242:
URL: https://github.com/apache/flink/pull/23242#discussion_r1299653435


##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/messages/RestResponseUnmarshallingTestBase.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.rest.messages;
+
+import org.apache.flink.runtime.rest.util.RestMapperUtils;
+
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Collection;
+
+/** Test base for verifying that unmarshalling REST {@link ResponseBody}s work properly. */
+public abstract class RestResponseUnmarshallingTestBase<R extends ResponseBody>

Review Comment:
   thx, i have fixed it



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientTest.java:
##########
@@ -87,14 +79,19 @@ public void testConnectionTimeout() throws Exception {
                             EmptyMessageParameters.getInstance(),
                             EmptyRequestBody.getInstance());
 
-            final Throwable cause = assertThrows(ExecutionException.class, future::get).getCause();
-            assertThat(cause, instanceOf(ConnectTimeoutException.class));
-            assertThat(cause.getMessage(), containsString(unroutableIp));
+            try {
+                future.get();
+                fail("Expected exception not thrown.");
+            } catch (ExecutionException e) {
+                final Throwable cause = e.getCause();
+                assertThat(cause).isInstanceOf(ConnectTimeoutException.class);
+                assertThat(cause.getMessage()).contains(unroutableIp);
+            }

Review Comment:
   thx, i have fixed it



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientTest.java:
##########
@@ -106,15 +103,15 @@ public void testInvalidVersionRejection() throws Exception {
                             EmptyRequestBody.getInstance(),
                             Collections.emptyList(),
                             RuntimeRestAPIVersion.V0);
-            Assert.fail("The request should have been rejected due to a version mismatch.");
+            fail("Expected exception not thrown.");
         } catch (IllegalArgumentException e) {

Review Comment:
   thx, i have fixed it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] Jiabao-Sun commented on a diff in pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "Jiabao-Sun (via GitHub)" <gi...@apache.org>.
Jiabao-Sun commented on code in PR #23242:
URL: https://github.com/apache/flink/pull/23242#discussion_r1299803604


##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestExternalHandlersITCase.java:
##########
@@ -128,29 +124,27 @@ void teardown() throws Exception {
     void testHandlersMustBeLoaded() {
         final List<InboundChannelHandlerFactory> inboundChannelHandlerFactories =
                 serverEndpoint.getInboundChannelHandlerFactories();
-        assertEquals(inboundChannelHandlerFactories.size(), 2);
-        assertTrue(
-                inboundChannelHandlerFactories.get(0) instanceof Prio1InboundChannelHandlerFactory);
-        assertTrue(
-                inboundChannelHandlerFactories.get(1) instanceof Prio0InboundChannelHandlerFactory);
+        assertThat(inboundChannelHandlerFactories.size()).isEqualTo(2);
+        assertThat(inboundChannelHandlerFactories.get(0))
+                .isInstanceOf(Prio1InboundChannelHandlerFactory.class);
+        assertThat(inboundChannelHandlerFactories.get(1))
+                .isInstanceOf(Prio0InboundChannelHandlerFactory.class);
 
         final List<OutboundChannelHandlerFactory> outboundChannelHandlerFactories =
                 restClient.getOutboundChannelHandlerFactories();
-        assertEquals(outboundChannelHandlerFactories.size(), 2);
-        assertTrue(
-                outboundChannelHandlerFactories.get(0)
-                        instanceof Prio1OutboundChannelHandlerFactory);
-        assertTrue(
-                outboundChannelHandlerFactories.get(1)
-                        instanceof Prio0OutboundChannelHandlerFactory);
+        assertThat(outboundChannelHandlerFactories.size()).isEqualTo(2);
+        assertThat(outboundChannelHandlerFactories.get(0))
+                .isInstanceOf(Prio1OutboundChannelHandlerFactory.class);
+        assertThat(outboundChannelHandlerFactories.get(1))
+                .isInstanceOf(Prio0OutboundChannelHandlerFactory.class);
 
         try {
             final CompletableFuture<TestResponse> response =
                     sendRequestToTestHandler(new TestRequest());
             response.get();
             fail("Request must fail with 2 times redirected URL");
         } catch (Exception e) {
-            assertTrue(e.getMessage().contains(REDIRECT2_URL));
+            assertThat(e.getMessage()).contains(REDIRECT2_URL);
         }

Review Comment:
   I think we can use `assertThatFuture` as well.



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestServerEndpointConfigurationTest.java:
##########
@@ -22,42 +22,38 @@
 import org.apache.flink.configuration.RestOptions;
 import org.apache.flink.configuration.WebOptions;
 import org.apache.flink.util.ConfigurationException;
-import org.apache.flink.util.TestLogger;
 
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
-import static org.hamcrest.CoreMatchers.containsString;
+import java.io.File;
+
+import static org.assertj.core.api.Assertions.assertThat;
 
 /** Tests for the {@link RestServerEndpointConfiguration}. */
-public class RestServerEndpointConfigurationTest extends TestLogger {
+class RestServerEndpointConfigurationTest {
 
     private static final String ADDRESS = "123.123.123.123";
     private static final String BIND_ADDRESS = "023.023.023.023";
     private static final String BIND_PORT = "7282";
     private static final int CONTENT_LENGTH = 1234;
 
-    @Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder();
-
     @Test
-    public void testBasicMapping() throws ConfigurationException {
+    void testBasicMapping(@TempDir File file) throws ConfigurationException {

Review Comment:
   ```suggestion
       void testBasicMapping(@TempDir File temporaryFolder) throws ConfigurationException {
   ```



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestServerEndpointITCase.java:
##########
@@ -109,34 +108,26 @@
 
 import static java.util.Objects.requireNonNull;
 import static org.apache.flink.core.testutils.CommonTestUtils.assertThrows;
+import static org.apache.flink.core.testutils.FlinkAssertions.assertThatFuture;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.hamcrest.CoreMatchers.hasItems;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.greaterThanOrEqualTo;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.lessThanOrEqualTo;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.fail;
 
 /** IT cases for {@link RestClient} and {@link RestServerEndpoint}. */
-@RunWith(Parameterized.class)
-public class RestServerEndpointITCase extends TestLogger {
+@ExtendWith(ParameterizedTestExtension.class)
+public class RestServerEndpointITCase {
 
     private static final JobID PATH_JOB_ID = new JobID();
     private static final JobID QUERY_JOB_ID = new JobID();
     private static final String JOB_ID_KEY = "jobid";
     private static final Time timeout = Time.seconds(10L);
     private static final int TEST_REST_MAX_CONTENT_LENGTH = 4096;
 
-    @ClassRule
-    public static final TestExecutorResource<ScheduledExecutorService> EXECUTOR_RESOURCE =
-            TestingUtils.defaultExecutorResource();
+    @RegisterExtension
+    public static final TestExecutorExtension<ScheduledExecutorService> EXECUTOR_RESOURCE =

Review Comment:
   ```suggestion
       private static final TestExecutorExtension<ScheduledExecutorService> EXECUTOR_RESOURCE =
   ```



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestServerEndpointITCase.java:
##########
@@ -519,18 +503,19 @@ public void testVersionSelection() throws Exception {
 
         try {
             version2Response.get(5, TimeUnit.SECONDS);
-            fail();
+            fail("Expected exception not thrown");
         } catch (ExecutionException ee) {
             RestClientException rce = (RestClientException) ee.getCause();
-            assertEquals(HttpResponseStatus.ACCEPTED, rce.getHttpResponseStatus());
+            assertThat(rce.getHttpResponseStatus()).isEqualTo(HttpResponseStatus.ACCEPTED);
         }

Review Comment:
   Same as above.



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestServerEndpointITCase.java:
##########
@@ -340,60 +331,52 @@ public void testBadHandlerRequest() throws Exception {
         } catch (ExecutionException ee) {
             Throwable t = ExceptionUtils.stripExecutionException(ee);
 
-            assertTrue(t instanceof RestClientException);
+            assertThat(t instanceof RestClientException).isTrue();
 
             RestClientException rce = (RestClientException) t;
 
-            assertEquals(HttpResponseStatus.BAD_REQUEST, rce.getHttpResponseStatus());
+            assertThat(rce.getHttpResponseStatus()).isEqualTo(HttpResponseStatus.BAD_REQUEST);

Review Comment:
   Maybe we can use `assertThatFuture` as well.



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestServerEndpointITCase.java:
##########
@@ -501,10 +485,10 @@ public void testVersionSelection() throws Exception {
 
         try {
             version1Response.get(5, TimeUnit.SECONDS);
-            fail();
+            fail("Expected exception not thrown");
         } catch (ExecutionException ee) {
             RestClientException rce = (RestClientException) ee.getCause();
-            assertEquals(HttpResponseStatus.OK, rce.getHttpResponseStatus());
+            assertThat(rce.getHttpResponseStatus()).isEqualTo(HttpResponseStatus.OK);
         }

Review Comment:
   I think we can use `assertThatFuture().eventuallyFailsWith(ExecutionException.class)...` as well.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] wangzzu commented on pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "wangzzu (via GitHub)" <gi...@apache.org>.
wangzzu commented on PR #23242:
URL: https://github.com/apache/flink/pull/23242#issuecomment-1685714991

   @Jiabao-Sun thx for your reviewing, i have fixed it


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] wangzzu commented on a diff in pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "wangzzu (via GitHub)" <gi...@apache.org>.
wangzzu commented on code in PR #23242:
URL: https://github.com/apache/flink/pull/23242#discussion_r1300073868


##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestServerEndpointITCase.java:
##########
@@ -109,34 +108,26 @@
 
 import static java.util.Objects.requireNonNull;
 import static org.apache.flink.core.testutils.CommonTestUtils.assertThrows;
+import static org.apache.flink.core.testutils.FlinkAssertions.assertThatFuture;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.hamcrest.CoreMatchers.hasItems;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.greaterThanOrEqualTo;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.lessThanOrEqualTo;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.fail;
 
 /** IT cases for {@link RestClient} and {@link RestServerEndpoint}. */
-@RunWith(Parameterized.class)
-public class RestServerEndpointITCase extends TestLogger {
+@ExtendWith(ParameterizedTestExtension.class)
+public class RestServerEndpointITCase {
 
     private static final JobID PATH_JOB_ID = new JobID();
     private static final JobID QUERY_JOB_ID = new JobID();
     private static final String JOB_ID_KEY = "jobid";
     private static final Time timeout = Time.seconds(10L);
     private static final int TEST_REST_MAX_CONTENT_LENGTH = 4096;
 
-    @ClassRule
-    public static final TestExecutorResource<ScheduledExecutorService> EXECUTOR_RESOURCE =
-            TestingUtils.defaultExecutorResource();
+    @RegisterExtension
+    public static final TestExecutorExtension<ScheduledExecutorService> EXECUTOR_RESOURCE =

Review Comment:
   fixed it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] wangzzu commented on a diff in pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "wangzzu (via GitHub)" <gi...@apache.org>.
wangzzu commented on code in PR #23242:
URL: https://github.com/apache/flink/pull/23242#discussion_r1301148961


##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientTest.java:
##########
@@ -226,16 +228,20 @@ public void testCloseClientBeforeRequest() throws Exception {
                             EmptyMessageParameters.getInstance(),
                             EmptyRequestBody.getInstance());
 
-            FlinkAssertions.assertThatFuture(future)
-                    .eventuallyFailsWith(ExecutionException.class)
+            // Call get() on the future with a timeout of 0s so we can test that the exception
+            // thrown is not a TimeoutException, which is what would be thrown if restClient were
+            // not already closed
+            assertThatFuture(future)
+                    .isCompletedExceptionally()
+                    .failsWithin(0, TimeUnit.SECONDS)
+                    .withThrowableOfType(ExecutionException.class)
                     .withCauseInstanceOf(IllegalStateException.class)
-                    .extracting(Throwable::getCause, as(THROWABLE))
-                    .hasMessage("RestClient is already closed");
+                    .withMessageContaining("RestClient is already closed");

Review Comment:
   What does this refer to?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] wangzzu commented on pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "wangzzu (via GitHub)" <gi...@apache.org>.
wangzzu commented on PR #23242:
URL: https://github.com/apache/flink/pull/23242#issuecomment-1687638804

   @Jiabao-Sun thanks for your hard views, i have fixed these, if you have time, can you help review this again


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] flinkbot commented on pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #23242:
URL: https://github.com/apache/flink/pull/23242#issuecomment-1685027734

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "3c730a1b86f3f09b5add1d608454afac78e0d063",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "3c730a1b86f3f09b5add1d608454afac78e0d063",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 3c730a1b86f3f09b5add1d608454afac78e0d063 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] Jiabao-Sun commented on a diff in pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "Jiabao-Sun (via GitHub)" <gi...@apache.org>.
Jiabao-Sun commented on code in PR #23242:
URL: https://github.com/apache/flink/pull/23242#discussion_r1299392539


##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/messages/RestResponseUnmarshallingTestBase.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.rest.messages;
+
+import org.apache.flink.runtime.rest.util.RestMapperUtils;
+
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JavaType;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Collection;
+
+/** Test base for verifying that unmarshalling REST {@link ResponseBody}s work properly. */
+public abstract class RestResponseUnmarshallingTestBase<R extends ResponseBody>

Review Comment:
   Why do we need to split this case separately?
   If we don't want to use parameters test in the subclass, we can add a `@ExtendWith(NoOpTestExtension.class)` annotation to the subclass.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] Jiabao-Sun commented on a diff in pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "Jiabao-Sun (via GitHub)" <gi...@apache.org>.
Jiabao-Sun commented on code in PR #23242:
URL: https://github.com/apache/flink/pull/23242#discussion_r1300285624


##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientMultipartTest.java:
##########
@@ -48,7 +48,7 @@ class RestClientMultipartTest {
     @TempDir public static Path tempDir;

Review Comment:
   ```suggestion
       @TempDir private static Path tempDir;
   ```



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientTest.java:
##########
@@ -196,9 +194,13 @@ public void testRestClientClosedHandling() throws Exception {
 
             restClient.close();
 
-            FlinkAssertions.assertThatFuture(responseFuture)
-                    .eventuallyFailsWith(ExecutionException.class)
-                    .withCauseInstanceOf(IOException.class);
+            try {
+                responseFuture.get();
+            } catch (ExecutionException ee) {
+                if (!ExceptionUtils.findThrowable(ee, IOException.class).isPresent()) {
+                    throw ee;
+                }
+            }

Review Comment:
   same as above.



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/cluster/JobManagerCustomLogHandlerTest.java:
##########
@@ -105,60 +96,60 @@ private static HandlerRequest<EmptyRequestBody> createHandlerRequest(String path
     }
 
     @Test
-    public void testGetJobManagerCustomLogsValidFilename() throws Exception {
+    void testGetJobManagerCustomLogsValidFilename() throws Exception {
         File actualFile = testInstance.getFile(createHandlerRequest(VALID_LOG_FILENAME));
-        assertThat(actualFile, is(notNullValue()));
+        assertThat(actualFile).isNotNull();
 
         String actualContent = String.join("", Files.readAllLines(actualFile.toPath()));
-        assertThat(actualContent, is(VALID_LOG_CONTENT));
+        assertThat(actualContent).isEqualTo(VALID_LOG_CONTENT);
     }
 
     @Test
-    public void testGetJobManagerCustomLogsValidFilenameWithPath() throws Exception {
+    void testGetJobManagerCustomLogsValidFilenameWithPath() throws Exception {
         File actualFile =
                 testInstance.getFile(
                         createHandlerRequest(String.format("foobar/%s", VALID_LOG_FILENAME)));
-        assertThat(actualFile, is(notNullValue()));
+        assertThat(actualFile).isNotNull();
 
         String actualContent = String.join("", Files.readAllLines(actualFile.toPath()));
-        assertThat(actualContent, is(VALID_LOG_CONTENT));
+        assertThat(actualContent).isEqualTo(VALID_LOG_CONTENT);
     }
 
     @Test
-    public void testGetJobManagerCustomLogsValidFilenameWithInvalidPath() throws Exception {
+    void testGetJobManagerCustomLogsValidFilenameWithInvalidPath() throws Exception {
         File actualFile =
                 testInstance.getFile(
                         createHandlerRequest(String.format("../%s", VALID_LOG_FILENAME)));
-        assertThat(actualFile, is(notNullValue()));
+        assertThat(actualFile).isNotNull();
 
         String actualContent = String.join("", Files.readAllLines(actualFile.toPath()));
-        assertThat(actualContent, is(VALID_LOG_CONTENT));
+        assertThat(actualContent).isEqualTo(VALID_LOG_CONTENT);
     }
 
     @Test
-    public void testGetJobManagerCustomLogsNotExistingFile() throws Exception {
+    void testGetJobManagerCustomLogsNotExistingFile() throws Exception {
         File actualFile = testInstance.getFile(createHandlerRequest("not-existing"));
-        assertThat(actualFile, is(notNullValue()));
-        assertFalse(actualFile.exists());
+        assertThat(actualFile).isNotNull();
+        assertThat(actualFile.exists()).isFalse();

Review Comment:
   ```suggestion
           assertThat(actualFile).isNotNull().exists();
   ```



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/job/JobSubmitHandlerTest.java:
##########
@@ -126,15 +130,15 @@ public void testSerializationFailureHandling() throws Exception {
             handler.handleRequest(
                     HandlerRequest.create(request, EmptyMessageParameters.getInstance()),
                     mockGateway);
-            Assert.fail();
+            fail("Expected exception not thrown");
         } catch (RestHandlerException rhe) {
-            Assert.assertEquals(HttpResponseStatus.BAD_REQUEST, rhe.getHttpResponseStatus());
+            assertThat(rhe.getHttpResponseStatus()).isEqualTo(HttpResponseStatus.BAD_REQUEST);

Review Comment:
   How about `assertThatThrownBy`



##########
flink-runtime-web/src/test/java/org/apache/flink/runtime/webmonitor/handlers/JarRunRequestBodyTest.java:
##########
@@ -21,13 +21,17 @@
 import org.apache.flink.api.common.JobID;
 import org.apache.flink.runtime.jobgraph.RestoreMode;
 import org.apache.flink.runtime.rest.messages.RestRequestMarshallingTestBase;
+import org.apache.flink.testutils.junit.extensions.parameterized.NoOpTestExtension;
+
+import org.junit.jupiter.api.extension.ExtendWith;
 
 import java.util.Arrays;
 import java.util.Collections;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
 /** Tests for {@link JarRunRequestBody}. */
+@ExtendWith(NoOpTestExtension.class)
 public class JarRunRequestBodyTest extends RestRequestMarshallingTestBase<JarRunRequestBody> {

Review Comment:
   ```suggestion
   class JarRunRequestBodyTest extends RestRequestMarshallingTestBase<JarRunRequestBody> {
   ```



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestExternalHandlersITCase.java:
##########
@@ -128,30 +124,23 @@ void teardown() throws Exception {
     void testHandlersMustBeLoaded() {
         final List<InboundChannelHandlerFactory> inboundChannelHandlerFactories =
                 serverEndpoint.getInboundChannelHandlerFactories();
-        assertEquals(inboundChannelHandlerFactories.size(), 2);
-        assertTrue(
-                inboundChannelHandlerFactories.get(0) instanceof Prio1InboundChannelHandlerFactory);
-        assertTrue(
-                inboundChannelHandlerFactories.get(1) instanceof Prio0InboundChannelHandlerFactory);
+        assertThat(inboundChannelHandlerFactories.size()).isEqualTo(2);

Review Comment:
   ```suggestion
           assertThat(inboundChannelHandlerFactories).hasSize(2);
   ```



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientTest.java:
##########
@@ -82,42 +79,39 @@ void testConnectionTimeout() throws Exception {
                             new TestMessageHeaders(),
                             EmptyMessageParameters.getInstance(),
                             EmptyRequestBody.getInstance());
-
-            FlinkAssertions.assertThatFuture(future)
+            assertThatFuture(future)
                     .eventuallyFailsWith(ExecutionException.class)
                     .withCauseInstanceOf(ConnectTimeoutException.class)
-                    .extracting(Throwable::getCause, as(InstanceOfAssertFactories.THROWABLE))
-                    .hasMessageContaining(unroutableIp);
+                    .withMessageContaining(unroutableIp);
         }
     }
 
     @Test
-    public void testInvalidVersionRejection() throws Exception {
-        try (final RestClient restClient =
-                new RestClient(new Configuration(), Executors.directExecutor())) {
-            assertThatThrownBy(
-                            () ->
-                                    restClient.sendRequest(
-                                            unroutableIp,
-                                            80,
-                                            new TestMessageHeaders(),
-                                            EmptyMessageParameters.getInstance(),
-                                            EmptyRequestBody.getInstance(),
-                                            Collections.emptyList(),
-                                            RuntimeRestAPIVersion.V0))
-                    .as("The request should have been rejected due to a version mismatch.")
-                    .isInstanceOf(IllegalArgumentException.class);
-        }
+    void testInvalidVersionRejection() throws Exception {
+        final RestClient restClient =
+                new RestClient(new Configuration(), Executors.directExecutor());

Review Comment:
   Why we remove the try resource code?
   I think it's better to close the restClient.



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientTest.java:
##########
@@ -54,16 +53,14 @@
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 
-import static org.assertj.core.api.Assertions.as;
+import static org.apache.flink.core.testutils.FlinkAssertions.assertThatFuture;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.assertj.core.api.InstanceOfAssertFactories.THROWABLE;
 
 /** Tests for {@link RestClient}. */
 class RestClientTest {
-
     @RegisterExtension
-    static final TestExecutorExtension<ScheduledExecutorService> EXECUTOR_EXTENSION =
+    private static final TestExecutorExtension<ScheduledExecutorService> EXECUTOR_RESOURCE =

Review Comment:
   ```suggestion
       private static final TestExecutorExtension<ScheduledExecutorService> EXECUTOR_EXTENSION =
   ```



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientTest.java:
##########
@@ -226,16 +228,20 @@ public void testCloseClientBeforeRequest() throws Exception {
                             EmptyMessageParameters.getInstance(),
                             EmptyRequestBody.getInstance());
 
-            FlinkAssertions.assertThatFuture(future)
-                    .eventuallyFailsWith(ExecutionException.class)
+            // Call get() on the future with a timeout of 0s so we can test that the exception
+            // thrown is not a TimeoutException, which is what would be thrown if restClient were
+            // not already closed
+            assertThatFuture(future)
+                    .isCompletedExceptionally()
+                    .failsWithin(0, TimeUnit.SECONDS)
+                    .withThrowableOfType(ExecutionException.class)
                     .withCauseInstanceOf(IllegalStateException.class)
-                    .extracting(Throwable::getCause, as(THROWABLE))
-                    .hasMessage("RestClient is already closed");
+                    .withMessageContaining("RestClient is already closed");

Review Comment:
   Can be short here?



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientTest.java:
##########
@@ -151,23 +145,27 @@ public void testConnectionClosedHandling() throws Exception {
                 connectionSocket.close();
             }
 
-            FlinkAssertions.assertThatFuture(responseFuture)
-                    .eventuallyFailsWith(ExecutionException.class)
-                    .withCauseInstanceOf(IOException.class);
+            try {
+                responseFuture.get();
+            } catch (ExecutionException ee) {
+                if (!ExceptionUtils.findThrowable(ee, IOException.class).isPresent()) {
+                    throw ee;
+                }
+            }

Review Comment:
   Why we made this change?
   The old code is better to me.
   ```java
   assertThatFuture(responseFuture)
                       .eventuallyFailsWith(ExecutionException.class)
                       .withCauseInstanceOf(IOException.class);
   ```



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestExternalHandlersITCase.java:
##########
@@ -128,30 +124,23 @@ void teardown() throws Exception {
     void testHandlersMustBeLoaded() {
         final List<InboundChannelHandlerFactory> inboundChannelHandlerFactories =
                 serverEndpoint.getInboundChannelHandlerFactories();
-        assertEquals(inboundChannelHandlerFactories.size(), 2);
-        assertTrue(
-                inboundChannelHandlerFactories.get(0) instanceof Prio1InboundChannelHandlerFactory);
-        assertTrue(
-                inboundChannelHandlerFactories.get(1) instanceof Prio0InboundChannelHandlerFactory);
+        assertThat(inboundChannelHandlerFactories.size()).isEqualTo(2);
+        assertThat(inboundChannelHandlerFactories.get(0))
+                .isInstanceOf(Prio1InboundChannelHandlerFactory.class);
+        assertThat(inboundChannelHandlerFactories.get(1))
+                .isInstanceOf(Prio0InboundChannelHandlerFactory.class);
 
         final List<OutboundChannelHandlerFactory> outboundChannelHandlerFactories =
                 restClient.getOutboundChannelHandlerFactories();
-        assertEquals(outboundChannelHandlerFactories.size(), 2);
-        assertTrue(
-                outboundChannelHandlerFactories.get(0)
-                        instanceof Prio1OutboundChannelHandlerFactory);
-        assertTrue(
-                outboundChannelHandlerFactories.get(1)
-                        instanceof Prio0OutboundChannelHandlerFactory);
-
-        try {
-            final CompletableFuture<TestResponse> response =
-                    sendRequestToTestHandler(new TestRequest());
-            response.get();
-            fail("Request must fail with 2 times redirected URL");
-        } catch (Exception e) {
-            assertTrue(e.getMessage().contains(REDIRECT2_URL));
-        }
+        assertThat(outboundChannelHandlerFactories.size()).isEqualTo(2);

Review Comment:
   ```suggestion
           assertThat(outboundChannelHandlerFactories).hasSize(2);
   ```



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/FileUploadsTest.java:
##########
@@ -68,47 +61,47 @@ public void testDirectoryScan() throws IOException {
                             .map(File::toPath)
                             .collect(Collectors.toList());
 
-            Assert.assertEquals(2, detectedFiles.size());
-            Assert.assertTrue(detectedFiles.contains(tmp.resolve(rootFile)));
-            Assert.assertTrue(detectedFiles.contains(tmp.resolve(subFile)));
+            assertThat(detectedFiles).hasSize(2);
+            assertThat(detectedFiles.contains(tmp.resolve(rootFile))).isTrue();
+            assertThat(detectedFiles.contains(tmp.resolve(subFile))).isTrue();

Review Comment:
   ```suggestion
               assertThat(detectedFiles).contains(tmp.resolve(rootFile), tmp.resolve(subFile))
   ```



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/InFlightRequestTrackerTest.java:
##########
@@ -18,70 +18,65 @@
 
 package org.apache.flink.runtime.rest.handler;
 
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import java.util.concurrent.CompletableFuture;
 
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
 
 /** Tests for {@link InFlightRequestTracker}. */
-public class InFlightRequestTrackerTest {
+class InFlightRequestTrackerTest {
 
     private InFlightRequestTracker inFlightRequestTracker;
 
-    @Before
-    public void setUp() {
+    @BeforeEach
+    void setUp() {
         inFlightRequestTracker = new InFlightRequestTracker();
     }
 
     @Test
-    public void testShouldFinishAwaitAsyncImmediatelyIfNoRequests() {
-        assertTrue(inFlightRequestTracker.awaitAsync().isDone());
+    void testShouldFinishAwaitAsyncImmediatelyIfNoRequests() {
+        assertThat(inFlightRequestTracker.awaitAsync()).isDone();
     }
 
     @Test
-    public void testShouldFinishAwaitAsyncIffAllRequestsDeregistered() {
+    void testShouldFinishAwaitAsyncIffAllRequestsDeregistered() {
         inFlightRequestTracker.registerRequest();
 
         final CompletableFuture<Void> awaitFuture = inFlightRequestTracker.awaitAsync();
-        assertFalse(awaitFuture.isDone());
+        assertThat(awaitFuture).isNotDone();
 
         inFlightRequestTracker.deregisterRequest();
-        assertTrue(awaitFuture.isDone());
+        assertThat(awaitFuture).isDone();
     }
 
     @Test
-    public void testAwaitAsyncIsIdempotent() {
+    void testAwaitAsyncIsIdempotent() {
         final CompletableFuture<Void> awaitFuture = inFlightRequestTracker.awaitAsync();
-        assertTrue(awaitFuture.isDone());
-
-        assertSame(
-                "The reference to the future must not change",
-                awaitFuture,
-                inFlightRequestTracker.awaitAsync());
+        assertThat(awaitFuture).isDone();
+        assertThat(awaitFuture)
+                .as("The reference to the future must not change")
+                .isEqualTo(inFlightRequestTracker.awaitAsync());

Review Comment:
   ```suggestion
           assertThatFuture(awaitFuture)
             .as("The reference to the future must not change")
             .isCompletedWithValue(inFlightRequestTracker.awaitAsync());
   ```



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestServerSSLAuthITCase.java:
##########
@@ -130,7 +130,8 @@ public void testConnectFailure() throws Exception {
             fail("should never complete normally");
         } catch (ExecutionException exception) {
             // that is what we want
-            assertTrue(ExceptionUtils.findThrowable(exception, SSLException.class).isPresent());
+            assertThat(ExceptionUtils.findThrowable(exception, SSLException.class).isPresent())
+                    .isTrue();

Review Comment:
   ```suggestion
               assertThat(ExceptionUtils.findThrowable(exception, SSLException.class)).isPresent();
   ```
   But I prefer `assertThatFuture` as well.



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/FileUploadsTest.java:
##########
@@ -33,30 +29,27 @@
 import java.util.Collection;
 import java.util.stream.Collectors;
 
-/** Tests for {@link FileUploads}. */
-public class FileUploadsTest extends TestLogger {
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
-    @Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder();
+/** Tests for {@link FileUploads}. */
+class FileUploadsTest {
 
     @Test
-    public void testRelativePathRejection() throws IOException {
+    void testRelativePathRejection() throws IOException {
         Path relative = Paths.get("root");
-        try {
-            new FileUploads(relative);
-            Assert.fail();
-        } catch (IllegalArgumentException iae) {
-            // expected
-        }
+        assertThatThrownBy(() -> new FileUploads(relative))
+                .isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
-    public void testDirectoryScan() throws IOException {
+    void testDirectoryScan(@TempDir File temporaryFolder) throws IOException {

Review Comment:
   How about declare `@TempDir` as class private property.



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/InFlightRequestTrackerTest.java:
##########
@@ -18,70 +18,65 @@
 
 package org.apache.flink.runtime.rest.handler;
 
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import java.util.concurrent.CompletableFuture;
 
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
 
 /** Tests for {@link InFlightRequestTracker}. */
-public class InFlightRequestTrackerTest {
+class InFlightRequestTrackerTest {
 
     private InFlightRequestTracker inFlightRequestTracker;
 
-    @Before
-    public void setUp() {
+    @BeforeEach
+    void setUp() {
         inFlightRequestTracker = new InFlightRequestTracker();
     }
 
     @Test
-    public void testShouldFinishAwaitAsyncImmediatelyIfNoRequests() {
-        assertTrue(inFlightRequestTracker.awaitAsync().isDone());
+    void testShouldFinishAwaitAsyncImmediatelyIfNoRequests() {
+        assertThat(inFlightRequestTracker.awaitAsync()).isDone();
     }
 
     @Test
-    public void testShouldFinishAwaitAsyncIffAllRequestsDeregistered() {
+    void testShouldFinishAwaitAsyncIffAllRequestsDeregistered() {
         inFlightRequestTracker.registerRequest();
 
         final CompletableFuture<Void> awaitFuture = inFlightRequestTracker.awaitAsync();
-        assertFalse(awaitFuture.isDone());
+        assertThat(awaitFuture).isNotDone();
 
         inFlightRequestTracker.deregisterRequest();
-        assertTrue(awaitFuture.isDone());
+        assertThat(awaitFuture).isDone();
     }
 
     @Test
-    public void testAwaitAsyncIsIdempotent() {
+    void testAwaitAsyncIsIdempotent() {
         final CompletableFuture<Void> awaitFuture = inFlightRequestTracker.awaitAsync();
-        assertTrue(awaitFuture.isDone());
-
-        assertSame(
-                "The reference to the future must not change",
-                awaitFuture,
-                inFlightRequestTracker.awaitAsync());
+        assertThat(awaitFuture).isDone();
+        assertThat(awaitFuture)
+                .as("The reference to the future must not change")
+                .isEqualTo(inFlightRequestTracker.awaitAsync());
     }
 
     @Test
-    public void testShouldTolerateRegisterAfterAwaitAsync() {
+    void testShouldTolerateRegisterAfterAwaitAsync() {
         final CompletableFuture<Void> awaitFuture = inFlightRequestTracker.awaitAsync();
-        assertTrue(awaitFuture.isDone());
+        assertThat(awaitFuture).isDone();
 
         inFlightRequestTracker.registerRequest();
 
-        assertSame(
-                "The reference to the future must not change",
-                awaitFuture,
-                inFlightRequestTracker.awaitAsync());
+        assertThat(awaitFuture)
+                .as("The reference to the future must not change")
+                .isEqualTo(inFlightRequestTracker.awaitAsync());

Review Comment:
   ```suggestion
                   .isSameAs(inFlightRequestTracker.awaitAsync());
   ```



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/job/JobSubmitHandlerTest.java:
##########
@@ -320,7 +324,7 @@ public void testFailedJobSubmission() throws Exception {
                     .get();
         } catch (Exception e) {
             Throwable t = ExceptionUtils.stripExecutionException(e);
-            Assert.assertEquals(errorMessage, t.getMessage());
+            assertThat(t.getMessage()).isEqualTo(errorMessage);

Review Comment:
   How about `assertThatThrownBy`



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/cluster/JobManagerCustomLogHandlerTest.java:
##########
@@ -105,60 +96,60 @@ private static HandlerRequest<EmptyRequestBody> createHandlerRequest(String path
     }
 
     @Test
-    public void testGetJobManagerCustomLogsValidFilename() throws Exception {
+    void testGetJobManagerCustomLogsValidFilename() throws Exception {
         File actualFile = testInstance.getFile(createHandlerRequest(VALID_LOG_FILENAME));
-        assertThat(actualFile, is(notNullValue()));
+        assertThat(actualFile).isNotNull();
 
         String actualContent = String.join("", Files.readAllLines(actualFile.toPath()));
-        assertThat(actualContent, is(VALID_LOG_CONTENT));
+        assertThat(actualContent).isEqualTo(VALID_LOG_CONTENT);
     }
 
     @Test
-    public void testGetJobManagerCustomLogsValidFilenameWithPath() throws Exception {
+    void testGetJobManagerCustomLogsValidFilenameWithPath() throws Exception {
         File actualFile =
                 testInstance.getFile(
                         createHandlerRequest(String.format("foobar/%s", VALID_LOG_FILENAME)));
-        assertThat(actualFile, is(notNullValue()));
+        assertThat(actualFile).isNotNull();
 
         String actualContent = String.join("", Files.readAllLines(actualFile.toPath()));
-        assertThat(actualContent, is(VALID_LOG_CONTENT));
+        assertThat(actualContent).isEqualTo(VALID_LOG_CONTENT);
     }
 
     @Test
-    public void testGetJobManagerCustomLogsValidFilenameWithInvalidPath() throws Exception {
+    void testGetJobManagerCustomLogsValidFilenameWithInvalidPath() throws Exception {
         File actualFile =
                 testInstance.getFile(
                         createHandlerRequest(String.format("../%s", VALID_LOG_FILENAME)));
-        assertThat(actualFile, is(notNullValue()));
+        assertThat(actualFile).isNotNull();
 
         String actualContent = String.join("", Files.readAllLines(actualFile.toPath()));
-        assertThat(actualContent, is(VALID_LOG_CONTENT));
+        assertThat(actualContent).isEqualTo(VALID_LOG_CONTENT);
     }
 
     @Test
-    public void testGetJobManagerCustomLogsNotExistingFile() throws Exception {
+    void testGetJobManagerCustomLogsNotExistingFile() throws Exception {
         File actualFile = testInstance.getFile(createHandlerRequest("not-existing"));
-        assertThat(actualFile, is(notNullValue()));
-        assertFalse(actualFile.exists());
+        assertThat(actualFile).isNotNull();
+        assertThat(actualFile.exists()).isFalse();
     }
 
     @Test
-    public void testGetJobManagerCustomLogsExistingButForbiddenFile() throws Exception {
+    void testGetJobManagerCustomLogsExistingButForbiddenFile() throws Exception {
         File actualFile =
                 testInstance.getFile(
                         createHandlerRequest(String.format("../%s", FORBIDDEN_FILENAME)));
-        assertThat(actualFile, is(notNullValue()));
-        assertFalse(actualFile.exists());
+        assertThat(actualFile).isNotNull();
+        assertThat(actualFile.exists()).isFalse();

Review Comment:
   ```suggestion
           assertThat(actualFile).isNotNull().exists();
   ```



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/cluster/JobManagerLogListHandlerTest.java:
##########
@@ -91,18 +83,17 @@ public void testGetJobManagerLogsList() throws Exception {
         LogListInfo logListInfo =
                 jobManagerLogListHandler.handleRequest(testRequest, dispatcherGateway).get();
 
-        assertThat(
-                logListInfo.getLogInfos(),
-                containsInAnyOrder(expectedLogInfo.toArray(new LogInfo[0])));
+        assertThat(logListInfo.getLogInfos())
+                .containsExactlyInAnyOrder(expectedLogInfo.toArray(new LogInfo[0]));

Review Comment:
   ```suggestion
                   .containsExactlyInAnyOrderElementsOf(expectedLogInfo);
   ```



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestServerEndpointITCase.java:
##########
@@ -340,60 +331,52 @@ public void testBadHandlerRequest() throws Exception {
         } catch (ExecutionException ee) {
             Throwable t = ExceptionUtils.stripExecutionException(ee);
 
-            assertTrue(t instanceof RestClientException);
+            assertThat(t instanceof RestClientException).isTrue();
 
             RestClientException rce = (RestClientException) t;
 
-            assertEquals(HttpResponseStatus.BAD_REQUEST, rce.getHttpResponseStatus());
+            assertThat(rce.getHttpResponseStatus()).isEqualTo(HttpResponseStatus.BAD_REQUEST);

Review Comment:
   Hi @wangzzu.
   
   I think we can use
   ```java
           assertThatFuture(response)
                   .eventuallyFailsWith(ExecutionException.class)
                   .havingCause()
                   .isInstanceOf(RestClientException.class)
                   .satisfies(
                           e ->
                                   Assertions.assertThat(
                                                   ((RestClientException) e).getHttpResponseStatus())
                                           .isSameAs(HttpResponseStatus.BAD_REQUEST));
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] wangzzu commented on a diff in pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "wangzzu (via GitHub)" <gi...@apache.org>.
wangzzu commented on code in PR #23242:
URL: https://github.com/apache/flink/pull/23242#discussion_r1301146027


##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestClientTest.java:
##########
@@ -151,23 +145,27 @@ public void testConnectionClosedHandling() throws Exception {
                 connectionSocket.close();
             }
 
-            FlinkAssertions.assertThatFuture(responseFuture)
-                    .eventuallyFailsWith(ExecutionException.class)
-                    .withCauseInstanceOf(IOException.class);
+            try {
+                responseFuture.get();
+            } catch (ExecutionException ee) {
+                if (!ExceptionUtils.findThrowable(ee, IOException.class).isPresent()) {
+                    throw ee;
+                }
+            }

Review Comment:
   I checked this, I have not changed here, but it would be better to use `assertThatFuture`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] wangzzu commented on a diff in pull request #23242: [FLINK-32851][runtime][JUnit5 Migration] The rest package of flink-runtime module

Posted by "wangzzu (via GitHub)" <gi...@apache.org>.
wangzzu commented on code in PR #23242:
URL: https://github.com/apache/flink/pull/23242#discussion_r1301140344


##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestServerEndpointITCase.java:
##########
@@ -340,60 +331,52 @@ public void testBadHandlerRequest() throws Exception {
         } catch (ExecutionException ee) {
             Throwable t = ExceptionUtils.stripExecutionException(ee);
 
-            assertTrue(t instanceof RestClientException);
+            assertThat(t instanceof RestClientException).isTrue();
 
             RestClientException rce = (RestClientException) t;
 
-            assertEquals(HttpResponseStatus.BAD_REQUEST, rce.getHttpResponseStatus());
+            assertThat(rce.getHttpResponseStatus()).isEqualTo(HttpResponseStatus.BAD_REQUEST);

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org