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 @@ -299,10 +299,12 @@ private String computePullFromWhichFilterServer(final String topic, final String
ConcurrentMap<String, TopicRouteData> topicRouteTable = this.mQClientFactory.getTopicRouteTable();
if (topicRouteTable != null) {
TopicRouteData topicRouteData = topicRouteTable.get(topic);
List<String> list = topicRouteData.getFilterServerTable().get(brokerAddr);
if (topicRouteData != null && topicRouteData.getFilterServerTable() != null) {
List<String> list = topicRouteData.getFilterServerTable().get(brokerAddr);

if (list != null && !list.isEmpty()) {
return list.get(randomNum() % list.size());
if (list != null && !list.isEmpty()) {
return list.get(randomNum() % list.size());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
Expand Down Expand Up @@ -153,6 +154,68 @@ public void testPullKernelImpl() throws Exception {
any(PullCallback.class));
}

@Test
public void testPullKernelImplWithMissingTopicRouteDataForClassFilter() {
when(mQClientFactory.getTopicRouteTable()).thenReturn(new ConcurrentHashMap<>());

assertFindFilterServerFailed();
}

@Test
public void testPullKernelImplWithMissingFilterServerTableForClassFilter() {
TopicRouteData topicRouteData = new TopicRouteData();
topicRouteData.setFilterServerTable(null);
ConcurrentMap<String, TopicRouteData> topicRouteTable = new ConcurrentHashMap<>();
topicRouteTable.put(defaultTopic, topicRouteData);
when(mQClientFactory.getTopicRouteTable()).thenReturn(topicRouteTable);

assertFindFilterServerFailed();
}

@Test
public void testPullKernelImplWithMissingBrokerFilterServerForClassFilter() {
TopicRouteData topicRouteData = new TopicRouteData();
topicRouteData.setFilterServerTable(new HashMap<>());
ConcurrentMap<String, TopicRouteData> topicRouteTable = new ConcurrentHashMap<>();
topicRouteTable.put(defaultTopic, topicRouteData);
when(mQClientFactory.getTopicRouteTable()).thenReturn(topicRouteTable);

assertFindFilterServerFailed();
}

@Test
public void testPullKernelImplWithEmptyFilterServerListForClassFilter() {
TopicRouteData topicRouteData = new TopicRouteData();
HashMap<String, List<String>> filterServerTable = new HashMap<>();
filterServerTable.put(defaultBrokerAddr, new ArrayList<>());
topicRouteData.setFilterServerTable(filterServerTable);
ConcurrentMap<String, TopicRouteData> topicRouteTable = new ConcurrentHashMap<>();
topicRouteTable.put(defaultTopic, topicRouteData);
when(mQClientFactory.getTopicRouteTable()).thenReturn(topicRouteTable);

assertFindFilterServerFailed();
}

private void assertFindFilterServerFailed() {
MQClientException actual = assertThrows(MQClientException.class, () -> pullAPIWrapper.pullKernelImpl(
createMessageQueue(),
"",
"",
1L,
1L,
1,
1,
PullSysFlag.buildSysFlag(false, false, false, true),
1L,
System.currentTimeMillis(),
defaultTimeout,
CommunicationMode.SYNC,
null
));

assertTrue(actual.getMessage().contains("Find Filter Server Failed"));
}

@Test
public void testSetConnectBrokerByUser() {
pullAPIWrapper.setConnectBrokerByUser(true);
Expand Down
Loading