From 81c41ac6fed88fda45b1d3bc5a10b1ebd6f1a341 Mon Sep 17 00:00:00 2001 From: wudi <676366545@qq.com> Date: Mon, 9 Sep 2024 17:08:50 +0800 Subject: [PATCH] update --- .../container/AbstractContainerTestBase.java | 6 +-- .../doris/flink/source/DorisSourceITCase.java | 42 ++++++++++++------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/flink-doris-connector/src/test/java/org/apache/doris/flink/container/AbstractContainerTestBase.java b/flink-doris-connector/src/test/java/org/apache/doris/flink/container/AbstractContainerTestBase.java index 4731d4776..61e0faac8 100644 --- a/flink-doris-connector/src/test/java/org/apache/doris/flink/container/AbstractContainerTestBase.java +++ b/flink-doris-connector/src/test/java/org/apache/doris/flink/container/AbstractContainerTestBase.java @@ -99,16 +99,16 @@ private static void closeDorisContainer() { // ------------------------------------------------------------------------ // test utilities // ------------------------------------------------------------------------ - public static void assertEqualsInAnyOrder(List expected, List actual) { + public static void assertEqualsInAnyOrder(List expected, List actual) { assertTrue(expected != null && actual != null); assertEqualsInOrder( expected.stream().sorted().collect(Collectors.toList()), actual.stream().sorted().collect(Collectors.toList())); } - public static void assertEqualsInOrder(List expected, List actual) { + public static void assertEqualsInOrder(List expected, List actual) { assertTrue(expected != null && actual != null); assertEquals(expected.size(), actual.size()); - assertArrayEquals(expected.toArray(new String[0]), actual.toArray(new String[0])); + assertArrayEquals(expected.toArray(new Object[0]), actual.toArray(new Object[0])); } } diff --git a/flink-doris-connector/src/test/java/org/apache/doris/flink/source/DorisSourceITCase.java b/flink-doris-connector/src/test/java/org/apache/doris/flink/source/DorisSourceITCase.java index 4eb9621fe..500e96d41 100644 --- a/flink-doris-connector/src/test/java/org/apache/doris/flink/source/DorisSourceITCase.java +++ b/flink-doris-connector/src/test/java/org/apache/doris/flink/source/DorisSourceITCase.java @@ -41,11 +41,9 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Properties; -import java.util.Set; /** DorisSource ITCase. */ public class DorisSourceITCase extends AbstractITCaseService { @@ -89,7 +87,7 @@ public void testSource() throws Exception { } } List expected = Arrays.asList("[doris, 18]", "[flink, 10]", "[apache, 12]"); - checkResult("testSource", expected.toArray(), actual.toArray()); + checkResultInAnyOrder("testSource", expected.toArray(), actual.toArray()); } @Test @@ -115,7 +113,7 @@ options, new SimpleListDeserializationSchema())) } } List expected = Arrays.asList("[doris, 18]", "[flink, 10]", "[apache, 12]"); - checkResult("testOldSourceApi", expected.toArray(), actual.toArray()); + checkResultInAnyOrder("testOldSourceApi", expected.toArray(), actual.toArray()); } @Test @@ -164,7 +162,7 @@ public void testTableSource() throws Exception { } } String[] expectedFilter = new String[] {"+I[doris, 18]"}; - checkResult("testTableSource", expectedFilter, actualFilter.toArray()); + checkResultInAnyOrder("testTableSource", expectedFilter, actualFilter.toArray()); } @Test @@ -201,7 +199,7 @@ public void testTableSourceOldApi() throws Exception { } } String[] expected = new String[] {"+I[doris, 18]", "+I[flink, 10]", "+I[apache, 12]"}; - checkResult("testTableSourceOldApi", expected, actual.toArray()); + checkResultInAnyOrder("testTableSourceOldApi", expected, actual.toArray()); } @Test @@ -247,7 +245,7 @@ public void testTableSourceAllOptions() throws Exception { } } String[] expected = new String[] {"+I[doris, 18]", "+I[flink, 10]", "+I[apache, 12]"}; - checkResult("testTableSourceAllOptions", expected, actual.toArray()); + checkResultInAnyOrder("testTableSourceAllOptions", expected, actual.toArray()); } @Test @@ -285,7 +283,8 @@ public void testTableSourceFilterAndProjectionPushDown() throws Exception { } } String[] expected = new String[] {"+I[18]"}; - checkResult("testTableSourceFilterAndProjectionPushDown", expected, actual.toArray()); + checkResultInAnyOrder( + "testTableSourceFilterAndProjectionPushDown", expected, actual.toArray()); } @Test @@ -328,10 +327,8 @@ public void testTableSourceFilterWithUnionAll() { LOG.error("Failed to execute sql. sql={}", querySql, e); throw new DorisRuntimeException(e); } - Set expected = new HashSet<>(Arrays.asList("+I[flink, 10]", "+I[doris, 18]")); - for (String a : actual) { - Assert.assertTrue(expected.contains(a)); - } + String[] expected = new String[] {"+I[flink, 10]", "+I[doris, 18]"}; + checkResultInAnyOrder("testTableSourceFilterWithUnionAll", expected, actual.toArray()); } @Test @@ -376,8 +373,10 @@ public void testJobManagerFailoverSource() throws Exception { () -> sleepMs(100)); } - assertEqualsInAnyOrder( - expectedSnapshotData, fetchRows(iterator, expectedSnapshotData.size())); + checkResultInAnyOrder( + "testJobManagerFailoverSource", + expectedSnapshotData.toArray(), + fetchRows(iterator, expectedSnapshotData.size()).toArray()); } @Test @@ -422,8 +421,10 @@ public void testTaskManagerFailoverSink() throws Exception { () -> sleepMs(100)); } - assertEqualsInAnyOrder( - expectedSnapshotData, fetchRows(iterator, expectedSnapshotData.size())); + checkResultInAnyOrder( + "testTaskManagerFailoverSink", + expectedSnapshotData.toArray(), + fetchRows(iterator, expectedSnapshotData.size()).toArray()); } private void checkResult(String testName, Object[] expected, Object[] actual) { @@ -435,6 +436,15 @@ private void checkResult(String testName, Object[] expected, Object[] actual) { Assert.assertArrayEquals(expected, actual); } + private void checkResultInAnyOrder(String testName, Object[] expected, Object[] actual) { + LOG.info( + "Checking DorisSourceITCase result. testName={}, actual={}, expected={}", + testName, + actual, + expected); + assertEqualsInAnyOrder(Arrays.asList(expected), Arrays.asList(actual)); + } + private void initializeTable(String table) { ContainerUtils.executeSQLStatement( getDorisQueryConnection(),