This is an automated email from the ASF dual-hosted git repository. jinrongtong pushed a commit to branch test-release in repository https://gitbox.apache.org/repos/asf/rocketmq.git
commit 5f3042c5095ba0aae8a2a385a06bd15421ef1c63 Author: Darkness463 <[email protected]> AuthorDate: Fri Jan 3 11:33:15 2020 +0800 [ISSUE #1110] Fix wrong topic max length in rocketmq client. (#1636) * Fix wrong topic max length in rocketmq client. * modify unit test of TooLongTopic --- client/src/main/java/org/apache/rocketmq/client/Validators.java | 6 ++++-- client/src/test/java/org/apache/rocketmq/client/ValidatorsTest.java | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/client/src/main/java/org/apache/rocketmq/client/Validators.java b/client/src/main/java/org/apache/rocketmq/client/Validators.java index a37a17b..d77faf3 100644 --- a/client/src/main/java/org/apache/rocketmq/client/Validators.java +++ b/client/src/main/java/org/apache/rocketmq/client/Validators.java @@ -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 diff --git a/client/src/test/java/org/apache/rocketmq/client/ValidatorsTest.java b/client/src/test/java/org/apache/rocketmq/client/ValidatorsTest.java index 5a012ce..e2b9abd 100644 --- a/client/src/test/java/org/apache/rocketmq/client/ValidatorsTest.java +++ b/client/src/test/java/org/apache/rocketmq/client/ValidatorsTest.java @@ -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"); } } }
