This is an automated email from the ASF dual-hosted git repository.

Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 32a1141d97 fix(admin): expose the instance record id in the instance 
API (#7731) (#7742)
32a1141d97 is described below

commit 32a1141d97d4978155f0a3563187c7565f3f0345
Author: konlue <[email protected]>
AuthorDate: Mon Oct 19 09:29:01 2026 +0800

    fix(admin): expose the instance record id in the instance API (#7731) 
(#7742)
---
 .../shenyu/admin/model/vo/InstanceInfoVO.java      | 23 ++++++
 .../service/impl/InstanceInfoServiceImpl.java      |  1 +
 .../admin/controller/InstanceControllerTest.java   | 13 +++-
 .../service/impl/InstanceInfoServiceImplTest.java  | 88 ++++++++++++++++++++++
 4 files changed, 122 insertions(+), 3 deletions(-)

diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/InstanceInfoVO.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/InstanceInfoVO.java
index 2eb204e235..18367d00c7 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/InstanceInfoVO.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/InstanceInfoVO.java
@@ -27,6 +27,11 @@ import java.util.Objects;
 public class InstanceInfoVO implements Serializable {
 
     private static final long serialVersionUID = -5798225577222473005L;
+
+    /**
+     * primary key.
+     */
+    private String id;
     
     /**
      * instance ip.
@@ -73,6 +78,24 @@ public class InstanceInfoVO implements Serializable {
      */
     private long lastHeartBeatTime;
     
+    /**
+     * get id.
+     *
+     * @return id
+     */
+    public String getId() {
+        return id;
+    }
+
+    /**
+     * set id.
+     *
+     * @param id id
+     */
+    public void setId(final String id) {
+        this.id = id;
+    }
+
     /**
      * get instanceIp.
      *
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/InstanceInfoServiceImpl.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/InstanceInfoServiceImpl.java
index 4a6ee389a6..c777e14cb7 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/InstanceInfoServiceImpl.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/InstanceInfoServiceImpl.java
@@ -107,6 +107,7 @@ public class InstanceInfoServiceImpl implements 
InstanceInfoService {
 
     private InstanceInfoVO buildInstanceInfoVO(final InstanceInfoDO 
instanceInfoDO) {
         InstanceInfoVO instanceInfoVO = new InstanceInfoVO();
+        instanceInfoVO.setId(instanceInfoDO.getId());
         instanceInfoVO.setInstanceIp(instanceInfoDO.getInstanceIp());
         instanceInfoVO.setInstancePort(instanceInfoDO.getInstancePort());
         instanceInfoVO.setInstanceType(instanceInfoDO.getInstanceType());
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/InstanceControllerTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/InstanceControllerTest.java
index f73df32148..9b052ec3c8 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/InstanceControllerTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/controller/InstanceControllerTest.java
@@ -77,9 +77,12 @@ public final class InstanceControllerTest {
 
     @Test
     public void testQueryPlugins() throws Exception {
-        PageParameter pageParameter = new PageParameter(1, 10);
+        final PageParameter pageParameter = new PageParameter(1, 10);
         List<InstanceInfoVO> vos = new ArrayList<>();
         vos.add(vo);
+        InstanceInfoVO second = buildVO();
+        second.setId("instance-2");
+        vos.add(second);
         CommonPager<InstanceInfoVO> pager = new CommonPager<>();
         pager.setPage(pageParameter);
         pager.setDataList(vos);
@@ -100,7 +103,9 @@ public final class InstanceControllerTest {
                         .param("pageSize", 
String.valueOf(pageParameter.getPageSize())))
                 .andExpect(status().isOk())
                 .andExpect(jsonPath("$.message", 
is(ShenyuResultMessage.QUERY_SUCCESS)))
-                .andExpect(jsonPath("$.data.dataList[0].instanceIp", 
is(vo.getInstanceIp())));
+                .andExpect(jsonPath("$.data.dataList[0].instanceIp", 
is(vo.getInstanceIp())))
+                .andExpect(jsonPath("$.data.dataList[0].id", is("instance-1")))
+                .andExpect(jsonPath("$.data.dataList[1].id", 
is("instance-2")));
     }
 
     @Test
@@ -109,7 +114,8 @@ public final class InstanceControllerTest {
         this.mockMvc.perform(MockMvcRequestBuilders.get("/instance/{id}", 
"123"))
                 .andExpect(status().isOk())
                 .andExpect(jsonPath("$.message", 
is(ShenyuResultMessage.DETAIL_SUCCESS)))
-                .andExpect(jsonPath("$.data.instanceIp", 
is(vo.getInstanceIp())));
+                .andExpect(jsonPath("$.data.instanceIp", 
is(vo.getInstanceIp())))
+                .andExpect(jsonPath("$.data.id", is("instance-1")));
     }
 
     @Test
@@ -131,6 +137,7 @@ public final class InstanceControllerTest {
 
     private InstanceInfoVO buildVO() {
         InstanceInfoVO v = new InstanceInfoVO();
+        v.setId("instance-1");
         v.setInstanceIp("127.0.0.1");
         v.setInstancePort("8080");
         v.setInstanceType("grpc");
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/impl/InstanceInfoServiceImplTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/impl/InstanceInfoServiceImplTest.java
new file mode 100644
index 0000000000..0a213be372
--- /dev/null
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/impl/InstanceInfoServiceImplTest.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.admin.service.impl;
+
+import org.apache.shenyu.admin.mapper.InstanceInfoMapper;
+import org.apache.shenyu.admin.model.entity.InstanceInfoDO;
+import org.apache.shenyu.admin.model.page.CommonPager;
+import org.apache.shenyu.admin.model.page.PageParameter;
+import org.apache.shenyu.admin.model.query.InstanceQuery;
+import org.apache.shenyu.admin.model.vo.InstanceInfoVO;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import java.util.Arrays;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.BDDMockito.given;
+
+/**
+ * Test case for {@link InstanceInfoServiceImpl}.
+ */
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+public final class InstanceInfoServiceImplTest {
+
+    @InjectMocks
+    private InstanceInfoServiceImpl instanceInfoService;
+
+    @Mock
+    private InstanceInfoMapper instanceInfoMapper;
+
+    @Test
+    public void testFindByIdExposesRecordId() {
+        
given(instanceInfoMapper.selectById("instance-1")).willReturn(buildDO("instance-1"));
+        InstanceInfoVO result = instanceInfoService.findById("instance-1");
+        assertNotNull(result);
+        assertEquals("instance-1", result.getId());
+    }
+
+    @Test
+    public void testListByPageExposesDistinctIds() {
+        given(instanceInfoMapper.selectByQuery(any(InstanceQuery.class)))
+                .willReturn(Arrays.asList(buildDO("instance-1"), 
buildDO("instance-2")));
+        CommonPager<InstanceInfoVO> pager = instanceInfoService.listByPage(
+                new InstanceQuery(new PageParameter(1, 10), "grpc", null, 
null, "ns"));
+        assertEquals(2, pager.getDataList().size());
+        InstanceInfoVO first = pager.getDataList().get(0);
+        InstanceInfoVO second = pager.getDataList().get(1);
+        assertEquals("instance-1", first.getId());
+        assertEquals("instance-2", second.getId());
+        assertNotEquals(first.getId(), second.getId());
+    }
+
+    private InstanceInfoDO buildDO(final String id) {
+        return InstanceInfoDO.builder()
+                .id(id)
+                .instanceIp("127.0.0.1")
+                .instancePort("8080")
+                .instanceType("grpc")
+                .instanceInfo("info")
+                .instanceState(1)
+                .namespaceId("ns")
+                .build();
+    }
+}

Reply via email to