Skip to content

[Enhancement] Add regression coverage for ShutdownHookThread and ServerUtil #10430

@lsq3497

Description

@lsq3497

Before Creating the Enhancement Request

  • I have confirmed that this should be classified as an enhancement rather than a bug/feature.

Summary

org.apache.rocketmq.srvutil.ShutdownHookThread and ServerUtil are shared utility classes used by RocketMQ entry modules. This change adds focused regression coverage for their observable behavior.

Motivation

These utilities are low-level and easy to regress:

  • ShutdownHookThread controls shutdown callback execution
  • ServerUtil builds CLI options and converts CommandLine to Properties
  • both are reused by multiple entry points

Without regression tests, small changes here may introduce:

  • duplicate shutdown callback execution
  • unclear behavior when the callback throws
  • incorrect command-line option construction
  • incorrect conversion from CommandLine to Properties

Describe the Solution You'd Like

Add focused unit tests under srvutil/src/test/java/org/apache/rocketmq/srvutil/ to cover:

  • repeated run() invocation semantics in ShutdownHookThread
  • callback exception handling in ShutdownHookThread
  • ServerUtil.buildCommandlineOptions()
  • ServerUtil.commandLine2Properties()

The scope should stay limited to observable behavior. No production logic changes are required.

Describe Alternatives You've Considered

  • Testing parseCmdLine() directly
    • Rejected because it can terminate the JVM via System.exit()
    • This makes the test setup less stable and harder to reuse
  • Expanding the scope to integration-level startup behavior
    • Rejected because this is a narrow regression task for utility code
    • The lower-cost unit coverage is enough for the intended contribution

Additional Context

Covered behavior:

  • repeated run() invocation on ShutdownHookThread
  • exception handling in the shutdown callback
  • ServerUtil.buildCommandlineOptions()
  • ServerUtil.commandLine2Properties()

Not covered:

  • parseCmdLine() exit behavior
  • JVM shutdown hook registration
  • integration-level startup behavior

Acceptance criteria:

  • tests added under srvutil/src/test/java/org/apache/rocketmq/srvutil/
  • tests pass locally
  • no production logic change
  • no unrelated refactor

Expected outcome:

  • stronger regression protection for srvutil
  • safer future changes in shutdown and CLI helper code
  • no production behavior change

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions