From 40712631c81b06b717f3c030a82ab1a34a35b397 Mon Sep 17 00:00:00 2001 From: TheRealHaui Date: Fri, 7 Nov 2025 19:17:55 +0100 Subject: [PATCH] Added some new tests --- .../tools/command/CommandUtilTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tools/src/test/java/org/apache/rocketmq/tools/command/CommandUtilTest.java b/tools/src/test/java/org/apache/rocketmq/tools/command/CommandUtilTest.java index ea089350cf8..bbc107584f4 100644 --- a/tools/src/test/java/org/apache/rocketmq/tools/command/CommandUtilTest.java +++ b/tools/src/test/java/org/apache/rocketmq/tools/command/CommandUtilTest.java @@ -40,6 +40,7 @@ import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; @@ -101,6 +102,34 @@ public void testFetchMasterAddrByClusterName() throws InterruptedException, MQBr assertThat(result.size()).isEqualTo(0); } + @Test + public void testFetchMasterAndSlaveAddrByClusterName() throws InterruptedException, MQBrokerException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException { + Set result = CommandUtil.fetchMasterAndSlaveAddrByClusterName(defaultMQAdminExtImpl, "default-cluster"); + assertThat(result.size()).isEqualTo(1); + assertThat(result.iterator().next()).isEqualTo("127.0.0.1:10911"); + } + + @Test + public void testFetchMasterAddrByBrokerNameThrowsException() { + assertThatThrownBy( () -> { + CommandUtil.fetchMasterAddrByBrokerName(defaultMQAdminExtImpl, "default-cluster"); + }) + .isInstanceOf(Exception.class) + .hasMessageContaining("No broker address for broker name"); + } + + @Test + public void testFetchMasterAndSlaveAddrByBrokerName() throws InterruptedException, MQBrokerException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException { + Set result = CommandUtil.fetchMasterAndSlaveAddrByBrokerName(defaultMQAdminExtImpl, "default-cluster"); + assertThat(result.size()).isEqualTo(0); + } + + @Test + public void testFetchBrokerNameByAddr() throws Exception { + String result = CommandUtil.fetchBrokerNameByAddr(defaultMQAdminExtImpl, "127.0.0.1:10911"); + assertThat(result).isEqualTo("default-broker"); + } + @Test public void testFetchBrokerNameByClusterName() throws Exception { Set result = CommandUtil.fetchBrokerNameByClusterName(defaultMQAdminExtImpl, "default-cluster");