Copilot commented on code in PR #7265: URL: https://github.com/apache/incubator-seata/pull/7265#discussion_r2036651670
########## discovery/seata-discovery-raft/src/test/java/org/apache/seata/discovery/registry/raft/RaftRegistryServiceImplTest.java: ########## @@ -175,4 +180,54 @@ public void testSelectEndpoint() throws JsonProcessingException, NoSuchMethodExc Assertions.assertTrue(transactionEndpointStr.contains("10.10.105.7:3009")); } } + + @Test + public void testSelectExternalEndpoint_NoMatch() throws Exception { + // Create a node with metadata including external endpoints that don't match preferred networks + Map<String, Object> metadata = new HashMap<>(); + List<LinkedHashMap<String, Object>> externalList = new ArrayList<>(); + + LinkedHashMap<String, Object> external1 = new LinkedHashMap<>(); + external1.put("host", "192.168.1.1"); + external1.put("controlPort", 7091); + external1.put("transactionPort", 8091); + externalList.add(external1); + + LinkedHashMap<String, Object> external2 = new LinkedHashMap<>(); + external2.put("host", "172.16.1.1"); // Doesn't match preferred network + external2.put("controlPort", 7092); + external2.put("transactionPort", 8092); + externalList.add(external2); + + metadata.put("external", externalList); + + Node node = new Node(); + node.setMetadata(metadata); + + // Access private selectExternalEndpoint method via reflection + Method selectExternalEndpointMethod = RaftRegistryServiceImpl.class.getDeclaredMethod( + "selectExternalEndpoint", Node.class, String[].class); + selectExternalEndpointMethod.setAccessible(true); + + // When selecting external endpoint, expect exception + Exception exception = assertThrows(Exception.class, () -> { + selectExternalEndpointMethod.invoke( + null, node, new String[]{"10.10.*"}); + }); + + // Then should receive ParseEndpointException + assertTrue(exception.getCause() instanceof ParseEndpointException); Review Comment: Using assertThrows(Exception.class, ...) is too generic; consider catching the more specific InvocationTargetException and then asserting that its cause is an instance of ParseEndpointException. ```suggestion try { selectExternalEndpointMethod.invoke( null, node, new String[]{"10.10.*"}); fail("Expected InvocationTargetException to be thrown"); } catch (InvocationTargetException e) { // Then should receive ParseEndpointException assertTrue(e.getCause() instanceof ParseEndpointException); } ``` -- 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: notifications-unsubscr...@seata.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For additional commands, e-mail: notifications-h...@seata.apache.org