vongosling commented on a change in pull request #2167:
URL: https://github.com/apache/rocketmq/pull/2167#discussion_r502380110



##########
File path: 
client/src/test/java/org/apache/rocketmq/client/impl/factory/MQClientInstanceTest.java
##########
@@ -74,6 +87,34 @@ public void testTopicRouteData2TopicPublishInfo() {
         assertThat(topicPublishInfo.getMessageQueueList().size()).isEqualTo(4);
     }
 
+    @Test
+    public void testFindBrokerAddressInSubscribe() {
+        // dledger normal case
+        String brokerName = "BrokerA";
+        HashMap<Long, String> addrMap = new HashMap<Long, String>();
+        addrMap.put(0L, "127.0.0.1:10911");
+        addrMap.put(1L, "127.0.0.1:10912");
+        addrMap.put(2L, "127.0.0.1:10913");
+        brokerAddrTable.put(brokerName, addrMap);
+        long brokerId = 1;
+        FindBrokerResult brokerResult = 
mqClientInstance.findBrokerAddressInSubscribe(brokerName, brokerId, false);
+        assertThat(brokerResult).isNotNull();
+        assertThat(brokerResult.getBrokerAddr()).isEqualTo("127.0.0.1:10912");
+        assertThat(brokerResult.isSlave()).isTrue();
+
+        // dledger case, when node n0 was voted as the leader
+        brokerName = "BrokerB";
+        HashMap<Long, String> addrMapNew = new HashMap<Long, String>();
+        addrMapNew.put(0L, "127.0.0.1:10911");
+        addrMapNew.put(2L, "127.0.0.1:10912");

Review comment:
       Is there any difference in your test case?(0,1,2 vs 0,2,3)

##########
File path: 
client/src/main/java/org/apache/rocketmq/client/impl/factory/MQClientInstance.java
##########
@@ -1044,9 +1044,14 @@ public FindBrokerResult findBrokerAddressInSubscribe(
             found = brokerAddr != null;
 
             if (!found && !onlyThisBroker) {
-                Entry<Long, String> entry = map.entrySet().iterator().next();
-                brokerAddr = entry.getValue();
-                slave = entry.getKey() != MixAll.MASTER_ID;
+                if (brokerId == 1 && map.size() > 2) {
+                    brokerAddr = map.get(2L);

Review comment:
       why just choose the concrete index 2 while not 3, 4 or other if size > 
2? Is there any optimized space? 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to