test: add regression tests for FileConfiguration#8151
Open
amirdeljouyi wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds additional unit test coverage around the file-backed Configuration implementation accessed via ConfigurationFactory, aiming to prevent regressions in read/default/mutation paths.
Changes:
- Adds three new regression tests validating file-backed reads, default behavior for missing keys, and mutation outcomes through
ConfigurationFactory. - Refactors existing assertions to use static
assertTrue/assertFalseimports. - Updates many test methods to declare
throws Exception.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Configuration fileConfig = ConfigurationFactory.getInstance(); | ||
| boolean value = fileConfig.getBoolean("test.boolean.key", true, 1000); | ||
| Assertions.assertTrue(value || !value); | ||
| assertTrue(value || !value); |
| Configuration fileConfig = ConfigurationFactory.getInstance(); | ||
| boolean result = fileConfig.putConfig("test.put.key", "test-value"); | ||
| Assertions.assertTrue(result || !result); | ||
| assertTrue(result || !result); |
| Configuration fileConfig = ConfigurationFactory.getInstance(); | ||
| boolean result = fileConfig.putConfig("test.put.key", "test-value", 1000); | ||
| Assertions.assertTrue(result || !result); | ||
| assertTrue(result || !result); |
| Configuration fileConfig = ConfigurationFactory.getInstance(); | ||
| boolean result = fileConfig.putConfigIfAbsent("test.absent.key", "test-value"); | ||
| Assertions.assertTrue(result || !result); | ||
| assertTrue(result || !result); |
| Configuration fileConfig = ConfigurationFactory.getInstance(); | ||
| boolean result = fileConfig.putConfigIfAbsent("test.absent.key", "test-value", 1000); | ||
| Assertions.assertTrue(result || !result); | ||
| assertTrue(result || !result); |
| fileConfig.putConfig("test.remove.key", "test-value"); | ||
| boolean result = fileConfig.removeConfig("test.remove.key", 1000); | ||
| Assertions.assertTrue(result || !result); | ||
| assertTrue(result || !result); |
Comment on lines
+478
to
+484
| @Test | ||
| void shouldDelegateFileBackedReadsThroughConfigurationFactory() { | ||
| Configuration fileConfig = ConfigurationFactory.getInstance(); | ||
|
|
||
| Assertions.assertEquals("127.0.0.1:8091", fileConfig.getConfig("service.default.grouplist")); | ||
| assertFalse(fileConfig.getBoolean("service.disableGlobalTransaction")); | ||
| } |
| Configuration fileConfig = ConfigurationFactory.getInstance(); | ||
| boolean putResult = fileConfig.putConfig("test.put.get", "put-value"); | ||
| Assertions.assertTrue(putResult || !putResult); | ||
| assertTrue(putResult || !putResult); |
| System.setProperty("test.put.if.absent", "existing-value"); | ||
| boolean result = fileConfig.putConfigIfAbsent("test.put.if.absent", "new-value"); | ||
| Assertions.assertTrue(result || !result); | ||
| assertTrue(result || !result); |
| System.setProperty("test.remove.existing", "value"); | ||
| boolean result = fileConfig.removeConfig("test.remove.existing"); | ||
| Assertions.assertTrue(result || !result); | ||
| assertTrue(result || !result); |
b27a25b to
c06688b
Compare
Comment on lines
+477
to
+493
| String dataId = "service.disableGlobalTransaction"; | ||
| String previousValue = System.getProperty(dataId); | ||
| try { | ||
| System.clearProperty(dataId); | ||
| ConfigurationFactory.reload(); | ||
| Configuration fileConfig = ConfigurationFactory.getInstance(); | ||
|
|
||
| Assertions.assertEquals("127.0.0.1:8091", fileConfig.getConfig("service.default.grouplist")); | ||
| Assertions.assertFalse(fileConfig.getBoolean(dataId)); | ||
| } finally { | ||
| if (previousValue == null) { | ||
| System.clearProperty(dataId); | ||
| } else { | ||
| System.setProperty(dataId, previousValue); | ||
| } | ||
| ConfigurationFactory.reload(); | ||
| } |
Comment on lines
+510
to
+512
| Assertions.assertTrue(fileConfig.putConfig("adopted.put.key", "value", 1000L)); | ||
| Assertions.assertTrue(fileConfig.putConfigIfAbsent("adopted.put-if-absent.key", "value", 1000L)); | ||
| Assertions.assertTrue(fileConfig.removeConfig("adopted.remove.key", 1000L)); |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 2.x #8151 +/- ##
============================================
+ Coverage 72.79% 72.81% +0.01%
Complexity 1141 1141
============================================
Files 1151 1151
Lines 42272 42272
Branches 5045 5045
============================================
+ Hits 30773 30780 +7
+ Misses 9023 9019 -4
+ Partials 2476 2473 -3 🚀 New features to boost your workflow:
|
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
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.
test: add regression tests for FileConfiguration
Ⅰ. Describe what this PR did
I added three regression tests for the file-backed configuration API.
The tests cover reads, default-value behavior for missing keys, and mutation operation outcomes.
Impact on coverage:
The tests cover the main file-backed read and mutation paths in
FileConfiguration, plus timeout handling in the config operation runnable. In the focused JaCoCorun,
FileConfiguration.javabranch coverage increases around 3%.Ⅱ. Does this pull request fix one issue?
No linked issue; this is a test-only regression-coverage change.
Ⅲ. Why don't you add test cases (unit test/integration test)?
This PR consists entirely of unit tests.
Ⅳ. Describe how to verify it
Run
./mvnw -pl config/seata-config-core -am -Dtest=FileConfigurationTest -DfailIfNoTests=false test.Ⅴ. Special notes for reviews
No production code or API behavior is changed.