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
15 changes: 8 additions & 7 deletions common/src/main/java/org/apache/rocketmq/common/KeyBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ public static String buildPopRetryTopicV1(String topic, String cid) {
}

public static String parseNormalTopic(String topic, String cid) {
if (topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX)) {
if (topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX + cid + POP_RETRY_SEPARATOR_V2)) {
return topic.substring((MixAll.RETRY_GROUP_TOPIC_PREFIX + cid + POP_RETRY_SEPARATOR_V2).length());
}
return topic.substring((MixAll.RETRY_GROUP_TOPIC_PREFIX + cid + POP_RETRY_SEPARATOR_V1).length());
} else {
return topic;
String retryPrefixV2 = MixAll.RETRY_GROUP_TOPIC_PREFIX + cid + POP_RETRY_SEPARATOR_V2;
if (topic.startsWith(retryPrefixV2)) {
return topic.substring(retryPrefixV2.length());
}
String retryPrefixV1 = MixAll.RETRY_GROUP_TOPIC_PREFIX + cid + POP_RETRY_SEPARATOR_V1;
if (topic.startsWith(retryPrefixV1)) {
return topic.substring(retryPrefixV1.length());
}
return topic;
}

public static String parseNormalTopic(String retryTopic) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ public void testParseNormalTopic() {
assertThat(KeyBuilder.parseNormalTopic(popRetryTopic)).isEqualTo(topic);
}

@Test
public void testParseNormalTopicDoesNotStripAnotherGroup() {
String retryTopic = KeyBuilder.buildPopRetryTopicV1(topic, "another-group");

assertThat(KeyBuilder.parseNormalTopic(retryTopic, group)).isEqualTo(retryTopic);
}

@Test
public void testParseNormalTopicDoesNotFailForRegularRetryTopic() {
String retryTopic = MixAll.RETRY_GROUP_TOPIC_PREFIX + group;

assertThat(KeyBuilder.parseNormalTopic(retryTopic, group)).isEqualTo(retryTopic);
}

@Test
public void testParseGroup() {
String popRetryTopic = KeyBuilder.buildPopRetryTopicV2(topic, group);
Expand All @@ -60,4 +74,4 @@ public void testIsPopRetryTopicV2() {
String popRetryTopicV1 = KeyBuilder.buildPopRetryTopicV1(topic, group);
assertThat(KeyBuilder.isPopRetryTopicV2(popRetryTopicV1)).isEqualTo(false);
}
}
}
Loading