Skip to content

Commit 376e76b

Browse files
xcsnx‘xcsnx’Aias00moremind
authored
[type:feat]fix upstreamCheck (#5742)
* fix * fix --------- Co-authored-by: ‘xcsnx’ <‘[email protected]’> Co-authored-by: aias00 <[email protected]> Co-authored-by: moremind <[email protected]>
1 parent 273ac4c commit 376e76b

File tree

6 files changed

+23
-11
lines changed

6 files changed

+23
-11
lines changed

shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/SelectorMapper.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ public interface SelectorMapper extends ExistProvider {
8686
*/
8787
List<SelectorDO> findByPluginIdsAndNamespaceId(@Param("list") List<String> pluginIds, String namespaceId);
8888

89+
/**
90+
* Find list by plugin id.
91+
*
92+
* @param pluginIds the plugin ids
93+
* @return the list
94+
*/
95+
List<SelectorDO> findByPluginIds(@Param("list") List<String> pluginIds);
96+
8997
/**
9098
* select list by name and namespaceId.
9199
*

shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ public int updateSelective(final SelectorDO selectorDO) {
272272
@Override
273273
@Transactional(rollbackFor = Exception.class)
274274
public int deleteByNamespaceId(final List<String> ids, final String namespaceId) {
275-
//todo:[Namespace] To be renovated
276275
final List<SelectorDO> selectors = selectorMapper.selectByIdSet(new TreeSet<>(ids));
277276
List<PluginDO> pluginDOS = pluginMapper.selectByIds(ListUtil.map(selectors, SelectorDO::getPluginId));
278277
unbindDiscovery(selectors, pluginDOS);

shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SyncDataServiceImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ public SyncDataServiceImpl(final AppAuthService appAuthService,
103103
this.discoveryService = discoveryService;
104104
}
105105

106-
//todo:[Namespace] Synchronize based on namespaceId
107106
@Override
108107
public boolean syncAll(final DataEventTypeEnum type) {
109108
appAuthService.syncData();

shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/UpstreamCheckService.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@
7676
import java.util.concurrent.TimeUnit;
7777
import java.util.stream.Collectors;
7878

79-
import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID;
80-
8179
/**
8280
* This is the upstream check service.
8381
*/
@@ -447,8 +445,7 @@ public void fetchUpstreamData() {
447445
}
448446
Map<String, String> pluginMap = pluginDOList.stream().filter(Objects::nonNull)
449447
.collect(Collectors.toMap(PluginDO::getId, PluginDO::getName, (value1, value2) -> value1));
450-
// todo:[To be refactored with namespace] Temporarily hardcode
451-
final List<SelectorDO> selectorDOList = selectorMapper.findByPluginIdsAndNamespaceId(new ArrayList<>(pluginMap.keySet()), SYS_DEFAULT_NAMESPACE_ID);
448+
final List<SelectorDO> selectorDOList = selectorMapper.findByPluginIds(new ArrayList<>(pluginMap.keySet()));
452449
long currentTimeMillis = System.currentTimeMillis();
453450
Optional.ofNullable(selectorDOList).orElseGet(ArrayList::new).stream()
454451
.filter(Objects::nonNull)

shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@
153153
AND namespace_id = #{namespaceId, jdbcType=VARCHAR}
154154
</select>
155155

156+
<select id="findByPluginIds" parameterType="java.util.List" resultMap="BaseResultMap">
157+
SELECT
158+
<include refid="Base_Column_List"/>
159+
FROM selector
160+
WHERE plugin_id IN
161+
<foreach item="id" collection="list" open="(" separator="," close=")">
162+
#{id, jdbcType=VARCHAR}
163+
</foreach>
164+
</select>
165+
156166
<select id="countByQuery" parameterType="org.apache.shenyu.admin.model.query.SelectorQuery"
157167
resultType="java.lang.Integer">
158168
SELECT COUNT(1)

shenyu-admin/src/test/java/org/apache/shenyu/admin/service/UpstreamCheckServiceTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,11 @@
6060
import java.util.Set;
6161
import java.util.concurrent.ScheduledThreadPoolExecutor;
6262

63-
import static org.hamcrest.Matchers.is;
6463
import static org.hamcrest.MatcherAssert.assertThat;
65-
import static org.junit.jupiter.api.Assertions.assertTrue;
66-
import static org.junit.jupiter.api.Assertions.assertFalse;
64+
import static org.hamcrest.Matchers.is;
6765
import static org.junit.jupiter.api.Assertions.assertEquals;
68-
import static org.mockito.ArgumentMatchers.any;
66+
import static org.junit.jupiter.api.Assertions.assertFalse;
67+
import static org.junit.jupiter.api.Assertions.assertTrue;
6968
import static org.mockito.ArgumentMatchers.anyList;
7069
import static org.mockito.ArgumentMatchers.anyString;
7170
import static org.mockito.Mockito.mockStatic;
@@ -258,7 +257,7 @@ public void testFetchUpstreamData() {
258257
.status(0)
259258
.build();
260259
when(pluginMapper.selectByNames(anyList())).thenReturn(Lists.newArrayList(pluginDO));
261-
when(selectorMapper.findByPluginIdsAndNamespaceId(anyList(), any())).thenReturn(Lists.newArrayList(selectorDOWithUrlError, selectorDOWithUrlReachable));
260+
when(selectorMapper.findByPluginIds(anyList())).thenReturn(Lists.newArrayList(selectorDOWithUrlError, selectorDOWithUrlReachable));
262261
when(discoveryUpstreamService.findBySelectorId(anyString())).thenReturn(Lists.newArrayList(discoveryUpstreamData));
263262
upstreamCheckService.fetchUpstreamData();
264263
assertTrue(upstreamMap.containsKey(MOCK_SELECTOR_NAME));

0 commit comments

Comments
 (0)