You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by GitBox <gi...@apache.org> on 2021/07/31 13:46:25 UTC

[GitHub] [incubator-shenyu] dengliming commented on a change in pull request #1846: [ISSUE #1824] Improve test coverage of org.apache.shenyu.admin.service.*

dengliming commented on a change in pull request #1846:
URL: https://github.com/apache/incubator-shenyu/pull/1846#discussion_r680361587



##########
File path: shenyu-admin/src/test/java/org/apache/shenyu/admin/service/UpstreamCheckServiceTest.java
##########
@@ -66,15 +90,53 @@
 
     private Map<String, List<DivideUpstream>> upstreamMap;
 
+    private Set<ZombieUpstream> zombieSet;
+
     @Before
     public void setUp() {
         shenyuRegisterCenterConfig.setRegisterType("http");
+        Properties properties = new Properties();
+        properties.setProperty(Constants.IS_CHECKED, "true");
+        shenyuRegisterCenterConfig.setProps(properties);
 
         //get static variable reference by reflection
         upstreamMap = (Map<String, List<DivideUpstream>>) ReflectionTestUtils.getField(UpstreamCheckService.class, "UPSTREAM_MAP");
+        zombieSet = (Set<ZombieUpstream>) ReflectionTestUtils.getField(UpstreamCheckService.class, "ZOMBIE_SET");
+
+        //mock data
+        PluginDO pluginDO = PluginDO.builder()
+                .name(PluginEnum.DIVIDE.getName())
+                .id(MOCK_PLUGIN_ID)
+                .build();
+        SelectorDO selectorDOWithUrlError = SelectorDO.builder()
+                .pluginId(MOCK_PLUGIN_ID)
+                .name(MOCK_SELECTOR_NAME)
+                .handle("[{\"upstreamHost\":\"localhost\",\"protocol\":\"http://\",\"upstreamUrl\":\"divide-upstream-50\",\"weight\":50}]")
+                .build();
+        SelectorDO selectorDOWithUrlReachable = SelectorDO.builder()
+                .pluginId(MOCK_PLUGIN_ID)
+                .name(MOCK_SELECTOR_NAME_OTHER)
+                .handle("[{\"upstreamHost\":\"localhost\",\"protocol\":\"http://\",\"localhost\":\"divide-upstream-60\",\"weight\":60}]")
+                .build();
+
+        //stubbing
+        when(pluginMapper.selectByNames(anyList())).thenReturn(Lists.newArrayList(pluginDO));
+        when(pluginMapper.selectById(anyString())).thenReturn(pluginDO);
+        when(selectorMapper.findByPluginId(anyString())).thenReturn(Lists.newArrayList(selectorDOWithUrlError, selectorDOWithUrlReachable));
+        when(selectorMapper.updateSelective(any(SelectorDO.class))).thenReturn(1);
+        when(selectorMapper.selectByName(anyString())).then(invocationOnMock -> {
+            Object[] args = invocationOnMock.getArguments();
+            if (MOCK_SELECTOR_NAME.equals(args[0])) {
+                return selectorDOWithUrlError;
+            } else if (MOCK_SELECTOR_NAME_OTHER.equals(args[0])) {
+                return selectorDOWithUrlReachable;
+            }
+            return null;
+        });
+        when(selectorConditionMapper.selectByQuery(any(SelectorConditionQuery.class))).thenReturn(Collections.emptyList());
+        doNothing().when(eventPublisher).publishEvent(any(DataChangedEvent.class));

Review comment:
       These codes already removed by [https://github.com/apache/incubator-shenyu/pull/1843](https://github.com/apache/incubator-shenyu/pull/1843). Please check again. Thanks.




-- 
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-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org