Fix ModuleEnvironment#getDynamicGlobalConfiguration (#13781)

* Update ModuleEnvironment#getDynamicGlobalConfiguration

* add unit test

* update
This commit is contained in:
jiangyuan 2024-02-29 15:25:22 +08:00 committed by GitHub
parent 17b75a7895
commit 428ca27a94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 13 deletions

View File

@ -29,8 +29,6 @@ import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_UNEXPECTED_EXCEPTION;
public class ModuleEnvironment extends Environment implements ModuleExt {
// delegate
@ -94,19 +92,13 @@ public class ModuleEnvironment extends Environment implements ModuleExt {
@Override
public Configuration getDynamicGlobalConfiguration() {
if (dynamicConfiguration == null) {
return applicationDelegate.getDynamicGlobalConfiguration();
CompositeConfiguration configuration = new CompositeConfiguration();
configuration.addConfiguration(applicationDelegate.getDynamicGlobalConfiguration());
configuration.addConfiguration(orderedPropertiesConfiguration);
return configuration;
}
if (dynamicGlobalConfiguration == null) {
if (dynamicConfiguration == null) {
if (logger.isWarnEnabled()) {
logger.warn(
COMMON_UNEXPECTED_EXCEPTION,
"",
"",
"dynamicConfiguration is null , return globalConfiguration.");
}
return getConfiguration();
}
dynamicGlobalConfiguration = new CompositeConfiguration();
dynamicGlobalConfiguration.addConfiguration(dynamicConfiguration);
dynamicGlobalConfiguration.addConfiguration(getConfiguration());

View File

@ -17,6 +17,8 @@
package org.apache.dubbo.common.config;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ModuleModel;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@ -32,4 +34,18 @@ class OrderedPropertiesConfigurationTest {
ApplicationModel.defaultModel().getDefaultModule());
Assertions.assertEquals("999", configuration.getInternalProperty("testKey"));
}
@Test
void testGetPropertyFromOrderedPropertiesConfiguration() {
FrameworkModel frameworkModel = new FrameworkModel();
ApplicationModel applicationModel = frameworkModel.newApplication();
ModuleModel moduleModel = applicationModel.newModule();
ModuleEnvironment moduleEnvironment = moduleModel.modelEnvironment();
Configuration configuration = moduleEnvironment.getDynamicGlobalConfiguration();
// MockOrderedPropertiesProvider2 initProperties
Assertions.assertEquals("999", configuration.getString("testKey"));
}
}