Skip to content

Commit b29df66

Browse files
committed
Merge pull request #853 from mziccard/fix-job-isdone
Job.isDone() returns true if the job does not exist
2 parents 3e7069a + 33a81a0 commit b29df66

File tree

2 files changed

+7
-10
lines changed
  • gcloud-java-bigquery/src

2 files changed

+7
-10
lines changed

gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/Job.java

+6-9
Original file line numberDiff line numberDiff line change
@@ -128,22 +128,19 @@ public boolean exists() {
128128

129129
/**
130130
* Checks if this job has completed its execution, either failing or succeeding. If the job does
131-
* not exist this method returns {@code false}. To correctly wait for job's completion check that
132-
* the job exists first, using {@link #exists()}:
131+
* not exist this method returns {@code true}. You can wait for job completion with:
133132
* <pre> {@code
134-
* if (job.exists()) {
135-
* while(!job.isDone()) {
136-
* Thread.sleep(1000L);
137-
* }
133+
* while(!job.isDone()) {
134+
* Thread.sleep(1000L);
138135
* }}</pre>
139136
*
140-
* @return {@code true} if this job is in {@link JobStatus.State#DONE} state, {@code false} if the
141-
* state is not {@link JobStatus.State#DONE} or the job does not exist
137+
* @return {@code true} if this job is in {@link JobStatus.State#DONE} state or if it does not
138+
* exist, {@code false} if the state is not {@link JobStatus.State#DONE}
142139
* @throws BigQueryException upon failure
143140
*/
144141
public boolean isDone() {
145142
Job job = bigquery.getJob(jobId(), BigQuery.JobOption.fields(BigQuery.JobField.STATUS));
146-
return job != null && job.status().state() == JobStatus.State.DONE;
143+
return job == null || job.status().state() == JobStatus.State.DONE;
147144
}
148145

149146
/**

gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/JobTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public void testIsDone_NotExists() throws Exception {
172172
expect(bigquery.getJob(JOB_INFO.jobId(), expectedOptions)).andReturn(null);
173173
replay(bigquery);
174174
initializeJob();
175-
assertFalse(job.isDone());
175+
assertTrue(job.isDone());
176176
}
177177

178178
@Test

0 commit comments

Comments
 (0)