Skip to content

Commit

Permalink
Bug fixes (#5351)
Browse files Browse the repository at this point in the history
* 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
mercyblitz committed Nov 19, 2019
1 parent 11a1750 commit 4506648
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public class DynamicConfigurationFactoryTest {
public void testDefaultExtension() {
DynamicConfigurationFactory factory = getExtensionLoader(DynamicConfigurationFactory.class).getDefaultExtension();
assertEquals(NopDynamicConfigurationFactory.class, factory.getClass());
assertEquals(factory, getExtensionLoader(DynamicConfigurationFactory.class).getExtension("nop"));
assertEquals(NopDynamicConfigurationFactory.class, getExtensionLoader(DynamicConfigurationFactory.class).getExtension("nop").getClass());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
*/
package org.apache.dubbo.common.config.configcenter.file;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory;
import org.apache.dubbo.common.config.configcenter.nop.NopDynamicConfiguration;

import org.junit.jupiter.api.Test;

Expand All @@ -33,9 +31,6 @@ public class FileSystemDynamicConfigurationFactoryTest {

@Test
public void testGetFactory() {
DynamicConfigurationFactory factory = DynamicConfigurationFactory.getDynamicConfigurationFactory("not-exists");
assertEquals(factory, DynamicConfigurationFactory.getDynamicConfigurationFactory("nop"));
assertEquals(factory.getDynamicConfiguration(URL.valueOf("dummy")), factory.getDynamicConfiguration(URL.valueOf("dummy")));
assertEquals(NopDynamicConfiguration.class, factory.getDynamicConfiguration(URL.valueOf("dummy")).getClass());
assertEquals(FileSystemDynamicConfigurationFactory.class, DynamicConfigurationFactory.getDynamicConfigurationFactory("file").getClass());
}
}
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

import java.util.EmptyStackException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class StackTest {
@Test
Expand Down
15 changes: 15 additions & 0 deletions dubbo-config/dubbo-config-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,20 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-configcenter-nacos</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-configcenter-consul</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>


</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static void main(String[] args) {
DubboBootstrap.getInstance()
.application(applicationConfig)
// Zookeeper in service registry type
.registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry-type=service"))
.registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry-type=service").useAsConfigCenter(true))
// Nacos
// .registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry.type=service"))
// .registry(RegistryBuilder.newBuilder().address("etcd3://127.0.0.1:2379?registry.type=service").build())
Expand Down
Loading

0 comments on commit 4506648

Please sign in to comment.