Skip to content

[ISSUE #10430] Add unit tests for srvutil package#10431

Open
lsq3497 wants to merge 2 commits into
apache:developfrom
lsq3497:develop-srvutil_test
Open

[ISSUE #10430] Add unit tests for srvutil package#10431
lsq3497 wants to merge 2 commits into
apache:developfrom
lsq3497:develop-srvutil_test

Conversation

@lsq3497
Copy link
Copy Markdown

@lsq3497 lsq3497 commented Jun 6, 2026

Which Issue(s) This PR Fixes

Fixes #10430

Brief Description

Add unit tests for ServerUtil and ShutdownHookThread in the srvutil package.

The added tests cover:

  • command line option construction
  • command line to properties conversion
  • null option handling
  • shutdown hook callback execution
  • exception handling during callback invocation

How Did You Test This Change?

Run unit tests locally and verified all tests pass successfully.

Copy link
Copy Markdown
Contributor

@RongtongJin RongtongJin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERROR: /home/runner/work/rocketmq/rocketmq/srvutil/BUILD.bazel:38:13: Building srvutil/libtests.jar (3 source files) failed: (Exit 1): java failed: error executing command (from target //srvutil:tests) external/remotejdk21_linux/bin/java '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED' ... (remaining 19 arguments skipped)
warning: [options] source value 8 is obsolete and will be removed in a future release
warning: [options] target value 8 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
srvutil/src/test/java/org/apache/rocketmq/srvutil/ServerUtilTest.java:34: warning: [strict] Using type org.apache.commons.cli.Options from an indirect dependency (TOOL_INFO: "bazel-out/k8-fastbuild/bin/external/maven/v1/https/repo1.maven.org/maven2/commons-cli/commons-cli/1.5.0/header_commons-cli-1.5.0.jar").
Options options = ServerUtil.buildCommandlineOptions(new Options());
^
srvutil/src/test/java/org/apache/rocketmq/srvutil/ShutdownHookThreadTest.java:37: warning: [strict] Using type org.apache.rocketmq.logging.org.slf4j.Logger from an indirect dependency (TOOL_INFO: "bazel-out/k8-fastbuild/bin/external/maven/v1/https/repo1.maven.org/maven2/io/github/aliyunmq/rocketmq-slf4j-api/1.0.1/header_rocketmq-slf4j-api-1.0.1.jar").
Logger logger = Mockito.mock(Logger.class);
^
srvutil/src/test/java/org/apache/rocketmq/srvutil/ServerUtilTest.java:34: warning: [strict] Using type org.apache.commons.cli.Options from an indirect dependency (TOOL_INFO: "bazel-out/k8-fastbuild/bin/external/maven/v1/https/repo1.maven.org/maven2/commons-cli/commons-cli/1.5.0/header_commons-cli-1.5.0.jar").
Options options = ServerUtil.buildCommandlineOptions(new Options());
^
srvutil/src/test/java/org/apache/rocketmq/srvutil/ShutdownHookThreadTest.java:37: warning: [strict] Using type org.apache.rocketmq.logging.org.slf4j.Logger from an indirect dependency (TOOL_INFO: "bazel-out/k8-fastbuild/bin/external/maven/v1/https/repo1.maven.org/maven2/io/github/aliyunmq/rocketmq-slf4j-api/1.0.1/header_rocketmq-slf4j-api-1.0.1.jar").
Logger logger = Mockito.mock(Logger.class);
^
srvutil/src/test/java/org/apache/rocketmq/srvutil/ShutdownHookThreadTest.java:46: error: [DoNotCall] Calling run on Thread runs work on this thread, rather than the given thread, you probably meant to call start
shutdownHookThread.run();
^
(see https://errorprone.info/bugpattern/DoNotCall)
srvutil/src/test/java/org/apache/rocketmq/srvutil/ShutdownHookThreadTest.java:47: error: [DoNotCall] Calling run on Thread runs work on this thread, rather than the given thread, you probably meant to call start
shutdownHookThread.run();
^
(see https://errorprone.info/bugpattern/DoNotCall)
srvutil/src/test/java/org/apache/rocketmq/srvutil/ShutdownHookThreadTest.java:64: error: [DoNotCall] Calling run on Thread runs work on this thread, rather than the given thread, you probably meant to call start
shutdownHookThread.run();
^
(see https://errorprone.info/bugpattern/DoNotCall)
INFO: Elapsed time: 20.353s, Critical Path: 10.52s
INFO: 1168 processes: 604 remote cache hit, 562 internal, 2 remote.

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 47.99%. Comparing base (330dccc) to head (a69e076).
⚠️ Report is 66 commits behind head on develop.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop   #10431      +/-   ##
=============================================
- Coverage      48.90%   47.99%   -0.91%     
+ Complexity     13363    13287      -76     
=============================================
  Files           1373     1377       +4     
  Lines          99870   100613     +743     
  Branches       12904    12992      +88     
=============================================
- Hits           48837    48293     -544     
- Misses         45114    46376    +1262     
- Partials        5919     5944      +25     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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] Add regression coverage for ShutdownHookThread and ServerUtil

3 participants