Copilot commented on code in PR #6355:
URL: https://github.com/apache/shenyu/pull/6355#discussion_r3354285671


##########
shenyu-admin/src/test/java/org/apache/shenyu/admin/service/UpstreamCheckServiceTest.java:
##########
@@ -214,17 +215,13 @@ private void testSubmitDeleted(final DivideUpstream 
divideUpstream) {
 
     @Test
     public void testReplace() {
-        ScheduledThreadPoolExecutor executor = new 
ScheduledThreadPoolExecutor(1, 
ShenyuThreadFactory.create("scheduled-upstream-task", false));
-        ReflectionTestUtils.setField(upstreamCheckService, "executor", 
executor);
         final DivideUpstream divideUpstream = DivideUpstream.builder()
                 .upstreamHost("localhost")
                 .build();
         final DivideUpstream divideUpstream2 = DivideUpstream.builder()
                 .upstreamHost("localhost2")
                 .build();
-        upstreamCheckService.submit(MOCK_SELECTOR_NAME_2, divideUpstream);
-        assertEquals(1, upstreamMap.get(MOCK_SELECTOR_NAME_2).size());
-        assertEquals("localhost", 
upstreamMap.get(MOCK_SELECTOR_NAME_2).get(0).getUpstreamHost());
+        upstreamMap.put(MOCK_SELECTOR_NAME_2, new 
CopyOnWriteArrayList<>(Collections.singletonList(divideUpstream)));
         upstreamCheckService.replace(MOCK_SELECTOR_NAME_2, 
Collections.singletonList(divideUpstream2));
         assertEquals(1, upstreamMap.get(MOCK_SELECTOR_NAME_2).size());
         assertEquals("localhost2", 
upstreamMap.get(MOCK_SELECTOR_NAME_2).get(0).getUpstreamHost());

Review Comment:
   `UPSTREAM_MAP` is a static shared cache (pulled via reflection in 
`setUp()`), so leaving entries behind can make this test order-dependent and 
harder to extend safely. Consider removing the selector key before setting up 
the initial state, and also pass a mutable list to `replace` (instead of 
`Collections.singletonList`) to avoid accidentally storing an immutable list in 
the shared map.



-- 
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]

Reply via email to