From e99857e80771ede2cb795dd249f2ac3ee14cf3f9 Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Fri, 9 Dec 2016 03:10:07 +1100 Subject: [PATCH] bigquery: wait for copy to finish (#1456) BigQuery integration tests previously create a table-copy job, verify properties, and delete the destination table. Deletion will fail if BigQuery hasn't gotten around to copy the table yet. The fix is to wait for the job to finish (1 min timeout) before deleting. --- .../cloud/bigquery/it/ITBigQueryTest.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 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 3ba8d75ae524..e2e201d77cf1 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 @@ -25,6 +25,7 @@ import static org.junit.Assert.fail; import com.google.cloud.Page; +import com.google.cloud.WaitForOption; import com.google.cloud.bigquery.BigQuery; import com.google.cloud.bigquery.BigQuery.DatasetField; import com.google.cloud.bigquery.BigQuery.DatasetOption; @@ -899,7 +900,7 @@ public void testListJobsWithSelectedFields() { } @Test - public void testCreateAndGetJob() { + public void testCreateAndGetJob() throws InterruptedException, TimeoutException { String sourceTableName = "test_create_and_get_job_source_table"; String destinationTableName = "test_create_and_get_job_destination_table"; TableId sourceTable = TableId.of(DATASET, sourceTableName); @@ -930,11 +931,18 @@ public void testCreateAndGetJob() { assertEquals(createdJob.getSelfLink(), remoteJob.getSelfLink()); assertEquals(createdJob.getUserEmail(), remoteJob.getUserEmail()); assertTrue(createdTable.delete()); + + Job completedJob = + remoteJob.waitFor( + WaitForOption.checkEvery(1, TimeUnit.SECONDS), + WaitForOption.timeout(1, TimeUnit.MINUTES)); + assertNotNull(completedJob); + assertNull(completedJob.getStatus().getError()); assertTrue(bigquery.delete(DATASET, destinationTableName)); } @Test - public void testCreateAndGetJobWithSelectedFields() { + public void testCreateAndGetJobWithSelectedFields() throws InterruptedException, TimeoutException { String sourceTableName = "test_create_and_get_job_with_selected_fields_source_table"; String destinationTableName = "test_create_and_get_job_with_selected_fields_destination_table"; TableId sourceTable = TableId.of(DATASET, sourceTableName); @@ -972,6 +980,13 @@ public void testCreateAndGetJobWithSelectedFields() { assertNull(remoteJob.getSelfLink()); assertNull(remoteJob.getUserEmail()); assertTrue(createdTable.delete()); + + Job completedJob = + remoteJob.waitFor( + WaitForOption.checkEvery(1, TimeUnit.SECONDS), + WaitForOption.timeout(1, TimeUnit.MINUTES)); + assertNotNull(completedJob); + assertNull(completedJob.getStatus().getError()); assertTrue(bigquery.delete(DATASET, destinationTableName)); }