-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Polish #5306 : [Migration] Upgrade the @SInCE tags in Javadoc migration cloud native to master * Polish #5306 : [Migration] Upgrade the @SInCE tags in Javadoc migration cloud native to master * Polish #5309 : [ISSURE] The beans of Dubbo's Config can't be found on the ReferenceBean's initialization * Polish #5312 : Resolve the demos' issues of zookeeper and nacos * Polish #5313 : [Migration] migrate the code in common module from cloud-native branch to master * Polish #5316 : [Refactor] Replace @EnableDubboConfigBinding Using spring-context-support * Polish #5317 : [Refactor] Refactor ReferenceAnnotationBeanPostProcessor using Alibaba spring-context-suuport API * Polish #5321 : Remove BeanFactoryUtils * Polish #5321 : Remove AnnotatedBeanDefinitionRegistryUtils * Polish #5321 : Remove AnnotationUtils * Polish #5321 : Remove ClassUtils * Polish #5321 : Remove BeanRegistrar * Polish #5321 : Remove ObjectUtils * Polish #5321 : Remove PropertySourcesUtils * Polish #5325 : [Migration] To migrate dubbo-metadata-api from cloud-native branch * Polish #5326 : [Migration] To migrate dubbo-metadata-processor from cloud-native branch * Polish #5329 : [Feature] To add the default metadata into ServiceInstance * Polish #5339 : [Refactor] Refactor the DynamicConfiguration interface * Polish bugfix * Fixes test cases * Merge remote-tracking branch 'upstream/master' into cloud-native-2.7.5 # Conflicts: # dubbo-configcenter/dubbo-configcenter-zookeeper/src/test/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationTest.java # dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMappingTest.java * Merge remote-tracking branch 'upstream/master' into cloud-native-2.7.5 # Conflicts: # dubbo-configcenter/dubbo-configcenter-zookeeper/src/test/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationTest.java # dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMappingTest.java
- Loading branch information
1 parent
11a1750
commit 4506648
Showing
12 changed files
with
230 additions
and
192 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
300 changes: 150 additions & 150 deletions
300
.../org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfigurationTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,150 +1,150 @@ | ||
///* | ||
// * Licensed to the Apache Software Foundation (ASF) under one or more | ||
// * contributor license agreements. See the NOTICE file distributed with | ||
// * this work for additional information regarding copyright ownership. | ||
// * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
// * (the "License"); you may not use this file except in compliance with | ||
// * the License. You may obtain a copy of the License at | ||
// * | ||
// * http://www.apache.org/licenses/LICENSE-2.0 | ||
// * | ||
// * Unless required by applicable law or agreed to in writing, software | ||
// * distributed under the License is distributed on an "AS IS" BASIS, | ||
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// * See the License for the specific language governing permissions and | ||
// * limitations under the License. | ||
// */ | ||
//package org.apache.dubbo.common.config.configcenter.file; | ||
// | ||
//import org.apache.dubbo.common.URL; | ||
// | ||
//import org.apache.commons.io.FileUtils; | ||
//import org.junit.jupiter.api.AfterEach; | ||
//import org.junit.jupiter.api.BeforeEach; | ||
//import org.junit.jupiter.api.Test; | ||
// | ||
//import java.io.File; | ||
//import java.util.concurrent.ThreadPoolExecutor; | ||
//import java.util.concurrent.atomic.AtomicBoolean; | ||
// | ||
//import static org.apache.commons.io.FileUtils.deleteQuietly; | ||
//import static org.apache.dubbo.common.URL.valueOf; | ||
//import static org.apache.dubbo.common.config.configcenter.DynamicConfiguration.DEFAULT_GROUP; | ||
//import static org.apache.dubbo.common.config.configcenter.file.FileSystemDynamicConfiguration.CONFIG_CENTER_DIR_PARAM_NAME; | ||
//import static org.junit.jupiter.api.Assertions.assertEquals; | ||
//import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
//import static org.junit.jupiter.api.Assertions.assertNull; | ||
//import static org.junit.jupiter.api.Assertions.assertTrue; | ||
// | ||
///** | ||
// * {@link FileSystemDynamicConfiguration} Test | ||
// */ | ||
//public class FileSystemDynamicConfigurationTest { | ||
// | ||
// private FileSystemDynamicConfiguration configuration; | ||
// | ||
// private static final String KEY = "abc-def-ghi"; | ||
// | ||
// private static final String CONTENT = "Hello,World"; | ||
// | ||
// @BeforeEach | ||
// public void init() { | ||
// File rootDirectory = new File(getClassPath(), "config-center"); | ||
// rootDirectory.mkdirs(); | ||
// URL url = valueOf("dubbo://127.0.0.1:20880").addParameter(CONFIG_CENTER_DIR_PARAM_NAME, rootDirectory.getAbsolutePath()); | ||
// configuration = new FileSystemDynamicConfiguration(url); | ||
// deleteQuietly(configuration.getRootDirectory()); | ||
// } | ||
// | ||
// @AfterEach | ||
// public void destroy() throws Exception { | ||
// configuration.close(); | ||
// } | ||
// | ||
// private String getClassPath() { | ||
// return getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); | ||
// } | ||
// | ||
// @Test | ||
// public void testInit() { | ||
// | ||
// assertEquals(new File(getClassPath(), "config-center"), configuration.getRootDirectory()); | ||
// assertEquals("UTF-8", configuration.getEncoding()); | ||
// assertEquals(ThreadPoolExecutor.class, configuration.getWorkersThreadPool().getClass()); | ||
// assertEquals(1, (configuration.getWorkersThreadPool()).getCorePoolSize()); | ||
// assertEquals(1, (configuration.getWorkersThreadPool()).getMaximumPoolSize()); | ||
// assertNotNull(configuration.getWatchEventsLoopThreadPool()); | ||
// assertEquals(1, (configuration.getWatchEventsLoopThreadPool()).getCorePoolSize()); | ||
// assertEquals(1, (configuration.getWatchEventsLoopThreadPool()).getMaximumPoolSize()); | ||
// | ||
// if (configuration.isBasedPoolingWatchService()) { | ||
// assertEquals(2, configuration.getDelay()); | ||
// } else { | ||
// assertNull(configuration.getDelay()); | ||
// } | ||
// } | ||
// | ||
// @Test | ||
// public void testPublishAndGetConfig() { | ||
// assertTrue(configuration.publishConfig(KEY, CONTENT)); | ||
// assertTrue(configuration.publishConfig(KEY, CONTENT)); | ||
// assertTrue(configuration.publishConfig(KEY, CONTENT)); | ||
// assertEquals(CONTENT, configuration.getConfig(KEY, DEFAULT_GROUP)); | ||
// } | ||
// | ||
// @Test | ||
// public void testAddAndRemoveListener() throws InterruptedException { | ||
// | ||
// configuration.publishConfig(KEY, "A"); | ||
// | ||
// AtomicBoolean processedEvent = new AtomicBoolean(); | ||
// | ||
// configuration.addListener(KEY, event -> { | ||
// | ||
// processedEvent.set(true); | ||
// assertEquals(KEY, event.getKey()); | ||
// System.out.printf("[%s] " + event + "\n", Thread.currentThread().getName()); | ||
// }); | ||
// | ||
// | ||
// configuration.publishConfig(KEY, "B"); | ||
// while (!processedEvent.get()) { | ||
// Thread.sleep(1 * 1000L); | ||
// } | ||
// | ||
// processedEvent.set(false); | ||
// configuration.publishConfig(KEY, "C"); | ||
// while (!processedEvent.get()) { | ||
// Thread.sleep(1 * 1000L); | ||
// } | ||
// | ||
// processedEvent.set(false); | ||
// configuration.publishConfig(KEY, "D"); | ||
// while (!processedEvent.get()) { | ||
// Thread.sleep(1 * 1000L); | ||
// } | ||
// | ||
// configuration.addListener("test", "test", event -> { | ||
// processedEvent.set(true); | ||
// assertEquals("test", event.getKey()); | ||
// System.out.printf("[%s] " + event + "\n", Thread.currentThread().getName()); | ||
// }); | ||
// processedEvent.set(false); | ||
// configuration.publishConfig("test", "test", "TEST"); | ||
// while (!processedEvent.get()) { | ||
// Thread.sleep(1 * 1000L); | ||
// } | ||
// | ||
// configuration.publishConfig("test", "test", "TEST"); | ||
// configuration.publishConfig("test", "test", "TEST"); | ||
// configuration.publishConfig("test", "test", "TEST"); | ||
// | ||
// | ||
// processedEvent.set(false); | ||
// File keyFile = configuration.configFile(KEY, DEFAULT_GROUP); | ||
// FileUtils.deleteQuietly(keyFile); | ||
// while (!processedEvent.get()) { | ||
// Thread.sleep(1 * 1000L); | ||
// } | ||
// } | ||
//} | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.dubbo.common.config.configcenter.file; | ||
|
||
import org.apache.dubbo.common.URL; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.File; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import static org.apache.commons.io.FileUtils.deleteQuietly; | ||
import static org.apache.dubbo.common.URL.valueOf; | ||
import static org.apache.dubbo.common.config.configcenter.DynamicConfiguration.DEFAULT_GROUP; | ||
import static org.apache.dubbo.common.config.configcenter.file.FileSystemDynamicConfiguration.CONFIG_CENTER_DIR_PARAM_NAME; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
/** | ||
* {@link FileSystemDynamicConfiguration} Test | ||
*/ | ||
public class FileSystemDynamicConfigurationTest { | ||
|
||
private FileSystemDynamicConfiguration configuration; | ||
|
||
private static final String KEY = "abc-def-ghi"; | ||
|
||
private static final String CONTENT = "Hello,World"; | ||
|
||
@BeforeEach | ||
public void init() { | ||
File rootDirectory = new File(getClassPath(), "config-center"); | ||
rootDirectory.mkdirs(); | ||
URL url = valueOf("dubbo://127.0.0.1:20880").addParameter(CONFIG_CENTER_DIR_PARAM_NAME, rootDirectory.getAbsolutePath()); | ||
configuration = new FileSystemDynamicConfiguration(url); | ||
deleteQuietly(configuration.getRootDirectory()); | ||
} | ||
|
||
@AfterEach | ||
public void destroy() throws Exception { | ||
configuration.close(); | ||
} | ||
|
||
private String getClassPath() { | ||
return getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); | ||
} | ||
|
||
@Test | ||
public void testInit() { | ||
|
||
assertEquals(new File(getClassPath(), "config-center"), configuration.getRootDirectory()); | ||
assertEquals("UTF-8", configuration.getEncoding()); | ||
assertEquals(ThreadPoolExecutor.class, configuration.getWorkersThreadPool().getClass()); | ||
assertEquals(1, (configuration.getWorkersThreadPool()).getCorePoolSize()); | ||
assertEquals(1, (configuration.getWorkersThreadPool()).getMaximumPoolSize()); | ||
assertNotNull(configuration.getWatchEventsLoopThreadPool()); | ||
assertEquals(1, (configuration.getWatchEventsLoopThreadPool()).getCorePoolSize()); | ||
assertEquals(1, (configuration.getWatchEventsLoopThreadPool()).getMaximumPoolSize()); | ||
|
||
if (configuration.isBasedPoolingWatchService()) { | ||
assertEquals(2, configuration.getDelay()); | ||
} else { | ||
assertNull(configuration.getDelay()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testPublishAndGetConfig() { | ||
assertTrue(configuration.publishConfig(KEY, CONTENT)); | ||
assertTrue(configuration.publishConfig(KEY, CONTENT)); | ||
assertTrue(configuration.publishConfig(KEY, CONTENT)); | ||
assertEquals(CONTENT, configuration.getConfig(KEY, DEFAULT_GROUP)); | ||
} | ||
|
||
@Test | ||
public void testAddAndRemoveListener() throws InterruptedException { | ||
|
||
configuration.publishConfig(KEY, "A"); | ||
|
||
AtomicBoolean processedEvent = new AtomicBoolean(); | ||
|
||
configuration.addListener(KEY, event -> { | ||
|
||
processedEvent.set(true); | ||
assertEquals(KEY, event.getKey()); | ||
System.out.printf("[%s] " + event + "\n", Thread.currentThread().getName()); | ||
}); | ||
|
||
|
||
configuration.publishConfig(KEY, "B"); | ||
while (!processedEvent.get()) { | ||
Thread.sleep(1 * 1000L); | ||
} | ||
|
||
processedEvent.set(false); | ||
configuration.publishConfig(KEY, "C"); | ||
while (!processedEvent.get()) { | ||
Thread.sleep(1 * 1000L); | ||
} | ||
|
||
processedEvent.set(false); | ||
configuration.publishConfig(KEY, "D"); | ||
while (!processedEvent.get()) { | ||
Thread.sleep(1 * 1000L); | ||
} | ||
|
||
configuration.addListener("test", "test", event -> { | ||
processedEvent.set(true); | ||
assertEquals("test", event.getKey()); | ||
System.out.printf("[%s] " + event + "\n", Thread.currentThread().getName()); | ||
}); | ||
processedEvent.set(false); | ||
configuration.publishConfig("test", "test", "TEST"); | ||
while (!processedEvent.get()) { | ||
Thread.sleep(1 * 1000L); | ||
} | ||
|
||
configuration.publishConfig("test", "test", "TEST"); | ||
configuration.publishConfig("test", "test", "TEST"); | ||
configuration.publishConfig("test", "test", "TEST"); | ||
|
||
|
||
processedEvent.set(false); | ||
File keyFile = configuration.configFile(KEY, DEFAULT_GROUP); | ||
FileUtils.deleteQuietly(keyFile); | ||
while (!processedEvent.get()) { | ||
Thread.sleep(1 * 1000L); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.