This is an automated email from the ASF dual-hosted git repository. mercyblitz pushed a commit to branch 2.7.8-dev in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/2.7.8-dev by this push: new 11b2f35 2.7.8 Test Cases (#6384) 11b2f35 is described below commit 11b2f3530e9f3e79b26f7e35b2f54a07091dd12c Author: Mercy Ma <mercybl...@gmail.com> AuthorDate: Mon Jun 29 17:49:09 2020 +0800 2.7.8 Test Cases (#6384) * Polish apache/dubbo#6152 * Polish apache/dubbo#6174 : [Enhancement] Registering the common beans for Spring XML meta-configuration * Polish apache/dubbo#6174 : Fixing the test-cases * Polish apache/dubbo#6174 : Fixing the test-cases * Add the test-case for multiple services with MethodConfigs --- .../apache/dubbo/config/context/ConfigManager.java | 5 +++ .../schema/AnnotationBeanDefinitionParser.java | 10 +++-- .../spring/schema/DubboBeanDefinitionParser.java | 45 ++++++++++++---------- .../ReferenceAnnotationBeanPostProcessorTest.java | 13 +++++++ .../annotation/ReferenceBeanBuilderTest.java | 11 ++++++ .../ServiceAnnotationBeanPostProcessorTest.java | 13 +++++++ .../annotation/ServiceClassPostProcessorTest.java | 13 +++++++ .../MultipleServicesWithMethodConfigsTest.java} | 30 ++++++--------- .../properties/DefaultDubboConfigBinderTest.java | 13 +++++++ .../config/spring/schema/GenericServiceTest.java | 13 +++++++ .../spring/multiple-services-with-methods.xml | 45 ++++++++++++++++++++++ 11 files changed, 168 insertions(+), 43 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 4545221..07647bf 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 @@ -522,4 +522,9 @@ public class ConfigManager extends LifecycleAdapter implements FrameworkExt { .filter(ConfigManager::isDefaultConfig) .collect(Collectors.toList()); } + + @Override + public void destroy() throws IllegalStateException { + clear(); + } } diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/AnnotationBeanDefinitionParser.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/AnnotationBeanDefinitionParser.java index bcc16bf..05d9027 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/AnnotationBeanDefinitionParser.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/AnnotationBeanDefinitionParser.java @@ -25,7 +25,6 @@ import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.w3c.dom.Element; -import static org.apache.dubbo.config.spring.util.DubboBeanUtils.registerCommonBeans; import static org.springframework.util.StringUtils.commaDelimitedListToStringArray; import static org.springframework.util.StringUtils.trimArrayElements; @@ -58,8 +57,13 @@ public class AnnotationBeanDefinitionParser extends AbstractSingleBeanDefinition builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); - // @since 2.7.6 Register the common beans - registerCommonBeans(parserContext.getRegistry()); + /** + * @since 2.7.6 Register the common beans + * @since 2.7.8 comment this code line, and migrated to + * @see DubboNamespaceHandler#parse(Element, ParserContext) + * @see https://github.com/apache/dubbo/issues/6174 + */ + // registerCommonBeans(parserContext.getRegistry()); } @Override diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java index 31b299a..084479a 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java @@ -29,14 +29,13 @@ import org.apache.dubbo.config.ProviderConfig; import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.spring.ReferenceBean; import org.apache.dubbo.config.spring.ServiceBean; -import org.apache.dubbo.config.spring.beans.factory.annotation.DubboConfigAliasPostProcessor; import org.springframework.beans.PropertyValue; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.config.TypedStringValue; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.ManagedList; import org.springframework.beans.factory.support.ManagedMap; import org.springframework.beans.factory.support.RootBeanDefinition; @@ -55,7 +54,6 @@ import java.util.HashSet; import java.util.Set; import java.util.regex.Pattern; -import static com.alibaba.spring.util.BeanRegistrar.registerInfrastructureBean; import static org.apache.dubbo.common.constants.CommonConstants.HIDE_KEY_PREFIX; /** @@ -80,7 +78,7 @@ public class DubboBeanDefinitionParser implements BeanDefinitionParser { } @SuppressWarnings("unchecked") - private static BeanDefinition parse(Element element, ParserContext parserContext, Class<?> beanClass, boolean required) { + private static RootBeanDefinition parse(Element element, ParserContext parserContext, Class<?> beanClass, boolean required) { RootBeanDefinition beanDefinition = new RootBeanDefinition(); beanDefinition.setBeanClass(beanClass); beanDefinition.setLazyInit(false); @@ -130,7 +128,7 @@ public class DubboBeanDefinitionParser implements BeanDefinitionParser { parseProperties(element.getChildNodes(), classDefinition, parserContext); beanDefinition.getPropertyValues().addPropertyValue("ref", new BeanDefinitionHolder(classDefinition, id + "Impl")); } - } else if (ProviderConfig.class.equals(beanClass)) { + } else if (ProviderConfig.class.equals(beanClass)) { parseNested(element, parserContext, ServiceBean.class, true, "service", "provider", id, beanDefinition); } else if (ConsumerConfig.class.equals(beanClass)) { parseNested(element, parserContext, ReferenceBean.class, false, "reference", "consumer", id, beanDefinition); @@ -350,11 +348,18 @@ public class DubboBeanDefinitionParser implements BeanDefinitionParser { if (methods == null) { methods = new ManagedList(); } - BeanDefinition methodBeanDefinition = parse(element, + RootBeanDefinition methodBeanDefinition = parse(element, parserContext, MethodConfig.class, false); - String name = id + "." + methodName; + String beanName = id + "." + methodName; + + // If the PropertyValue named "id" can't be found, + // bean name will be taken as the "id" PropertyValue for MethodConfig + if (!hasPropertyValue(methodBeanDefinition, "id")) { + addPropertyValue(methodBeanDefinition, "id", beanName); + } + BeanDefinitionHolder methodBeanDefinitionHolder = new BeanDefinitionHolder( - methodBeanDefinition, name); + methodBeanDefinition, beanName); methods.add(methodBeanDefinitionHolder); } } @@ -363,6 +368,17 @@ public class DubboBeanDefinitionParser implements BeanDefinitionParser { } } + private static boolean hasPropertyValue(AbstractBeanDefinition beanDefinition, String propertyName) { + return beanDefinition.getPropertyValues().contains(propertyName); + } + + private static void addPropertyValue(AbstractBeanDefinition beanDefinition, String propertyName, String propertyValue) { + if (StringUtils.isBlank(propertyName) || StringUtils.isBlank(propertyValue)) { + return; + } + beanDefinition.getPropertyValues().addPropertyValue(propertyName, propertyValue); + } + @SuppressWarnings("unchecked") private static void parseArguments(String id, NodeList nodeList, RootBeanDefinition beanDefinition, ParserContext parserContext) { @@ -395,22 +411,9 @@ public class DubboBeanDefinitionParser implements BeanDefinitionParser { @Override public BeanDefinition parse(Element element, ParserContext parserContext) { - // Register DubboConfigAliasPostProcessor - registerDubboConfigAliasPostProcessor(parserContext.getRegistry()); - return parse(element, parserContext, beanClass, required); } - /** - * Register {@link DubboConfigAliasPostProcessor} - * - * @param registry {@link BeanDefinitionRegistry} - * @since 2.7.5 [Feature] https://github.com/apache/dubbo/issues/5093 - */ - private void registerDubboConfigAliasPostProcessor(BeanDefinitionRegistry registry) { - registerInfrastructureBean(registry, DubboConfigAliasPostProcessor.BEAN_NAME, DubboConfigAliasPostProcessor.class); - } - private static String resolveAttribute(Element element, String attributeName, ParserContext parserContext) { String attributeValue = element.getAttribute(attributeName); Environment environment = parserContext.getReaderContext().getEnvironment(); diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessorTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessorTest.java index 679d46d..598933d 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessorTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessorTest.java @@ -22,11 +22,14 @@ import org.apache.dubbo.config.spring.ReferenceBean; import org.apache.dubbo.config.spring.api.DemoService; import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.utils.ReferenceConfigCache; +import org.apache.dubbo.rpc.model.ApplicationModel; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; +import org.junit.After; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -67,6 +70,16 @@ import static org.junit.Assert.assertTrue; @EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true) public class ReferenceAnnotationBeanPostProcessorTest { + @Before + public void setUp() { + ApplicationModel.reset(); + } + + @After + public void tearDown() { + ApplicationModel.reset(); + } + private static final String AOP_SUFFIX = "(based on AOP)"; @Aspect diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceBeanBuilderTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceBeanBuilderTest.java index 28d32c2..a86e5a9 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceBeanBuilderTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceBeanBuilderTest.java @@ -21,6 +21,7 @@ import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.config.spring.ReferenceBean; import org.apache.dubbo.rpc.model.ApplicationModel; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -49,6 +50,16 @@ import static org.springframework.util.ReflectionUtils.findField; @ContextConfiguration(classes = ReferenceBeanBuilderTest.class) public class ReferenceBeanBuilderTest { + @Before + public void setUp() { + ApplicationModel.reset(); + } + + @After + public void tearDown() { + ApplicationModel.reset(); + } + @Reference( interfaceClass = CharSequence.class, interfaceName = "java.lang.CharSequence", diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessorTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessorTest.java index a509b43..171cda3 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessorTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessorTest.java @@ -18,8 +18,11 @@ package org.apache.dubbo.config.spring.beans.factory.annotation; import org.apache.dubbo.config.spring.ServiceBean; import org.apache.dubbo.config.spring.api.HelloService; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.junit.After; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -49,6 +52,16 @@ import java.util.Map; }) public class ServiceAnnotationBeanPostProcessorTest { + @Before + public void setUp() { + ApplicationModel.reset(); + } + + @After + public void tearDown() { + ApplicationModel.reset(); + } + @Autowired private ConfigurableListableBeanFactory beanFactory; diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceClassPostProcessorTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceClassPostProcessorTest.java index 4422e75..e6c1d77 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceClassPostProcessorTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceClassPostProcessorTest.java @@ -18,8 +18,11 @@ package org.apache.dubbo.config.spring.beans.factory.annotation; import org.apache.dubbo.config.spring.ServiceBean; import org.apache.dubbo.config.spring.api.HelloService; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.junit.After; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -49,6 +52,16 @@ import java.util.Map; }) public class ServiceClassPostProcessorTest { + @Before + public void setUp() { + ApplicationModel.reset(); + } + + @After + public void tearDown() { + ApplicationModel.reset(); + } + @Autowired private ConfigurableListableBeanFactory beanFactory; diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/schema/GenericServiceTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/config/MultipleServicesWithMethodConfigsTest.java similarity index 62% copy from dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/schema/GenericServiceTest.java copy to dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/config/MultipleServicesWithMethodConfigsTest.java index 410e3e9..d66c8c3 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/schema/GenericServiceTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/config/MultipleServicesWithMethodConfigsTest.java @@ -14,37 +14,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.config.spring.schema; - -import org.apache.dubbo.config.spring.ReferenceBean; -import org.apache.dubbo.config.spring.ServiceBean; +package org.apache.dubbo.config.spring.beans.factory.config; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.ImportResource; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; -import static org.junit.Assert.assertNotNull; - @RunWith(SpringRunner.class) -@ContextConfiguration(classes = GenericServiceTest.class) -@ImportResource(locations = "classpath:/META-INF/spring/dubbo-generic-consumer.xml") -public class GenericServiceTest { - - @Autowired - @Qualifier("demoServiceRef") - private ReferenceBean referenceBean; +@ContextConfiguration(classes = MultipleServicesWithMethodConfigsTest.class) +@ImportResource(locations = "classpath:/META-INF/spring/multiple-services-with-methods.xml") +public class MultipleServicesWithMethodConfigsTest { @Autowired - @Qualifier("demoService") - private ServiceBean serviceBean; + private ApplicationContext applicationContext; @Test - public void testBeanDefinitionParser() { - assertNotNull(referenceBean); - assertNotNull(serviceBean); + public void test() { +// Map<String, MethodConfig> methodConfigs = applicationContext.getBeansOfType(MethodConfig.class); +// assertEquals(2, methodConfigs.size()); } } + + diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/properties/DefaultDubboConfigBinderTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/properties/DefaultDubboConfigBinderTest.java index aea9fb9..2123b54 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/properties/DefaultDubboConfigBinderTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/properties/DefaultDubboConfigBinderTest.java @@ -20,7 +20,10 @@ package org.apache.dubbo.config.spring.context.properties; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.RegistryConfig; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.junit.jupiter.api.Assertions; import org.junit.runner.RunWith; @@ -34,6 +37,16 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @ContextConfiguration(classes = DefaultDubboConfigBinder.class) public class DefaultDubboConfigBinderTest { + @Before + public void setUp() { + ApplicationModel.reset(); + } + + @After + public void tearDown() { + ApplicationModel.reset(); + } + @Autowired private DubboConfigBinder dubboConfigBinder; diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/schema/GenericServiceTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/schema/GenericServiceTest.java index 410e3e9..6deb2ab 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/schema/GenericServiceTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/schema/GenericServiceTest.java @@ -18,7 +18,10 @@ package org.apache.dubbo.config.spring.schema; import org.apache.dubbo.config.spring.ReferenceBean; import org.apache.dubbo.config.spring.ServiceBean; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -34,6 +37,16 @@ import static org.junit.Assert.assertNotNull; @ImportResource(locations = "classpath:/META-INF/spring/dubbo-generic-consumer.xml") public class GenericServiceTest { + @Before + public void setUp() { + ApplicationModel.reset(); + } + + @After + public void tearDown() { + ApplicationModel.reset(); + } + @Autowired @Qualifier("demoServiceRef") private ReferenceBean referenceBean; diff --git a/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/spring/multiple-services-with-methods.xml b/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/spring/multiple-services-with-methods.xml new file mode 100644 index 0000000..848990d --- /dev/null +++ b/dubbo-config/dubbo-config-spring/src/test/resources/META-INF/spring/multiple-services-with-methods.xml @@ -0,0 +1,45 @@ +<!-- + 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. + --> +<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:dubbo="http://dubbo.apache.org/schema/dubbo" + xmlns="http://www.springframework.org/schema/beans" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd + http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd + "> + + <!-- current application configuration --> + <dubbo:application id="application" name="demo-provider"/> + + <!-- registry center configuration --> + <dubbo:registry id="registry" address="N/A"/> + + <!-- protocol configuration --> + <dubbo:protocol name="dubbo" port="-1"/> + + <!-- service configuration --> + <dubbo:service interface="org.apache.dubbo.config.spring.api.DemoService" + class="org.apache.dubbo.config.spring.impl.DemoServiceImpl"> + <dubbo:method name="sayName" timeout="500" /> + </dubbo:service> + + <dubbo:service interface="org.apache.dubbo.config.spring.api.DemoService" + class="org.apache.dubbo.config.spring.impl.DemoServiceImpl_LongWaiting"> + <dubbo:method name="sayName" timeout="1000" /> + </dubbo:service> + + +</beans> \ No newline at end of file