Repository navigation
Conversation
Add direct unit tests for three previously untested utility classes in the common module to improve coverage: - MessageUtilsTest (14 tests): sharding key index determinism, range and deduplication, plus deleteProperty boundary cases (first/middle/last entry, repeated keys, name prefix collisions, missing value separator). - QueueTypeUtilsTest (6 tests): CQ type resolution from topic attributes, including absent config, null/empty attributes and explicit values. - BinaryUtilTest (7 tests): MD5 generation for strings/bytes and ASCII validation for null, control characters and non-ASCII input.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which Issue(s) This PR Fixes
Fixes #8262
What is the purpose of the change
org.apache.rocketmq.common.utilscontains a set of small but widely used helpers (MessageUtils,QueueTypeUtils,BinaryUtil), yet many of their branches are not covered by tests. This PR adds 27 unit tests for these three utilities, helping to raise the test coverage ofrocketmq-commonas requested in #8262. No production code is touched - the PR only adds test classes.Brief changelog
MessageUtilsTest(14 cases)getShardingKeyIndexis deterministic and always within[0, queues), including the empty-key case.getShardingKeyIndexByMsgreads the sharding-key property when present and falls back to the empty key otherwise.getShardingKeyIndexesdeduplicates identical message ids.deletePropertyedge cases: null property string, unrelated properties kept, property at the beginning / middle / only property, trailing separator preserved, all occurrences of the same name removed, name-prefix mismatch, and missing name-value separator.QueueTypeUtilsTest(6 cases)getCQTypewith absent topic config, null attributes, empty attributes, unrelated attributes, explicitSimpleCQ, and explicitBatchCQ.BinaryUtilTest(7 cases)generateMd5from string and from bytes, and the two producing the same digest.calculateMd5returns exactly 16 bytes.isAsciiwithnull, printable characters, control characters and non-ASCII bytes.Verifying this change
All tests pass locally:
mvn -pl common testalso reportsYou have 0 Checkstyle violations.Does this pull request potentially affect one of the following parts
Documentation