Copilot commented on code in PR #6355:
URL: https://github.com/apache/shenyu/pull/6355#discussion_r3355747764
##########
shenyu-admin/src/test/java/org/apache/shenyu/admin/service/UpstreamCheckServiceTest.java:
##########
@@ -214,18 +215,15 @@ 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());
- upstreamCheckService.replace(MOCK_SELECTOR_NAME_2,
Collections.singletonList(divideUpstream2));
+ upstreamMap.remove(MOCK_SELECTOR_NAME_2);
+ upstreamMap.put(MOCK_SELECTOR_NAME_2, new
CopyOnWriteArrayList<>(Collections.singletonList(divideUpstream)));
+ upstreamCheckService.replace(MOCK_SELECTOR_NAME_2, new
CopyOnWriteArrayList<>(Collections.singletonList(divideUpstream2)));
Review Comment:
testReplace directly mutates the internal static UPSTREAM_MAP (via
upstreamMap) to set up the precondition. Since the purpose here is to verify
replace() behavior, the setup can be done via the public API
(removeByKey/replace) to avoid coupling the test to the implementation detail
that UPSTREAM_MAP is exposed via reflection.
--
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]