Skip to content

Commit 08ef8bf

Browse files
authored
chore: added UIID to prevent concurrency error (GoogleCloudPlatform#4127)
* chore: added UIID to prevent concurrency error * fixed lint * reverted registry ID * replaced with single UUID instead nested ones * replaced registry millis with UUID + millis * fixed erros
1 parent a287f8e commit 08ef8bf

File tree

1 file changed

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

1 file changed

+12
-8
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.io.PrintStream;
3333
import java.nio.charset.StandardCharsets;
3434
import java.util.List;
35+
import java.util.UUID;
3536
import org.eclipse.paho.client.mqttv3.MqttClient;
3637
import org.junit.After;
3738
import org.junit.Assert;
@@ -45,22 +46,25 @@
4546
@RunWith(JUnit4.class)
4647
@SuppressWarnings("checkstyle:abbreviationaswordinname")
4748
public class ManagerIT {
48-
private ByteArrayOutputStream bout;
49-
private PrintStream out;
50-
private DeviceRegistryExample app;
51-
5249
private static final String CLOUD_REGION = "us-central1";
5350
private static final String ES_PATH = "resources/ec_public.pem";
5451
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
55-
private static final String REGISTRY_ID = "java-reg-" + (System.currentTimeMillis() / 100L);
52+
private static final String REGISTRY_ID =
53+
"java-reg-"
54+
+ UUID.randomUUID().toString().substring(0, 10) + "-"
55+
+ (System.currentTimeMillis() / 100L);
5656
private static final String RSA_PATH = "resources/rsa_cert.pem";
5757
private static final String PKCS_PATH = "resources/rsa_private_pkcs8";
58-
private static final String TOPIC_ID = "java-pst-" + (System.currentTimeMillis() / 100L);
58+
private static final String TOPIC_ID =
59+
"java-pst-"
60+
+ UUID.randomUUID().toString().substring(0, 20);
5961
private static final String MEMBER = "group:dpebot@google.com";
6062
private static final String ROLE = "roles/viewer";
61-
6263
private static Topic topic;
6364
private static boolean hasCleared = false;
65+
private ByteArrayOutputStream bout;
66+
private PrintStream out;
67+
private DeviceRegistryExample app;
6468

6569
@Before
6670
public void setUp() throws Exception {
@@ -105,7 +109,7 @@ public void clearTestRegistries() throws Exception {
105109
if (registryId.startsWith("java-reg-")) {
106110
long currSecs = System.currentTimeMillis() / 1000L;
107111
long regSecs =
108-
Long.parseLong(registryId.substring("java-reg-".length(), registryId.length()));
112+
Long.parseLong(registryId.substring("java-reg-".length() + 11, registryId.length()));
109113
long diffSecs = currSecs - regSecs;
110114
if (diffSecs > (60 * 60 * 24 * 7 * 10)) { // tests from last week or older
111115
System.out.println("Remove Id: " + r.getId());

0 commit comments

Comments
 (0)