提交 9db11c74 编写于 作者: D Darkness463 提交者: Heng Du

[ISSUE #1110] Fix wrong topic max length in rocketmq client. (#1636)

* Fix wrong topic max length in rocketmq client.

* modify unit test of TooLongTopic
上级 93745553
......@@ -33,6 +33,7 @@ public class Validators {
public static final String VALID_PATTERN_STR = "^[%|a-zA-Z0-9_-]+$";
public static final Pattern PATTERN = Pattern.compile(VALID_PATTERN_STR);
public static final int CHARACTER_MAX_LENGTH = 255;
public static final int TOPIC_MAX_LENGTH = 127;
/**
* @return The resulting {@code String}
......@@ -111,8 +112,9 @@ public class Validators {
VALID_PATTERN_STR), null);
}
if (topic.length() > CHARACTER_MAX_LENGTH) {
throw new MQClientException("The specified topic is longer than topic max length 255.", null);
if (topic.length() > TOPIC_MAX_LENGTH) {
throw new MQClientException(
String.format("The specified topic is longer than topic max length %d.", TOPIC_MAX_LENGTH), null);
}
//whether the same with system reserved keyword
......
......@@ -71,13 +71,13 @@ public class ValidatorsTest {
@Test
public void testCheckTopic_TooLongTopic() {
String tooLongTopic = StringUtils.rightPad("TooLongTopic", Validators.CHARACTER_MAX_LENGTH + 1, "_");
assertThat(tooLongTopic.length()).isGreaterThan(Validators.CHARACTER_MAX_LENGTH);
String tooLongTopic = StringUtils.rightPad("TooLongTopic", Validators.TOPIC_MAX_LENGTH + 1, "_");
assertThat(tooLongTopic.length()).isGreaterThan(Validators.TOPIC_MAX_LENGTH);
try {
Validators.checkTopic(tooLongTopic);
failBecauseExceptionWasNotThrown(MQClientException.class);
} catch (MQClientException e) {
assertThat(e).hasMessageStartingWith("The specified topic is longer than topic max length 255.");
assertThat(e).hasMessageStartingWith("The specified topic is longer than topic max length");
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册