Skip to content

Commit

Permalink
[ISSUE #9152] Fix Ci
Browse files Browse the repository at this point in the history
  • Loading branch information
qianye1001 committed Feb 5, 2025
1 parent 61ef8fa commit 668de8b
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,7 @@ private RemotingCommand getConsumeStats(ChannelHandlerContext ctx,
String group = requestHeader.getConsumerGroup();

ConsumeStats consumeStats = new ConsumeStats();
Set<String> topicsForCollecting = getTopicsForCollecting(topicListProvided, topicProvided, group);
Set<String> topicsForCollecting = getTopicsForCollectingConsumeStats(topicListProvided, topicProvided, group);

for (String topic : topicsForCollecting) {
TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic);
Expand Down Expand Up @@ -2022,7 +2022,8 @@ private RemotingCommand getConsumeStats(ChannelHandlerContext ctx,
return response;
}

private Set<String> getTopicsForCollecting(List<String> topicListProvided, String topicProvided, String group) {
private Set<String> getTopicsForCollectingConsumeStats(List<String> topicListProvided, String topicProvided,
String group) {
Set<String> topicsForCollecting = new HashSet<>();
if (!topicListProvided.isEmpty()) {
// if topic list is provided, only collect the topics in the list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public List<String> fetchTopicList() {
}

public void updateTopicList(List<String> topicList) {
if (topicList == null) {
if (topicList == null || topicList.isEmpty()) {
return;
}
StringBuilder sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* 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 org.apache.rocketmq.remoting.protocol.header;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

public class GetConsumeStatsRequestHeaderTest {

private GetConsumeStatsRequestHeader header;

@Before
public void setUp() {
header = new GetConsumeStatsRequestHeader();
}

@Test
public void updateTopicList_NullTopicList_DoesNotUpdate() {
header.updateTopicList(null);
assertNull(header.getTopicList());
}

@Test
public void updateTopicList_EmptyTopicList_SetsEmptyString() {
header.updateTopicList(Collections.emptyList());
assertNull(header.getTopicList());
}

@Test
public void updateTopicList_SingleTopic_SetsSingleTopicString() {
List<String> topicList = Collections.singletonList("TopicA");
header.updateTopicList(topicList);
assertEquals("TopicA;", header.getTopicList());
}

@Test
public void updateTopicList_MultipleTopics_SetsMultipleTopicsString() {
List<String> topicList = Arrays.asList("TopicA", "TopicB", "TopicC");
header.updateTopicList(topicList);
assertEquals("TopicA;TopicB;TopicC;", header.getTopicList());
}

@Test
public void updateTopicList_RepeatedTopics_SetsRepeatedTopicsString() {
List<String> topicList = Arrays.asList("TopicA", "TopicA", "TopicB");
header.updateTopicList(topicList);
assertEquals("TopicA;TopicA;TopicB;", header.getTopicList());
}

@Test
public void fetchTopicList_NullTopicList_ReturnsEmptyList() {
header.setTopicList(null);
List<String> topicList = header.fetchTopicList();
assertEquals(Collections.emptyList(), topicList);

header.updateTopicList(new ArrayList<>());
topicList = header.fetchTopicList();
assertEquals(Collections.emptyList(), topicList);
}

@Test
public void fetchTopicList_EmptyTopicList_ReturnsEmptyList() {
header.setTopicList("");
List<String> topicList = header.fetchTopicList();
assertEquals(Collections.emptyList(), topicList);
}

@Test
public void fetchTopicList_BlankTopicList_ReturnsEmptyList() {
header.setTopicList(" ");
List<String> topicList = header.fetchTopicList();
assertEquals(Collections.emptyList(), topicList);
}

@Test
public void fetchTopicList_SingleTopic_ReturnsSingleTopicList() {
header.setTopicList("TopicA");
List<String> topicList = header.fetchTopicList();
assertEquals(Collections.singletonList("TopicA"), topicList);
}

@Test
public void fetchTopicList_MultipleTopics_ReturnsTopicList() {
header.setTopicList("TopicA;TopicB;TopicC");
List<String> topicList = header.fetchTopicList();
assertEquals(Arrays.asList("TopicA", "TopicB", "TopicC"), topicList);
}

@Test
public void fetchTopicList_TopicListEndsWithSeparator_ReturnsTopicList() {
header.setTopicList("TopicA;TopicB;");
List<String> topicList = header.fetchTopicList();
assertEquals(Arrays.asList("TopicA", "TopicB"), topicList);
}

@Test
public void fetchTopicList_TopicListStartsWithSeparator_ReturnsTopicList() {
header.setTopicList(";TopicA;TopicB");
List<String> topicList = header.fetchTopicList();
assertEquals(Arrays.asList("TopicA", "TopicB"), topicList);
}
}

0 comments on commit 668de8b

Please sign in to comment.