This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.1
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.1 by this push:
new 55cb82454b remind user to add qos dependency (#10683)
55cb82454b is described below
commit 55cb82454b3c565361bd8850085858409a6c0f2d
Author: pandaapo <[email protected]>
AuthorDate: Mon Oct 24 11:13:25 2022 +0800
remind user to add qos dependency (#10683)
---
.../apache/dubbo/config/context/ConfigManager.java | 8 +++
.../dubbo/config/utils/ConfigValidationUtils.java | 14 ++++-
.../config/utils/ConfigValidationUtilsTest.java | 67 +++++++++++++++++++++-
.../dubbo-demo-xml/dubbo-demo-xml-provider/pom.xml | 4 ++
.../src/main/resources/dubbo.properties | 4 +-
...aultPropertiesEnvironmentPostProcessorTest.java | 12 ++--
...oDefaultPropertiesEnvironmentPostProcessor.java | 2 +-
...aultPropertiesEnvironmentPostProcessorTest.java | 12 ++--
8 files changed, 107 insertions(+), 16 deletions(-)
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/config/context/ConfigManager.java
b/dubbo-common/src/main/java/org/apache/dubbo/config/context/ConfigManager.java
index e599eb75cf..140f9b1a3f 100644
---
a/dubbo-common/src/main/java/org/apache/dubbo/config/context/ConfigManager.java
+++
b/dubbo-common/src/main/java/org/apache/dubbo/config/context/ConfigManager.java
@@ -295,6 +295,14 @@ public class ConfigManager extends AbstractConfigManager
implements ApplicationE
}
protocolPortMap.put(port, protocol);
}
+
+ // Log the current configurations.
+ logger.info("The current configurations or effective configurations
are as follows:");
+ for (Class<? extends AbstractConfig> configType : multipleConfigTypes)
{
+ getConfigs(configType).stream().forEach((config) -> {
+ logger.info(config.toString());
+ });
+ }
}
public ConfigMode getConfigMode() {
diff --git
a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java
b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java
index 17c73636d3..a716800abb 100644
---
a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java
+++
b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java
@@ -26,6 +26,7 @@ import org.apache.dubbo.common.serialize.Serialization;
import org.apache.dubbo.common.status.StatusChecker;
import org.apache.dubbo.common.status.reporter.FrameworkStatusReportService;
import org.apache.dubbo.common.threadpool.ThreadPool;
+import org.apache.dubbo.common.utils.ClassUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.ConfigUtils;
import org.apache.dubbo.common.utils.NetUtils;
@@ -144,7 +145,7 @@ import static org.apache.dubbo.rpc.Constants.TOKEN_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY;
public class ConfigValidationUtils {
- private static final ErrorTypeAwareLogger logger =
LoggerFactory.getErrorTypeAwareLogger(ConfigValidationUtils.class);
+ private static ErrorTypeAwareLogger logger =
LoggerFactory.getErrorTypeAwareLogger(ConfigValidationUtils.class);
/**
* The maximum length of a <b>parameter's value</b>
*/
@@ -489,6 +490,17 @@ public class ConfigValidationUtils {
checkName(ARCHITECTURE, config.getArchitecture());
checkName(ENVIRONMENT, config.getEnvironment());
checkParameterName(config.getParameters());
+ checkQosDependency(config);
+ }
+
+ private static void checkQosDependency(ApplicationConfig config) {
+ if (!Boolean.FALSE.equals(config.getQosEnable())) {
+ try {
+
ClassUtils.forName("org.apache.dubbo.qos.protocol.QosProtocolWrapper");
+ } catch (ClassNotFoundException e) {
+ logger.warn("No QosProtocolWrapper class was found. Please
check the dependency of dubbo-qos whether was imported correctly.", e);
+ }
+ }
}
public static void validateModuleConfig(ModuleConfig config) {
diff --git
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/ConfigValidationUtilsTest.java
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/ConfigValidationUtilsTest.java
index 8112d5c9dc..03d4ce58c4 100644
---
a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/ConfigValidationUtilsTest.java
+++
b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/ConfigValidationUtilsTest.java
@@ -16,14 +16,27 @@
*/
package org.apache.dubbo.config.utils;
+import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.config.AbstractInterfaceConfig;
+import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.MetadataReportConfig;
import org.apache.dubbo.config.api.Greeting;
import org.apache.dubbo.config.mock.GreetingMock1;
import org.apache.dubbo.config.mock.GreetingMock2;
-
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
public class ConfigValidationUtilsTest {
@@ -82,6 +95,58 @@ public class ConfigValidationUtilsTest {
});
}
+ @Test
+ public void testValidateApplicationConfig() throws Exception {
+ try (MockedStatic<ConfigValidationUtils> mockedStatic =
Mockito.mockStatic(ConfigValidationUtils.class);) {
+ mockedStatic.when(() ->
ConfigValidationUtils.validateApplicationConfig(any())).thenCallRealMethod();
+ ApplicationConfig config = new ApplicationConfig();
+ Assertions.assertThrows(IllegalStateException.class,() -> {
+ ConfigValidationUtils.validateApplicationConfig(config);
+ });
+
+ config.setName("testName");
+ config.setOwner("testOwner");
+ config.setOrganization("testOrg");
+ config.setArchitecture("testArchitecture");
+ config.setEnvironment("test");
+ Map<String, String> map = new HashMap();
+ map.put("k1", "v1");
+ map.put("k2", "v2");
+ config.setParameters(map);
+ ConfigValidationUtils.validateApplicationConfig(config);
+ mockedStatic.verify(() -> {
+ ConfigValidationUtils.checkName(any(), any());
+ }, times(4));
+ mockedStatic.verify(() -> {
+ ConfigValidationUtils.checkMultiName(any(), any());
+ }, times(1));
+ mockedStatic.verify(() -> {
+ ConfigValidationUtils.checkParameterName(any());
+ }, times(1));
+ }
+ }
+
+ @Test
+ public void testCheckQosInApplicationConfig() throws Exception {
+ ConfigValidationUtils mock = Mockito.mock(ConfigValidationUtils.class);
+ ErrorTypeAwareLogger loggerMock =
Mockito.mock(ErrorTypeAwareLogger.class);
+ injectField(mock.getClass().getDeclaredField("logger"), loggerMock);
+ ApplicationConfig config = new ApplicationConfig();
+ config.setName("testName");
+ config.setQosEnable(false);
+ mock.validateApplicationConfig(config);
+ verify(loggerMock, never()).warn(any(), any());
+
+ config.setQosEnable(true);
+ mock.validateApplicationConfig(config);
+ verify(loggerMock).warn(eq("No QosProtocolWrapper class was found.
Please check the dependency of dubbo-qos whether was imported correctly."),
any());
+ }
+
+ private void injectField(Field field, Object newValue) throws Exception {
+ field.setAccessible(true);
+ field.set(null, newValue);
+ }
+
public static class InterfaceConfig extends AbstractInterfaceConfig {
}
diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/pom.xml
b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/pom.xml
index 4237066e30..f20ae0eafd 100644
--- a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/pom.xml
+++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/pom.xml
@@ -115,5 +115,9 @@
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-triple</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-qos</artifactId>
+ </dependency>
</dependencies>
</project>
diff --git
a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/resources/dubbo.properties
b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/resources/dubbo.properties
index ad602baa94..dde68cbdf0 100644
---
a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/resources/dubbo.properties
+++
b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/resources/dubbo.properties
@@ -1 +1,3 @@
-dubbo.application.qos.port=22222
+dubbo.application.qos-enable=true
+dubbo.application.qos-port=22222
+dubbo.application.qos-accept-foreign-ip=true
diff --git
a/dubbo-spring-boot/dubbo-spring-boot-autoconfigure/src/test/java/org/apache/dubbo/spring/boot/env/DubboDefaultPropertiesEnvironmentPostProcessorTest.java
b/dubbo-spring-boot/dubbo-spring-boot-autoconfigure/src/test/java/org/apache/dubbo/spring/boot/env/DubboDefaultPropertiesEnvironmentPostProcessorTest.java
index 9e2de9a822..bde4c383a7 100644
---
a/dubbo-spring-boot/dubbo-spring-boot-autoconfigure/src/test/java/org/apache/dubbo/spring/boot/env/DubboDefaultPropertiesEnvironmentPostProcessorTest.java
+++
b/dubbo-spring-boot/dubbo-spring-boot-autoconfigure/src/test/java/org/apache/dubbo/spring/boot/env/DubboDefaultPropertiesEnvironmentPostProcessorTest.java
@@ -53,7 +53,7 @@ public class
DubboDefaultPropertiesEnvironmentPostProcessorTest {
PropertySource defaultPropertySource =
propertySources.get("defaultProperties");
Assert.assertNotNull(defaultPropertySource);
Assert.assertEquals("true",
defaultPropertySource.getProperty("dubbo.config.multiple"));
- Assert.assertEquals("false",
defaultPropertySource.getProperty("dubbo.application.qos-enable"));
+ Assert.assertEquals("true",
defaultPropertySource.getProperty("dubbo.application.qos-enable"));
// Case 2 : Only set property "spring.application.name"
environment.setProperty("spring.application.name",
"demo-dubbo-application");
@@ -63,7 +63,7 @@ public class
DubboDefaultPropertiesEnvironmentPostProcessorTest {
Assert.assertEquals("demo-dubbo-application", dubboApplicationName);
// Case 3 : Only set property "dubbo.application.name"
- // Rest environment
+ // Reset environment
environment = new MockEnvironment();
propertySources = environment.getPropertySources();
environment.setProperty("dubbo.application.name",
"demo-dubbo-application");
@@ -74,7 +74,7 @@ public class
DubboDefaultPropertiesEnvironmentPostProcessorTest {
Assert.assertEquals("demo-dubbo-application", dubboApplicationName);
// Case 4 : If "defaultProperties" PropertySource is present in
PropertySources
- // Rest environment
+ // Reset environment
environment = new MockEnvironment();
propertySources = environment.getPropertySources();
propertySources.addLast(new MapPropertySource("defaultProperties", new
HashMap<String, Object>()));
@@ -84,14 +84,14 @@ public class
DubboDefaultPropertiesEnvironmentPostProcessorTest {
dubboApplicationName =
defaultPropertySource.getProperty("dubbo.application.name");
Assert.assertEquals("demo-dubbo-application", dubboApplicationName);
- // Case 5 : Rest dubbo.config.multiple and dubbo.application.qos-enable
+ // Case 5 : Reset dubbo.config.multiple and
dubbo.application.qos-enable
environment = new MockEnvironment();
propertySources = environment.getPropertySources();
propertySources.addLast(new MapPropertySource("defaultProperties", new
HashMap<String, Object>()));
environment.setProperty("dubbo.config.multiple", "false");
- environment.setProperty("dubbo.application.qos-enable", "true");
+ environment.setProperty("dubbo.application.qos-enable", "false");
instance.postProcessEnvironment(environment, springApplication);
Assert.assertEquals("false",
environment.getProperty("dubbo.config.multiple"));
- Assert.assertEquals("true",
environment.getProperty("dubbo.application.qos-enable"));
+ Assert.assertEquals("false",
environment.getProperty("dubbo.application.qos-enable"));
}
}
diff --git
a/dubbo-spring-boot/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/env/DubboDefaultPropertiesEnvironmentPostProcessor.java
b/dubbo-spring-boot/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/env/DubboDefaultPropertiesEnvironmentPostProcessor.java
index 9c3ff97031..44a0ae59de 100644
---
a/dubbo-spring-boot/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/env/DubboDefaultPropertiesEnvironmentPostProcessor.java
+++
b/dubbo-spring-boot/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/env/DubboDefaultPropertiesEnvironmentPostProcessor.java
@@ -91,7 +91,7 @@ public class DubboDefaultPropertiesEnvironmentPostProcessor
implements Environme
}
private void setDubboApplicationQosEnableProperty(Map<String, Object>
defaultProperties) {
- defaultProperties.put(DUBBO_APPLICATION_QOS_ENABLE_PROPERTY,
Boolean.FALSE.toString());
+ defaultProperties.put(DUBBO_APPLICATION_QOS_ENABLE_PROPERTY,
Boolean.TRUE.toString());
}
/**
diff --git
a/dubbo-spring-boot/dubbo-spring-boot-compatible/autoconfigure/src/test/java/org/apache/dubbo/spring/boot/env/DubboDefaultPropertiesEnvironmentPostProcessorTest.java
b/dubbo-spring-boot/dubbo-spring-boot-compatible/autoconfigure/src/test/java/org/apache/dubbo/spring/boot/env/DubboDefaultPropertiesEnvironmentPostProcessorTest.java
index 9e2de9a822..bde4c383a7 100644
---
a/dubbo-spring-boot/dubbo-spring-boot-compatible/autoconfigure/src/test/java/org/apache/dubbo/spring/boot/env/DubboDefaultPropertiesEnvironmentPostProcessorTest.java
+++
b/dubbo-spring-boot/dubbo-spring-boot-compatible/autoconfigure/src/test/java/org/apache/dubbo/spring/boot/env/DubboDefaultPropertiesEnvironmentPostProcessorTest.java
@@ -53,7 +53,7 @@ public class
DubboDefaultPropertiesEnvironmentPostProcessorTest {
PropertySource defaultPropertySource =
propertySources.get("defaultProperties");
Assert.assertNotNull(defaultPropertySource);
Assert.assertEquals("true",
defaultPropertySource.getProperty("dubbo.config.multiple"));
- Assert.assertEquals("false",
defaultPropertySource.getProperty("dubbo.application.qos-enable"));
+ Assert.assertEquals("true",
defaultPropertySource.getProperty("dubbo.application.qos-enable"));
// Case 2 : Only set property "spring.application.name"
environment.setProperty("spring.application.name",
"demo-dubbo-application");
@@ -63,7 +63,7 @@ public class
DubboDefaultPropertiesEnvironmentPostProcessorTest {
Assert.assertEquals("demo-dubbo-application", dubboApplicationName);
// Case 3 : Only set property "dubbo.application.name"
- // Rest environment
+ // Reset environment
environment = new MockEnvironment();
propertySources = environment.getPropertySources();
environment.setProperty("dubbo.application.name",
"demo-dubbo-application");
@@ -74,7 +74,7 @@ public class
DubboDefaultPropertiesEnvironmentPostProcessorTest {
Assert.assertEquals("demo-dubbo-application", dubboApplicationName);
// Case 4 : If "defaultProperties" PropertySource is present in
PropertySources
- // Rest environment
+ // Reset environment
environment = new MockEnvironment();
propertySources = environment.getPropertySources();
propertySources.addLast(new MapPropertySource("defaultProperties", new
HashMap<String, Object>()));
@@ -84,14 +84,14 @@ public class
DubboDefaultPropertiesEnvironmentPostProcessorTest {
dubboApplicationName =
defaultPropertySource.getProperty("dubbo.application.name");
Assert.assertEquals("demo-dubbo-application", dubboApplicationName);
- // Case 5 : Rest dubbo.config.multiple and dubbo.application.qos-enable
+ // Case 5 : Reset dubbo.config.multiple and
dubbo.application.qos-enable
environment = new MockEnvironment();
propertySources = environment.getPropertySources();
propertySources.addLast(new MapPropertySource("defaultProperties", new
HashMap<String, Object>()));
environment.setProperty("dubbo.config.multiple", "false");
- environment.setProperty("dubbo.application.qos-enable", "true");
+ environment.setProperty("dubbo.application.qos-enable", "false");
instance.postProcessEnvironment(environment, springApplication);
Assert.assertEquals("false",
environment.getProperty("dubbo.config.multiple"));
- Assert.assertEquals("true",
environment.getProperty("dubbo.application.qos-enable"));
+ Assert.assertEquals("false",
environment.getProperty("dubbo.application.qos-enable"));
}
}