You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by zh...@apache.org on 2022/10/20 06:11:52 UTC

[flink] branch master updated: [FLINK-28324][flink-sql-client] Migrate tests to JUnit5

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 7f639a8ce47 [FLINK-28324][flink-sql-client] Migrate tests to JUnit5
7f639a8ce47 is described below

commit 7f639a8ce4741f072621ac87976aa2589e9cfae0
Author: zhouli <zh...@foxmail.com>
AuthorDate: Tue Oct 18 16:20:38 2022 +0800

    [FLINK-28324][flink-sql-client] Migrate tests to JUnit5
    
    This closes #20168.
---
 .../apache/flink/table/client/SqlClientTest.java   | 52 ++++++-------
 .../flink/table/client/cli/CliClientITCase.java    | 91 +++++++++++++---------
 .../client/cli/CliClientMultiStatementITTest.java  |  9 +--
 .../flink/table/client/cli/CliClientTest.java      | 45 ++++++-----
 .../flink/table/client/cli/CliResultViewTest.java  | 16 ++--
 .../table/client/cli/CliTableauResultViewTest.java | 85 ++++++++++----------
 .../flink/table/client/cli/CliUtilsTest.java       | 28 ++++---
 .../table/client/cli/utils/SqlParserHelper.java    |  2 +-
 .../client/gateway/context/SessionContextTest.java | 47 ++++++-----
 .../table/client/gateway/local/DependencyTest.java |  8 +-
 .../client/gateway/local/LocalExecutorITCase.java  | 34 +++-----
 .../local/result/ChangelogCollectResultTest.java   |  6 +-
 .../result/MaterializedCollectBatchResultTest.java |  8 +-
 .../MaterializedCollectStreamResultTest.java       |  8 +-
 .../org.junit.jupiter.api.extension.Extension      | 16 ++++
 15 files changed, 235 insertions(+), 220 deletions(-)

diff --git a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/SqlClientTest.java b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/SqlClientTest.java
index 5c356002675..0de32949d4f 100644
--- a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/SqlClientTest.java
+++ b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/SqlClientTest.java
@@ -23,12 +23,10 @@ import org.apache.flink.table.client.cli.TerminalUtils;
 import org.apache.flink.util.FileUtils;
 
 import org.jline.terminal.Terminal;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.junit.rules.Timeout;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -38,6 +36,7 @@ import java.io.OutputStream;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
+import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.StandardOpenOption;
 import java.util.Arrays;
@@ -45,29 +44,26 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.TimeUnit;
 
 import static org.apache.flink.configuration.ConfigConstants.ENV_FLINK_CONF_DIR;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 /** Tests for {@link SqlClient}. */
