Skip to content

Commit e99857e

Browse files
pongadgarrettjonesgoogle
authored andcommitted
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.
1 parent 4567c49 commit e99857e

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java

+17-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import static org.junit.Assert.fail;
2626

2727
import com.google.cloud.Page;
28+
import com.google.cloud.WaitForOption;
2829
import com.google.cloud.bigquery.BigQuery;
2930
import com.google.cloud.bigquery.BigQuery.DatasetField;
3031
import com.google.cloud.bigquery.BigQuery.DatasetOption;
@@ -899,7 +900,7 @@ public void testListJobsWithSelectedFields() {
899900
}
900901

901902
@Test
902-
public void testCreateAndGetJob() {
903+
public void testCreateAndGetJob() throws InterruptedException, TimeoutException {
903904
String sourceTableName = "test_create_and_get_job_source_table";
904905
String destinationTableName = "test_create_and_get_job_destination_table";
905906
TableId sourceTable = TableId.of(DATASET, sourceTableName);
@@ -930,11 +931,18 @@ public void testCreateAndGetJob() {
930931
assertEquals(createdJob.getSelfLink(), remoteJob.getSelfLink());
931932
assertEquals(createdJob.getUserEmail(), remoteJob.getUserEmail());
932933
assertTrue(createdTable.delete());
934+
935+
Job completedJob =
936+
remoteJob.waitFor(
937+
WaitForOption.checkEvery(1, TimeUnit.SECONDS),
938+
WaitForOption.timeout(1, TimeUnit.MINUTES));
939+
assertNotNull(completedJob);
940+
assertNull(completedJob.getStatus().getError());
933941
assertTrue(bigquery.delete(DATASET, destinationTableName));
934942
}
935943

936944
@Test
937-
public void testCreateAndGetJobWithSelectedFields() {
945+
public void testCreateAndGetJobWithSelectedFields() throws InterruptedException, TimeoutException {
938946
String sourceTableName = "test_create_and_get_job_with_selected_fields_source_table";
939947
String destinationTableName = "test_create_and_get_job_with_selected_fields_destination_table";
940948
TableId sourceTable = TableId.of(DATASET, sourceTableName);
@@ -972,6 +980,13 @@ public void testCreateAndGetJobWithSelectedFields() {
972980
assertNull(remoteJob.getSelfLink());
973981
assertNull(remoteJob.getUserEmail());
974982
assertTrue(createdTable.delete());
983+
984+
Job completedJob =
985+
remoteJob.waitFor(
986+
WaitForOption.checkEvery(1, TimeUnit.SECONDS),
987+
WaitForOption.timeout(1, TimeUnit.MINUTES));
988+
assertNotNull(completedJob);
989+
assertNull(completedJob.getStatus().getError());
975990
assertTrue(bigquery.delete(DATASET, destinationTableName));
976991
}
977992

0 commit comments

Comments
 (0)