From 8261052cd93c26a1b6494585fd085b3d1b2040b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Mon, 1 Apr 2024 12:26:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E6=B5=8B=E5=B0=8F=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../seata/config/FileConfigurationTest.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/config/seata-config-core/src/test/java/org/apache/seata/config/FileConfigurationTest.java b/config/seata-config-core/src/test/java/org/apache/seata/config/FileConfigurationTest.java index 5c754e0b8b2..15f929837b6 100644 --- a/config/seata-config-core/src/test/java/org/apache/seata/config/FileConfigurationTest.java +++ b/config/seata-config-core/src/test/java/org/apache/seata/config/FileConfigurationTest.java @@ -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);