Skip to content

HDDS-14717. Improve test coverage for OzoneManagerStateMachine#9825

Open
fapifta wants to merge 1 commit intoapache:masterfrom
fapifta:HDDS-14717
Open

HDDS-14717. Improve test coverage for OzoneManagerStateMachine#9825
fapifta wants to merge 1 commit intoapache:masterfrom
fapifta:HDDS-14717

Conversation

@fapifta
Copy link
Contributor

@fapifta fapifta commented Feb 25, 2026

What changes were proposed in this pull request?

Provide a one-liner summary of the changes in the PR Title field above.
It should be in the form of HDDS-1234. Short summary of the change.

Please describe your PR in detail:
This PR and its description was fully done by Claude-code based on my direction and requests.

  • Significantly expands unit test coverage for OzoneManagerStateMachine, growing from ~5 tests to 30+
    tests covering startTransaction, preAppendTransaction, applyTransaction, runCommand, processResponse,
    createErrorResponse, query, takeSnapshot, loadSnapshotInfoFromDB, leader/configuration change
    notifications, snapshot installation, and lifecycle methods (pause/stop/close).
  • Adds a @VisibleForTesting constructor that accepts mock-friendly dependencies (OzoneManager,
    OzoneManagerDoubleBuffer, RequestHandler, ExecutorService, NettyMetrics), replacing the heavy setup that
    required a real OmMetadataManagerImpl and Ratis server.
  • Widens visibility of processResponse, runCommand, and createErrorResponse from private to
    package-private for direct unit testing.
  • Removes the unused SimpleStateMachineStorage field and its initialization in initialize().
  • Adds a test in TestOzoneManagerRequestHandler verifying that audit log messages include the correct
    transaction index and command type when handleWriteRequestImpl encounters an exception.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-14717

How was this patch tested?

New tests were running locally.

Generated-by: Claude - Opus 4.6

@fapifta fapifta requested a review from adoroszlai February 25, 2026 08:55
public void initialize(RaftServer server, RaftGroupId id, RaftStorage raftStorage) throws IOException {
getLifeCycle().startAndTransition(() -> {
super.initialize(server, id, raftStorage);
storage.init(raftStorage);

Choose a reason for hiding this comment

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

why init() is removed here? its functional change, not just adding new tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you look through the earlier code, this storage variable was created and then never used outside of this call in the OM state machine.
If you check the BaseStateMachine, that also does not do anything with the RaftStorage given to super.initialize as a parameter.
In Ozone Manager, the state machine's storage related methods are mapped to a state stored in RocksDB.
See BaseStateMachine.getStateMachineStorage() where implementation is empty, and does not return anything, which means storage is not used there, as it is not used in the initialize method either. This is not overridden by OzoneManagerStateMachine.
See the usage of getStateMachineStorage() method, it is used only from the getLatestSnapshot() method in the BaseStateMachineStorage class, this method is overridden by OzoneManagerStateMachine, where getLatestSnapshot() uses a call to RocksDB to get the SnapshotInfo.

Based on all of this, I don't see a real use of the variable, and this seems to me dead code, please let me know if you disagree and/or if I am missing something.

Copy link
Contributor

Choose a reason for hiding this comment

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

@szetszwo Is storage.init(raftStorage) needed here?

Copy link
Contributor

Choose a reason for hiding this comment

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

storage is a unused field (except here). We definite could (and should) remove it.

Comment on lines +819 to +822
assertEquals(3, peerIds.size());
assertTrue(peerIds.contains("om1"));
assertTrue(peerIds.contains("om2"));
assertTrue(peerIds.contains("om3"));
Copy link
Contributor

Choose a reason for hiding this comment

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

If any of these assertions fail, we don't get much info about the actual state (which peers were present). This one is better:

assertThat(peerIds)
    .containsExactlyInAnyOrder("om1", "om2", "om3");

@adoroszlai adoroszlai requested a review from szetszwo February 27, 2026 11:12
Copy link
Contributor

@szetszwo szetszwo left a comment

Choose a reason for hiding this comment

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

+1 the change looks good for OzoneManagerStateMachine

(Sorry that I have not checked the changes in the tests.)

Comment on lines -97 to -98
private final SimpleStateMachineStorage storage =
new SimpleStateMachineStorage();
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 Good catch for removing this unused field.

public void initialize(RaftServer server, RaftGroupId id, RaftStorage raftStorage) throws IOException {
getLifeCycle().startAndTransition(() -> {
super.initialize(server, id, raftStorage);
storage.init(raftStorage);
Copy link
Contributor

Choose a reason for hiding this comment

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

storage is a unused field (except here). We definite could (and should) remove it.

Copy link

@yandrey321 yandrey321 left a comment

Choose a reason for hiding this comment

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

lgtm

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.

4 participants