From 136d6fb0e9126f35d7325a10ca931f3342c91357 Mon Sep 17 00:00:00 2001 From: Praful Makani Date: Tue, 8 Sep 2020 20:46:12 +0530 Subject: [PATCH] test: fix flaky test (#726) * test: fix flaky test * test: fix flaky test --- .../cloud/bigquery/it/ITBigQueryTest.java | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index dd5aeb618..b99690011 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -860,7 +860,7 @@ public void testListTablesWithRangePartitioning() { @Test public void testListPartitions() throws InterruptedException { - String tableName = "test_table_partitions"; + String tableName = "test_table_partitions_" + UUID.randomUUID().toString().substring(0, 8); Date date = Date.fromJavaUtilDate(new java.util.Date()); String partitionDate = date.toString().replaceAll("-", ""); TableId tableId = TableId.of(DATASET, tableName + "$" + partitionDate); @@ -873,18 +873,15 @@ public void testListPartitions() throws InterruptedException { Job job = bigquery.create(JobInfo.of(QueryJobConfiguration.newBuilder(query).build())); job.waitFor(); assertTrue(job.isDone()); - try { - Map row = new HashMap(); - row.put("StringField", "StringValue"); - InsertAllRequest request = InsertAllRequest.newBuilder(tableId).addRow(row).build(); - InsertAllResponse response = bigquery.insertAll(request); - assertFalse(response.hasErrors()); - assertEquals(0, response.getInsertErrors().size()); - List partitions = bigquery.listPartitions(TableId.of(DATASET, tableName)); - assertEquals(1, partitions.size()); - } finally { - bigquery.delete(tableId); - } + Map row = new HashMap<>(); + row.put("StringField", "StringValue"); + InsertAllRequest request = InsertAllRequest.newBuilder(tableId).addRow(row).build(); + InsertAllResponse response = bigquery.insertAll(request); + assertFalse(response.hasErrors()); + assertEquals(0, response.getInsertErrors().size()); + List partitions = bigquery.listPartitions(TableId.of(DATASET, tableName)); + assertEquals(1, partitions.size()); + bigquery.delete(tableId); } @Test