Skip to content

Commit

Permalink
Job.isDone() returns true if the job does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Apr 5, 2016
1 parent 25ccf08 commit 33a81a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
* <pre> {@code
* if (job.exists()) {
* while(!job.isDone()) {
* Thread.sleep(1000L);
* }
* while(!job.isDone()) {
* Thread.sleep(1000L);
* }}</pre>
*
* @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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 33a81a0

Please sign in to comment.