This is an automated email from the ASF dual-hosted git repository.
mapohl 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 adc476a0df2 [FLINK-27938][tests] Migrate flink-connectors-hbase-base
to JUnit5
adc476a0df2 is described below
commit adc476a0df2355226df19c37c0834ee0d9c19023
Author: Sergey Nuyanzin <[email protected]>
AuthorDate: Wed Jun 8 14:10:19 2022 +0200
[FLINK-27938][tests] Migrate flink-connectors-hbase-base to JUnit5
---
.../flink-connector-hbase-base/pom.xml | 6 +++
.../hbase/util/HBaseConfigLoadingTest.java | 49 +++++++++++-----------
.../flink/connector/hbase/util/HBaseSerdeTest.java | 39 +++++++++--------
.../org.junit.jupiter.api.extension.Extension | 16 +++++++
4 files changed, 66 insertions(+), 44 deletions(-)
diff --git a/flink-connectors/flink-connector-hbase-base/pom.xml
b/flink-connectors/flink-connector-hbase-base/pom.xml
index 31f91200459..5aec449ad05 100644
--- a/flink-connectors/flink-connector-hbase-base/pom.xml
+++ b/flink-connectors/flink-connector-hbase-base/pom.xml
@@ -180,6 +180,12 @@ under the License.
<goals>
<goal>test-jar</goal>
</goals>
+ <configuration>
+ <excludes>
+ <!-- test-jar
is still used by JUnit4 modules -->
+
<exclude>META-INF/services/org.junit.jupiter.api.extension.Extension</exclude>
+ </excludes>
+ </configuration>
</execution>
</executions>
</plugin>
diff --git
a/flink-connectors/flink-connector-hbase-base/src/test/java/org/apache/flink/connector/hbase/util/HBaseConfigLoadingTest.java
b/flink-connectors/flink-connector-hbase-base/src/test/java/org/apache/flink/connector/hbase/util/HBaseConfigLoadingTest.java
index a8c40daad66..7b64ac7b266 100644
---
a/flink-connectors/flink-connector-hbase-base/src/test/java/org/apache/flink/connector/hbase/util/HBaseConfigLoadingTest.java
+++
b/flink-connectors/flink-connector-hbase-base/src/test/java/org/apache/flink/connector/hbase/util/HBaseConfigLoadingTest.java
@@ -20,41 +20,41 @@ package org.apache.flink.connector.hbase.util;
import org.apache.flink.core.testutils.CommonTestUtils;
-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.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests that validate the loading of the HBase configuration, relative to
entries in the Flink
* configuration and the environment variables.
*/
-public class HBaseConfigLoadingTest {
+class HBaseConfigLoadingTest {
private static final String IN_HBASE_CONFIG_KEY = "hbase_conf_key";
private static final String IN_HBASE_CONFIG_VALUE = "hbase_conf_value!";
- @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
+ @TempDir Path tmpDir;
@Test
- public void loadFromClasspathByDefault() {
+ void loadFromClasspathByDefault() {
org.apache.hadoop.conf.Configuration hbaseConf =
HBaseConfigurationUtil.getHBaseConfiguration();
- assertEquals(IN_HBASE_CONFIG_VALUE, hbaseConf.get(IN_HBASE_CONFIG_KEY,
null));
+ assertThat(hbaseConf.get(IN_HBASE_CONFIG_KEY,
null)).isEqualTo(IN_HBASE_CONFIG_VALUE);
}
@Test
- public void loadFromEnvVariables() throws Exception {
+ void loadFromEnvVariables() throws Exception {
final String k1 = "where?";
final String v1 = "I'm on a boat";
final String k2 = "when?";
@@ -64,13 +64,13 @@ public class HBaseConfigLoadingTest {
final String k4 = "which way?";
final String v4 = "south, always south...";
- final File hbaseConfDir = tempFolder.newFolder();
+ final File hbaseConfDir = tmpDir.toFile();
- final File hbaseHome = tempFolder.newFolder();
+ final File hbaseHome = Files.createTempDirectory(tmpDir,
"junit_hbaseHome_").toFile();
final File hbaseHomeConf = new File(hbaseHome, "conf");
- assertTrue(hbaseHomeConf.mkdirs());
+ assertThat(hbaseHomeConf.mkdirs()).isTrue();
final File file1 = new File(hbaseConfDir, "hbase-default.xml");
final File file2 = new File(hbaseConfDir, "hbase-site.xml");
@@ -96,28 +96,28 @@ public class HBaseConfigLoadingTest {
}
// contains extra entries
- assertEquals(v1, hbaseConf.get(k1, null));
- assertEquals(v2, hbaseConf.get(k2, null));
- assertEquals(v3, hbaseConf.get(k3, null));
- assertEquals(v4, hbaseConf.get(k4, null));
+ assertThat(hbaseConf.get(k1, null)).isEqualTo(v1);
+ assertThat(hbaseConf.get(k2, null)).isEqualTo(v2);
+ assertThat(hbaseConf.get(k3, null)).isEqualTo(v3);
+ assertThat(hbaseConf.get(k4, null)).isEqualTo(v4);
// also contains classpath defaults
- assertEquals(IN_HBASE_CONFIG_VALUE, hbaseConf.get(IN_HBASE_CONFIG_KEY,
null));
+ assertThat(hbaseConf.get(IN_HBASE_CONFIG_KEY,
null)).isEqualTo(IN_HBASE_CONFIG_VALUE);
}
@Test
- public void loadOverlappingConfig() throws Exception {
+ void loadOverlappingConfig() throws Exception {
final String k1 = "key1";
final String v1 = "from HBASE_HOME/conf";
final String v2 = "from HBASE_CONF_DIR";
- final File hbaseHome = tempFolder.newFolder("hbaseHome");
+ final File hbaseHome = tmpDir.resolve("hbaseHome").toFile();
final File hbaseHomeConf = new File(hbaseHome, "conf");
- final File hbaseConfDir = tempFolder.newFolder("hbaseConfDir");
+ final File hbaseConfDir = tmpDir.resolve("hbaseConfDir").toFile();
- assertTrue(hbaseHomeConf.mkdirs());
+ assertThat(hbaseHomeConf.mkdirs()).isTrue();
final File file1 = new File(hbaseHomeConf, "hbase-site.xml");
Map<String, String> properties1 = new HashMap<>();
@@ -125,6 +125,7 @@ public class HBaseConfigLoadingTest {
printConfigs(file1, properties1);
// HBASE_CONF_DIR conf will override k1 with v2
+ assertThat(hbaseConfDir.mkdirs()).isTrue();
final File file2 = new File(hbaseConfDir, "hbase-site.xml");
Map<String, String> properties2 = new HashMap<>();
properties2.put(k1, v2);
@@ -144,10 +145,10 @@ public class HBaseConfigLoadingTest {
}
// contains extra entries
- assertEquals(v2, hbaseConf.get(k1, null));
+ assertThat(hbaseConf.get(k1, null)).isEqualTo(v2);
// also contains classpath defaults
- assertEquals(IN_HBASE_CONFIG_VALUE, hbaseConf.get(IN_HBASE_CONFIG_KEY,
null));
+ assertThat(hbaseConf.get(IN_HBASE_CONFIG_KEY,
null)).isEqualTo(IN_HBASE_CONFIG_VALUE);
}
private static void printConfig(File file, String key, String value)
throws IOException {
diff --git
a/flink-connectors/flink-connector-hbase-base/src/test/java/org/apache/flink/connector/hbase/util/HBaseSerdeTest.java
b/flink-connectors/flink-connector-hbase-base/src/test/java/org/apache/flink/connector/hbase/util/HBaseSerdeTest.java
index 81189bdb477..3e9afb1b321 100644
---
a/flink-connectors/flink-connector-hbase-base/src/test/java/org/apache/flink/connector/hbase/util/HBaseSerdeTest.java
+++
b/flink-connectors/flink-connector-hbase-base/src/test/java/org/apache/flink/connector/hbase/util/HBaseSerdeTest.java
@@ -26,7 +26,7 @@ import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
@@ -37,12 +37,10 @@ import static org.apache.flink.table.api.DataTypes.FIELD;
import static org.apache.flink.table.api.DataTypes.INT;
import static org.apache.flink.table.api.DataTypes.ROW;
import static org.apache.flink.table.api.DataTypes.STRING;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
/** Test for {@link HBaseSerde}. */
-public class HBaseSerdeTest {
+class HBaseSerdeTest {
private static final String ROW_KEY = "rowkey";
@@ -59,7 +57,7 @@ public class HBaseSerdeTest {
private static final String F3COL3 = "col3";
@Test
- public void convertToNewRowTest() {
+ void convertToNewRowTest() {
HBaseSerde serde = createHBaseSerde();
List<List<Cell>> cellsList = prepareCells();
List<RowData> resultRowDatas = new ArrayList<>();
@@ -70,17 +68,17 @@ public class HBaseSerdeTest {
resultRowDataStr.add(row.toString());
}
- // this verifies RowData is not reused
- assertFalse(resultRowDatas.get(0) == resultRowDatas.get(1));
-
- List<String> expected = new ArrayList<>();
- expected.add("+I(1,+I(10),+I(Hello-1,100),+I(1.01,false,Welt-1))");
- expected.add("+I(2,+I(20),+I(Hello-2,200),+I(2.02,true,Welt-2))");
- assertEquals(expected, resultRowDataStr);
+ assertThat(resultRowDatas.get(0))
+ .as("RowData should not be reused")
+ .isNotSameAs(resultRowDatas.get(1));
+ assertThat(resultRowDataStr)
+ .containsExactly(
+ "+I(1,+I(10),+I(Hello-1,100),+I(1.01,false,Welt-1))",
+ "+I(2,+I(20),+I(Hello-2,200),+I(2.02,true,Welt-2))");
}
@Test
- public void convertToReusedRowTest() {
+ void convertToReusedRowTest() {
HBaseSerde serde = createHBaseSerde();
List<List<Cell>> cellsList = prepareCells();
List<RowData> resultRowDatas = new ArrayList<>();
@@ -91,13 +89,14 @@ public class HBaseSerdeTest {
resultRowDataStr.add(row.toString());
}
- // this verifies RowData is reused
- assertTrue(resultRowDatas.get(0) == resultRowDatas.get(1));
+ assertThat(resultRowDatas.get(0))
+ .as("RowData should be reused")
+ .isSameAs(resultRowDatas.get(1));
- List<String> expected = new ArrayList<>();
- expected.add("+I(1,+I(10),+I(Hello-1,100),+I(1.01,false,Welt-1))");
- expected.add("+I(2,+I(20),+I(Hello-2,200),+I(2.02,true,Welt-2))");
- assertEquals(expected, resultRowDataStr);
+ assertThat(resultRowDataStr)
+ .containsExactly(
+ "+I(1,+I(10),+I(Hello-1,100),+I(1.01,false,Welt-1))",
+ "+I(2,+I(20),+I(Hello-2,200),+I(2.02,true,Welt-2))");
}
private HBaseSerde createHBaseSerde() {
diff --git
a/flink-connectors/flink-connector-hbase-base/src/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension
b/flink-connectors/flink-connector-hbase-base/src/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension
new file mode 100644
index 00000000000..28999133c2b
--- /dev/null
+++
b/flink-connectors/flink-connector-hbase-base/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
\ No newline at end of file