Skip to content

Commit 384bc26

Browse files
Fixed code and test
1 parent afdf55f commit 384bc26

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

compute/cloud-client/src/main/java/compute/disks/consistencygroup/AddDiskToConsistencyGroup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public static Disk addDiskToConsistencyGroup(
8484

8585
Operation response = disksClient.addResourcePoliciesAsync(disksRequest).get();
8686
if (response.hasError()) {
87-
return null;
87+
throw new Error("Error attaching disk to consistency group! " + response.getError());
8888
}
8989
System.out.println(disksClient.get(project, location, diskName).getResourcePoliciesList());
9090
return disksClient.get(project, location, diskName);

compute/cloud-client/src/main/java/compute/disks/consistencygroup/CreateDiskConsistencyGroup.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static void main(String[] args)
4040

4141
// Creates a new disk consistency group resource policy in the specified project and region.
4242
// Return a link to the consistency group.
43-
public static String createDiskConsistencyGroup(
43+
public static Operation.Status createDiskConsistencyGroup(
4444
String project, String region, String consistencyGroupName)
4545
throws IOException, ExecutionException, InterruptedException {
4646
// Initialize client that will be used to send requests. This client only needs to be created
@@ -58,9 +58,9 @@ public static String createDiskConsistencyGroup(
5858
regionResourcePoliciesClient.insertAsync(project, region, resourcePolicy).get();
5959

6060
if (response.hasError()) {
61-
return null;
61+
throw new Error("Error creating consistency group! " + response.getError());
6262
}
63-
return regionResourcePoliciesClient.get(project, region, consistencyGroupName).getSelfLink();
63+
return response.getStatus();
6464
}
6565
}
6666
}

compute/cloud-client/src/main/java/compute/disks/consistencygroup/DeleteDiskConsistencyGroup.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static void main(String[] args)
3838
}
3939

4040
// Deletes a disk consistency group resource policy in the specified project and region.
41-
public static void deleteDiskConsistencyGroup(
41+
public static Operation.Status deleteDiskConsistencyGroup(
4242
String project, String region, String consistencyGroupName)
4343
throws IOException, ExecutionException, InterruptedException {
4444
// Initialize client that will be used to send requests. This client only needs to be created
@@ -48,11 +48,9 @@ public static void deleteDiskConsistencyGroup(
4848
.deleteAsync(project, region, consistencyGroupName).get();
4949

5050
if (response.hasError()) {
51-
return;
51+
throw new Error("Error deleting disk! " + response.getError());
5252
}
53-
System.out.println(
54-
"Disk consistency group resource policy deleted successfully: "
55-
+ consistencyGroupName);
53+
return response.getStatus();
5654
}
5755
}
5856
}

compute/cloud-client/src/test/java/compute/disks/ConsistencyGroupIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static org.junit.Assert.assertTrue;
2323

2424
import com.google.cloud.compute.v1.Disk;
25+
import com.google.cloud.compute.v1.Operation;
2526
import compute.Util;
2627
import compute.disks.consistencygroup.AddDiskToConsistencyGroup;
2728
import compute.disks.consistencygroup.CreateDiskConsistencyGroup;
@@ -89,11 +90,10 @@ public static void cleanUp()
8990
@Order(1)
9091
public void testCreateDiskConsistencyGroupResourcePolicy()
9192
throws IOException, ExecutionException, InterruptedException {
92-
String consistencyGroupLink = CreateDiskConsistencyGroup.createDiskConsistencyGroup(
93+
Operation.Status status = CreateDiskConsistencyGroup.createDiskConsistencyGroup(
9394
PROJECT_ID, REGION, CONSISTENCY_GROUP_NAME);
9495

95-
assertNotNull(consistencyGroupLink);
96-
assertThat(consistencyGroupLink.contains(CONSISTENCY_GROUP_NAME));
96+
assertThat(status).isEqualTo(Operation.Status.DONE);
9797
}
9898

9999
@Test

0 commit comments

Comments
 (0)