From 9fd97947e0f85089d68c874b7dfaab0756e1afb9 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Wed, 13 Apr 2016 10:04:30 +0200 Subject: [PATCH] Compute's Operation.isDone() return true if operation does not exist --- .../com/google/gcloud/compute/Operation.java | 16 +++++++--------- .../com/google/gcloud/compute/OperationTest.java | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/Operation.java b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/Operation.java index 4270147777a6..2b35dac3fd2b 100644 --- a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/Operation.java +++ b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/Operation.java @@ -640,23 +640,21 @@ public boolean exists() throws ComputeException { /** * Checks if this operation has completed its execution, either failing or succeeding. If the - * operation does not exist this method returns {@code false}. To correctly wait for operation's - * completion, check that the operation exists first using {@link #exists()}: + * operation does not exist this method returns {@code true}. You can wait for operation + * completion with: *
 {@code
-   * if (operation.exists()) {
-   *   while(!operation.isDone()) {
-   *     Thread.sleep(1000L);
-   *   }
+   * while(!operation.isDone()) {
+   *   Thread.sleep(1000L);
    * }}
* - * @return {@code true} if this operation is in {@link Operation.Status#DONE} state, {@code false} - * if the state is not {@link Operation.Status#DONE} or the operation does not exist + * @return {@code true} if this operation is in {@link Operation.Status#DONE} state or if it does + * not exist, {@code false} if the state is not {@link Operation.Status#DONE} * @throws ComputeException upon failure */ public boolean isDone() throws ComputeException { Operation operation = compute.get(operationId, Compute.OperationOption.fields(Compute.OperationField.STATUS)); - return operation != null && operation.status() == Status.DONE; + return operation == null || operation.status() == Status.DONE; } /** diff --git a/gcloud-java-compute/src/test/java/com/google/gcloud/compute/OperationTest.java b/gcloud-java-compute/src/test/java/com/google/gcloud/compute/OperationTest.java index bc756bdbfe6a..450097c4ef30 100644 --- a/gcloud-java-compute/src/test/java/com/google/gcloud/compute/OperationTest.java +++ b/gcloud-java-compute/src/test/java/com/google/gcloud/compute/OperationTest.java @@ -352,7 +352,7 @@ public void testIsDone_NotExists() throws Exception { expect(compute.get(GLOBAL_OPERATION_ID, expectedOptions)).andReturn(null); replay(compute); initializeOperation(); - assertFalse(operation.isDone()); + assertTrue(operation.isDone()); verify(compute); }