From 33a81a0433d45e1ca2e203a1be9d93b27b28fc74 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 5 Apr 2016 11:21:13 +0200 Subject: [PATCH] Job.isDone() returns true if the job does not exist --- .../main/java/com/google/gcloud/bigquery/Job.java | 15 ++++++--------- .../java/com/google/gcloud/bigquery/JobTest.java | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/Job.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/Job.java index 586395a0f879..7f8237473b15 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/Job.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/Job.java @@ -128,22 +128,19 @@ public boolean exists() { /** * Checks if this job has completed its execution, either failing or succeeding. If the job does - * not exist this method returns {@code false}. To correctly wait for job's completion check that - * the job exists first, using {@link #exists()}: + * not exist this method returns {@code true}. You can wait for job completion with: *
 {@code
-   * if (job.exists()) {
-   *   while(!job.isDone()) {
-   *     Thread.sleep(1000L);
-   *   }
+   * while(!job.isDone()) {
+   *   Thread.sleep(1000L);
    * }}
* - * @return {@code true} if this job is in {@link JobStatus.State#DONE} state, {@code false} if the - * state is not {@link JobStatus.State#DONE} or the job does not exist + * @return {@code true} if this job is in {@link JobStatus.State#DONE} state or if it does not + * exist, {@code false} if the state is not {@link JobStatus.State#DONE} * @throws BigQueryException upon failure */ public boolean isDone() { Job job = bigquery.getJob(jobId(), BigQuery.JobOption.fields(BigQuery.JobField.STATUS)); - return job != null && job.status().state() == JobStatus.State.DONE; + return job == null || job.status().state() == JobStatus.State.DONE; } /** diff --git a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/JobTest.java b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/JobTest.java index e066bbed2fb4..61c9c521196a 100644 --- a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/JobTest.java +++ b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/JobTest.java @@ -172,7 +172,7 @@ public void testIsDone_NotExists() throws Exception { expect(bigquery.getJob(JOB_INFO.jobId(), expectedOptions)).andReturn(null); replay(bigquery); initializeJob(); - assertFalse(job.isDone()); + assertTrue(job.isDone()); } @Test