Skip to content

Commit 33c1426

Browse files
authored
Clear current registry between tests. (GoogleCloudPlatform#2852)
* Clear current registry between tests. * Corrects naming on registry ID
1 parent 934fdd9 commit 33c1426

File tree

1 file changed

+11
-1
lines changed
  • iot/api-client/manager/src/test/java/com/example/cloud/iot/examples

1 file changed

+11
-1
lines changed

iot/api-client/manager/src/test/java/com/example/cloud/iot/examples/ManagerIT.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class ManagerIT {
5555
private static final String CLOUD_REGION = "us-central1";
5656
private static final String ES_PATH = "resources/ec_public.pem";
5757
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
58-
private static final String REGISTRY_ID = "java-reg" + (System.currentTimeMillis() / 100L);
58+
private static final String REGISTRY_ID = "java-reg-" + (System.currentTimeMillis() / 100L);
5959
private static final String RSA_PATH = "resources/rsa_cert.pem";
6060
private static final String PKCS_PATH = "resources/rsa_private_pkcs8";
6161
private static final String TOPIC_ID = "java-pst-" + (System.currentTimeMillis() / 100L);
@@ -115,6 +115,16 @@ public void clearTestRegistries() throws Exception {
115115
DeviceRegistryExample.clearRegistry(CLOUD_REGION, PROJECT_ID, registryId);
116116
}
117117
}
118+
// Also remove the current test registry
119+
try {
120+
DeviceRegistryExample.clearRegistry(CLOUD_REGION, PROJECT_ID, REGISTRY_ID);
121+
} catch (com.google.api.client.googleapis.json.GoogleJsonResponseException gjre) {
122+
if (gjre.getStatusCode() == 404) {
123+
// Expected, the registry resource is available for creation.
124+
} else {
125+
throw gjre;
126+
}
127+
}
118128
}
119129
} else {
120130
System.out.println("Project has no registries.");

0 commit comments

Comments
 (0)