From 7c9b5895e84964c8c3fde4938a9b90cd048c1b7f Mon Sep 17 00:00:00 2001 From: Qingsheng Ren Date: Thu, 8 Jul 2021 12:09:08 +0800 Subject: [PATCH 1/2] [FLINK-23255][test] Introduce JUnit 5 dependencies --- .../pom.xml | 6 +- .../flink-end-to-end-tests-common/pom.xml | 5 +- .../flink-end-to-end-tests-hbase/pom.xml | 5 +- .../flink-glue-schema-registry-test/pom.xml | 5 +- .../flink-streaming-kinesis-test/pom.xml | 5 +- flink-table/flink-sql-parser-hive/pom.xml | 17 ----- flink-table/flink-sql-parser/pom.xml | 17 ----- .../flink-connector-test-utils/pom.xml | 5 +- .../flink-test-utils-junit/pom.xml | 8 ++- .../flink-test-utils/pom.xml | 5 +- .../flink/test/junit5/JUnitJupiterTest.java | 66 +++++++++++++++++++ pom.xml | 25 +++++-- 12 files changed, 107 insertions(+), 62 deletions(-) create mode 100644 flink-tests/src/test/java/org/apache/flink/test/junit5/JUnitJupiterTest.java diff --git a/flink-end-to-end-tests/flink-end-to-end-tests-common-kafka/pom.xml b/flink-end-to-end-tests/flink-end-to-end-tests-common-kafka/pom.xml index 4ef4d4c00c4d1..ba5d81fd72f3e 100644 --- a/flink-end-to-end-tests/flink-end-to-end-tests-common-kafka/pom.xml +++ b/flink-end-to-end-tests/flink-end-to-end-tests-common-kafka/pom.xml @@ -49,10 +49,10 @@ under the License. compile - junit - junit + org.junit.jupiter + junit-jupiter + compile - org.apache.flink flink-streaming-kafka-test_${scala.binary.version} diff --git a/flink-end-to-end-tests/flink-end-to-end-tests-common/pom.xml b/flink-end-to-end-tests/flink-end-to-end-tests-common/pom.xml index a2b464aefe3cd..aa8b3016f9807 100644 --- a/flink-end-to-end-tests/flink-end-to-end-tests-common/pom.xml +++ b/flink-end-to-end-tests/flink-end-to-end-tests-common/pom.xml @@ -45,9 +45,8 @@ under the License. flink-shaded-jackson - junit - junit - ${junit.version} + org.junit.jupiter + junit-jupiter compile diff --git a/flink-end-to-end-tests/flink-end-to-end-tests-hbase/pom.xml b/flink-end-to-end-tests/flink-end-to-end-tests-hbase/pom.xml index b3f458aaaa101..e0a7f7bf8d7db 100644 --- a/flink-end-to-end-tests/flink-end-to-end-tests-hbase/pom.xml +++ b/flink-end-to-end-tests/flink-end-to-end-tests-hbase/pom.xml @@ -42,8 +42,9 @@ under the License. compile - junit - junit + org.junit.jupiter + junit-jupiter + compile diff --git a/flink-end-to-end-tests/flink-glue-schema-registry-test/pom.xml b/flink-end-to-end-tests/flink-glue-schema-registry-test/pom.xml index 3967004ea9c16..4ce19370b0a87 100644 --- a/flink-end-to-end-tests/flink-glue-schema-registry-test/pom.xml +++ b/flink-end-to-end-tests/flink-glue-schema-registry-test/pom.xml @@ -181,8 +181,9 @@ under the License. - junit - junit + org.junit.jupiter + junit-jupiter + compile diff --git a/flink-end-to-end-tests/flink-streaming-kinesis-test/pom.xml b/flink-end-to-end-tests/flink-streaming-kinesis-test/pom.xml index df65ec06c1375..edd6f61a946a9 100644 --- a/flink-end-to-end-tests/flink-streaming-kinesis-test/pom.xml +++ b/flink-end-to-end-tests/flink-streaming-kinesis-test/pom.xml @@ -66,9 +66,8 @@ under the License. - junit - junit - ${junit.version} + org.junit.jupiter + junit-jupiter compile diff --git a/flink-table/flink-sql-parser-hive/pom.xml b/flink-table/flink-sql-parser-hive/pom.xml index 3f042ce63e54a..e29b49707db11 100644 --- a/flink-table/flink-sql-parser-hive/pom.xml +++ b/flink-table/flink-sql-parser-hive/pom.xml @@ -86,23 +86,6 @@ under the License. test test-jar - - - org.junit.jupiter - junit-jupiter-engine - 5.7.2 - test - - - - org.junit.vintage - junit-vintage-engine - 5.7.2 - test - diff --git a/flink-table/flink-sql-parser/pom.xml b/flink-table/flink-sql-parser/pom.xml index e56c60dfaa49c..81fe1019ed9df 100644 --- a/flink-table/flink-sql-parser/pom.xml +++ b/flink-table/flink-sql-parser/pom.xml @@ -187,23 +187,6 @@ under the License. test test-jar - - - org.junit.jupiter - junit-jupiter-engine - 5.7.2 - test - - - - org.junit.vintage - junit-vintage-engine - 5.7.2 - test - diff --git a/flink-test-utils-parent/flink-connector-test-utils/pom.xml b/flink-test-utils-parent/flink-connector-test-utils/pom.xml index fa9b5c264acda..55d5ef0d5095b 100644 --- a/flink-test-utils-parent/flink-connector-test-utils/pom.xml +++ b/flink-test-utils-parent/flink-connector-test-utils/pom.xml @@ -49,9 +49,8 @@ - junit - junit - ${junit.version} + org.junit.jupiter + junit-jupiter compile diff --git a/flink-test-utils-parent/flink-test-utils-junit/pom.xml b/flink-test-utils-parent/flink-test-utils-junit/pom.xml index 2714c8ed53904..22ad453058535 100644 --- a/flink-test-utils-parent/flink-test-utils-junit/pom.xml +++ b/flink-test-utils-parent/flink-test-utils-junit/pom.xml @@ -36,21 +36,23 @@ under the License. - junit - junit - ${junit.version} + org.junit.jupiter + junit-jupiter compile + org.apache.logging.log4j log4j-slf4j-impl compile + org.apache.logging.log4j log4j-api compile + org.apache.logging.log4j log4j-core diff --git a/flink-test-utils-parent/flink-test-utils/pom.xml b/flink-test-utils-parent/flink-test-utils/pom.xml index 94897529ae6f6..200b6ca11967f 100644 --- a/flink-test-utils-parent/flink-test-utils/pom.xml +++ b/flink-test-utils-parent/flink-test-utils/pom.xml @@ -79,9 +79,8 @@ under the License. - junit - junit - ${junit.version} + org.junit.jupiter + junit-jupiter compile diff --git a/flink-tests/src/test/java/org/apache/flink/test/junit5/JUnitJupiterTest.java b/flink-tests/src/test/java/org/apache/flink/test/junit5/JUnitJupiterTest.java new file mode 100644 index 0000000000000..ad7ecfe591f5f --- /dev/null +++ b/flink-tests/src/test/java/org/apache/flink/test/junit5/JUnitJupiterTest.java @@ -0,0 +1,66 @@ +/* + * 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.test.junit5; + +import org.apache.commons.lang3.StringUtils; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestFactory; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import java.util.Arrays; +import java.util.Collection; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + +/** Temporary JUnit 5 tests for validating JUnit jupiter engine truly works. */ +public class JUnitJupiterTest { + @Test + @DisplayName("Assumption and Assertion Test") + public void assumptionAssertionTest() { + assumeTrue(true, "This case is absolutely true"); + assertTrue(true, "This case is absolutely true"); + } + + @ParameterizedTest + @DisplayName("Parameterized Test") + @ValueSource(strings = {"racecar", "radar", "able was I ere I saw elba"}) + public void parameterizedTest(String word) { + assertTrue(isPalindrome(word), "The string in parameter should be palindrome"); + } + + @TestFactory + @DisplayName("Dynamic Test") + Collection dynamicTest() { + String word = "madam"; + String anotherWord = "flink"; + return Arrays.asList( + DynamicTest.dynamicTest("1st dynamic test", () -> assertTrue(isPalindrome(word))), + DynamicTest.dynamicTest( + "2nd dynamic test", () -> assertFalse(isPalindrome(anotherWord)))); + } + + private boolean isPalindrome(String word) { + return StringUtils.reverse(word).equals(word); + } +} diff --git a/pom.xml b/pom.xml index 923fe9354b36c..92b78864a427d 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,8 @@ under the License. 1.10.0 1.2.0 2.3.1 - 4.13.2 + 4.13.2 + 5.7.2 2.21.0 2.0.4 1.3 @@ -185,11 +186,15 @@ under the License. + + org.junit.jupiter + junit-jupiter + test + - junit - junit - jar + org.junit.vintage + junit-vintage-engine test @@ -559,10 +564,18 @@ under the License. + + org.junit + junit-bom + ${junit5.version} + pom + import + + junit junit - ${junit.version} + ${junit4.version} @@ -1520,7 +1533,7 @@ under the License. org.apache.maven.plugins maven-surefire-plugin - 2.22.1 + 2.22.2 ${flink.forkCount} ${flink.reuseForks} From 78665674e5cbe67c4260f4a44467cb8cad379d11 Mon Sep 17 00:00:00 2001 From: Qingsheng Ren Date: Thu, 5 Aug 2021 16:18:18 +0800 Subject: [PATCH 2/2] [FLINK-23255][test] Add vintage engine for test util modules --- flink-test-utils-parent/flink-connector-test-utils/pom.xml | 6 ++++++ flink-test-utils-parent/flink-test-utils-junit/pom.xml | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/flink-test-utils-parent/flink-connector-test-utils/pom.xml b/flink-test-utils-parent/flink-connector-test-utils/pom.xml index 55d5ef0d5095b..a8c6836d55968 100644 --- a/flink-test-utils-parent/flink-connector-test-utils/pom.xml +++ b/flink-test-utils-parent/flink-connector-test-utils/pom.xml @@ -53,5 +53,11 @@ junit-jupiter compile + + + org.junit.vintage + junit-vintage-engine + compile + diff --git a/flink-test-utils-parent/flink-test-utils-junit/pom.xml b/flink-test-utils-parent/flink-test-utils-junit/pom.xml index 22ad453058535..58f431e5c67f7 100644 --- a/flink-test-utils-parent/flink-test-utils-junit/pom.xml +++ b/flink-test-utils-parent/flink-test-utils-junit/pom.xml @@ -41,6 +41,12 @@ under the License. compile + + org.junit.vintage + junit-vintage-engine + compile + + org.apache.logging.log4j log4j-slf4j-impl