Skip to content

Commit 7c6b6d1

Browse files
Fixed tests
1 parent de29722 commit 7c6b6d1

File tree

8 files changed

+40
-30
lines changed

8 files changed

+40
-30
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
import java.io.IOException;
2828
import java.util.Arrays;
2929
import java.util.concurrent.ExecutionException;
30+
import java.util.concurrent.TimeUnit;
31+
import java.util.concurrent.TimeoutException;
3032

3133
public class AddDiskToConsistencyGroup {
3234
public static void main(String[] args)
33-
throws IOException, ExecutionException, InterruptedException {
35+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
3436
// TODO(developer): Replace these variables before running the sample.
3537
// The project that contains the disk.
3638
String project = "YOUR_PROJECT_ID";
@@ -51,7 +53,7 @@ public static void main(String[] args)
5153
public static Operation.Status addDiskToConsistencyGroup(
5254
String project, String location, String diskName,
5355
String consistencyGroupName, String consistencyGroupLocation)
54-
throws IOException, ExecutionException, InterruptedException {
56+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
5557
String consistencyGroupUrl = String.format(
5658
"https://www.googleapis.com/compute/v1/projects/%s/regions/%s/resourcePolicies/%s",
5759
project, consistencyGroupLocation, consistencyGroupName);
@@ -70,7 +72,7 @@ public static Operation.Status addDiskToConsistencyGroup(
7072
.addAllResourcePolicies(Arrays.asList(consistencyGroupUrl))
7173
.build())
7274
.build();
73-
response = disksClient.addResourcePoliciesAsync(request).get();
75+
response = disksClient.addResourcePoliciesAsync(request).get(1, TimeUnit.MINUTES);
7476
}
7577
} else {
7678
try (DisksClient disksClient = DisksClient.create()) {
@@ -84,7 +86,7 @@ public static Operation.Status addDiskToConsistencyGroup(
8486
.addAllResourcePolicies(Arrays.asList(consistencyGroupUrl))
8587
.build())
8688
.build();
87-
response = disksClient.addResourcePoliciesAsync(request).get();
89+
response = disksClient.addResourcePoliciesAsync(request).get(1, TimeUnit.MINUTES);
8890
}
8991
}
9092
if (response.hasError()) {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
import com.google.cloud.compute.v1.ResourcePolicy;
2424
import java.io.IOException;
2525
import java.util.concurrent.ExecutionException;
26+
import java.util.concurrent.TimeUnit;
27+
import java.util.concurrent.TimeoutException;
2628

2729
public class CreateDiskConsistencyGroup {
2830

2931
public static void main(String[] args)
30-
throws IOException, ExecutionException, InterruptedException {
32+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
3133
// TODO(developer): Replace these variables before running the sample.
3234
// Project ID or project number of the Cloud project you want to use.
3335
String project = "YOUR_PROJECT_ID";
@@ -42,7 +44,7 @@ public static void main(String[] args)
4244
// Creates a new disk consistency group resource policy in the specified project and region.
4345
public static Operation.Status createDiskConsistencyGroup(
4446
String project, String region, String consistencyGroupName)
45-
throws IOException, ExecutionException, InterruptedException {
47+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
4648
// Initialize client that will be used to send requests. This client only needs to be created
4749
// once, and can be reused for multiple requests.
4850
try (ResourcePoliciesClient regionResourcePoliciesClient = ResourcePoliciesClient.create()) {
@@ -61,7 +63,7 @@ public static Operation.Status createDiskConsistencyGroup(
6163
.build();
6264

6365
Operation response =
64-
regionResourcePoliciesClient.insertAsync(request).get();
66+
regionResourcePoliciesClient.insertAsync(request).get(1, TimeUnit.MINUTES);
6567

6668
if (response.hasError()) {
6769
throw new Error("Error creating consistency group! " + response.getError());

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
import com.google.cloud.compute.v1.ResourcePoliciesClient;
2222
import java.io.IOException;
2323
import java.util.concurrent.ExecutionException;
24+
import java.util.concurrent.TimeUnit;
25+
import java.util.concurrent.TimeoutException;
2426

2527
public class DeleteDiskConsistencyGroup {
2628

2729
public static void main(String[] args)
28-
throws IOException, ExecutionException, InterruptedException {
30+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
2931
// TODO(developer): Replace these variables before running the sample.
3032
// Project ID or project number of the Cloud project you want to use.
3133
String project = "YOUR_PROJECT_ID";
@@ -40,12 +42,12 @@ public static void main(String[] args)
4042
// Deletes a disk consistency group resource policy in the specified project and region.
4143
public static Operation.Status deleteDiskConsistencyGroup(
4244
String project, String region, String consistencyGroupName)
43-
throws IOException, ExecutionException, InterruptedException {
45+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
4446
// Initialize client that will be used to send requests. This client only needs to be created
4547
// once, and can be reused for multiple requests.
4648
try (ResourcePoliciesClient resourcePoliciesClient = ResourcePoliciesClient.create()) {
4749
Operation response = resourcePoliciesClient
48-
.deleteAsync(project, region, consistencyGroupName).get();
50+
.deleteAsync(project, region, consistencyGroupName).get(1, TimeUnit.MINUTES);
4951

5052
if (response.hasError()) {
5153
throw new Error("Error deleting disk! " + response.getError());

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
import java.io.IOException;
2828
import java.util.Arrays;
2929
import java.util.concurrent.ExecutionException;
30+
import java.util.concurrent.TimeUnit;
31+
import java.util.concurrent.TimeoutException;
3032

3133
public class RemoveDiskFromConsistencyGroup {
3234

3335
public static void main(String[] args)
34-
throws IOException, ExecutionException, InterruptedException {
36+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
3537
// TODO(developer): Replace these variables before running the sample.
3638
// The project that contains the disk.
3739
String project = "YOUR_PROJECT_ID";
@@ -52,7 +54,7 @@ public static void main(String[] args)
5254
public static Operation.Status removeDiskFromConsistencyGroup(
5355
String project, String location, String diskName,
5456
String consistencyGroupName, String consistencyGroupLocation)
55-
throws IOException, ExecutionException, InterruptedException {
57+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
5658
String consistencyGroupUrl = String.format(
5759
"https://www.googleapis.com/compute/v1/projects/%s/regions/%s/resourcePolicies/%s",
5860
project, consistencyGroupLocation, consistencyGroupName);
@@ -72,7 +74,7 @@ public static Operation.Status removeDiskFromConsistencyGroup(
7274
.build())
7375
.build();
7476

75-
response = disksClient.removeResourcePoliciesAsync(request).get();
77+
response = disksClient.removeResourcePoliciesAsync(request).get(1, TimeUnit.MINUTES);
7678
}
7779
} else {
7880
try (DisksClient disksClient = DisksClient.create()) {
@@ -86,7 +88,7 @@ public static Operation.Status removeDiskFromConsistencyGroup(
8688
.addAllResourcePolicies(Arrays.asList(consistencyGroupUrl))
8789
.build())
8890
.build();
89-
response = disksClient.removeResourcePoliciesAsync(request).get();
91+
response = disksClient.removeResourcePoliciesAsync(request).get(1, TimeUnit.MINUTES);
9092
}
9193
}
9294
if (response.hasError()) {

compute/cloud-client/src/main/java/compute/disks/storagepool/CreateDiskInStoragePool.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static void main(String[] args)
5858
public static Disk createDiskInStoragePool(String projectId, String zone, String diskName,
5959
String storagePoolName, String diskType,
6060
long diskSizeGb, long iops, long throughput)
61-
throws IOException, ExecutionException, InterruptedException {
61+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
6262
// Initialize client that will be used to send requests. This client only needs to be created
6363
// once, and can be reused for multiple requests.
6464
try (DisksClient client = DisksClient.create()) {
@@ -80,7 +80,7 @@ public static Disk createDiskInStoragePool(String projectId, String zone, String
8080
.build();
8181

8282
// Wait for the insert disk operation to complete.
83-
Operation operation = client.insertAsync(request).get();
83+
Operation operation = client.insertAsync(request).get(1, TimeUnit.MINUTES);
8484

8585
if (operation.hasError()) {
8686
System.out.println("Disk creation failed!");

compute/cloud-client/src/main/java/compute/disks/storagepool/CreateHyperdiskStoragePool.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static void main(String[] args)
6161
public static StoragePool createHyperdiskStoragePool(String projectId, String zone,
6262
String storagePoolName, String storagePoolType, String capacityProvisioningType,
6363
long capacity, long iops, long throughput, String performanceProvisioningType)
64-
throws IOException, ExecutionException, InterruptedException {
64+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
6565
// Initialize client that will be used to send requests. This client only needs to be created
6666
// once, and can be reused for multiple requests.
6767
try (StoragePoolsClient client = StoragePoolsClient.create()) {
@@ -84,7 +84,7 @@ public static StoragePool createHyperdiskStoragePool(String projectId, String zo
8484
.build();
8585

8686
// Wait for the insert disk operation to complete.
87-
Operation operation = client.insertAsync(request).get();
87+
Operation operation = client.insertAsync(request).get(1, TimeUnit.MINUTES);
8888

8989
if (operation.hasError()) {
9090
System.out.println("StoragePool creation failed!");

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

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

1919
import static org.junit.Assert.assertEquals;
20+
import static org.mockito.ArgumentMatchers.anyLong;
2021
import static org.mockito.Mockito.any;
2122
import static org.mockito.Mockito.mock;
2223
import static org.mockito.Mockito.mockStatic;
@@ -61,14 +62,14 @@ public void testCreateDiskConsistencyGroupResourcePolicy() throws Exception {
6162
mockedResourcePoliciesClient.when(ResourcePoliciesClient::create).thenReturn(mockClient);
6263
when(mockClient.insertAsync(any(InsertResourcePolicyRequest.class)))
6364
.thenReturn(mockFuture);
64-
when(mockFuture.get()).thenReturn(operation);
65+
when(mockFuture.get(anyLong(), any(TimeUnit.class))).thenReturn(operation);
6566
when(operation.getStatus()).thenReturn(Operation.Status.DONE);
6667

6768
Operation.Status status = CreateDiskConsistencyGroup.createDiskConsistencyGroup(
6869
PROJECT_ID, REGION, CONSISTENCY_GROUP_NAME);
6970

7071
verify(mockClient, times(1)).insertAsync(any(InsertResourcePolicyRequest.class));
71-
verify(mockFuture, times(1)).get();
72+
verify(mockFuture, times(1)).get(anyLong(), any(TimeUnit.class));
7273
assertEquals(Operation.Status.DONE, status);
7374
}
7475
}
@@ -84,15 +85,15 @@ public void testAddRegionalDiskToConsistencyGroup() throws Exception {
8485
mockedRegionDisksClient.when(RegionDisksClient::create).thenReturn(mockClient);
8586
when(mockClient.addResourcePoliciesAsync(any(AddResourcePoliciesRegionDiskRequest.class)))
8687
.thenReturn(mockFuture);
87-
when(mockFuture.get()).thenReturn(operation);
88+
when(mockFuture.get(anyLong(), any(TimeUnit.class))).thenReturn(operation);
8889
when(operation.getStatus()).thenReturn(Operation.Status.DONE);
8990

9091
Operation.Status status = AddDiskToConsistencyGroup.addDiskToConsistencyGroup(
9192
PROJECT_ID, REGION, DISK_NAME, CONSISTENCY_GROUP_NAME, REGION);
9293

9394
verify(mockClient, times(1))
9495
.addResourcePoliciesAsync(any(AddResourcePoliciesRegionDiskRequest.class));
95-
verify(mockFuture, times(1)).get();
96+
verify(mockFuture, times(1)).get(anyLong(), any(TimeUnit.class));
9697
assertEquals(Operation.Status.DONE, status);
9798
}
9899
}
@@ -108,15 +109,15 @@ public void testRemoveDiskFromConsistencyGroup() throws Exception {
108109
mockedRegionDisksClient.when(RegionDisksClient::create).thenReturn(mockClient);
109110
when(mockClient.removeResourcePoliciesAsync(
110111
any(RemoveResourcePoliciesRegionDiskRequest.class))).thenReturn(mockFuture);
111-
when(mockFuture.get()).thenReturn(operation);
112+
when(mockFuture.get(anyLong(), any(TimeUnit.class))).thenReturn(operation);
112113
when(operation.getStatus()).thenReturn(Operation.Status.DONE);
113114

114115
Operation.Status status = RemoveDiskFromConsistencyGroup.removeDiskFromConsistencyGroup(
115116
PROJECT_ID, REGION, DISK_NAME, CONSISTENCY_GROUP_NAME, REGION);
116117

117118
verify(mockClient, times(1))
118119
.removeResourcePoliciesAsync(any(RemoveResourcePoliciesRegionDiskRequest.class));
119-
verify(mockFuture, times(1)).get();
120+
verify(mockFuture, times(1)).get(anyLong(), any(TimeUnit.class));
120121
assertEquals(Operation.Status.DONE, status);
121122
}
122123
}
@@ -132,15 +133,15 @@ public void testDeleteDiskConsistencyGroup() throws Exception {
132133
mockedResourcePoliciesClient.when(ResourcePoliciesClient::create).thenReturn(mockClient);
133134
when(mockClient.deleteAsync(PROJECT_ID, REGION, CONSISTENCY_GROUP_NAME))
134135
.thenReturn(mockFuture);
135-
when(mockFuture.get()).thenReturn(operation);
136+
when(mockFuture.get(anyLong(), any(TimeUnit.class))).thenReturn(operation);
136137
when(operation.getStatus()).thenReturn(Operation.Status.DONE);
137138

138139
Operation.Status status = DeleteDiskConsistencyGroup.deleteDiskConsistencyGroup(
139140
PROJECT_ID, REGION, CONSISTENCY_GROUP_NAME);
140141

141142
verify(mockClient, times(1))
142143
.deleteAsync(PROJECT_ID, REGION, CONSISTENCY_GROUP_NAME);
143-
verify(mockFuture, times(1)).get();
144+
verify(mockFuture, times(1)).get(anyLong(), any(TimeUnit.class));
144145
assertEquals(Operation.Status.DONE, status);
145146
}
146147
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static org.junit.Assert.assertEquals;
2020
import static org.mockito.ArgumentMatchers.any;
21+
import static org.mockito.ArgumentMatchers.anyLong;
2122
import static org.mockito.Mockito.mock;
2223
import static org.mockito.Mockito.mockStatic;
2324
import static org.mockito.Mockito.times;
@@ -76,7 +77,7 @@ public void testCreateHyperdiskStoragePool() throws Exception {
7677
mockedStoragePoolsClient.when(StoragePoolsClient::create).thenReturn(mockClient);
7778
when(mockClient.insertAsync(any(InsertStoragePoolRequest.class)))
7879
.thenReturn(mockFuture);
79-
when(mockFuture.get()).thenReturn(operation);
80+
when(mockFuture.get(anyLong(), any(TimeUnit.class))).thenReturn(operation);
8081
when(operation.getStatus()).thenReturn(Operation.Status.DONE);
8182
when(mockClient.get(PROJECT_ID, ZONE, STORAGE_POOL_NAME)).thenReturn(storagePool);
8283

@@ -87,7 +88,7 @@ public void testCreateHyperdiskStoragePool() throws Exception {
8788
PERFORMANCE_PROVISIONING_TYPE);
8889

8990
verify(mockClient, times(1)).insertAsync(any(InsertStoragePoolRequest.class));
90-
verify(mockFuture, times(1)).get();
91+
verify(mockFuture, times(1)).get(anyLong(), any(TimeUnit.class));
9192
assertEquals(storagePool, expectedStoragePool);
9293
}
9394
}
@@ -114,7 +115,7 @@ public void testCreateDiskInStoragePool() throws Exception {
114115

115116
mockedDisksClient.when(DisksClient::create).thenReturn(mockClient);
116117
when(mockClient.insertAsync(any(InsertDiskRequest.class))).thenReturn(mockFuture);
117-
when(mockFuture.get()).thenReturn(operation);
118+
when(mockFuture.get(anyLong(), any(TimeUnit.class))).thenReturn(operation);
118119
when(operation.getStatus()).thenReturn(Operation.Status.DONE);
119120
when(mockClient.get(PROJECT_ID, ZONE, HYPERDISK_IN_POOL_NAME)).thenReturn(expectedHyperdisk);
120121

@@ -124,7 +125,7 @@ public void testCreateDiskInStoragePool() throws Exception {
124125
diskType, 10, 3000, 140);
125126

126127
verify(mockClient, times(1)).insertAsync(any(InsertDiskRequest.class));
127-
verify(mockFuture, times(1)).get();
128+
verify(mockFuture, times(1)).get(anyLong(), any(TimeUnit.class));
128129
assertEquals(expectedHyperdisk, returnedDisk);
129130
}
130131
}

0 commit comments

Comments
 (0)