Copilot commented on code in PR #62993:
URL: https://github.com/apache/doris/pull/62993#discussion_r3178347524


##########
fe/fe-core/src/test/java/org/apache/doris/cloud/system/CloudSystemInfoServiceTest.java:
##########
@@ -973,6 +983,52 @@ public void 
testGetMinPipelineExecutorSizeWithConnectContext() {
         }
     }
 
+    @Test
+    public void testAddBackendsGenerateUniqueCloudUniqueIdPerBackend() throws 
Exception {
+        infoService = new CloudSystemInfoService();
+
+        CloudEnv cloudEnv = Mockito.mock(CloudEnv.class);
+        MetaServiceProxy metaServiceProxy = 
Mockito.mock(MetaServiceProxy.class);
+        AtomicReference<Cloud.AlterClusterRequest> addNodeRequestRef = new 
AtomicReference<>();
+
+        
Mockito.when(cloudEnv.getCloudInstanceId()).thenReturn("instance-test");
+
+        try (MockedStatic<Env> mockedEnv = Mockito.mockStatic(Env.class);
+                MockedStatic<MetaServiceProxy> mockedMetaServiceProxy = 
Mockito.mockStatic(MetaServiceProxy.class)) {
+            mockedEnv.when(Env::getCurrentEnv).thenReturn(cloudEnv);
+            
mockedMetaServiceProxy.when(MetaServiceProxy::getInstance).thenReturn(metaServiceProxy);
+
+            
Mockito.when(metaServiceProxy.alterCluster(Mockito.any())).thenAnswer(invocation
 -> {
+                Cloud.AlterClusterRequest request = invocation.getArgument(0);
+                if (request.getOp() == 
Cloud.AlterClusterRequest.Operation.ADD_NODE) {
+                    addNodeRequestRef.set(request);
+                }
+                return Cloud.AlterClusterResponse.newBuilder()
+                        .setStatus(Cloud.MetaServiceResponseStatus.newBuilder()
+                                .setCode(Cloud.MetaServiceCode.OK)
+                                .setMsg("OK"))
+                        .build();
+            });
+
+            Map<String, String> tagMap = Tag.DEFAULT_BACKEND_TAG.toMap();
+            tagMap.put(Tag.COMPUTE_GROUP_NAME, "test_compute_group");
+
+            List<HostInfo> hostInfos = new ArrayList<>();
+            hostInfos.add(new HostInfo("192.168.1.189", 9050));
+            hostInfos.add(new HostInfo("192.168.1.189", 9052));
+
+            infoService.addBackends(hostInfos, tagMap);
+        }
+
+        Cloud.AlterClusterRequest addNodeRequest = addNodeRequestRef.get();
+        Assert.assertNotNull(addNodeRequest);
+        Assert.assertEquals(2, addNodeRequest.getCluster().getNodesCount());
+
+        Set<String> cloudUniqueIds = new HashSet<>();
+        addNodeRequest.getCluster().getNodesList().forEach(node -> 
cloudUniqueIds.add(node.getCloudUniqueId()));
+        Assert.assertEquals(2, cloudUniqueIds.size());
+    }

Review Comment:
   This test validates cloudUniqueId uniqueness but depends on 
RandomIdentifierGenerator/SecureRandom in production code, making it 
nondeterministic (a rare collision would fail the test even if the logic is 
correct). Consider mocking RandomIdentifierGenerator.generateRandomIdentifier() 
to return a deterministic sequence (including the extra call used for 
computeGroupId) so the assertion is stable and only exercises the intended 
behavior change.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to