@@ -3354,7 +3354,8 @@ void testQueryWithArrowFormatMultiplePagesWithMaxResults()
33543354 .build ();
33553355 ReadRowsResponse streamResponse =
33563356 ReadRowsResponse .newBuilder ().setArrowRecordBatch (protoBatch ).build ();
3357- when (mockServerStream .iterator ()).thenReturn (ImmutableList .of (streamResponse ).iterator ());
3357+ when (mockServerStream .iterator ())
3358+ .thenAnswer (invocation -> ImmutableList .of (streamResponse ).iterator ());
33583359
33593360 BigQueryReadClient mockReadClient =
33603361 mock (BigQueryReadClient .class , withSettings ().withoutAnnotations ());
@@ -3375,25 +3376,28 @@ void testQueryWithArrowFormatMultiplePagesWithMaxResults()
33753376 Page <FieldValueList > page2 = result .getNextPage ();
33763377 assertNotNull (page2 );
33773378 List <FieldValueList > page2Rows = ImmutableList .copyOf (page2 .getValues ());
3378- // Since maxResults is 2 and initialRowOffset is 1, page2 should only contain 1 row even though
3379- // stream returned 2 rows
3380- assertEquals (1 , page2Rows .size ());
3379+ // Since maxResults configures the page size (2 rows), page2 contains the 2 rows from the stream
3380+ assertEquals (2 , page2Rows .size ());
33813381 assertEquals ("2" , page2Rows .get (0 ).get (0 ).getStringValue ());
3382- // Since totalRowsReturned == maxResults, hasNextPage must be false
3382+ assertEquals ("3" , page2Rows .get (1 ).get (0 ).getStringValue ());
3383+ // End of stream reached (total 3 rows read across pages 1 and 2), hasNextPage must be false
33833384 assertFalse (page2 .hasNextPage ());
33843385 assertNull (page2 .getNextPage ());
33853386
3386- // When maxResults is 1, initialRowOffset (1) already reaches maxResults, so hasNextPage is
3387- // false immediately
3387+ // When maxResults is 1, page token is still preserved for subsequent pages
33883388 QueryJobConfiguration configMax1 =
33893389 QueryJobConfiguration .newBuilder ("SELECT id FROM test" )
33903390 .setQueryResultsFormat (QueryResultsFormat .ARROW )
33913391 .setMaxResults (1L )
33923392 .build ();
33933393 TableResult resultMax1 = bigquery .query (configMax1 );
33943394 assertNotNull (resultMax1 );
3395- assertFalse (resultMax1 .hasNextPage ());
3396- assertNull (resultMax1 .getNextPage ());
3395+ assertTrue (resultMax1 .hasNextPage ());
3396+ Page <FieldValueList > page2Max1 = resultMax1 .getNextPage ();
3397+ assertNotNull (page2Max1 );
3398+ List <FieldValueList > page2Max1Rows = ImmutableList .copyOf (page2Max1 .getValues ());
3399+ assertEquals (1 , page2Max1Rows .size ());
3400+ assertEquals ("2" , page2Max1Rows .get (0 ).get (0 ).getStringValue ());
33973401 }
33983402
33993403 @ Test
0 commit comments