FinberA0A opened a new pull request, #11506:
URL: https://github.com/apache/rocketmq/pull/11506
### Which Issue(s) This PR Fixes
Fixes #8262
### What is the purpose of the change
`org.apache.rocketmq.common.utils` contains 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 of `rocketmq-common` as requested
in #8262. No production code is touched - the PR only adds test classes.
### Brief changelog
- Add `MessageUtilsTest` (14 cases)
- `getShardingKeyIndex` is deterministic and always within `[0, queues)`,
including the empty-key case.
- `getShardingKeyIndexByMsg` reads the sharding-key property when present
and falls back to the empty key otherwise.
- `getShardingKeyIndexes` deduplicates identical message ids.
- `deleteProperty` edge 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.
- Add `QueueTypeUtilsTest` (6 cases)
- `getCQType` with absent topic config, null attributes, empty attributes,
unrelated attributes, explicit `SimpleCQ`, and explicit `BatchCQ`.
- Add `BinaryUtilTest` (7 cases)
- `generateMd5` from string and from bytes, and the two producing the same
digest.
- `calculateMd5` returns exactly 16 bytes.
- `isAscii` with `null`, printable characters, control characters and
non-ASCII bytes.
### Verifying this change
```bash
cd common
mvn -B test -Dtest=MessageUtilsTest,QueueTypeUtilsTest,BinaryUtilTest
```
All tests pass locally:
```text
Tests run: 7, Failures: 0, Errors: 0, Skipped: 0 - BinaryUtilTest
Tests run: 14, Failures: 0, Errors: 0, Skipped: 0 - MessageUtilsTest
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0 - QueueTypeUtilsTest
Tests run: 27, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS
```
`mvn -pl common test` also reports `You have 0 Checkstyle violations.`
### Does this pull request potentially affect one of the following parts
- [ ] Dependencies (add or upgrade a dependency)
- [ ] The public API
- [ ] The core module
- [ ] The broker module
- [ ] The nameserver module
- [x] Nothing
### Documentation
- [ ] Does this pull request introduce a new feature?
- [ ] If yes, how is the feature documented?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]