Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public static String fetchBrokerNameByAddr(final MQAdminExt adminExt, final Stri
while (it.hasNext()) {
Map.Entry<String, BrokerData> entry = it.next();
HashMap<Long, String> brokerAddrs = entry.getValue().getBrokerAddrs();
if (brokerAddrs.containsValue(addr)) {
if (brokerAddrs != null && brokerAddrs.containsValue(addr)) {
return entry.getKey();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -101,6 +102,14 @@ public void testFetchMasterAddrByClusterName() throws InterruptedException, MQBr
assertThat(result.size()).isEqualTo(0);
}

@Test
public void testFetchBrokerNameByAddrThrowsCorrectExceptionWhenNothingFound() {
assertThatThrownBy(() -> CommandUtil.fetchBrokerNameByAddr(defaultMQAdminExtImpl, "127.0.0.2:10911"))
.isInstanceOf(Exception.class)
.hasMessageContaining("Make sure the specified clusterName exists or the name server connected to is correct.");

}

@Test
public void testFetchBrokerNameByClusterName() throws Exception {
Set<String> result = CommandUtil.fetchBrokerNameByClusterName(defaultMQAdminExtImpl, "default-cluster");
Expand Down
Loading