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 989d5a0793 fix(admin): InstanceInfoServiceImpl.findById always returns 
null (#6908)
989d5a0793 is described below

commit 989d5a079371c9d466d97c377725a9cfc86b88c3
Author: 杨俊杰 <[email protected]>
AuthorDate: Fri Aug 14 13:19:20 2026 +0800

    fix(admin): InstanceInfoServiceImpl.findById always returns null (#6908)
    
    The method body was a `return null;` stub that never read from
    instanceInfoMapper. InstanceController.detailInstanceInfo passes the
    result straight through as the response payload, so GET /instance/{id}
    always answered with null data and the instance detail view was
    non-functional.
    
    Query instanceInfoMapper.selectById and map through the existing
    buildInstanceInfoVO helper, keeping null for a missing row so the
    controller contract is unchanged.
    
    Replace the existing testFindById, which asserted the stub behaviour,
    with a mapped-result case and a not-found case.
    
    Fixes #6618
    
    Co-authored-by: Cursor <[email protected]>
    Co-authored-by: Liming Deng <[email protected]>
---
 .../admin/service/impl/InstanceInfoServiceImpl.java     |  3 ++-
 .../shenyu/admin/service/InstanceInfoServiceTest.java   | 17 +++++++++++++++--
 2 files changed, 17 insertions(+), 3 deletions(-)

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 ea9cda2fa2..2cf0ffdb95 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
@@ -90,7 +90,8 @@ public class InstanceInfoServiceImpl implements 
InstanceInfoService {
 
     @Override
     public InstanceInfoVO findById(final String id) {
-        return null;
+        InstanceInfoDO instanceInfoDO = instanceInfoMapper.selectById(id);
+        return Objects.isNull(instanceInfoDO) ? null : 
this.buildInstanceInfoVO(instanceInfoDO);
     }
 
     private List<InstanceInfoVO> buildInstanceInfoVO(final 
List<InstanceInfoDO> instanceInfoDOList) {
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/InstanceInfoServiceTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/InstanceInfoServiceTest.java
index ab14251dcf..59ca4e3254 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/InstanceInfoServiceTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/InstanceInfoServiceTest.java
@@ -39,6 +39,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.hasSize;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
@@ -98,8 +99,20 @@ public final class InstanceInfoServiceTest {
 
     @Test
     void testFindById() {
-        // current implementation returns null
-        assertEquals(null, instanceInfoService.findById("any"));
+        InstanceInfoDO instanceInfoDO = buildDO();
+        when(instanceInfoMapper.selectById("id-1")).thenReturn(instanceInfoDO);
+        InstanceInfoVO instanceInfoVO = instanceInfoService.findById("id-1");
+        assertNotNull(instanceInfoVO);
+        assertEquals(instanceInfoDO.getInstanceIp(), 
instanceInfoVO.getInstanceIp());
+        assertEquals(instanceInfoDO.getInstancePort(), 
instanceInfoVO.getInstancePort());
+        assertEquals(instanceInfoDO.getInstanceType(), 
instanceInfoVO.getInstanceType());
+        assertEquals(instanceInfoDO.getNamespaceId(), 
instanceInfoVO.getNamespaceId());
+    }
+
+    @Test
+    void testFindByIdNotFound() {
+        when(instanceInfoMapper.selectById("not-exist")).thenReturn(null);
+        assertNull(instanceInfoService.findById("not-exist"));
     }
 
     private InstanceInfoVO buildVO() {

Reply via email to