Skip to content

Commit c06688b

Browse files
committed
test: add regression tests for FileConfiguration
1 parent b57d96c commit c06688b

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

config/seata-config-core/src/test/java/org/apache/seata/config/FileConfigurationTest.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,4 +471,48 @@ void testGetConfigFromEnvironmentVariable() {
471471
String path = fileConfig.getConfigFromSys("PATH");
472472
Assertions.assertNotNull(path);
473473
}
474+
475+
@Test
476+
void shouldDelegateFileBackedReadsThroughConfigurationFactory() {
477+
String dataId = "service.disableGlobalTransaction";
478+
String previousValue = System.getProperty(dataId);
479+
try {
480+
System.clearProperty(dataId);
481+
ConfigurationFactory.reload();
482+
Configuration fileConfig = ConfigurationFactory.getInstance();
483+
484+
Assertions.assertEquals("127.0.0.1:8091", fileConfig.getConfig("service.default.grouplist"));
485+
Assertions.assertFalse(fileConfig.getBoolean(dataId));
486+
} finally {
487+
if (previousValue == null) {
488+
System.clearProperty(dataId);
489+
} else {
490+
System.setProperty(dataId, previousValue);
491+
}
492+
ConfigurationFactory.reload();
493+
}
494+
}
495+
496+
@Test
497+
void shouldReturnDefaultsForMissingConfigurationThroughConfigurationFactory() {
498+
Configuration fileConfig = ConfigurationFactory.getInstance();
499+
500+
Assertions.assertNull(fileConfig.getConfig("adopted.missing.key"));
501+
Assertions.assertEquals("fallback", fileConfig.getLatestConfig("adopted.missing.key", "fallback", 1000L));
502+
Assertions.assertEquals(39, fileConfig.getInt("adopted.missing.int", 39));
503+
Assertions.assertEquals((short) 2, fileConfig.getShort("adopted.missing.short", (short) 2));
504+
}
505+
506+
@Test
507+
void shouldReportMutationOperationOutcomeThroughConfigurationFactory() {
508+
Configuration fileConfig = ConfigurationFactory.getInstance();
509+
510+
Assertions.assertTrue(fileConfig.putConfig("adopted.put.key", "value", 1000L));
511+
Assertions.assertTrue(fileConfig.putConfigIfAbsent("adopted.put-if-absent.key", "value", 1000L));
512+
Assertions.assertTrue(fileConfig.removeConfig("adopted.remove.key", 1000L));
513+
514+
Assertions.assertFalse(fileConfig.putConfig("adopted.expired.put.key", "value", -1L));
515+
Assertions.assertFalse(fileConfig.putConfigIfAbsent("adopted.expired.put-if-absent.key", "value", -1L));
516+
Assertions.assertFalse(fileConfig.removeConfig("adopted.expired.remove.key", -1L));
517+
}
474518
}

0 commit comments

Comments
 (0)