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

lizhimins pushed a commit to branch rocketmq-studio
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git


The following commit(s) were added to refs/heads/rocketmq-studio by this push:
     new a88a71c8 fix(tencent): count consumer groups from API totals (#1594)
a88a71c8 is described below

commit a88a71c84dec9efc2cd8bf0779c09f28c319318f
Author: youngkermit8-coder <[email protected]>
AuthorDate: Thu Aug 13 19:38:41 2026 +0800

    fix(tencent): count consumer groups from API totals (#1594)
---
 .../provider/tencent/TencentInstanceProvider.java  | 17 ++++++-
 .../tencent/TencentInstanceProviderTest.java       | 52 ++++++++++++++++++++++
 2 files changed, 68 insertions(+), 1 deletion(-)

diff --git 
a/server/src/main/java/org/apache/rocketmq/studio/provider/tencent/TencentInstanceProvider.java
 
b/server/src/main/java/org/apache/rocketmq/studio/provider/tencent/TencentInstanceProvider.java
index f249d92d..6e38ce1a 100644
--- 
a/server/src/main/java/org/apache/rocketmq/studio/provider/tencent/TencentInstanceProvider.java
+++ 
b/server/src/main/java/org/apache/rocketmq/studio/provider/tencent/TencentInstanceProvider.java
@@ -148,7 +148,22 @@ public class TencentInstanceProvider implements 
InstanceProvider {
 
     @Override
     public int countGroups(String instanceId) {
-        return listConsumerGroups(instanceId, null, false).size();
+        Context context = resolve(instanceId);
+        DescribeConsumerGroupListRequest request = new 
DescribeConsumerGroupListRequest();
+        request.setInstanceId(context.cloudInstanceId());
+        request.setOffset(0L);
+        request.setLimit(1L);
+        DescribeConsumerGroupListResponse response = clientFactory.call(
+                context.credentialId(), context.regionId(), client -> 
client.DescribeConsumerGroupList(request));
+        Long totalCount = response == null ? null : response.getTotalCount();
+        if (totalCount == null) {
+            return 0;
+        }
+        if (totalCount < 0L || totalCount > Integer.MAX_VALUE) {
+            throw new BusinessException(502,
+                    "Tencent Cloud returned an invalid consumer group count: " 
+ totalCount);
+        }
+        return totalCount.intValue();
     }
 
     @Override
diff --git 
a/server/src/test/java/org/apache/rocketmq/studio/provider/tencent/TencentInstanceProviderTest.java
 
b/server/src/test/java/org/apache/rocketmq/studio/provider/tencent/TencentInstanceProviderTest.java
index f61d5d0e..f0459255 100644
--- 
a/server/src/test/java/org/apache/rocketmq/studio/provider/tencent/TencentInstanceProviderTest.java
+++ 
b/server/src/test/java/org/apache/rocketmq/studio/provider/tencent/TencentInstanceProviderTest.java
@@ -31,6 +31,7 @@ import 
com.tencentcloudapi.trocket.v20230308.models.DescribeMessageTraceResponse
 import com.tencentcloudapi.trocket.v20230308.models.MessageItem;
 import com.tencentcloudapi.trocket.v20230308.models.MessageTraceItem;
 import 
com.tencentcloudapi.trocket.v20230308.models.DescribeTopicListByGroupResponse;
+import 
com.tencentcloudapi.trocket.v20230308.models.DescribeConsumerGroupListRequest;
 import com.tencentcloudapi.trocket.v20230308.models.DescribeTopicListResponse;
 import com.tencentcloudapi.trocket.v20230308.models.DescribeTopicRequest;
 import com.tencentcloudapi.trocket.v20230308.models.DescribeTopicResponse;
@@ -148,6 +149,57 @@ class TencentInstanceProviderTest {
                         
.atZone(java.time.ZoneId.systemDefault()).toLocalDateTime());
     }
 
+    @Test
+    void countGroupsShouldUseTencentTotalCountTest() throws Exception {
+        DescribeConsumerGroupListResponse response = new 
DescribeConsumerGroupListResponse();
+        response.setTotalCount(37L);
+        when(client.DescribeConsumerGroupList(any())).thenReturn(response);
+
+        int count = provider.countGroups(STUDIO_INSTANCE_ID);
+
+        ArgumentCaptor<DescribeConsumerGroupListRequest> captor =
+                
ArgumentCaptor.forClass(DescribeConsumerGroupListRequest.class);
+        verify(client).DescribeConsumerGroupList(captor.capture());
+        
assertThat(captor.getValue().getInstanceId()).isEqualTo(CLOUD_INSTANCE_ID);
+        assertThat(captor.getValue().getOffset()).isZero();
+        assertThat(captor.getValue().getLimit()).isEqualTo(1L);
+        assertThat(count).isEqualTo(37);
+    }
+
+    @Test
+    void countGroupsShouldTreatMissingTotalCountAsZeroTest() throws Exception {
+        when(client.DescribeConsumerGroupList(any())).thenReturn(new 
DescribeConsumerGroupListResponse());
+
+        assertThat(provider.countGroups(STUDIO_INSTANCE_ID)).isZero();
+    }
+
+    @Test
+    void countGroupsShouldTreatNullResponseAsZeroTest() throws Exception {
+        when(client.DescribeConsumerGroupList(any())).thenReturn(null);
+
+        assertThat(provider.countGroups(STUDIO_INSTANCE_ID)).isZero();
+    }
+
+    @Test
+    void countGroupsShouldRejectCountsOutsideIntegerRangeTest() throws 
Exception {
+        DescribeConsumerGroupListResponse response = new 
DescribeConsumerGroupListResponse();
+        response.setTotalCount((long) Integer.MAX_VALUE + 1L);
+        when(client.DescribeConsumerGroupList(any())).thenReturn(response);
+
+        assertThatThrownBy(() -> provider.countGroups(STUDIO_INSTANCE_ID))
+                .hasMessage("Tencent Cloud returned an invalid consumer group 
count: 2147483648");
+    }
+
+    @Test
+    void countGroupsShouldRejectNegativeCountsTest() throws Exception {
+        DescribeConsumerGroupListResponse response = new 
DescribeConsumerGroupListResponse();
+        response.setTotalCount(-1L);
+        when(client.DescribeConsumerGroupList(any())).thenReturn(response);
+
+        assertThatThrownBy(() -> provider.countGroups(STUDIO_INSTANCE_ID))
+                .hasMessage("Tencent Cloud returned an invalid consumer group 
count: -1");
+    }
+
     @Test
     void createTopicShouldCallTencentOpenApiTest() throws Exception {
         when(client.CreateTopic(any())).thenReturn(null);

Reply via email to