diff --git a/xds/src/main/java/io/grpc/xds/GoogleCloudToProdNameResolver.java b/xds/src/main/java/io/grpc/xds/GoogleCloudToProdNameResolver.java index 2845d0a00e8..3ec0434a22a 100644 --- a/xds/src/main/java/io/grpc/xds/GoogleCloudToProdNameResolver.java +++ b/xds/src/main/java/io/grpc/xds/GoogleCloudToProdNameResolver.java @@ -175,7 +175,7 @@ public void run() { private ImmutableMap generateBootstrap(String zone, boolean supportIpv6) { ImmutableMap.Builder nodeBuilder = ImmutableMap.builder(); - nodeBuilder.put("id", "C2P-" + rand.nextInt()); + nodeBuilder.put("id", "C2P-" + (rand.nextInt() & Integer.MAX_VALUE)); if (!zone.isEmpty()) { nodeBuilder.put("locality", ImmutableMap.of("zone", zone)); } diff --git a/xds/src/test/java/io/grpc/xds/GoogleCloudToProdNameResolverTest.java b/xds/src/test/java/io/grpc/xds/GoogleCloudToProdNameResolverTest.java index 58be7108405..7c777b84bf7 100644 --- a/xds/src/test/java/io/grpc/xds/GoogleCloudToProdNameResolverTest.java +++ b/xds/src/test/java/io/grpc/xds/GoogleCloudToProdNameResolverTest.java @@ -104,8 +104,7 @@ public void close(Executor instance) {} @Mock private NameResolver.Listener2 mockListener; - @Mock - private Random mockRandom; + private Random random = new Random(1); @Captor private ArgumentCaptor errorCaptor; private boolean originalIsOnGcp; @@ -114,7 +113,6 @@ public void close(Executor instance) {} @Before public void setUp() { - when(mockRandom.nextInt()).thenReturn(123456789); nsRegistry.register(new FakeNsProvider("dns")); nsRegistry.register(new FakeNsProvider("xds")); originalIsOnGcp = GoogleCloudToProdNameResolver.isOnGcp; @@ -146,7 +144,7 @@ public HttpURLConnection createConnection(String url) throws IOException { } }; resolver = new GoogleCloudToProdNameResolver( - TARGET_URI, args, fakeExecutorResource, mockRandom, fakeXdsClientPoolFactory, + TARGET_URI, args, fakeExecutorResource, random, fakeXdsClientPoolFactory, nsRegistry.asFactory()); resolver.setHttpConnectionProvider(httpConnections); } @@ -183,7 +181,7 @@ public void onGcpAndNoProvidedBootstrapDelegateToXds() { Map bootstrap = fakeXdsClientPoolFactory.bootstrapRef.get(); Map node = (Map) bootstrap.get("node"); assertThat(node).containsExactly( - "id", "C2P-123456789", + "id", "C2P-991614323", "locality", ImmutableMap.of("zone", ZONE), "metadata", ImmutableMap.of("TRAFFICDIRECTOR_DIRECTPATH_C2P_IPV6_CAPABLE", true)); Map server = Iterables.getOnlyElement(