@@ -219,7 +219,6 @@ class ITBigQueryTest {
219219
220220 private static final byte [] BYTES = {0xD , 0xE , 0xA , 0xD };
221221 private static final String BYTES_BASE64 = BaseEncoding .base64 ().encode (BYTES );
222- private static final Long EXPIRATION_MS = 86400000L ;
223222 private static final Logger LOG = Logger .getLogger (ITBigQueryTest .class .getName ());
224223 private static final String DATASET = RemoteBigQueryHelper .generateDatasetName ();
225224 private static final String UK_DATASET = RemoteBigQueryHelper .generateDatasetName ();
@@ -2626,29 +2625,39 @@ void testListTables() {
26262625
26272626 @ Test
26282627 void testListTablesWithPartitioning () {
2628+ long expirationMs = 86400000L ;
2629+ Type partitionType = Type .DAY ;
26292630 String tableName = "test_list_tables_partitioning" ;
2630- TimePartitioning timePartitioning = TimePartitioning .of (Type .DAY , EXPIRATION_MS );
26312631 StandardTableDefinition tableDefinition =
26322632 StandardTableDefinition .newBuilder ()
26332633 .setSchema (TABLE_SCHEMA )
2634- .setTimePartitioning (timePartitioning )
2634+ .setTimePartitioning (TimePartitioning . of ( partitionType , expirationMs ) )
26352635 .build ();
26362636 TableInfo tableInfo = TableInfo .of (TableId .of (DATASET , tableName ), tableDefinition );
26372637 Table createdPartitioningTable = bigquery .create (tableInfo );
26382638 assertNotNull (createdPartitioningTable );
26392639 try {
26402640 Page <Table > tables = bigquery .listTables (DATASET );
26412641 boolean found = false ;
2642- Iterator <Table > tableIterator = tables .getValues ().iterator ();
2643- while (tableIterator .hasNext () && !found ) {
2644- StandardTableDefinition standardTableDefinition = tableIterator .next ().getDefinition ();
2645- if (standardTableDefinition .getTimePartitioning () != null
2646- && standardTableDefinition .getTimePartitioning ().getType ().equals (Type .DAY )
2647- && standardTableDefinition
2648- .getTimePartitioning ()
2649- .getExpirationMs ()
2650- .equals (EXPIRATION_MS )) {
2642+ for (Table table : tables .getValues ()) {
2643+ // Look for the table that matches the newly partitioned table. Other tables in the
2644+ // dataset may not be partitioned or may be partitioned but may not be expiring
2645+ // (e.g. `null` expirationMs).
2646+ if (!table
2647+ .getTableId ()
2648+ .getTable ()
2649+ .equals (createdPartitioningTable .getTableId ().getTable ())) {
2650+ continue ;
2651+ }
2652+
2653+ StandardTableDefinition standardTableDefinition = table .getDefinition ();
2654+ TimePartitioning timePartitioning = standardTableDefinition .getTimePartitioning ();
2655+ assertNotNull (timePartitioning );
2656+ assertNotNull (timePartitioning .getExpirationMs ());
2657+ if (timePartitioning .getType ().equals (partitionType )
2658+ && timePartitioning .getExpirationMs ().equals (expirationMs )) {
26512659 found = true ;
2660+ break ;
26522661 }
26532662 }
26542663 assertTrue (found );
0 commit comments