|
17 | 17 | package tpu; |
18 | 18 |
|
19 | 19 | import static com.google.common.truth.Truth.assertThat; |
| 20 | +import static com.google.common.truth.Truth.assertWithMessage; |
20 | 21 |
|
21 | | -import com.google.api.gax.rpc.NotFoundException; |
22 | 22 | import com.google.cloud.tpu.v2alpha1.QueuedResource; |
23 | | -import java.io.IOException; |
24 | 23 | import java.util.UUID; |
25 | 24 | import java.util.concurrent.TimeUnit; |
26 | 25 | import org.junit.Test; |
27 | 26 | import org.junit.jupiter.api.AfterAll; |
28 | | -import org.junit.jupiter.api.Assertions; |
29 | 27 | import org.junit.jupiter.api.BeforeAll; |
30 | 28 | import org.junit.jupiter.api.Timeout; |
31 | 29 | import org.junit.runner.RunWith; |
32 | 30 | import org.junit.runners.JUnit4; |
33 | 31 |
|
34 | 32 | @RunWith(JUnit4.class) |
35 | 33 | @Timeout(value = 6, unit = TimeUnit.MINUTES) |
36 | | -public class CreateQueuedResourceWithNetworkIT { |
| 34 | +public class QueuedResourceIT { |
37 | 35 |
|
38 | 36 | private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); |
39 | 37 | private static final String ZONE = "europe-west4-a"; |
40 | | - static String javaVersion = System.getProperty("java.version").substring(0, 2); |
41 | | - private static final String NODE_NAME = "test-tpu-queued-resource-network-" + javaVersion + "-" |
42 | | - + UUID.randomUUID().toString().substring(0, 8); |
| 38 | + private static final String NODE_NAME = "test-tpu-queued-resource-network-" + UUID.randomUUID(); |
43 | 39 | private static final String TPU_TYPE = "v2-8"; |
44 | 40 | private static final String TPU_SOFTWARE_VERSION = "tpu-vm-tf-2.14.1"; |
45 | | - private static final String QUEUED_RESOURCE_NAME = "queued-resource-network-" + javaVersion + "-" |
46 | | - + UUID.randomUUID().toString().substring(0, 8); |
| 41 | + private static final String QUEUED_RESOURCE_NAME = "queued-resource-network-" + UUID.randomUUID(); |
47 | 42 | private static final String NETWORK_NAME = "default"; |
48 | 43 |
|
49 | | - @BeforeAll |
50 | | - public static void setUp() throws IOException { |
| 44 | + public static void requireEnvVar(String envVarName) { |
| 45 | + assertWithMessage(String.format("Missing environment variable '%s' ", envVarName)) |
| 46 | + .that(System.getenv(envVarName)).isNotEmpty(); |
| 47 | + } |
51 | 48 |
|
52 | | - // Cleanup existing stale resources. |
53 | | - Util.cleanUpExistingQueuedResources("queued-resource-network-", PROJECT_ID, ZONE); |
| 49 | + @BeforeAll |
| 50 | + public static void setUp() { |
| 51 | + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); |
| 52 | + requireEnvVar("GOOGLE_CLOUD_PROJECT"); |
54 | 53 | } |
55 | 54 |
|
56 | 55 | @AfterAll |
57 | 56 | public static void cleanup() { |
58 | 57 | DeleteForceQueuedResource.deleteForceQueuedResource(PROJECT_ID, ZONE, QUEUED_RESOURCE_NAME); |
59 | | - |
60 | | - // Test that resource is deleted |
61 | | - Assertions.assertThrows( |
62 | | - NotFoundException.class, |
63 | | - () -> GetQueuedResource.getQueuedResource(PROJECT_ID, ZONE, QUEUED_RESOURCE_NAME)); |
64 | 58 | } |
65 | 59 |
|
66 | 60 | @Test |
67 | 61 | public void testCreateQueuedResourceWithSpecifiedNetwork() throws Exception { |
68 | | - |
69 | 62 | QueuedResource queuedResource = CreateQueuedResourceWithNetwork.createQueuedResourceWithNetwork( |
70 | 63 | PROJECT_ID, ZONE, QUEUED_RESOURCE_NAME, NODE_NAME, |
71 | 64 | TPU_TYPE, TPU_SOFTWARE_VERSION, NETWORK_NAME); |
|
0 commit comments