This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new 8db3c04cf fix(instance): stop reporting unmeasured resource counts as
available (#6775)
8db3c04cf is described below
commit 8db3c04cf866bfea362d4c93883ecdddac9a73e8
Author: Apulupie <[email protected]>
AuthorDate: Fri Nov 27 12:48:33 2026 +0800
fix(instance): stop reporting unmeasured resource counts as available
(#6775)
---
.../rocketmq/studio/instance/InstanceVO.java | 10 +++++-
.../studio/instance/InstanceServiceTest.java | 41 ++++++++++++++++++++++
2 files changed, 50 insertions(+), 1 deletion(-)
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/instance/InstanceVO.java
b/server/src/main/java/org/apache/rocketmq/studio/instance/InstanceVO.java
index f38f83664..37ca62290 100644
--- a/server/src/main/java/org/apache/rocketmq/studio/instance/InstanceVO.java
+++ b/server/src/main/java/org/apache/rocketmq/studio/instance/InstanceVO.java
@@ -46,6 +46,14 @@ public class InstanceVO extends BaseEntity {
private String nameserverName;
private int topicCount;
private int consumerGroupCount;
+ /**
+ * Whether {@link #topicCount} and {@link #consumerGroupCount} were
measured for this value.
+ * Counts are not columns on the row: they are resolved per request, so
only the calls that
+ * actually resolve them ({@code listInstances}) can claim them.
Defaulting to {@code true} made
+ * every value that was never measured - the create and update responses,
say - report the
+ * read-back zeros as a measured fact, which the field's contract in
{@code docs/api-spec.md}
+ * forbids.
+ */
@Builder.Default
- private boolean resourceCountsAvailable = true;
+ private boolean resourceCountsAvailable = false;
}
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/instance/InstanceServiceTest.java
b/server/src/test/java/org/apache/rocketmq/studio/instance/InstanceServiceTest.java
index 053584d38..9561c0616 100644
---
a/server/src/test/java/org/apache/rocketmq/studio/instance/InstanceServiceTest.java
+++
b/server/src/test/java/org/apache/rocketmq/studio/instance/InstanceServiceTest.java
@@ -678,6 +678,47 @@ class InstanceServiceTest {
.hasMessage("InstanceVO endpoint must not exceed 512
characters");
}
+ @Test
+ void
updateInstanceShouldNotPresentUnmeasuredResourceCountsAsAvailableTest() {
+ InstanceVO existing =
InstanceVO.builder().name("inst-a").type(InstanceType.PROXY_CLUSTER)
+ .endpoint("namesrv:9876").build();
+ existing.setId(1L);
+ InstanceVO request =
InstanceVO.builder().endpoint("namesrv:9877").build();
+ request.setId(1L);
+
when(instanceRepository.findById(1L)).thenReturn(Optional.of(existing));
+
when(instanceRepository.save(any(InstanceVO.class))).thenAnswer(invocation ->
invocation.getArgument(0));
+
+ InstanceVO updated = instanceService.updateInstance(request);
+
+ // Counts are not columns on the row, so this response carries
whatever the read-back had and
+ // this call never measured them. docs/api-spec.md defines
resourceCountsAvailable as saying
+ // whether the two numbers can be trusted, so leaving it on the
default claimed a measurement
+ // that never happened.
+ assertThat(updated.isResourceCountsAvailable()).isFalse();
+ }
+
+ @Test
+ void
createInstanceShouldNotPresentUnmeasuredResourceCountsAsAvailableTest() {
+ InstanceVO input = InstanceVO.builder()
+ .name("new-instance")
+ .endpoint("10.0.1.1:8080")
+ .type(InstanceType.PROXY_CLUSTER)
+ .build();
+
when(instanceRepository.save(any(InstanceVO.class))).thenAnswer(invocation -> {
+ InstanceVO saved = invocation.getArgument(0);
+ if (saved.getId() == null) {
+ saved.setId(1L);
+ }
+ return saved;
+ });
+
+ InstanceVO created = instanceService.createInstance(input);
+
+ // Registering an instance does not count the resources of the cluster
it points at, so the
+ // response must not report "0 topics, 0 consumer groups" as a
measurement either.
+ assertThat(created.isResourceCountsAvailable()).isFalse();
+ }
+
@Test
void createInstanceShouldBoundTheEndpointByCodePointsTest() {
when(instanceRepository.save(any(InstanceVO.class))).thenAnswer(invocation ->
invocation.getArgument(0));