Skip to content

Commit

Permalink
bigquery: wait for copy to finish (#1456)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pongad authored and garrettjonesgoogle committed Dec 8, 2016
1 parent 4567c49 commit e99857e
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}

Expand Down

0 comments on commit e99857e

Please sign in to comment.