镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

[ISSUE #8262] Add unit tests for MessageUtils, QueueTypeUtils and BinaryUtil - #11506

Open
FinberA0A wants to merge 1 commit into
apache:developfrom
FinberA0A:test/add-common-utils-unit-tests
Open

FinberA0A wants to merge 1 commit into
apache:developfrom
FinberA0A:test/add-common-utils-unit-tests

Conversation

@FinberA0A

Copy link
Copy Markdown

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

cd common
mvn -B test -Dtest=MessageUtilsTest,QueueTypeUtilsTest,BinaryUtilTest

All tests pass locally:

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
  • Nothing

Documentation

  • Does this pull request introduce a new feature?
  • If yes, how is the feature documented?

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement] Increase the code test coverage of the project to more than 50% with the help of Tongyi Lingma's capabilities.

1 participant