7070import java .util .stream .Stream ;
7171
7272import static org .apache .fluss .flink .FlinkConnectorOptions .BOOTSTRAP_SERVERS ;
73+ import static org .apache .fluss .flink .source .testutils .FlinkRowAssertionsUtils .assertQueryResultExactOrder ;
7374import static org .apache .fluss .flink .source .testutils .FlinkRowAssertionsUtils .assertResultsIgnoreOrder ;
75+ import static org .apache .fluss .flink .source .testutils .FlinkRowAssertionsUtils .collectRowsWithTimeout ;
7476import static org .apache .fluss .flink .utils .FlinkTestBase .waitUntilPartitions ;
7577import static org .apache .fluss .flink .utils .FlinkTestBase .writeRows ;
7678import static org .apache .fluss .flink .utils .FlinkTestBase .writeRowsToPartition ;
@@ -205,16 +207,7 @@ void testNonPkTableRead() throws Exception {
205207 writeRows (conn , tablePath , rows , true );
206208
207209 List <String > expected = Arrays .asList ("+I[1, v1]" , "+I[2, v2]" , "+I[3, v3]" );
208- try (org .apache .flink .util .CloseableIterator <Row > rowIter =
209- tEnv .executeSql ("select * from non_pk_table_test" ).collect ()) {
210- int expectRecords = expected .size ();
211- List <String > actual = new ArrayList <>(expectRecords );
212- for (int i = 0 ; i < expectRecords ; i ++) {
213- String row = rowIter .next ().toString ();
214- actual .add (row );
215- }
216- assertThat (actual ).containsExactlyElementsOf (expected );
217- }
210+ assertQueryResultExactOrder (tEnv , "select * from non_pk_table_test" , expected );
218211 }
219212
220213 @ ParameterizedTest
@@ -262,17 +255,7 @@ void testAppendTableProjectPushDown(String logFormat) throws Exception {
262255 "+I[v8, 8000, 800]" ,
263256 "+I[v9, 9000, 900]" ,
264257 "+I[v10, 10000, 1000]" );
265- try (org .apache .flink .util .CloseableIterator <Row > rowIter =
266- tEnv .executeSql (query ).collect ()) {
267- int expectRecords = expected .size ();
268- List <String > actual = new ArrayList <>(expectRecords );
269- for (int i = 0 ; i < expectRecords ; i ++) {
270- Row r = rowIter .next ();
271- String row = r .toString ();
272- actual .add (row );
273- }
274- assertThat (actual ).containsExactlyElementsOf (expected );
275- }
258+ assertQueryResultExactOrder (tEnv , query , expected );
276259 }
277260
278261 @ ParameterizedTest
@@ -331,22 +314,15 @@ void testTableProjectPushDown(String mode) throws Exception {
331314 "+I[v8, 8, 800]" ,
332315 "+I[v9, 9, 900]" ,
333316 "+I[v10, 10, 1000]" );
334- try (org .apache .flink .util .CloseableIterator <Row > rowIter =
335- tEnv .executeSql (query ).collect ()) {
336- int expectRecords = expected .size ();
337- List <String > actual = new ArrayList <>(expectRecords );
338- if (testPkLog ) {
339- // delay the write after collect job start,
340- // to make sure reading from log instead of snapshot
341- writeRows (conn , tablePath , rows , false );
342- }
343- for (int i = 0 ; i < expectRecords ; i ++) {
344- Row r = rowIter .next ();
345- String row = r .toString ();
346- actual .add (row );
347- }
348- assertThat (actual ).containsExactlyElementsOf (expected );
317+ org .apache .flink .util .CloseableIterator <Row > rowIter = tEnv .executeSql (query ).collect ();
318+ if (testPkLog ) {
319+ // delay the write after collect job start,
320+ // to make sure reading from log instead of snapshot
321+ writeRows (conn , tablePath , rows , false );
349322 }
323+ int expectRecords = expected .size ();
324+ List <String > actual = collectRowsWithTimeout (rowIter , expectRecords );
325+ assertThat (actual ).containsExactlyElementsOf (expected );
350326 }
351327
352328 @ Test
@@ -451,12 +427,12 @@ void testReadLogTableWithDifferentScanStartupMode(boolean isPartitioned) throws
451427 "+I[8, v8, 800, 8000]" ,
452428 "+I[9, v9, 900, 9000]" ,
453429 "+I[10, v10, 1000, 10000]" );
454- assertQueryResult ( query , expected );
430+ assertQueryResultExactOrder ( tEnv , query , expected );
455431
456432 // 2. read kv table with scan.startup.mode='earliest'
457433 options = " /*+ OPTIONS('scan.startup.mode' = 'earliest') */" ;
458434 query = "select a, b, c, d from " + tableName + options ;
459- assertQueryResult ( query , expected );
435+ assertQueryResultExactOrder ( tEnv , query , expected );
460436
461437 // 3. read log table with scan.startup.mode='timestamp'
462438 expected =
@@ -471,7 +447,7 @@ void testReadLogTableWithDifferentScanStartupMode(boolean isPartitioned) throws
471447 " /*+ OPTIONS('scan.startup.mode' = 'timestamp', 'scan.startup.timestamp' ='%d') */" ,
472448 timestamp );
473449 query = "select a, b, c, d from " + tableName + options ;
474- assertQueryResult ( query , expected );
450+ assertQueryResultExactOrder ( tEnv , query , expected );
475451 }
476452
477453 @ Test
@@ -501,20 +477,13 @@ void testReadKvTableWithScanStartupModeEqualsFull() throws Exception {
501477 "-U[2, v2]" ,
502478 "+U[2, v22]" ,
503479 "+I[4, v4]" );
504- try (org .apache .flink .util .CloseableIterator <Row > rowIter =
505- tEnv .executeSql (query ).collect ()) {
506- int expectRecords = 8 ;
507- List <String > actual = new ArrayList <>(expectRecords );
508- // delay to write after collect job start, to make sure reading from log instead of
509- // snapshot
510- writeRows (conn , tablePath , rows2 , false );
511- for (int i = 0 ; i < expectRecords ; i ++) {
512- Row r = rowIter .next ();
513- String row = r .toString ();
514- actual .add (row );
515- }
516- assertThat (actual ).containsExactlyElementsOf (expected );
517- }
480+ org .apache .flink .util .CloseableIterator <Row > rowIter = tEnv .executeSql (query ).collect ();
481+ int expectRecords = 8 ;
482+ // delay to write after collect job start, to make sure reading from log instead of
483+ // snapshot
484+ writeRows (conn , tablePath , rows2 , false );
485+ List <String > actual = collectRowsWithTimeout (rowIter , expectRecords );
486+ assertThat (actual ).containsExactlyElementsOf (expected );
518487 }
519488
520489 private static Stream <Arguments > readKvTableScanStartupModeArgs () {
@@ -595,17 +564,7 @@ void testReadKvTableWithEarliestAndTimestampScanStartupMode(String mode, boolean
595564 "-U[2, v2]" ,
596565 "+U[2, v22]" ,
597566 "+I[4, v4]" );
598- try (org .apache .flink .util .CloseableIterator <Row > rowIter =
599- tEnv .executeSql (query ).collect ()) {
600- int expectRecords = 10 ;
601- List <String > actual = new ArrayList <>(expectRecords );
602- for (int i = 0 ; i < expectRecords ; i ++) {
603- Row r = rowIter .next ();
604- String row = r .toString ();
605- actual .add (row );
606- }
607- assertThat (actual ).containsExactlyElementsOf (expected );
608- }
567+ assertQueryResultExactOrder (tEnv , query , expected );
609568 }
610569
611570 @ ParameterizedTest
@@ -687,25 +646,20 @@ void testReadTimestampGreaterThanMaxTimestamp() throws Exception {
687646 "the fetch timestamp %s is larger than the current timestamp" ,
688647 currentTimeMillis + Duration .ofMinutes (5 ).toMillis ()));
689648
690- try ( org .apache .flink .util .CloseableIterator <Row > rowIter =
649+ org .apache .flink .util .CloseableIterator <Row > rowIter =
691650 tEnv .executeSql (
692651 String .format (
693652 "select * from timestamp_table /*+ OPTIONS('scan.startup.mode' = 'timestamp', 'scan.startup.timestamp' = '%s') */ " ,
694653 currentTimeMillis ))
695- .collect ()) {
696- CLOCK .advanceTime (Duration .ofMillis (100L ));
697- // write second batch record.
698- rows = Arrays .asList (row (4 , "v4" ), row (5 , "v5" ), row (6 , "v6" ));
699- writeRows (conn , tablePath , rows , true );
700- List <String > expected = Arrays .asList ("+I[4, v4]" , "+I[5, v5]" , "+I[6, v6]" );
701- int expectRecords = expected .size ();
702- List <String > actual = new ArrayList <>(expectRecords );
703- for (int i = 0 ; i < expectRecords ; i ++) {
704- String row = rowIter .next ().toString ();
705- actual .add (row );
706- }
707- assertThat (actual ).containsExactlyElementsOf (expected );
708- }
654+ .collect ();
655+ CLOCK .advanceTime (Duration .ofMillis (100L ));
656+ // write second batch record.
657+ rows = Arrays .asList (row (4 , "v4" ), row (5 , "v5" ), row (6 , "v6" ));
658+ writeRows (conn , tablePath , rows , true );
659+ List <String > expected = Arrays .asList ("+I[4, v4]" , "+I[5, v5]" , "+I[6, v6]" );
660+ int expectRecords = expected .size ();
661+ List <String > actual = collectRowsWithTimeout (rowIter , expectRecords );
662+ assertThat (actual ).containsExactlyElementsOf (expected );
709663 }
710664
711665 // -------------------------------------------------------------------------------------
@@ -1319,20 +1273,6 @@ private void waitUntilAllBucketFinishSnapshot(
13191273 "Fail to wait until all bucket finish snapshot" );
13201274 }
13211275
1322- private void assertQueryResult (String query , List <String > expected ) throws Exception {
1323- try (org .apache .flink .util .CloseableIterator <Row > rowIter =
1324- tEnv .executeSql (query ).collect ()) {
1325- int expectRecords = expected .size ();
1326- List <String > actual = new ArrayList <>(expectRecords );
1327- for (int i = 0 ; i < expectRecords ; i ++) {
1328- Row r = rowIter .next ();
1329- String row = r .toString ();
1330- actual .add (row );
1331- }
1332- assertThat (actual ).containsExactlyElementsOf (expected );
1333- }
1334- }
1335-
13361276 private GenericRow rowWithPartition (Object [] values , @ Nullable String partition ) {
13371277 if (partition == null ) {
13381278 return row (values );
0 commit comments