Skip to content

Commit e243370

Browse files
fix(compute): bug fixes HyperdisksIT test (#9480)
* Splited HyperdisksIT test for solving PoolProvisionedIops issue, fixed naming * Deleted redundant asserts * Created additional zone to fix the issue * Fixed indentation * added comment
1 parent 140f01e commit e243370

File tree

1 file changed

+42
-38
lines changed

1 file changed

+42
-38
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/*
2-
* Copyright 2024 Google LLC
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
1616

1717
package compute.disks;
1818

@@ -41,17 +41,20 @@
4141
@RunWith(JUnit4.class)
4242
@Timeout(value = 40, unit = TimeUnit.MINUTES)
4343
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
44-
public class HypedisksIT {
44+
public class HyperdisksIT {
4545
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
46-
private static final String ZONE = "europe-west1-b";
46+
// Zone in which the hyperdisk will be created.
47+
private static final String ZONE_1 = "europe-west1-b";
48+
// Zone in which the storage pool will be created.
49+
private static final String ZONE_2 = "us-central1-a";
4750
private static String HYPERDISK_NAME;
4851
private static String HYPERDISK_IN_POOL_NAME;
4952
private static String STORAGE_POOL_NAME;
5053

5154
// Check if the required environment variables are set.
5255
public static void requireEnvVar(String envVarName) {
5356
assertWithMessage(String.format("Missing environment variable '%s' ", envVarName))
54-
.that(System.getenv(envVarName)).isNotEmpty();
57+
.that(System.getenv(envVarName)).isNotEmpty();
5558
}
5659

5760
@BeforeAll
@@ -66,62 +69,63 @@ public static void setUp() {
6669

6770
@AfterAll
6871
public static void cleanup()
69-
throws IOException, InterruptedException, ExecutionException, TimeoutException {
72+
throws IOException, InterruptedException, ExecutionException, TimeoutException {
7073
// Delete all disks created for testing.
71-
DeleteDisk.deleteDisk(PROJECT_ID, ZONE, HYPERDISK_NAME);
72-
DeleteDisk.deleteDisk(PROJECT_ID, ZONE, HYPERDISK_IN_POOL_NAME);
74+
DeleteDisk.deleteDisk(PROJECT_ID, ZONE_1, HYPERDISK_NAME);
75+
DeleteDisk.deleteDisk(PROJECT_ID, ZONE_2, HYPERDISK_IN_POOL_NAME);
7376

7477
try (StoragePoolsClient client = StoragePoolsClient.create()) {
75-
client.deleteAsync(PROJECT_ID, ZONE, STORAGE_POOL_NAME);
78+
client.deleteAsync(PROJECT_ID, ZONE_2, STORAGE_POOL_NAME);
7679
}
7780
}
7881

7982
@Test
8083
public void stage1_CreateHyperdiskTest()
81-
throws IOException, ExecutionException, InterruptedException, TimeoutException {
82-
String diskType = String.format("zones/%s/diskTypes/hyperdisk-balanced", ZONE);
84+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
85+
String diskType = String.format("zones/%s/diskTypes/hyperdisk-balanced", ZONE_1);
8386

8487
Disk hyperdisk = CreateHyperdisk
85-
.createHyperdisk(PROJECT_ID, ZONE, HYPERDISK_NAME, diskType, 10, 3000, 140);
88+
.createHyperdisk(PROJECT_ID, ZONE_1, HYPERDISK_NAME, diskType,
89+
10, 3000, 140);
8690

8791
Assert.assertNotNull(hyperdisk);
8892
Assert.assertEquals(HYPERDISK_NAME, hyperdisk.getName());
8993
Assert.assertEquals(3000, hyperdisk.getProvisionedIops());
9094
Assert.assertEquals(140, hyperdisk.getProvisionedThroughput());
9195
Assert.assertEquals(10, hyperdisk.getSizeGb());
9296
Assert.assertTrue(hyperdisk.getType().contains("hyperdisk-balanced"));
93-
Assert.assertTrue(hyperdisk.getZone().contains(ZONE));
97+
Assert.assertTrue(hyperdisk.getZone().contains(ZONE_1));
9498
}
9599

96100
@Test
97101
public void stage1_CreateHyperdiskStoragePoolTest()
98-
throws IOException, ExecutionException, InterruptedException, TimeoutException {
102+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
99103
String poolType = String.format("projects/%s/zones/%s/storagePoolTypes/hyperdisk-balanced",
100-
PROJECT_ID, ZONE);
104+
PROJECT_ID, ZONE_2);
101105
StoragePool storagePool = CreateHyperdiskStoragePool
102-
.createHyperdiskStoragePool(PROJECT_ID, ZONE, STORAGE_POOL_NAME, poolType,
103-
"advanced", 10240, 20000, 10240);
106+
.createHyperdiskStoragePool(PROJECT_ID, ZONE_2, STORAGE_POOL_NAME, poolType,
107+
"advanced", 10240, 10000, 10240);
104108

105109
Assert.assertNotNull(storagePool);
106110
Assert.assertEquals(STORAGE_POOL_NAME, storagePool.getName());
107-
Assert.assertEquals(20000, storagePool.getPoolProvisionedIops());
111+
Assert.assertEquals(10000, storagePool.getPoolProvisionedIops());
108112
Assert.assertEquals(10240, storagePool.getPoolProvisionedThroughput());
109113
Assert.assertEquals(10240, storagePool.getPoolProvisionedCapacityGb());
110114
Assert.assertTrue(storagePool.getStoragePoolType().contains("hyperdisk-balanced"));
111115
Assert.assertTrue(storagePool.getCapacityProvisioningType().equalsIgnoreCase("advanced"));
112-
Assert.assertTrue(storagePool.getZone().contains(ZONE));
116+
Assert.assertTrue(storagePool.getZone().contains(ZONE_2));
113117
}
114118

115119
@Test
116120
public void stage2_CreateHyperdiskStoragePoolTest()
117-
throws IOException, ExecutionException, InterruptedException, TimeoutException {
118-
String diskType = String.format("zones/%s/diskTypes/hyperdisk-balanced", ZONE);
121+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
122+
String diskType = String.format("zones/%s/diskTypes/hyperdisk-balanced", ZONE_2);
119123
String storagePoolLink = String
120-
.format("https://www.googleapis.com/compute/v1/projects/%s/zones/%s/storagePools/%s",
121-
PROJECT_ID, ZONE, STORAGE_POOL_NAME);
124+
.format("https://www.googleapis.com/compute/v1/projects/%s/zones/%s/storagePools/%s",
125+
PROJECT_ID, ZONE_2, STORAGE_POOL_NAME);
122126
Disk disk = CreateDiskInStoragePool
123-
.createDiskInStoragePool(PROJECT_ID, ZONE, HYPERDISK_IN_POOL_NAME, storagePoolLink,
124-
diskType, 10, 3000, 140);
127+
.createDiskInStoragePool(PROJECT_ID, ZONE_2, HYPERDISK_IN_POOL_NAME, storagePoolLink,
128+
diskType, 10, 3000, 140);
125129

126130
Assert.assertNotNull(disk);
127131
Assert.assertEquals(HYPERDISK_IN_POOL_NAME, disk.getName());
@@ -130,6 +134,6 @@ public void stage2_CreateHyperdiskStoragePoolTest()
130134
Assert.assertEquals(140, disk.getProvisionedThroughput());
131135
Assert.assertEquals(10, disk.getSizeGb());
132136
Assert.assertTrue(disk.getType().contains("hyperdisk-balanced"));
133-
Assert.assertTrue(disk.getZone().contains(ZONE));
137+
Assert.assertTrue(disk.getZone().contains(ZONE_2));
134138
}
135139
}

0 commit comments

Comments
 (0)