Skip to content

Commit 9520be3

Browse files
Fixed test
1 parent 8a5b2f0 commit 9520be3

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

compute/cloud-client/src/main/java/compute/snapshot/DeleteSnapshotSchedule.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package compute.snapshot;
1818

1919
// [START compute_snapshot_schedule_delete]
20+
import com.google.cloud.compute.v1.Operation;
2021
import com.google.cloud.compute.v1.ResourcePoliciesClient;
2122
import java.io.IOException;
2223
import java.util.concurrent.ExecutionException;
@@ -38,13 +39,20 @@ public static void main(String[] args)
3839
}
3940

4041
// Deletes a snapshot schedule policy.
41-
public static void deleteSnapshotSchedule(String projectId, String region, String scheduleName)
42+
public static Operation.Status deleteSnapshotSchedule(
43+
String projectId, String region, String scheduleName)
4244
throws IOException, ExecutionException, InterruptedException, TimeoutException {
43-
45+
// Initialize client that will be used to send requests. This client only needs to be created
46+
// once, and can be reused for multiple requests.
4447
try (ResourcePoliciesClient resourcePoliciesClient = ResourcePoliciesClient.create()) {
45-
resourcePoliciesClient.deleteAsync(projectId, region, scheduleName).get(3, TimeUnit.MINUTES);
48+
Operation response = resourcePoliciesClient.deleteAsync(projectId, region, scheduleName)
49+
.get(3, TimeUnit.MINUTES);
4650

47-
System.out.println("Snapshot schedule deleted successfully: " + scheduleName);
51+
if (response.hasError()) {
52+
System.out.printf("Snapshot schedule deletion failed: %s%n", response.getError());
53+
return null;
54+
}
55+
return response.getStatus();
4856
}
4957
}
5058
}

compute/cloud-client/src/test/java/compute/snapshot/SnapshotIT.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
import static com.google.common.truth.Truth.assertWithMessage;
2121

2222
import com.google.cloud.compute.v1.Operation;
23-
import java.io.ByteArrayOutputStream;
2423
import java.io.IOException;
25-
import java.io.PrintStream;
2624
import java.util.UUID;
2725
import java.util.concurrent.ExecutionException;
2826
import java.util.concurrent.TimeUnit;
@@ -63,16 +61,11 @@ public static void setUp()
6361
@AfterAll
6462
public static void cleanup()
6563
throws IOException, ExecutionException, InterruptedException, TimeoutException {
66-
ByteArrayOutputStream stdOut = new ByteArrayOutputStream();
67-
System.setOut(new PrintStream(stdOut));
68-
6964
// Delete snapshot schedule created for testing.
70-
DeleteSnapshotSchedule.deleteSnapshotSchedule(PROJECT_ID, REGION, SCHEDULE_NAME);
71-
72-
assertThat(stdOut.toString())
73-
.contains("Snapshot schedule deleted successfully: " + SCHEDULE_NAME);
65+
Operation.Status status = DeleteSnapshotSchedule
66+
.deleteSnapshotSchedule(PROJECT_ID, REGION, SCHEDULE_NAME);
7467

75-
stdOut.close();
68+
assertThat(status).isEqualTo(Operation.Status.DONE);
7669
}
7770

7871
@Test
@@ -81,6 +74,7 @@ public void testCreateSnapshotScheduleHourly()
8174
Operation.Status status = CreateSnapshotSchedule.createSnapshotSchedule(
8275
PROJECT_ID, REGION, SCHEDULE_NAME, SCHEDULE_DESCRIPTION,
8376
MAX_RETENTION_DAYS, STORAGE_LOCATION, ON_SOURCE_DISK_DELETE);
77+
8478
assertThat(status).isEqualTo(Operation.Status.DONE);
8579
}
8680
}

0 commit comments

Comments
 (0)