Skip to content

Commit 2d0fc31

Browse files
Fixed test
1 parent 996c3d9 commit 2d0fc31

File tree

2 files changed

+3
-26
lines changed

2 files changed

+3
-26
lines changed

tpu/src/main/java/tpu/CreateSpotTpuVm.java

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,12 @@
1717
package tpu;
1818

1919
//[START tpu_vm_create_spot]
20-
import com.google.api.gax.longrunning.OperationTimedPollAlgorithm;
21-
import com.google.api.gax.retrying.RetrySettings;
2220
import com.google.cloud.tpu.v2.CreateNodeRequest;
2321
import com.google.cloud.tpu.v2.Node;
2422
import com.google.cloud.tpu.v2.SchedulingConfig;
2523
import com.google.cloud.tpu.v2.TpuClient;
26-
import com.google.cloud.tpu.v2.TpuSettings;
2724
import java.io.IOException;
2825
import java.util.concurrent.ExecutionException;
29-
import org.threeten.bp.Duration;
3026

3127
public class CreateSpotTpuVm {
3228
public static void main(String[] args)
@@ -37,7 +33,7 @@ public static void main(String[] args)
3733
// The zone in which to create the TPU.
3834
// For more information about supported TPU types for specific zones,
3935
// see https://cloud.google.com/tpu/docs/regions-zones
40-
String zone = "europe-west4-a";
36+
String zone = "us-central1-f";
4137
// The name for your TPU.
4238
String nodeName = "YOUR_TPY_NAME";
4339
// The accelerator type that specifies the version and size of the Cloud TPU you want to create.
@@ -55,27 +51,9 @@ public static void main(String[] args)
5551
public static Node createSpotTpuVm(
5652
String projectId, String zone, String nodeName, String tpuType, String tpuSoftwareVersion)
5753
throws IOException, ExecutionException, InterruptedException {
58-
// With these settings the client library handles the Operation's polling mechanism
59-
// and prevent CancellationException error
60-
TpuSettings.Builder clientSettings =
61-
TpuSettings.newBuilder();
62-
clientSettings
63-
.createNodeOperationSettings()
64-
.setPollingAlgorithm(
65-
OperationTimedPollAlgorithm.create(
66-
RetrySettings.newBuilder()
67-
.setInitialRetryDelay(Duration.ofMillis(5000L))
68-
.setRetryDelayMultiplier(1.5)
69-
.setMaxRetryDelay(Duration.ofMillis(45000L))
70-
.setInitialRpcTimeout(Duration.ZERO)
71-
.setRpcTimeoutMultiplier(1.0)
72-
.setMaxRpcTimeout(Duration.ZERO)
73-
.setTotalTimeout(Duration.ofHours(24L))
74-
.build()));
75-
7654
// Initialize client that will be used to send requests. This client only needs to be created
7755
// once, and can be reused for multiple requests.
78-
try (TpuClient tpuClient = TpuClient.create(clientSettings.build())) {
56+
try (TpuClient tpuClient = TpuClient.create()) {
7957
String parent = String.format("projects/%s/locations/%s", projectId, zone);
8058
// TODO: Wait for update of library to change preemptible to spot=True
8159
SchedulingConfig schedulingConfig = SchedulingConfig.newBuilder()

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ public void testCreateSpotTpuVm() throws Exception {
148148
TpuClient mockTpuClient = mock(TpuClient.class);
149149
OperationFuture mockFuture = mock(OperationFuture.class);
150150

151-
mockedTpuClient.when(() -> TpuClient.create(any(TpuSettings.class)))
152-
.thenReturn(mockTpuClient);
151+
mockedTpuClient.when(TpuClient::create).thenReturn(mockTpuClient);
153152
when(mockTpuClient.createNodeAsync(any(CreateNodeRequest.class)))
154153
.thenReturn(mockFuture);
155154
when(mockFuture.get()).thenReturn(mockNode);

0 commit comments

Comments
 (0)