Skip to content

Commit 6956852

Browse files
Fixed naming
1 parent d832b31 commit 6956852

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

tpu/src/main/java/tpu/GetTpuVm.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,15 @@ public static void main(String[] args) throws IOException {
4343
// Describes a TPU VM with the specified name in the given project and zone.
4444
public static Node getTpuVm(String projectId, String zone, String nodeName)
4545
throws IOException {
46-
Node node;
4746
// Initialize client that will be used to send requests. This client only needs to be created
4847
// once, and can be reused for multiple requests.
4948
try (TpuClient tpuClient = TpuClient.create()) {
5049
String name = NodeName.of(projectId, zone, nodeName).toString();
5150

5251
GetNodeRequest request = GetNodeRequest.newBuilder().setName(name).build();
53-
node = tpuClient.getNode(request);
52+
53+
return tpuClient.getNode(request);
5454
}
55-
return node;
5655
}
5756
}
5857
//[END tpu_vm_get]

tpu/src/main/java/tpu/ListTpuVms.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,14 @@ public static void main(String[] args) throws IOException {
4040
// Lists TPU VMs in the specified zone.
4141
public static ListNodesPagedResponse listTpuVms(String projectId, String zone)
4242
throws IOException {
43-
ListNodesPagedResponse response;
4443
// Initialize client that will be used to send requests. This client only needs to be created
4544
// once, and can be reused for multiple requests.
4645
try (TpuClient tpuClient = TpuClient.create()) {
4746
String parent = String.format("projects/%s/locations/%s", projectId, zone);
4847

4948
ListNodesRequest request = ListNodesRequest.newBuilder().setParent(parent).build();
50-
response = tpuClient.listNodes(request);
49+
return tpuClient.listNodes(request);
5150
}
52-
return response;
5351
}
5452
}
5553
//[END tpu_vm_list]

tpu/src/test/java/tpu/TpuVmIT.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ public class TpuVmIT {
5050
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
5151
private static final String ZONE = "europe-west4-a";
5252
static String javaVersion = System.getProperty("java.version").substring(0, 2);
53-
private static final String TPU_VM_NAME = "test-tpu-" + javaVersion + "-"
53+
private static final String NODE_NAME = "test-tpu-" + javaVersion + "-"
5454
+ UUID.randomUUID().toString().substring(0, 8);
55-
private static final String ACCELERATOR_TYPE = "v2-8";
56-
private static final String VERSION = "tpu-vm-tf-2.14.1";
57-
private static final String TPU_VM_PATH_NAME =
58-
String.format("projects/%s/locations/%s/nodes/%s", PROJECT_ID, ZONE, TPU_VM_NAME);
55+
private static final String TPU_TYPE = "v2-8";
56+
private static final String TPU_SOFTWARE_VERSION = "tpu-vm-tf-2.14.1";
57+
private static final String NODE_PATH_NAME =
58+
String.format("projects/%s/locations/%s/nodes/%s", PROJECT_ID, ZONE, NODE_NAME);
5959

6060
public static void requireEnvVar(String envVarName) {
6161
assertWithMessage(String.format("Missing environment variable '%s' ", envVarName))
@@ -74,12 +74,12 @@ public static void setUp()
7474

7575
@AfterAll
7676
public static void cleanup() throws Exception {
77-
DeleteTpuVm.deleteTpuVm(PROJECT_ID, ZONE, TPU_VM_NAME);
77+
DeleteTpuVm.deleteTpuVm(PROJECT_ID, ZONE, NODE_NAME);
7878

7979
// Test that TPUs is deleted
8080
Assertions.assertThrows(
8181
NotFoundException.class,
82-
() -> GetTpuVm.getTpuVm(PROJECT_ID, ZONE, TPU_VM_NAME));
82+
() -> GetTpuVm.getTpuVm(PROJECT_ID, ZONE, NODE_NAME));
8383
}
8484

8585
@Test
@@ -88,20 +88,20 @@ public void testCreateTpuVm() throws IOException, ExecutionException, Interrupte
8888
final PrintStream out = System.out;
8989
ByteArrayOutputStream stdOut = new ByteArrayOutputStream();
9090
System.setOut(new PrintStream(stdOut));
91-
CreateTpuVm.createTpuVm(PROJECT_ID, ZONE, TPU_VM_NAME, ACCELERATOR_TYPE, VERSION);
91+
CreateTpuVm.createTpuVm(PROJECT_ID, ZONE, NODE_NAME, TPU_TYPE , TPU_SOFTWARE_VERSION);
9292

93-
assertThat(stdOut.toString()).contains("TPU VM created: " + TPU_VM_PATH_NAME);
93+
assertThat(stdOut.toString()).contains("TPU VM created: " + NODE_PATH_NAME);
9494
stdOut.close();
9595
System.setOut(out);
9696
}
9797

9898
@Test
9999
@Order(2)
100100
public void testGetTpuVm() throws IOException {
101-
Node node = GetTpuVm.getTpuVm(PROJECT_ID, ZONE, TPU_VM_NAME);
101+
Node node = GetTpuVm.getTpuVm(PROJECT_ID, ZONE, NODE_NAME);
102102

103103
assertNotNull(node);
104-
assertThat(node.getName()).isEqualTo(TPU_VM_PATH_NAME);
104+
assertThat(node.getName()).isEqualTo(NODE_PATH_NAME);
105105
}
106106

107107
@Test
@@ -118,17 +118,17 @@ public void testListTpuVm() throws IOException {
118118
@Test
119119
@Order(2)
120120
public void testStopTpuVm() throws IOException, ExecutionException, InterruptedException {
121-
StopTpuVm.stopTpuVm(PROJECT_ID, ZONE, TPU_VM_NAME);
122-
Node node = GetTpuVm.getTpuVm(PROJECT_ID, ZONE, TPU_VM_NAME);
121+
StopTpuVm.stopTpuVm(PROJECT_ID, ZONE, NODE_NAME);
122+
Node node = GetTpuVm.getTpuVm(PROJECT_ID, ZONE, NODE_NAME);
123123

124124
assertThat(node.getState()).isEqualTo(STOPPED);
125125
}
126126

127127
@Test
128128
@Order(3)
129129
public void testStartTpuVm() throws IOException, ExecutionException, InterruptedException {
130-
StartTpuVm.startTpuVm(PROJECT_ID, ZONE, TPU_VM_NAME);
131-
Node node = GetTpuVm.getTpuVm(PROJECT_ID, ZONE, TPU_VM_NAME);
130+
StartTpuVm.startTpuVm(PROJECT_ID, ZONE, NODE_NAME);
131+
Node node = GetTpuVm.getTpuVm(PROJECT_ID, ZONE, NODE_NAME);
132132

133133
assertThat(node.getState()).isEqualTo(READY);
134134
}

0 commit comments

Comments
 (0)