-public class SqlClientTest {
+class SqlClientTest {
 
-    @Rule public TemporaryFolder tempFolder = new TemporaryFolder();
+    @TempDir private Path tempFolder;
 
     private Map<String, String> originalEnv;
 
     private String historyPath;
 
-    @Rule public Timeout timeout = new Timeout(1000, TimeUnit.SECONDS);
-
-    @Before
-    public void before() throws IOException {
+    @BeforeEach
+    void before() throws IOException {
         originalEnv = System.getenv();
 
         // prepare conf dir
-        File confFolder = tempFolder.newFolder("conf");
+        File confFolder = Files.createTempDirectory(tempFolder, "conf").toFile();
         File confYaml = new File(confFolder, "flink-conf.yaml");
         if (!confYaml.createNewFile()) {
             throw new IOException("Can't create testing flink-conf.yaml file.");
@@ -78,44 +74,44 @@ public class SqlClientTest {
         map.put(ENV_FLINK_CONF_DIR, confFolder.getAbsolutePath());
         CommonTestUtils.setEnv(map);
 
-        historyPath = tempFolder.newFile("history").toString();
+        historyPath = Files.createTempFile(tempFolder, "history", "").toFile().getPath();
     }
 
-    @After
-    public void after() {
+    @AfterEach
+    void after() {
         CommonTestUtils.setEnv(originalEnv);
     }
 
     @Test
-    public void testEmbeddedWithOptions() throws Exception {
+    void testEmbeddedWithOptions() throws Exception {
         String[] args = new String[] {"embedded", "-hist", historyPath};
         String actual = runSqlClient(args);
         assertThat(actual).contains("Command history file path: " + historyPath);
     }
 
     @Test
-    public void testEmbeddedWithLongOptions() throws Exception {
+    void testEmbeddedWithLongOptions() throws Exception {
         String[] args = new String[] {"embedded", "--history", historyPath};
         String actual = runSqlClient(args);
         assertThat(actual).contains("Command history file path: " + historyPath);
     }
 
     @Test
-    public void testEmbeddedWithoutOptions() throws Exception {
+    void testEmbeddedWithoutOptions() throws Exception {
         String[] args = new String[] {"embedded"};
         String actual = runSqlClient(args);
         assertThat(actual).contains("Command history file path: ");
     }
 
     @Test
-    public void testEmptyOptions() throws Exception {
+    void testEmptyOptions() throws Exception {
         String[] args = new String[] {};
         String actual = runSqlClient(args);
         assertThat(actual).contains("Command history file path");
     }
 
     @Test
-    public void testUnsupportedGatewayMode() {
+    void testUnsupportedGatewayMode() {
         String[] args = new String[] {"gateway"};
         assertThatThrownBy(() -> SqlClient.main(args))
                 .isInstanceOf(SqlClientException.class)
@@ -123,7 +119,7 @@ public class SqlClientTest {
     }
 
     @Test
-    public void testErrorMessage() throws Exception {
+    void testErrorMessage() throws Exception {
         // prepare statements which will throw exception
         String stmts =
                 "CREATE TABLE T (a int) WITH ('connector' = 'invalid');\n"
@@ -147,7 +143,7 @@ public class SqlClientTest {
     }
 
     @Test
-    public void testVerboseErrorMessage() throws Exception {
+    void testVerboseErrorMessage() throws Exception {
         // prepare statements which will throw exception
         String stmts =
                 "CREATE TABLE T (a int) WITH ('connector' = 'invalid');\n"
@@ -168,7 +164,7 @@ public class SqlClientTest {
     }
 
     @Test
-    public void testInitFile() throws Exception {
+    void testInitFile() throws Exception {
         List<String> statements =
                 Arrays.asList(
                         "-- define table \n"
@@ -187,7 +183,7 @@ public class SqlClientTest {
     }
 
     @Test
-    public void testExecuteSqlFile() throws Exception {
+    void testExecuteSqlFile() throws Exception {
         List<String> statements = Collections.singletonList("HELP;\n");
         String sqlFilePath = createSqlFile(statements, "test-sql.sql");
         String[] args = new String[] {"-f", sqlFilePath};
@@ -201,7 +197,7 @@ public class SqlClientTest {
     }
 
     @Test
-    public void testExecuteSqlWithHDFSFile() {
+    void testExecuteSqlWithHDFSFile() {
         String[] args = new String[] {"-f", "hdfs://path/to/file/test.sql"};
         assertThatThrownBy(() -> runSqlClient(args))
                 .isInstanceOf(SqlClientException.class)
@@ -226,7 +222,7 @@ public class SqlClientTest {
 
     private String createSqlFile(List<String> statements, String name) throws IOException {
         // create sql file
-        File sqlFileFolder = tempFolder.newFolder("sql-file");
+        File sqlFileFolder = Files.createTempDirectory(tempFolder, "sql-file").toFile();
         File sqlFile = new File(sqlFileFolder, name);
         if (!sqlFile.createNewFile()) {
             throw new IOException(String.format("Can't create testing %s.", name));
diff --git a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliClientITCase.java b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliClientITCase.java
index a3e22009ba1..f3eed1cb0d0 100644
--- a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliClientITCase.java
+++ b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliClientITCase.java
@@ -20,6 +20,7 @@ package org.apache.flink.table.client.cli;
 
 import org.apache.flink.client.cli.DefaultCLI;
 import org.apache.flink.configuration.Configuration;
+import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration;
 import org.apache.flink.table.api.config.ExecutionConfigOptions;
 import org.apache.flink.table.client.cli.utils.SqlScriptReader;
 import org.apache.flink.table.client.cli.utils.TestSqlStatement;
@@ -27,7 +28,8 @@ import org.apache.flink.table.client.gateway.Executor;
 import org.apache.flink.table.client.gateway.context.DefaultContext;
 import org.apache.flink.table.client.gateway.local.LocalExecutor;
 import org.apache.flink.table.planner.utils.TableTestUtil;
-import org.apache.flink.test.util.AbstractTestBase;
+import org.apache.flink.test.junit5.InjectClusterClientConfiguration;
+import org.apache.flink.test.junit5.MiniClusterExtension;
 import org.apache.flink.util.UserClassLoaderJarTestUtils;
 
 import org.apache.flink.shaded.guava30.com.google.common.io.PatternFilenameFilter;
@@ -38,13 +40,12 @@ import org.apache.commons.lang3.StringUtils;
 import org.jline.reader.MaskingCallback;
 import org.jline.terminal.Terminal;
 import org.jline.terminal.impl.DumbTerminal;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
@@ -56,6 +57,7 @@ import java.io.InputStream;
 import java.io.StringReader;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
@@ -64,7 +66,9 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import static org.apache.commons.lang3.StringUtils.repeat;
 import static org.apache.flink.configuration.JobManagerOptions.ADDRESS;
@@ -76,8 +80,7 @@ import static org.apache.flink.table.utils.UserDefinedFunctions.GENERATED_UPPER_
 import static org.assertj.core.api.Assertions.assertThat;
 
 /** Test that runs every {@code xx.q} file in "resources/sql/" path as a test. */
-@RunWith(Parameterized.class)
-public class CliClientITCase extends AbstractTestBase {
+class CliClientITCase {
 
     private static final String HIVE_ADD_ONE_UDF_CLASS = "HiveAddOneFunc";
     private static final String HIVE_ADD_ONE_UDF_CODE =
@@ -92,12 +95,17 @@ public class CliClientITCase extends AbstractTestBase {
     private static Path historyPath;
     private static Map<String, String> replaceVars;
 
-    @ClassRule public static TemporaryFolder tempFolder = new TemporaryFolder();
+    @TempDir private static Path tempFolder;
 
-    @Parameterized.Parameter public String sqlPath;
+    @RegisterExtension
+    private static final MiniClusterExtension MINI_CLUSTER_RESOURCE =
+            new MiniClusterExtension(
+                    new MiniClusterResourceConfiguration.Builder()
+                            .setNumberTaskManagers(1)
+                            .setNumberSlotsPerTaskManager(4)
+                            .build());
 
-    @Parameterized.Parameters(name = "{0}")
-    public static Object[] parameters() throws Exception {
+    static Stream<String> sqlPaths() throws Exception {
         String first = "sql/table.q";
         URL url = CliClientITCase.class.getResource("/" + first);
         File firstFile = Paths.get(url.toURI()).toFile();
@@ -108,11 +116,12 @@ public class CliClientITCase extends AbstractTestBase {
         for (File f : Util.first(dir.listFiles(filter), new File[0])) {
             paths.add(f.getAbsolutePath().substring(commonPrefixLength));
         }
-        return paths.toArray();
+        return paths.stream();
     }
 
-    @BeforeClass
-    public static void setup() throws IOException {
+    @BeforeAll
+    static void setup(@InjectClusterClientConfiguration Configuration configuration)
+            throws IOException {
         Map<String, String> classNameCodes = new HashMap<>();
         classNameCodes.put(
                 GENERATED_LOWER_UDF_CLASS,
@@ -124,7 +133,7 @@ public class CliClientITCase extends AbstractTestBase {
 
         File udfJar =
                 UserClassLoaderJarTestUtils.createJarFile(
-                        tempFolder.newFolder("test-jar"),
+                        Files.createTempDirectory(tempFolder, "test-jar").toFile(),
                         "test-classloader-udf.jar",
                         classNameCodes);
         URL udfDependency = udfJar.toURI().toURL();
@@ -132,37 +141,44 @@ public class CliClientITCase extends AbstractTestBase {
         // we need to pad the displayed "jars" tableau to have the same width of path string
         // 4 for the "jars" characters, see `set.q` test file
         int paddingLen = path.length() - 4;
-        historyPath = tempFolder.newFile("history").toPath();
+        historyPath = Files.createTempFile(tempFolder, "history", "");
 
         replaceVars = new HashMap<>();
         replaceVars.put("$VAR_UDF_JAR_PATH", path);
         replaceVars.put("$VAR_UDF_JAR_PATH_DASH", repeat('-', paddingLen));
         replaceVars.put("$VAR_UDF_JAR_PATH_SPACE", repeat(' ', paddingLen));
         replaceVars.put("$VAR_PIPELINE_JARS_URL", udfDependency.toString());
-        replaceVars.put(
-                "$VAR_REST_PORT",
-                MINI_CLUSTER_RESOURCE.getClientConfiguration().get(PORT).toString());
-        replaceVars.put(
-                "$VAR_JOBMANAGER_RPC_ADDRESS",
-                MINI_CLUSTER_RESOURCE.getClientConfiguration().get(ADDRESS));
+        replaceVars.put("$VAR_REST_PORT", configuration.get(PORT).toString());
+        replaceVars.put("$VAR_JOBMANAGER_RPC_ADDRESS", configuration.get(ADDRESS));
     }
 
-    @Before
-    public void before() throws IOException {
-        // initialize new folders for every tests, so the vars can be reused by every SQL scripts
-        replaceVars.put("$VAR_STREAMING_PATH", tempFolder.newFolder().toPath().toString());
-        replaceVars.put("$VAR_STREAMING_PATH2", tempFolder.newFolder().toPath().toString());
-        replaceVars.put("$VAR_BATCH_PATH", tempFolder.newFolder().toPath().toString());
-        replaceVars.put("$VAR_BATCH_PATH2", tempFolder.newFolder().toPath().toString());
+    @BeforeEach
+    void before() throws IOException {
+        // initialize new folders for every test, so the vars can be reused by every SQL script
+        replaceVars.put(
+                "$VAR_STREAMING_PATH",
+                Files.createTempDirectory(tempFolder, UUID.randomUUID().toString()).toString());
+        replaceVars.put(
+                "$VAR_STREAMING_PATH2",
+                Files.createTempDirectory(tempFolder, UUID.randomUUID().toString()).toString());
+        replaceVars.put(
+                "$VAR_BATCH_PATH",
+                Files.createTempDirectory(tempFolder, UUID.randomUUID().toString()).toString());
+        replaceVars.put(
+                "$VAR_BATCH_PATH2",
+                Files.createTempDirectory(tempFolder, UUID.randomUUID().toString()).toString());
     }
 
-    @Test
-    public void testSqlStatements() throws IOException {
+    @ParameterizedTest
+    @MethodSource("sqlPaths")
+    void testSqlStatements(
+            String sqlPath, @InjectClusterClientConfiguration Configuration configuration)
+            throws IOException {
         String in = getInputFromPath(sqlPath);
         List<TestSqlStatement> testSqlStatements = parseSqlScript(in);
         List<String> sqlStatements =
                 testSqlStatements.stream().map(s -> s.sql).collect(Collectors.toList());
-        List<Result> actualResults = runSqlStatements(sqlStatements);
+        List<Result> actualResults = runSqlStatements(sqlStatements, configuration);
         String out = transformOutput(testSqlStatements, actualResults);
         assertThat(out).isEqualTo(in);
     }
@@ -173,12 +189,13 @@ public class CliClientITCase extends AbstractTestBase {
      * @param statements the SQL statements to run
      * @return the printed results on SQL Client
      */
-    private List<Result> runSqlStatements(List<String> statements) throws IOException {
+    private List<Result> runSqlStatements(List<String> statements, Configuration configuration)
+            throws IOException {
         final String sqlContent = String.join("", statements);
         DefaultContext defaultContext =
                 new DefaultContext(
                         Collections.emptyList(),
-                        new Configuration(MINI_CLUSTER_RESOURCE.getClientConfiguration())
+                        new Configuration(configuration)
                                 // Make sure we use the new cast behaviour
                                 .set(
                                         ExecutionConfigOptions.TABLE_EXEC_LEGACY_CAST_BEHAVIOUR,
diff --git a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliClientMultiStatementITTest.java b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliClientMultiStatementITTest.java
index b4bc9e7770a..cbb87a40bcf 100644
--- a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliClientMultiStatementITTest.java
+++ b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliClientMultiStatementITTest.java
@@ -25,7 +25,6 @@ import org.apache.flink.table.planner.utils.TableTestUtil;
 import org.apache.flink.shaded.guava30.com.google.common.io.PatternFilenameFilter;
 
 import org.apache.calcite.util.Util;
-import org.junit.runners.Parameterized;
 
 import java.io.File;
 import java.io.FilenameFilter;
@@ -33,12 +32,12 @@ import java.net.URL;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Stream;
 
 /** Test that runs every {@code xx.q} file in "resources/sql_multi/" path as a test. */
-public class CliClientMultiStatementITTest extends CliClientITCase {
+class CliClientMultiStatementITTest extends CliClientITCase {
 
-    @Parameterized.Parameters(name = "{0}")
-    public static Object[] parameters() throws Exception {
+    static Stream<String> sqlPaths() throws Exception {
         String first = "sql_multi/statement_set.q";
         URL url = CliClientITCase.class.getResource("/" + first);
         File firstFile = Paths.get(url.toURI()).toFile();
@@ -49,7 +48,7 @@ public class CliClientMultiStatementITTest extends CliClientITCase {
         for (File f : Util.first(dir.listFiles(filter), new File[0])) {
             paths.add(f.getAbsolutePath().substring(commonPrefixLength));
         }
-        return paths.toArray();
+        return paths.stream();
     }
 
     protected List<TestSqlStatement> parseSqlScript(String input) {
diff --git a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliClientTest.java b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliClientTest.java
index cefe1e76a7e..f2ade51bfe1 100644
--- a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliClientTest.java
+++ b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliClientTest.java
@@ -45,7 +45,6 @@ import org.apache.flink.table.operations.Operation;
 import org.apache.flink.table.operations.QueryOperation;
 import org.apache.flink.types.Row;
 import org.apache.flink.util.CloseableIterator;
-import org.apache.flink.util.TestLogger;
 
 import org.jline.reader.Candidate;
 import org.jline.reader.LineReader;
@@ -54,7 +53,7 @@ import org.jline.reader.ParsedLine;
 import org.jline.reader.Parser;
 import org.jline.terminal.Terminal;
 import org.jline.terminal.impl.DumbTerminal;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import javax.annotation.Nullable;
 
@@ -82,7 +81,7 @@ import static org.apache.flink.table.client.cli.CliStrings.MESSAGE_SQL_EXECUTION
 import static org.assertj.core.api.Assertions.assertThat;
 
 /** Tests for the {@link CliClient}. */
-public class CliClientTest extends TestLogger {
+class CliClientTest {
 
     private static final String INSERT_INTO_STATEMENT =
             "INSERT INTO MyTable SELECT * FROM MyOtherTable";
@@ -93,20 +92,20 @@ public class CliClientTest extends TestLogger {
     private static final String HIVE_SQL_WITH_COMPLETER = "SELECT POSITION  FROM source_table;";
 
     @Test
-    public void testUpdateSubmission() throws Exception {
+    void testUpdateSubmission() throws Exception {
         verifyUpdateSubmission(INSERT_INTO_STATEMENT, false, false);
         verifyUpdateSubmission(INSERT_OVERWRITE_STATEMENT, false, false);
     }
 
     @Test
-    public void testFailedUpdateSubmission() throws Exception {
+    void testFailedUpdateSubmission() throws Exception {
         // fail at executor
         verifyUpdateSubmission(INSERT_INTO_STATEMENT, true, true);
         verifyUpdateSubmission(INSERT_OVERWRITE_STATEMENT, true, true);
     }
 
     @Test
-    public void testExecuteSqlFile() throws Exception {
+    void testExecuteSqlFile() throws Exception {
         MockExecutor executor = new MockExecutor();
         executeSqlFromContent(
                 executor,
@@ -118,14 +117,14 @@ public class CliClientTest extends TestLogger {
     }
 
     @Test
-    public void testExecuteSqlFileWithoutSqlCompleter() throws Exception {
+    void testExecuteSqlFileWithoutSqlCompleter() throws Exception {
         MockExecutor executor = new MockExecutor(new SqlParserHelper(SqlDialect.HIVE));
         executeSqlFromContent(executor, ORIGIN_HIVE_SQL);
         assertThat(executor.receivedStatement).contains(HIVE_SQL_WITHOUT_COMPLETER);
     }
 
     @Test
-    public void testExecuteSqlInteractiveWithSqlCompleter() throws Exception {
+    void testExecuteSqlInteractiveWithSqlCompleter() throws Exception {
         final MockExecutor mockExecutor = new MockExecutor(new SqlParserHelper(SqlDialect.HIVE));
         String sessionId = mockExecutor.openSession("test-session");
 
@@ -141,7 +140,7 @@ public class CliClientTest extends TestLogger {
     }
 
     @Test
-    public void testSqlCompletion() throws IOException {
+    void testSqlCompletion() throws IOException {
         verifySqlCompletion("", 0, Arrays.asList("CLEAR", "HELP", "EXIT", "QUIT", "RESET", "SET"));
         verifySqlCompletion("SELE", 4, Collections.emptyList());
         verifySqlCompletion("QU", 2, Collections.singletonList("QUIT"));
@@ -154,7 +153,7 @@ public class CliClientTest extends TestLogger {
     }
 
     @Test
-    public void testHistoryFile() throws Exception {
+    void testHistoryFile() throws Exception {
         final MockExecutor mockExecutor = new MockExecutor();
         String sessionId = mockExecutor.openSession("test-session");
 
@@ -167,14 +166,14 @@ public class CliClientTest extends TestLogger {
                                 () -> terminal, sessionId, mockExecutor, historyFilePath, null)) {
             client.executeInInteractiveMode();
             List<String> content = Files.readAllLines(historyFilePath);
-            assertThat(content.size()).isEqualTo(2);
+            assertThat(content).hasSize(2);
             assertThat(content.get(0)).contains("help");
             assertThat(content.get(1)).contains("use catalog cat");
         }
     }
 
     @Test
-    public void testGetEOFinNonInteractiveMode() throws Exception {
+    void testGetEOFinNonInteractiveMode() throws Exception {
         final List<String> statements =
                 Arrays.asList("DESC MyOtherTable;", "SHOW TABLES"); // meet EOF
         String content = String.join("\n", statements);
@@ -187,7 +186,7 @@ public class CliClientTest extends TestLogger {
     }
 
     @Test
-    public void testUnknownStatementInNonInteractiveMode() throws Exception {
+    void testUnknownStatementInNonInteractiveMode() throws Exception {
         final List<String> statements =
                 Arrays.asList(
                         "ERT INTO MyOtherTable VALUES (1, 101), (2, 102);",
@@ -203,7 +202,7 @@ public class CliClientTest extends TestLogger {
     }
 
     @Test
-    public void testFailedExecutionInNonInteractiveMode() throws Exception {
+    void testFailedExecutionInNonInteractiveMode() throws Exception {
         final List<String> statements =
                 Arrays.asList(
                         "INSERT INTO MyOtherTable VALUES (1, 101), (2, 102);",
@@ -220,7 +219,7 @@ public class CliClientTest extends TestLogger {
     }
 
     @Test
-    public void testIllegalResultModeInNonInteractiveMode() throws Exception {
+    void testIllegalResultModeInNonInteractiveMode() throws Exception {
         // When client executes sql file, it requires sql-client.execution.result-mode = tableau;
         // Therefore, it will get execution error and stop executing the sql follows the illegal
         // statement.
@@ -245,7 +244,7 @@ public class CliClientTest extends TestLogger {
     }
 
     @Test
-    public void testIllegalStatementInInitFile() throws Exception {
+    void testIllegalStatementInInitFile() throws Exception {
         final List<String> statements =
                 Arrays.asList(
                         "CREATE TABLE source (a int, b string) with ( 'connector' = 'values');",
@@ -263,8 +262,8 @@ public class CliClientTest extends TestLogger {
         assertThat(cliClient.executeInitialization(content)).isFalse();
     }
 
-    @Test(timeout = 10000)
-    public void testCancelExecutionInNonInteractiveMode() throws Exception {
+    @Test
+    void testCancelExecutionInNonInteractiveMode() throws Exception {
         // add "\n" with quit to trigger commit the line
         final List<String> statements =
                 Arrays.asList(
@@ -324,7 +323,7 @@ public class CliClientTest extends TestLogger {
     }
 
     @Test
-    public void testCancelExecutionInteractiveMode() throws Exception {
+    void testCancelExecutionInteractiveMode() throws Exception {
         final MockExecutor mockExecutor = new MockExecutor();
         mockExecutor.isSync = true;
 
@@ -361,8 +360,8 @@ public class CliClientTest extends TestLogger {
         }
     }
 
-    @Test(timeout = 10000)
-    public void testStopJob() throws Exception {
+    @Test
+    void testStopJob() throws Exception {
         final MockExecutor mockExecutor = new MockExecutor();
         mockExecutor.isSync = false;
 
@@ -384,8 +383,8 @@ public class CliClientTest extends TestLogger {
         }
     }
 
-    @Test(timeout = 10000)
-    public void testStopJobWithSavepoint() throws Exception {
+    @Test
+    void testStopJobWithSavepoint() throws Exception {
         final MockExecutor mockExecutor = new MockExecutor();
         mockExecutor.isSync = false;
         final String mockSavepoint = "/my/savepoint/path";
diff --git a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliResultViewTest.java b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliResultViewTest.java
index bba5f9cb5c2..e49253b7b3a 100644
--- a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliResultViewTest.java
+++ b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliResultViewTest.java
@@ -40,7 +40,7 @@ import org.apache.flink.table.utils.DateTimeUtils;
 import org.jline.reader.MaskingCallback;
 import org.jline.terminal.Terminal;
 import org.jline.utils.AttributedString;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import javax.annotation.Nullable;
 
@@ -58,35 +58,35 @@ import static org.apache.flink.table.client.config.SqlClientOptions.EXECUTION_RE
 import static org.assertj.core.api.Assertions.assertThat;
 
 /** Contains basic tests for the {@link CliResultView}. */
-public class CliResultViewTest {
+class CliResultViewTest {
 
     @Test
-    public void testTableResultViewKeepJobResult() throws Exception {
+    void testTableResultViewKeepJobResult() throws Exception {
         testResultViewClearResult(TypedResult.endOfStream(), true, 0);
     }
 
     @Test
-    public void testTableResultViewClearEmptyResult() throws Exception {
+    void testTableResultViewClearEmptyResult() throws Exception {
         testResultViewClearResult(TypedResult.empty(), true, 1);
     }
 
     @Test
-    public void testTableResultViewClearPayloadResult() throws Exception {
+    void testTableResultViewClearPayloadResult() throws Exception {
         testResultViewClearResult(TypedResult.payload(1), true, 1);
     }
 
     @Test
-    public void testChangelogResultViewKeepJobResult() throws Exception {
+    void testChangelogResultViewKeepJobResult() throws Exception {
         testResultViewClearResult(TypedResult.endOfStream(), false, 0);
     }
 
     @Test
-    public void testChangelogResultViewClearEmptyResult() throws Exception {
+    void testChangelogResultViewClearEmptyResult() throws Exception {
         testResultViewClearResult(TypedResult.empty(), false, 1);
     }
 
     @Test
-    public void testChangelogResultViewClearPayloadResult() throws Exception {
+    void testChangelogResultViewClearPayloadResult() throws Exception {
         testResultViewClearResult(TypedResult.payload(Collections.emptyList()), false, 1);
     }
 
diff --git a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliTableauResultViewTest.java b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliTableauResultViewTest.java
index 396178a0b08..b5fc9bf706c 100644
--- a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliTableauResultViewTest.java
+++ b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliTableauResultViewTest.java
@@ -34,23 +34,23 @@ import org.apache.flink.table.data.conversion.DataStructureConverters;
 import org.apache.flink.table.planner.functions.casting.RowDataToStringConverterImpl;
 import org.apache.flink.table.utils.DateTimeUtils;
 import org.apache.flink.table.utils.print.RowDataToStringConverter;
-import org.apache.flink.testutils.executor.TestExecutorResource;
+import org.apache.flink.testutils.TestingUtils;
+import org.apache.flink.testutils.executor.TestExecutorExtension;
 import org.apache.flink.types.Row;
 import org.apache.flink.types.RowKind;
 
 import org.jline.terminal.Terminal;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
 import java.io.ByteArrayOutputStream;
 import java.math.BigDecimal;
 import java.sql.Timestamp;
 import java.util.Arrays;
 import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
@@ -60,10 +60,10 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.fail;
 
 /** Tests for CliTableauResultView. */
-public class CliTableauResultViewTest {
-    @ClassRule
-    public static final TestExecutorResource<ExecutorService> EXECUTOR_RESOURCE =
-            new TestExecutorResource<>(Executors::newSingleThreadExecutor);
+class CliTableauResultViewTest {
+    @RegisterExtension
+    static final TestExecutorExtension<ScheduledExecutorService> EXECUTOR_RESOURCE =
+            TestingUtils.defaultExecutorExtension();
 
     private ByteArrayOutputStream terminalOutput;
     private Terminal terminal;
@@ -72,8 +72,8 @@ public class CliTableauResultViewTest {
     private List<RowData> streamingData;
     private RowDataToStringConverter rowDataToStringConverter;
 
-    @Before
-    public void setUp() {
+    @BeforeEach
+    void setUp() {
         terminalOutput = new ByteArrayOutputStream();
         terminal = TerminalUtils.createDumbTerminal(terminalOutput);
 
@@ -183,7 +183,7 @@ public class CliTableauResultViewTest {
     }
 
     @Test
-    public void testBatchResult() {
+    void testBatchResult() {
         final Configuration testConfig = new Configuration();
         testConfig.set(EXECUTION_RESULT_MODE, ResultMode.TABLEAU);
         testConfig.set(RUNTIME_MODE, RuntimeExecutionMode.BATCH);
@@ -205,8 +205,8 @@ public class CliTableauResultViewTest {
 
         view.displayResults();
         view.close();
-        assertThat(terminalOutput.toString())
-                .isEqualTo(
+        assertThat(terminalOutput)
+                .hasToString(
                         "+---------+-------------+----------------------+--------------------------------+----------------+----------------------------+---------------------+"
                                 + System.lineSeparator()
                                 + "| boolean |         int |               bigint |                        varchar | decimal(10, 5) |                  timestamp |              binary |"
@@ -233,11 +233,11 @@ public class CliTableauResultViewTest {
                                 + System.lineSeparator()
                                 + "8 rows in set"
                                 + System.lineSeparator());
-        assertThat(mockExecutor.getNumCancelCalls()).isEqualTo(0);
+        assertThat(mockExecutor.getNumCancelCalls()).isZero();
     }
 
     @Test
-    public void testCancelBatchResult() throws Exception {
+    void testCancelBatchResult() throws Exception {
         final Configuration testConfig = new Configuration();
         testConfig.set(EXECUTION_RESULT_MODE, ResultMode.TABLEAU);
         testConfig.set(RUNTIME_MODE, RuntimeExecutionMode.BATCH);
@@ -265,19 +265,20 @@ public class CliTableauResultViewTest {
         terminal.raise(Terminal.Signal.INT);
         furture.get(5, TimeUnit.SECONDS);
 
-        assertThat(terminalOutput.toString())
-                .isEqualTo("Query terminated, received a total of 0 row" + System.lineSeparator());
+        assertThat(terminalOutput)
+                .hasToString(
+                        "Query terminated, received a total of 0 row" + System.lineSeparator());
 
         // didn't have a chance to read page
-        assertThat(mockExecutor.getNumRetrieveResultPageCalls()).isEqualTo(0);
+        assertThat(mockExecutor.getNumRetrieveResultPageCalls()).isZero();
         // tried to cancel query
-        assertThat(mockExecutor.getNumCancelCalls()).isEqualTo(1);
+        assertThat(mockExecutor.getNumCancelCalls()).isOne();
 
         view.close();
     }
 
     @Test
-    public void testEmptyBatchResult() {
+    void testEmptyBatchResult() {
         final Configuration testConfig = new Configuration();
         testConfig.set(EXECUTION_RESULT_MODE, ResultMode.TABLEAU);
         testConfig.set(RUNTIME_MODE, RuntimeExecutionMode.BATCH);
@@ -299,12 +300,12 @@ public class CliTableauResultViewTest {
         view.displayResults();
         view.close();
 
-        assertThat(terminalOutput.toString()).isEqualTo("Empty set" + System.lineSeparator());
-        assertThat(mockExecutor.getNumCancelCalls()).isEqualTo(0);
+        assertThat(terminalOutput).hasToString("Empty set" + System.lineSeparator());
+        assertThat(mockExecutor.getNumCancelCalls()).isZero();
     }
 
     @Test
-    public void testFailedBatchResult() {
+    void testFailedBatchResult() {
         final Configuration testConfig = new Configuration();
         testConfig.set(EXECUTION_RESULT_MODE, ResultMode.TABLEAU);
         testConfig.set(RUNTIME_MODE, RuntimeExecutionMode.BATCH);
@@ -331,11 +332,11 @@ public class CliTableauResultViewTest {
         }
         view.close();
 
-        assertThat(mockExecutor.getNumCancelCalls()).isEqualTo(1);
+        assertThat(mockExecutor.getNumCancelCalls()).isOne();
     }
 
     @Test
-    public void testStreamingResult() {
+    void testStreamingResult() {
         final Configuration testConfig = new Configuration();
         testConfig.set(EXECUTION_RESULT_MODE, ResultMode.TABLEAU);
         testConfig.set(RUNTIME_MODE, RuntimeExecutionMode.STREAMING);
@@ -366,8 +367,8 @@ public class CliTableauResultViewTest {
         // width < 2 in IDE by default, every CJK character usually's width is 2, you can open this
         // source file
         // by vim or just cat the file to check the regular result.
-        assertThat(terminalOutput.toString())
-                .isEqualTo(
+        assertThat(terminalOutput)
+                .hasToString(
                         "+----+---------+-------------+----------------------+--------------------------------+----------------+----------------------------+--------------------------------+"
                                 + System.lineSeparator()
                                 + "| op | boolean |         int |               bigint |                        varchar | decimal(10, 5) |                  timestamp |                         binary |"
@@ -394,11 +395,11 @@ public class CliTableauResultViewTest {
                                 + System.lineSeparator()
                                 + "Received a total of 8 rows"
                                 + System.lineSeparator());
-        assertThat(mockExecutor.getNumCancelCalls()).isEqualTo(0);
+        assertThat(mockExecutor.getNumCancelCalls()).isZero();
     }
 
     @Test
-    public void testEmptyStreamingResult() {
+    void testEmptyStreamingResult() {
         final Configuration testConfig = new Configuration();
         testConfig.set(EXECUTION_RESULT_MODE, ResultMode.TABLEAU);
         testConfig.set(RUNTIME_MODE, RuntimeExecutionMode.STREAMING);
@@ -416,8 +417,8 @@ public class CliTableauResultViewTest {
         view.displayResults();
         view.close();
 
-        assertThat(terminalOutput.toString())
-                .isEqualTo(
+        assertThat(terminalOutput)
+                .hasToString(
                         "+----+---------+-------------+----------------------+--------------------------------+----------------+----------------------------+--------------------------------+"
                                 + System.lineSeparator()
                                 + "| op | boolean |         int |               bigint |                        varchar | decimal(10, 5) |                  timestamp |                         binary |"
@@ -426,11 +427,11 @@ public class CliTableauResultViewTest {
                                 + System.lineSeparator()
                                 + "Received a total of 0 row"
                                 + System.lineSeparator());
-        assertThat(mockExecutor.getNumCancelCalls()).isEqualTo(0);
+        assertThat(mockExecutor.getNumCancelCalls()).isZero();
     }
 
     @Test
-    public void testCancelStreamingResult() throws Exception {
+    void testCancelStreamingResult() throws Exception {
         final Configuration testConfig = new Configuration();
         testConfig.set(EXECUTION_RESULT_MODE, ResultMode.TABLEAU);
         testConfig.set(RUNTIME_MODE, RuntimeExecutionMode.STREAMING);
@@ -461,8 +462,8 @@ public class CliTableauResultViewTest {
         furture.get(5, TimeUnit.SECONDS);
         view.close();
 
-        assertThat(terminalOutput.toString())
-                .isEqualTo(
+        assertThat(terminalOutput)
+                .hasToString(
                         "+----+---------+-------------+----------------------+--------------------------------+----------------+----------------------------+--------------------------------+"
                                 + System.lineSeparator()
                                 + "| op | boolean |         int |               bigint |                        varchar | decimal(10, 5) |                  timestamp |                         binary |"
@@ -480,11 +481,11 @@ public class CliTableauResultViewTest {
                                 + "Query terminated, received a total of 4 rows"
                                 + System.lineSeparator());
 
-        assertThat(mockExecutor.getNumCancelCalls()).isEqualTo(1);
+        assertThat(mockExecutor.getNumCancelCalls()).isOne();
     }
 
     @Test
-    public void testFailedStreamingResult() {
+    void testFailedStreamingResult() {
         final Configuration testConfig = new Configuration();
         testConfig.set(EXECUTION_RESULT_MODE, ResultMode.TABLEAU);
         testConfig.set(RUNTIME_MODE, RuntimeExecutionMode.STREAMING);
@@ -513,8 +514,8 @@ public class CliTableauResultViewTest {
         }
         view.close();
 
-        assertThat(terminalOutput.toString())
-                .isEqualTo(
+        assertThat(terminalOutput)
+                .hasToString(
                         "+----+---------+-------------+----------------------+--------------------------------+----------------+----------------------------+--------------------------------+"
                                 + System.lineSeparator()
                                 + "| op | boolean |         int |               bigint |                        varchar | decimal(10, 5) |                  timestamp |                         binary |"
@@ -529,6 +530,6 @@ public class CliTableauResultViewTest {
                                 + System.lineSeparator()
                                 + "| -D |   FALSE | -2147483648 |  9223372036854775807 |                         <NULL> |    12345.06789 | 2020-03-01 18:39:14.123000 |            x'32333485365d737e' |"
                                 + System.lineSeparator());
-        assertThat(mockExecutor.getNumCancelCalls()).isEqualTo(1);
+        assertThat(mockExecutor.getNumCancelCalls()).isOne();
     }
 }
diff --git a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliUtilsTest.java b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliUtilsTest.java
index cb271942c9d..18201c2adb3 100644
--- a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliUtilsTest.java
+++ b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/CliUtilsTest.java
@@ -18,9 +18,8 @@
 
 package org.apache.flink.table.client.cli;
 
-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 java.io.IOException;
 import java.nio.file.Files;
@@ -30,34 +29,33 @@ import java.nio.file.Paths;
 import static org.assertj.core.api.Assertions.assertThat;
 
 /** Test {@link CliUtils}. */
-public class CliUtilsTest {
+class CliUtilsTest {
 
-    @Rule public TemporaryFolder realFolder = new TemporaryFolder();
+    @TempDir private Path realFolder;
 
-    @Rule public TemporaryFolder linkFolder = new TemporaryFolder();
+    @TempDir private Path linkFolder;
 
     @Test
-    public void testCreateFileRealDir() {
-        Path realDirHistoryFile = Paths.get(realFolder.getRoot().toString(), "history.file");
+    void testCreateFileRealDir() {
+        Path realDirHistoryFile = Paths.get(realFolder.toFile().getPath(), "history.file");
         CliUtils.createFile(realDirHistoryFile);
         assertThat(Files.exists(realDirHistoryFile)).isTrue();
     }
 
     @Test
-    public void testCreateFileLinkDir() throws IOException {
-        Path link = Paths.get(linkFolder.getRoot().getAbsolutePath(), "link");
-        Files.createSymbolicLink(link, realFolder.getRoot().toPath());
+    void testCreateFileLinkDir() throws IOException {
+        Path link = Paths.get(linkFolder.toFile().getPath(), "link");
+        Files.createSymbolicLink(link, realFolder);
         Path linkDirHistoryFile = Paths.get(link.toAbsolutePath().toString(), "history.file");
-        Path realLinkDirHistoryFile = Paths.get(realFolder.getRoot().toString(), "history.file");
+        Path realLinkDirHistoryFile = Paths.get(realFolder.toFile().getPath(), "history.file");
         CliUtils.createFile(linkDirHistoryFile);
         assertThat(Files.exists(linkDirHistoryFile)).isTrue();
         assertThat(Files.exists(realLinkDirHistoryFile)).isTrue();
     }
 
     @Test
-    public void testCreateFileSubDir() {
-        Path subDirHistoryFile =
-                Paths.get(realFolder.getRoot().toString(), "subdir", "history.file");
+    void testCreateFileSubDir() {
+        Path subDirHistoryFile = Paths.get(realFolder.toFile().getPath(), "subdir", "history.file");
         CliUtils.createFile(subDirHistoryFile);
         assertThat(Files.exists(subDirHistoryFile)).isTrue();
     }
diff --git a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/utils/SqlParserHelper.java b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/utils/SqlParserHelper.java
index 2e931e00f5b..8de112e9f77 100644
--- a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/utils/SqlParserHelper.java
+++ b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/cli/utils/SqlParserHelper.java
@@ -26,7 +26,7 @@ import org.apache.flink.table.catalog.hive.HiveCatalog;
 import org.apache.flink.table.catalog.hive.HiveTestUtils;
 import org.apache.flink.table.delegation.Parser;
 
-/** An utility class that provides pre-prepared tables and sql parser. */
+/** A utility class that provides pre-prepared tables and sql parser. */
 public class SqlParserHelper {
     // return the sql parser instance hold by this table evn.
     private TableEnvironment tableEnv;
diff --git a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/context/SessionContextTest.java b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/context/SessionContextTest.java
index 24b1fcecfda..91892d127b2 100644
--- a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/context/SessionContextTest.java
+++ b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/context/SessionContextTest.java
@@ -26,15 +26,16 @@ import org.apache.flink.types.Row;
 import org.apache.flink.util.CollectionUtil;
 import org.apache.flink.util.UserClassLoaderJarTestUtils;
 
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
@@ -53,31 +54,31 @@ import static org.assertj.core.api.Assertions.fail;
 import static org.assertj.core.api.HamcrestCondition.matching;
 
 /** Test {@link SessionContext}. */
-public class SessionContextTest {
+class SessionContextTest {
 
-    @ClassRule public static TemporaryFolder tempFolder = new TemporaryFolder();
+    @TempDir private static Path tempFolder;
 
     private static File udfJar;
 
     private SessionContext sessionContext;
 
-    @BeforeClass
-    public static void prepare() throws Exception {
+    @BeforeAll
+    static void prepare() throws Exception {
         udfJar =
                 UserClassLoaderJarTestUtils.createJarFile(
-                        tempFolder.newFolder("test-jar"),
+                        Files.createTempDirectory(tempFolder, "test-jar").toFile(),
                         "test-classloader-udf.jar",
                         GENERATED_LOWER_UDF_CLASS,
                         String.format(GENERATED_LOWER_UDF_CODE, GENERATED_LOWER_UDF_CLASS));
     }
 
-    @Before
-    public void setup() {
+    @BeforeEach
+    void setup() {
         sessionContext = createSessionContext();
     }
 
     @Test
-    public void testSetAndResetOption() {
+    void testSetAndResetOption() {
         // table config option
         sessionContext.set(TABLE_SQL_DIALECT.key(), "hive");
         // runtime config option
@@ -102,7 +103,7 @@ public class SessionContextTest {
     }
 
     @Test
-    public void testSetAndResetKeyInConfigOptions() {
+    void testSetAndResetKeyInConfigOptions() {
         // table config option
         sessionContext.set(TABLE_SQL_DIALECT.key(), "hive");
         // runtime config option
@@ -131,41 +132,39 @@ public class SessionContextTest {
     }
 
     @Test
-    public void testSetAndResetArbitraryKey() {
+    void testSetAndResetArbitraryKey() {
         // other property not in flink-conf
         sessionContext.set("aa", "11");
         sessionContext.set("bb", "22");
 
-        assertThat(getConfigurationMap().get("aa")).isEqualTo("11");
-        assertThat(getConfigurationMap().get("bb")).isEqualTo("22");
+        assertThat(getConfigurationMap()).containsEntry("aa", "11").containsEntry("bb", "22");
 
         sessionContext.reset("aa");
-        assertThat(getConfigurationMap().get("aa")).isNull();
-        assertThat(getConfigurationMap().get("bb")).isEqualTo("22");
+        assertThat(getConfigurationMap()).doesNotContainKey("aa").containsEntry("bb", "22");
 
         sessionContext.reset("bb");
-        assertThat(getConfigurationMap().get("bb")).isNull();
+        assertThat(getConfigurationMap()).doesNotContainKey("bb");
     }
 
     @Test
-    public void testRemoveJarWithFullPath() {
+    void testRemoveJarWithFullPath() {
         validateRemoveJar(udfJar.getPath());
     }
 
     @Test
-    public void testRemoveJarWithRelativePath() throws IOException {
+    void testRemoveJarWithRelativePath() throws IOException {
         validateRemoveJar(
                 new File(".").getCanonicalFile().toPath().relativize(udfJar.toPath()).toString());
     }
 
     @Test
-    public void testRemoveIllegalJar() {
+    void testRemoveIllegalJar() {
         validateRemoveJarWithException(
                 "/path/to/illegal.jar", "Failed to unregister the jar resource");
     }
 
     @Test
-    public void testRemoveRemoteJar() {
+    void testRemoveRemoteJar() {
         Configuration innerConfig = (Configuration) sessionContext.getReadableConfig();
         innerConfig.set(JARS, Collections.singletonList("hdfs://remote:10080/remote.jar"));
 
diff --git a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/DependencyTest.java b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/DependencyTest.java
index 2de67ff74fc..eb8aba1ff9d 100644
--- a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/DependencyTest.java
+++ b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/DependencyTest.java
@@ -55,7 +55,7 @@ import org.apache.flink.table.types.DataType;
 import org.apache.flink.types.Row;
 import org.apache.flink.util.CollectionUtil;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import java.util.Arrays;
 import java.util.Collections;
@@ -70,7 +70,7 @@ import java.util.stream.IntStream;
 import static org.assertj.core.api.Assertions.assertThat;
 
 /** Dependency tests for {@link LocalExecutor}. Mainly for testing classloading of dependencies. */
-public class DependencyTest {
+class DependencyTest {
 
     public static final String CONNECTOR_TYPE_VALUE = "test-connector";
     public static final String TEST_PROPERTY = "test-property";
@@ -97,7 +97,7 @@ public class DependencyTest {
     private static final String SESSION_ID = "test-session";
 
     @Test
-    public void testTableFactoryDiscovery() throws Exception {
+    void testTableFactoryDiscovery() throws Exception {
         final LocalExecutor executor = createLocalExecutor();
         try {
             final TableResult tableResult =
@@ -134,7 +134,7 @@ public class DependencyTest {
     }
 
     @Test
-    public void testSqlParseWithUserClassLoader() throws Exception {
+    void testSqlParseWithUserClassLoader() throws Exception {
         final LocalExecutor executor = createLocalExecutor();
         try {
             Operation operation =
diff --git a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/LocalExecutorITCase.java b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/LocalExecutorITCase.java
index 73b03112fcf..967cb9da21c 100644
--- a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/LocalExecutorITCase.java
+++ b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/LocalExecutorITCase.java
@@ -51,13 +51,11 @@ import org.apache.flink.test.junit5.InjectClusterClient;
 import org.apache.flink.test.junit5.MiniClusterExtension;
 import org.apache.flink.test.util.TestBaseUtils;
 import org.apache.flink.util.StringUtils;
-import org.apache.flink.util.TestLogger;
 import org.apache.flink.util.UserClassLoaderJarTestUtils;
 
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Order;
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.Timeout;
 import org.junit.jupiter.api.extension.RegisterExtension;
 import org.junit.jupiter.api.io.TempDir;
 
@@ -86,7 +84,7 @@ import static org.apache.flink.util.Preconditions.checkState;
 import static org.assertj.core.api.Assertions.assertThat;
 
 /** Contains basic tests for the {@link LocalExecutor}. */
-public class LocalExecutorITCase extends TestLogger {
+class LocalExecutorITCase {
 
     private static final int NUM_TMS = 2;
     private static final int NUM_SLOTS_PER_TM = 2;
@@ -112,7 +110,7 @@ public class LocalExecutorITCase extends TestLogger {
     private static URL udfDependency;
 
     @BeforeAll
-    public static void setup(@InjectClusterClient ClusterClient<?> injectedClusterClient)
+    static void setup(@InjectClusterClient ClusterClient<?> injectedClusterClient)
             throws Exception {
         clusterClient = injectedClusterClient;
         File udfJar =
@@ -138,7 +136,7 @@ public class LocalExecutorITCase extends TestLogger {
     }
 
     @Test
-    public void testCompleteStatement() {
+    void testCompleteStatement() {
         final Executor executor = createLocalExecutor();
         String sessionId = executor.openSession("test-session");
         assertThat(sessionId).isEqualTo("test-session");
@@ -164,8 +162,7 @@ public class LocalExecutorITCase extends TestLogger {
     }
 
     @Test
-    @Timeout(value = 90)
-    public void testStreamQueryExecutionChangelog() throws Exception {
+    void testStreamQueryExecutionChangelog() throws Exception {
         final URL url = getClass().getClassLoader().getResource("test-data.csv");
         Objects.requireNonNull(url);
         final Map<String, String> replaceVars = new HashMap<>();
@@ -212,8 +209,7 @@ public class LocalExecutorITCase extends TestLogger {
     }
 
     @Test
-    @Timeout(value = 90)
-    public void testStreamQueryExecutionChangelogMultipleTimes() throws Exception {
+    void testStreamQueryExecutionChangelogMultipleTimes() throws Exception {
         final URL url = getClass().getClassLoader().getResource("test-data.csv");
         Objects.requireNonNull(url);
         final Map<String, String> replaceVars = new HashMap<>();
@@ -262,8 +258,7 @@ public class LocalExecutorITCase extends TestLogger {
     }
 
     @Test
-    @Timeout(value = 90)
-    public void testStreamQueryExecutionTable() throws Exception {
+    void testStreamQueryExecutionTable() throws Exception {
         final URL url = getClass().getClassLoader().getResource("test-data.csv");
         Objects.requireNonNull(url);
 
@@ -288,8 +283,7 @@ public class LocalExecutorITCase extends TestLogger {
     }
 
     @Test
-    @Timeout(value = 90)
-    public void testStreamQueryExecutionTableMultipleTimes() throws Exception {
+    void testStreamQueryExecutionTableMultipleTimes() throws Exception {
         final URL url = getClass().getClassLoader().getResource("test-data.csv");
         Objects.requireNonNull(url);
 
@@ -315,8 +309,7 @@ public class LocalExecutorITCase extends TestLogger {
     }
 
     @Test
-    @Timeout(value = 90)
-    public void testStreamQueryExecutionLimitedTable() throws Exception {
+    void testStreamQueryExecutionLimitedTable() throws Exception {
         final URL url = getClass().getClassLoader().getResource("test-data.csv");
         Objects.requireNonNull(url);
 
@@ -337,8 +330,7 @@ public class LocalExecutorITCase extends TestLogger {
     }
 
     @Test
-    @Timeout(value = 90)
-    public void testBatchQueryExecution() throws Exception {
+    void testBatchQueryExecution() throws Exception {
         final URL url = getClass().getClassLoader().getResource("test-data.csv");
         Objects.requireNonNull(url);
         final Map<String, String> replaceVars = new HashMap<>();
@@ -384,8 +376,7 @@ public class LocalExecutorITCase extends TestLogger {
     }
 
     @Test
-    @Timeout(value = 90)
-    public void testBatchQueryExecutionMultipleTimes() throws Exception {
+    void testBatchQueryExecutionMultipleTimes() throws Exception {
         final URL url = getClass().getClassLoader().getResource("test-data.csv");
         Objects.requireNonNull(url);
         final Map<String, String> replaceVars = new HashMap<>();
@@ -433,8 +424,7 @@ public class LocalExecutorITCase extends TestLogger {
     }
 
     @Test
-    @Timeout(value = 90)
-    public void testStopJob() throws Exception {
+    void testStopJob() throws Exception {
         final Map<String, String> configMap = new HashMap<>();
         configMap.put(EXECUTION_RESULT_MODE.key(), ResultMode.TABLE.name());
         configMap.put(RUNTIME_MODE.key(), RuntimeExecutionMode.STREAMING.name());
@@ -466,7 +456,7 @@ public class LocalExecutorITCase extends TestLogger {
             } while (jobStatus != JobStatus.RUNNING);
 
             Optional<String> savepoint = executor.stopJob(sessionId, jobId.toString(), true, true);
-            assertThat(savepoint.isPresent()).isTrue();
+            assertThat(savepoint).isPresent();
         } finally {
             executor.closeSession(sessionId);
         }
diff --git a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/result/ChangelogCollectResultTest.java b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/result/ChangelogCollectResultTest.java
index 4238a04093b..b4982f50c1e 100644
--- a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/result/ChangelogCollectResultTest.java
+++ b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/result/ChangelogCollectResultTest.java
@@ -29,7 +29,7 @@ import org.apache.flink.table.data.RowData;
 import org.apache.flink.types.Row;
 import org.apache.flink.util.CloseableIterator;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import java.util.List;
 import java.util.stream.IntStream;
@@ -37,10 +37,10 @@ import java.util.stream.IntStream;
 import static org.assertj.core.api.Assertions.assertThat;
 
 /** Tests for {@link ChangelogCollectResult}. */
-public class ChangelogCollectResultTest {
+class ChangelogCollectResultTest {
 
     @Test
-    public void testRetrieveChanges() throws Exception {
+    void testRetrieveChanges() throws Exception {
         int totalCount = ChangelogCollectResult.CHANGE_RECORD_BUFFER_SIZE * 2;
         CloseableIterator<Row> data =
                 CloseableIterator.adapterForIterator(
diff --git a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/result/MaterializedCollectBatchResultTest.java b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/result/MaterializedCollectBatchResultTest.java
index 4be0bf644ae..50d11fe2bd5 100644
--- a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/result/MaterializedCollectBatchResultTest.java
+++ b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/result/MaterializedCollectBatchResultTest.java
@@ -31,7 +31,7 @@ import org.apache.flink.table.data.conversion.DataStructureConverters;
 import org.apache.flink.table.types.DataType;
 import org.apache.flink.types.Row;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import java.util.Arrays;
 import java.util.Collections;
@@ -40,10 +40,10 @@ import java.util.function.Function;
 import static org.assertj.core.api.Assertions.assertThat;
 
 /** Tests for {@link MaterializedCollectBatchResult}. */
-public class MaterializedCollectBatchResultTest extends BaseMaterializedResultTest {
+class MaterializedCollectBatchResultTest extends BaseMaterializedResultTest {
 
     @Test
-    public void testSnapshot() throws Exception {
+    void testSnapshot() throws Exception {
         final ResolvedSchema schema =
                 ResolvedSchema.physical(
                         new String[] {"f0", "f1"},
@@ -114,7 +114,7 @@ public class MaterializedCollectBatchResultTest extends BaseMaterializedResultTe
     }
 
     @Test
-    public void testLimitedSnapshot() throws Exception {
+    void testLimitedSnapshot() throws Exception {
         final ResolvedSchema schema =
                 ResolvedSchema.physical(
                         new String[] {"f0", "f1"},
diff --git a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/result/MaterializedCollectStreamResultTest.java b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/result/MaterializedCollectStreamResultTest.java
index 6ab06a21ad8..9d749fcfc81 100644
--- a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/result/MaterializedCollectStreamResultTest.java
+++ b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/result/MaterializedCollectStreamResultTest.java
@@ -32,7 +32,7 @@ import org.apache.flink.table.types.DataType;
 import org.apache.flink.types.Row;
 import org.apache.flink.types.RowKind;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import java.util.Arrays;
 import java.util.Collections;
@@ -41,10 +41,10 @@ import java.util.function.Function;
 import static org.assertj.core.api.Assertions.assertThat;
 
 /** Tests for {@link MaterializedCollectStreamResult}. */
-public class MaterializedCollectStreamResultTest extends BaseMaterializedResultTest {
+class MaterializedCollectStreamResultTest extends BaseMaterializedResultTest {
 
     @Test
-    public void testSnapshot() throws Exception {
+    void testSnapshot() throws Exception {
         final ResolvedSchema schema =
                 ResolvedSchema.physical(
                         new String[] {"f0", "f1"},
@@ -121,7 +121,7 @@ public class MaterializedCollectStreamResultTest extends BaseMaterializedResultT
     }
 
     @Test
-    public void testLimitedSnapshot() throws Exception {
+    void testLimitedSnapshot() throws Exception {
         final ResolvedSchema schema =
                 ResolvedSchema.physical(
                         new String[] {"f0", "f1"},
diff --git a/flink-table/flink-sql-client/src/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension b/flink-table/flink-sql-client/src/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension
new file mode 100644
index 00000000000..0b74fd4603c
--- /dev/null
+++ b/flink-table/flink-sql-client/src/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension
@@ -0,0 +1,16 @@
+# 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.
+
+org.apache.flink.util.TestLoggerExtension