From 565035da136a6716945d4ea6894757016004b289 Mon Sep 17 00:00:00 2001 From: liuhy Date: Sat, 25 Jul 2026 17:30:00 -0700 Subject: [PATCH] [Studio] Preserve cluster id in provider stub --- .../cluster/broker/ClusterProviderStub.java | 10 ++-- .../broker/ClusterProviderStubTest.java | 48 +++++++++++++++++++ 2 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 server/src/test/java/com/rocketmq/studio/cluster/broker/ClusterProviderStubTest.java diff --git a/server/src/main/java/com/rocketmq/studio/cluster/broker/ClusterProviderStub.java b/server/src/main/java/com/rocketmq/studio/cluster/broker/ClusterProviderStub.java index e5988fe8..efbd56bf 100644 --- a/server/src/main/java/com/rocketmq/studio/cluster/broker/ClusterProviderStub.java +++ b/server/src/main/java/com/rocketmq/studio/cluster/broker/ClusterProviderStub.java @@ -30,16 +30,16 @@ public class ClusterProviderStub implements ClusterProvider { @Override public List discoverClusters() { - return List.of(buildSampleCluster()); + return List.of(buildSampleCluster("cluster-001")); } @Override public ClusterVO refreshClusterDetail(String clusterId) { - return buildSampleCluster(); + return buildSampleCluster(clusterId); } - private ClusterVO buildSampleCluster() { - return ClusterVO.builder() + private ClusterVO buildSampleCluster(String clusterId) { + ClusterVO cluster = ClusterVO.builder() .name("rmq-cluster-01") .brokers(List.of( BrokerVO.builder() @@ -81,5 +81,7 @@ private ClusterVO buildSampleCluster() { .build() )) .build(); + cluster.setId(clusterId); + return cluster; } } diff --git a/server/src/test/java/com/rocketmq/studio/cluster/broker/ClusterProviderStubTest.java b/server/src/test/java/com/rocketmq/studio/cluster/broker/ClusterProviderStubTest.java new file mode 100644 index 00000000..ebf904b6 --- /dev/null +++ b/server/src/test/java/com/rocketmq/studio/cluster/broker/ClusterProviderStubTest.java @@ -0,0 +1,48 @@ +/* + * 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 com.rocketmq.studio.cluster.broker; + +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +class ClusterProviderStubTest { + + private final ClusterProviderStub provider = new ClusterProviderStub(); + + @Test + void discoverClustersShouldReturnStableClusterId() { + List clusters = provider.discoverClusters(); + + assertThat(clusters).hasSize(1); + assertThat(clusters.get(0).getId()).isEqualTo("cluster-001"); + assertThat(clusters.get(0).getBrokers()).isNotEmpty(); + assertThat(clusters.get(0).getProxies()).isNotEmpty(); + assertThat(clusters.get(0).getNameServers()).isNotEmpty(); + } + + @Test + void refreshClusterDetailShouldPreserveRequestedClusterId() { + ClusterVO detail = provider.refreshClusterDetail("cluster-prod"); + + assertThat(detail.getId()).isEqualTo("cluster-prod"); + assertThat(detail.getName()).isEqualTo("rmq-cluster-01"); + assertThat(detail.getBrokers()).hasSize(2); + } +}