This is an automated email from the ASF dual-hosted git repository.
danny0405 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git
The following commit(s) were added to refs/heads/master by this push:
new f18e9284208 [MINOR] Fix flaky tests in ITTestHoodieDataSource caused
by unordered hashmap (#7641)
f18e9284208 is described below
commit f18e9284208f1fbd1f0bc0e30b317dae623f6ea4
Author: Alexander Trushev <[email protected]>
AuthorDate: Thu Jan 12 11:31:49 2023 +0300
[MINOR] Fix flaky tests in ITTestHoodieDataSource caused by unordered
hashmap (#7641)
---
.../apache/hudi/table/ITTestHoodieDataSource.java | 25 +++++----
.../test/java/org/apache/hudi/utils/TestData.java | 59 ++++++++++++++++++++++
2 files changed, 74 insertions(+), 10 deletions(-)
diff --git
a/hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/table/ITTestHoodieDataSource.java
b/hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/table/ITTestHoodieDataSource.java
index ba8952c2a76..f831910de9b 100644
---
a/hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/table/ITTestHoodieDataSource.java
+++
b/hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/table/ITTestHoodieDataSource.java
@@ -59,6 +59,7 @@ import org.junit.jupiter.params.provider.ValueSource;
import java.io.File;
import java.time.ZoneId;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@@ -71,7 +72,11 @@ import java.util.stream.Stream;
import static org.apache.hudi.utils.TestConfigurations.catalog;
import static org.apache.hudi.utils.TestConfigurations.sql;
+import static org.apache.hudi.utils.TestData.array;
+import static org.apache.hudi.utils.TestData.assertRowsEqualsUnordered;
import static org.apache.hudi.utils.TestData.assertRowsEquals;
+import static org.apache.hudi.utils.TestData.map;
+import static org.apache.hudi.utils.TestData.row;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -1345,11 +1350,11 @@ public class ITTestHoodieDataSource {
List<Row> result = CollectionUtil.iterableToList(
() -> tableEnv.sqlQuery("select * from t1").execute().collect());
- final String expected = "["
- + "+I[1, [abc1, def1], {abc1=1, def1=3}, +I[1, abc1]], "
- + "+I[2, [abc2, def2], {def2=3, abc2=1}, +I[2, abc2]], "
- + "+I[3, [abc3, def3], {def3=3, abc3=1}, +I[3, abc3]]]";
- assertRowsEquals(result, expected);
+ List<Row> expected = Arrays.asList(
+ row(1, array("abc1", "def1"), map("abc1", 1, "def1", 3), row(1,
"abc1")),
+ row(2, array("abc2", "def2"), map("abc2", 1, "def2", 3), row(2,
"abc2")),
+ row(3, array("abc3", "def3"), map("abc3", 1, "def3", 3), row(3,
"abc3")));
+ assertRowsEqualsUnordered(result, expected);
}
@ParameterizedTest
@@ -1374,11 +1379,11 @@ public class ITTestHoodieDataSource {
List<Row> result = CollectionUtil.iterableToList(
() -> tableEnv.sqlQuery("select * from t1").execute().collect());
- final String expected = "["
- + "+I[1, [abc1, def1], [1, 1], {abc1=1, def1=3}, +I[[abc1, def1],
+I[1, abc1]]], "
- + "+I[2, [abc2, def2], [2, 2], {def2=3, abc2=1}, +I[[abc2, def2],
+I[2, abc2]]], "
- + "+I[3, [abc3, def3], [3, 3], {def3=3, abc3=1}, +I[[abc3, def3],
+I[3, abc3]]]]";
- assertRowsEquals(result, expected);
+ List<Row> expected = Arrays.asList(
+ row(1, array("abc1", "def1"), array(1, 1), map("abc1", 1, "def1", 3),
row(array("abc1", "def1"), row(1, "abc1"))),
+ row(2, array("abc2", "def2"), array(2, 2), map("abc2", 1, "def2", 3),
row(array("abc2", "def2"), row(2, "abc2"))),
+ row(3, array("abc3", "def3"), array(3, 3), map("abc3", 1, "def3", 3),
row(array("abc3", "def3"), row(3, "abc3"))));
+ assertRowsEqualsUnordered(result, expected);
}
@ParameterizedTest
diff --git
a/hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/utils/TestData.java
b/hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/utils/TestData.java
index 3e76b5bcf9b..7d798fff9f1 100644
---
a/hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/utils/TestData.java
+++
b/hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/utils/TestData.java
@@ -71,8 +71,10 @@ import java.io.FileFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -557,6 +559,16 @@ public class TestData {
assertThat(rowsString, is(rowDataToString(expected)));
}
+ /**
+ * Assert that expected and actual collection of rows are equal regardless
of the order.
+ *
+ * @param expected expected row collection
+ * @param actual actual row collection
+ */
+ public static void assertRowsEqualsUnordered(Collection<Row> expected,
Collection<Row> actual) {
+ assertEquals(new HashSet<>(expected), new HashSet<>(actual));
+ }
+
/**
* Checks the source data set are written as expected.
*
@@ -908,4 +920,51 @@ public class TestData {
rowData.setRowKind(RowKind.UPDATE_AFTER);
return rowData;
}
+
+ /**
+ * Creates row with specified field values.
+ * <p>This method is used to define row in convenient way such as:
+ *
+ * <pre> {@code
+ * row(1, array("abc1", "def1"), map("abc1", 1, "def1", 3), row(1, "abc1"))
+ * }</pre>
+ */
+ public static Row row(Object... values) {
+ return Row.of(values);
+ }
+
+ /**
+ * Creates array with specified values.
+ * <p>This method is used to define row in convenient way such as:
+ *
+ * <pre> {@code
+ * row(1, array("abc1", "def1"), map("abc1", 1, "def1", 3), row(1, "abc1"))
+ * }</pre>
+ */
+ @SafeVarargs
+ public static <T> T[] array(T... values) {
+ return values;
+ }
+
+ /**
+ * Creates map with specified keys and values.
+ * <p>This method is used to define row in convenient way such as:
+ *
+ * <pre> {@code
+ * row(1, array("abc1", "def1"), map("abc1", 1, "def1", 3), row(1, "abc1"))
+ * }</pre>
+ *
+ * <p>NOTE: be careful of the order of keys and values. If you make
+ * a mistake, {@link ClassCastException} will occur later than the
+ * creation of the map due to type erasure.
+ */
+ public static <K, V> Map<K, V> map(Object... kwargs) {
+ HashMap<Object, Object> map = new HashMap<>();
+ for (int i = 0; i < kwargs.length; i += 2) {
+ map.put(kwargs[i], kwargs[i + 1]);
+ }
+ @SuppressWarnings("unchecked")
+ Map<K, V> resultMap = (Map<K, V>) map;
+ return resultMap;
+ }
}