Skip to content

Commit 9fd9794

Browse files
committed
Compute's Operation.isDone() return true if operation does not exist
1 parent 246e5a7 commit 9fd9794

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

gcloud-java-compute/src/main/java/com/google/gcloud/compute/Operation.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -640,23 +640,21 @@ public boolean exists() throws ComputeException {
640640

641641
/**
642642
* Checks if this operation has completed its execution, either failing or succeeding. If the
643-
* operation does not exist this method returns {@code false}. To correctly wait for operation's
644-
* completion, check that the operation exists first using {@link #exists()}:
643+
* operation does not exist this method returns {@code true}. You can wait for operation
644+
* completion with:
645645
* <pre> {@code
646-
* if (operation.exists()) {
647-
* while(!operation.isDone()) {
648-
* Thread.sleep(1000L);
649-
* }
646+
* while(!operation.isDone()) {
647+
* Thread.sleep(1000L);
650648
* }}</pre>
651649
*
652-
* @return {@code true} if this operation is in {@link Operation.Status#DONE} state, {@code false}
653-
* if the state is not {@link Operation.Status#DONE} or the operation does not exist
650+
* @return {@code true} if this operation is in {@link Operation.Status#DONE} state or if it does
651+
* not exist, {@code false} if the state is not {@link Operation.Status#DONE}
654652
* @throws ComputeException upon failure
655653
*/
656654
public boolean isDone() throws ComputeException {
657655
Operation operation =
658656
compute.get(operationId, Compute.OperationOption.fields(Compute.OperationField.STATUS));
659-
return operation != null && operation.status() == Status.DONE;
657+
return operation == null || operation.status() == Status.DONE;
660658
}
661659

662660
/**

gcloud-java-compute/src/test/java/com/google/gcloud/compute/OperationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public void testIsDone_NotExists() throws Exception {
352352
expect(compute.get(GLOBAL_OPERATION_ID, expectedOptions)).andReturn(null);
353353
replay(compute);
354354
initializeOperation();
355-
assertFalse(operation.isDone());
355+
assertTrue(operation.isDone());
356356
verify(compute);
357357
}
358358

0 commit comments

Comments
 (0)