Skip to content

Commit

Permalink
单测小调整。
Browse files Browse the repository at this point in the history
  • Loading branch information
wangliang181230 committed Apr 1, 2024
1 parent 818822e commit 8261052
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,24 @@ void tearDown() {
@Test
void addConfigListener() throws InterruptedException {
Configuration fileConfig = ConfigurationFactory.getInstance();
CountDownLatch countDownLatch = new CountDownLatch(1);
String dataId = "service.disableGlobalTransaction";

CountDownLatch countDownLatch = new CountDownLatch(1);
boolean value = fileConfig.getBoolean(dataId);
fileConfig.addConfigListener(dataId, new CachedConfigurationChangeListener() {
@Override
public void onChangeEvent(ConfigurationChangeEvent event) {
Assertions.assertEquals(Boolean.parseBoolean(event.getNewValue()),
!Boolean.parseBoolean(event.getOldValue()));
countDownLatch.countDown();
}
});
fileConfig.addConfigListener(dataId, event -> {
Assertions.assertEquals(Boolean.parseBoolean(event.getNewValue()),
!Boolean.parseBoolean(event.getOldValue()));
countDownLatch.countDown();
});
System.setProperty(dataId, String.valueOf(!value));
countDownLatch.await(2, TimeUnit.SECONDS);
countDownLatch.await(20, TimeUnit.SECONDS);
Assertions.assertEquals(value, !fileConfig.getBoolean(dataId));

System.setProperty("file.listener.enabled", "false");

//wait for loop safety, loop time is LISTENER_CONFIG_INTERVAL=1s
Thread.sleep(1500);

System.setProperty(dataId, String.valueOf(value));
//sleep for a period of time to simulate waiting for a cache refresh.Actually, it doesn't trigger.
Thread.sleep(1000);
Expand Down

0 comments on commit 8261052

Please sign in to comment.