-
Notifications
You must be signed in to change notification settings - Fork 8.9k
test: add comprehensive unit tests for RaftRegistryServiceImpl #7779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
WangzJi
wants to merge
9
commits into
apache:2.x
Choose a base branch
from
WangzJi:claude/raft-registry-service-impl-011CV4AXp6GJAAkeRroKDAix
base: 2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
test: add comprehensive unit tests for RaftRegistryServiceImpl #7779
WangzJi
wants to merge
9
commits into
apache:2.x
from
WangzJi:claude/raft-registry-service-impl-011CV4AXp6GJAAkeRroKDAix
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Added 35 new unit test cases for RaftRegistryServiceImpl class to improve
code coverage. Tests cover:
1. Core functionality:
- Singleton pattern verification
- Empty implementation methods (register/unregister/subscribe/unsubscribe)
- Close method and CLOSED flag management
- Endpoint selection with and without preferredNetworks
2. Authentication and token management:
- Token refresh with success and failure scenarios
- Token expiration checks
- JWT token update verification
3. Metadata operations:
- Cluster metadata acquisition (success and auth failure scenarios)
- Metadata lookup with existing data
- Alive lookup in Raft mode with leader
- Query HTTP address with nodes
4. Endpoint selection:
- Control and transaction endpoint selection
- External endpoint selection with various edge cases:
* Empty/null metadata
* Empty external endpoint list
* No matching network patterns
* Successful matching with preferredNetworks
- Endpoint creation and validation
5. Network preference matching:
- Prefix pattern matching (10.10.*)
- Regex pattern matching
- Handling blank patterns
6. Configuration key methods:
- Raft server address key
- Username and password keys
- Preferred networks configuration
- Token expiration time key
- Metadata max age key
7. Background operations:
- Watch method for cluster changes
- Alive lookup refresh in Raft mode
All test methods follow camelCase naming convention ending with "Test"
(e.g., loginFailedTest, getInstanceTest, selectEndpointTest).
Tests use Mockito for HTTP mocking and reflection to access private methods.
Proper cleanup is implemented in @AfterEach to reset CLOSED flag between tests.
Fixed test failures by:
- Adjusting endpoint selection assertions for internal vs external addresses
- Setting up INIT_ADDRESSES to prevent NullPointerException
- Handling Map.put() return value behavior correctly
- Removing invalid "term" field from Node JSON test data
4815a7f to
5817eba
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 2.x #7779 +/- ##
============================================
+ Coverage 70.95% 71.27% +0.31%
- Complexity 992 1042 +50
============================================
Files 1322 1322
Lines 50322 50322
Branches 5946 5946
============================================
+ Hits 35705 35866 +161
+ Misses 11670 11500 -170
- Partials 2947 2956 +9 🚀 New features to boost your workflow:
|
Enhanced tests for `RaftRegistryServiceImpl`: - Improved assertions for endpoint selection methods. - Added tests for null response, null status line, and unauthorized responses in the `watch` method. - Reformatted and cleaned up test methods.
lokidundun
approved these changes
Nov 28, 2025
Contributor
lokidundun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
maple525866
reviewed
Dec 1, 2025
...raft/src/test/java/org/apache/seata/discovery/registry/raft/RaftRegistryServiceImplTest.java
Show resolved
Hide resolved
...raft/src/test/java/org/apache/seata/discovery/registry/raft/RaftRegistryServiceImplTest.java
Show resolved
Hide resolved
...raft/src/test/java/org/apache/seata/discovery/registry/raft/RaftRegistryServiceImplTest.java
Outdated
Show resolved
Hide resolved
maple525866
approved these changes
Dec 1, 2025
Contributor
maple525866
left a comment
There was a problem hiding this 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ⅰ. Describe what this PR did
Ⅱ. Does this pull request fix one issue?
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews