2323
2424import java .net .InetSocketAddress ;
2525import java .net .URISyntaxException ;
26+ import java .util .ArrayList ;
2627import java .util .HashMap ;
28+ import java .util .List ;
2729import java .util .Map ;
2830import java .util .stream .IntStream ;
2931import java .util .stream .Stream ;
@@ -380,6 +382,7 @@ public void multipleFlightStreamsFreed() throws Exception {
380382
381383 try (FlightSqlClient flightSqlClient = new FlightSqlClient (clientConfig )) {
382384
385+ List <AutoCloseable > autoCloseables = new ArrayList <>();
383386 for (int i = 0 ; i < 20 ; i ++) {
384387 Stream <VectorSchemaRoot > stream = flightSqlClient .execute (
385388 "select * from cpu" ,
@@ -389,14 +392,19 @@ public void multipleFlightStreamsFreed() throws Exception {
389392 Map .of ());
390393
391394 stream .forEach (VectorSchemaRoot ::contentToTSVString );
395+ autoCloseables .add (flightSqlClient .autoCloseables .get (flightSqlClient .autoCloseables .size () - 1 ));
396+
392397 }
393398 Assertions .assertThat (flightSqlClient .autoCloseables .size ()).isEqualTo (9 );
394- // N.B. can pick up references from other tests...
395- Assertions .assertThat (FlightSqlClient .CLOSEABLE_CLOSED_LEDGER .size ()).isLessThan (20 );
396- for (AutoCloseable closeable : FlightSqlClient .CLOSEABLE_CLOSED_LEDGER .keySet ()) {
397- Assertions .assertThat (FlightSqlClient .CLOSEABLE_CLOSED_LEDGER .get (closeable )).isTrue (); // Is closed
399+ for (int i = 0 ; i < autoCloseables .size (); i ++) {
400+ if (i < FlightSqlClient .AUTOCLOSEABLE_CHECK_LIMIT + 1 ) {
401+ Assertions .assertThat (flightSqlClient .autoCloseables .contains (autoCloseables .get (i ))).isFalse ();
402+ Assertions .assertThat (FlightSqlClient .CLOSEABLE_CLOSED_LEDGER .get (autoCloseables .get (i ))).isNull ();
403+ } else {
404+ Assertions .assertThat (flightSqlClient .autoCloseables .contains (autoCloseables .get (i ))).isTrue ();
405+ Assertions .assertThat (flightSqlClient .autoCloseables .contains (autoCloseables .get (i ))).isTrue ();
406+ }
398407 }
399-
400408 }
401409 }
402410
0 commit comments