From e7ce16d9923326605d16677c24a2c480c7ee30c4 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 8 Aug 2019 10:42:14 +0800 Subject: [PATCH] Dubbo Cloud Native (#4764) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Polish apache/dubbo#4542 : [Enhancement] Adapt the Java standard Event/Listener mechanism * Polish apache/dubbo#4541 : [Feature] Add local File System DynamicConfigurationFactory‘s extension * Polish apache#4541 : Bugfix * Polish apache/dubbo#4541 : Optimization * Polish apache/dubbo#4541 : Add the compatibility for PollingWatchService on the some platforms * Polish apache/dubbo#4541 : Add delay publish without ThreadPoolExecutor * Polish apache/dubbo#4541 : Refactor the extension name * Polish apache/dubbo#4541 : Add remove ops * Polish apache/dubbo#4541 : Add testable constructor * Polish apache/dubbo#4541 : Add getConfigGroups method * Polish apache/dubbo#4610 : [Refactor] Refactor the bootstrap module * Polish apache/dubbo#4541 : Fix the nulling URL issue * Polish apache/dubbo#4622 : [Refactor] Refactor ConfigManager * Polish apache/dubbo#4622 : [Refactor] Refactor ConfigManager * Polish apache/dubbo#4622 : Support multiple configcenters * Polish apache/dubbo#4671 : ServiceNameMapping will not map the group, version and protocol * update referenceCount log (#4683) Add comments to support multiple shared connections * Polish /apache/dubbo#4687 : Remove the duplicated test code in dubbo-config-spring (#4688) * #4685 修改代码if判断false问题 if (hasException == false)修改成if (!hasException) (#4695) * Fixed Service annotation method parameters are not in effect (#4598) * keep demo simple, and switch to use zookeeper as registry center (#4705) * keep demo simple, and switch to use zookeeper as registry center * remove comment * @Reference auto-wires the instance of generic interface #4594 (#4677) * try to shorten maven output to make travis build pass (#4710) * use CountDownLatch to check zk registry if establish connection (#4589) * Minor change * Rename the extension name of WritableMetadataService * Polish apache/dubbo#4759 : [Refactor] Change the signature of methods of MetadataService #4759 * Merge remote-tracking branch 'upstream/master' into dubbo-cloud-native # Conflicts: # dubbo-all/pom.xml # dubbo-bom/pom.xml # dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java # dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java # dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConfigCenterConfig.java # dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java # dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryConfig.java # dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java # dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java # dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/DynamicConfiguration.java # dubbo-configcenter/dubbo-configcenter-api/src/test/java/org/apache/dubbo/configcenter/mock/MockDynamicConfiguration.java # dubbo-configcenter/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfiguration.java # dubbo-configcenter/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java # dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java # dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java # dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java # dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java # dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifier.java # dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReport.java # dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifierTest.java # dubbo-metadata/dubbo-metadata-definition-protobuf/src/main/java/org/apache/dubbo/metadata/definition/protobuf/ProtobufTypeBuilder.java # dubbo-metadata/dubbo-metadata-definition-protobuf/src/test/java/org/apache/dubbo/metadata/definition/protobuf/ProtobufTypeBuilderTest.java # dubbo-metadata/pom.xml # dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java # dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java # dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistryFactory.java # dubbo-rpc/dubbo-rpc-xml/src/main/java/org/apache/dubbo/xml/rpc/protocol/xmlrpc/XmlRpcProtocol.java * Polish apache/dubbo#3984 : Add the implementation of Page getInstances(String serviceName, int offset, int pageSize, boolean healthyOnly) * Code merge --- .travis.yml | 2 +- dubbo-bom/pom.xml | 1 + dubbo-bootstrap/pom.xml | 40 +--- .../dubbo/bootstrap/DubboBootstrap.java | 50 +++-- .../DubboServiceConsumerBootstrap.java | 1 - .../DubboServiceProviderBootstrap.java | 1 - dubbo-cluster/pom.xml | 1 + .../condition/config/ListenableRouter.java | 2 +- .../rpc/cluster/router/tag/TagRouter.java | 2 +- .../support/wrapper/MockClusterInvoker.java | 2 +- .../rpc/cluster/router/TagRouterTest.java | 5 +- .../support/AbstractClusterInvokerTest.java | 2 +- dubbo-common/pom.xml | 1 + .../dubbo/common/config/Configuration.java | 2 - .../AbstractDynamicConfiguration.java | 182 ++++++++++++++++++ .../configcenter/DynamicConfiguration.java | 98 ++++++---- .../file/FileSystemDynamicConfiguration.java | 23 ++- .../nop/NopDynamicConfiguration.java | 6 +- .../CompositeDynamicConfiguration.java | 5 + .../common/constants/CommonConstants.java | 2 +- .../extension/AdaptiveClassCodeGenerator.java | 10 +- .../dubbo/common/bytecode/MixinTest.java | 1 - .../config/InmemoryConfigurationTest.java | 6 +- .../threadlocal/InternalThreadLocalTest.java | 1 - .../dubbo/common/utils/PojoUtilsTest.java | 5 +- dubbo-compatible/pom.xml | 1 + .../rpc/protocol/dubbo/FutureAdapter.java | 6 +- .../apache/dubbo/config/MethodConfigTest.java | 1 - .../apache/dubbo/filter/LegacyInvoker.java | 2 +- .../org/apache/dubbo/rpc/RpcContextTest.java | 6 +- dubbo-config/dubbo-config-api/pom.xml | 1 + .../dubbo/config/ApplicationConfig.java | 1 - .../apache/dubbo/config/ReferenceConfig.java | 14 +- .../apache/dubbo/config/RegistryConfig.java | 10 +- .../apache/dubbo/config/ServiceConfig.java | 5 +- .../dubbo/config/ReferenceConfigTest.java | 8 +- ...nfigurableMetadataServiceExporterTest.java | 5 +- dubbo-config/dubbo-config-spring/pom.xml | 1 + .../annotation/ReferenceBeanBuilder.java | 9 + .../ServiceAnnotationBeanPostProcessor.java | 14 ++ .../config/spring/util/AnnotationUtils.java | 20 +- ...erenceAnnotationBeanPostProcessorTest.java | 89 +++++---- ...erviceAnnotationBeanPostProcessorTest.java | 13 ++ .../annotation/EnableDubboConfigTest.java | 11 ++ .../annotation/provider/DemoServiceImpl.java | 4 +- .../DubboComponentScanRegistrarTest.java | 118 ------------ .../DubboConfigBindingRegistrarTest.java | 88 --------- .../DubboConfigBindingsRegistrarTest.java | 63 ------ .../DubboConfigConfigurationTest.java | 99 ---------- .../annotation/EnableDubboConfigTest.java | 120 ------------ .../context/annotation/EnableDubboTest.java | 162 ---------------- .../consumer/ConsumerConfiguration.java | 126 ------------ .../test/TestConsumerConfiguration.java | 96 --------- .../annotation/provider/DemoServiceImpl.java | 55 ------ .../annotation/provider/HelloServiceImpl.java | 34 ---- .../provider/ProviderConfiguration.java | 109 ----------- .../DefaultDubboConfigBinderTest.java | 94 --------- dubbo-config/pom.xml | 1 + .../nop/NopDynamicConfigurationTest.java | 70 ------- .../dubbo-configcenter-apollo/pom.xml | 1 + .../apollo/ApolloDynamicConfiguration.java | 10 +- .../dubbo-configcenter-consul/pom.xml | 3 +- .../consul/ConsulDynamicConfiguration.java | 6 +- .../dubbo-configcenter-etcd/pom.xml | 3 +- .../etcd/EtcdDynamicConfiguration.java | 20 +- .../dubbo-configcenter-nacos/pom.xml | 3 +- .../nacos/NacosDynamicConfiguration.java | 8 +- .../nacos/NacosDynamicConfigurationTest.java | 6 +- .../dubbo-configcenter-zookeeper/pom.xml | 1 + .../ZookeeperDynamicConfiguration.java | 86 +++++---- .../ZookeeperDynamicConfigurationTest.java | 2 +- dubbo-configcenter/pom.xml | 1 + dubbo-container/dubbo-container-api/pom.xml | 1 + dubbo-container/dubbo-container-log4j/pom.xml | 1 + .../dubbo-container-logback/pom.xml | 1 + .../dubbo-container-spring/pom.xml | 1 + dubbo-container/pom.xml | 1 + .../dubbo-demo-annotation-consumer/pom.xml | 3 +- .../spring/dubbo-consumer.properties | 2 +- .../dubbo-demo-annotation-provider/pom.xml | 3 +- .../dubbo/demo/provider/Application.java | 6 +- .../dubbo-demo-api-consumer/pom.xml | 3 +- .../dubbo/demo/consumer/Application.java | 6 +- .../dubbo-demo-api-provider/pom.xml | 3 +- .../dubbo/demo/provider/Application.java | 6 +- dubbo-demo/dubbo-demo-api/pom.xml | 3 +- dubbo-demo/dubbo-demo-interface/pom.xml | 1 + .../dubbo-demo-xml-consumer/pom.xml | 1 + .../dubbo/demo/consumer/Application.java | 4 - .../main/resources/spring/dubbo-consumer.xml | 4 +- .../dubbo-demo-xml-provider/pom.xml | 4 +- .../dubbo/demo/provider/Application.java | 4 - .../main/resources/spring/dubbo-provider.xml | 6 +- dubbo-demo/dubbo-demo-xml/pom.xml | 3 +- dubbo-demo/pom.xml | 1 + dubbo-dependencies/pom.xml | 3 +- dubbo-distribution/pom.xml | 1 + dubbo-filter/dubbo-filter-cache/pom.xml | 1 + dubbo-filter/dubbo-filter-validation/pom.xml | 1 + dubbo-filter/pom.xml | 1 + .../pom.xml | 3 +- dubbo-metadata/dubbo-metadata-api/pom.xml | 1 + ...ynamicConfigurationServiceNameMapping.java | 13 +- .../dubbo/metadata/MetadataService.java | 99 ++++++++-- .../metadata/WritableMetadataService.java | 2 +- .../definition/model/MethodDefinition.java | 18 +- .../InMemoryWritableMetadataService.java | 101 ++++------ .../store/RemoteWritableMetadataService.java | 20 +- ...che.dubbo.metadata.WritableMetadataService | 2 +- ...icConfigurationServiceNameMappingTest.java | 38 +--- .../InMemoryWritableMetadataServiceTest.java | 32 +-- .../identifier/MetadataIdentifierTest.java | 2 +- .../support/AbstractMetadataReportTest.java | 14 +- .../RemoteWritableMeatadataServiceTest.java | 4 +- ...ubbo.metadata.report.MetadataReportFactory | 1 + .../dubbo-metadata-report-consul/pom.xml | 3 +- .../dubbo-metadata-report-etcd/pom.xml | 3 +- .../dubbo-metadata-report-nacos/pom.xml | 3 +- .../dubbo-metadata-report-redis/pom.xml | 3 +- .../dubbo-metadata-report-zookeeper/pom.xml | 4 +- dubbo-metadata/pom.xml | 1 - dubbo-monitor/dubbo-monitor-api/pom.xml | 1 + dubbo-monitor/dubbo-monitor-default/pom.xml | 1 + .../monitor/dubbo/MetricsFilterTest.java | 2 - dubbo-monitor/pom.xml | 1 + dubbo-plugin/dubbo-qos/pom.xml | 1 + .../qos/command/util/CommandHelperTest.java | 3 +- dubbo-plugin/pom.xml | 3 +- dubbo-registry/dubbo-registry-api/pom.xml | 1 + .../registry/client/ServiceInstance.java | 43 ----- .../CompositeMetadataServiceURLBuilder.java | 81 ++++++++ ...tedServicesRevisionMetadataCustomizer.java | 4 +- .../client/metadata/MetadataServiceProxy.java | 9 +- .../metadata/MetadataServiceURLBuilder.java | 62 ++---- ...ataServiceURLParamsMetadataCustomizer.java | 4 +- .../ServiceInstanceMetadataUtils.java | 14 +- .../SpringCloudMetadataServiceURLBuilder.java | 49 +++++ .../StandardMetadataServiceURLBuilder.java | 74 +++++++ .../DefaultMetadataServiceProxyFactory.java | 11 +- .../proxy/MetadataServiceProxyFactory.java | 2 +- .../support/ServiceOrientedRegistry.java | 32 ++- ...lient.metadata.MetadataServiceProxyFactory | 1 - ...metadata.proxy.MetadataServiceProxyFactory | 2 +- ....client.metadata.MetadataServiceURLBuilder | 2 + .../client/DefaultServiceInstanceTest.java | 34 ++-- ...stomizableServiceInstanceListenerTest.java | 29 ++- .../listener/LoggingEventListenerTest.java | 85 ++++++++ .../ServiceInstancesChangedListenerTest.java | 54 ++++++ .../MetadataServiceURLBuilderTest.java | 53 +++++ .../ServiceInstanceMetadataUtilsTest.java | 17 +- ...ingCloudMetadataServiceURLBuilderTest.java | 51 +++++ .../support/ServiceOrientedRegistryTest.java | 32 +-- dubbo-registry/dubbo-registry-consul/pom.xml | 1 + dubbo-registry/dubbo-registry-default/pom.xml | 1 + .../registry/dubbo/RegistryProtocolTest.java | 2 +- dubbo-registry/dubbo-registry-etcd3/pom.xml | 1 + .../registry/etcd/EtcdServiceDiscovery.java | 4 - .../dubbo/registry/etcd/EtcdRegistryTest.java | 2 +- .../dubbo-registry-multicast/pom.xml | 1 + .../registry/multicast/MulticastRegistry.java | 6 +- .../dubbo-registry-multiple/pom.xml | 1 + .../registry/nacos/NacosRegistryFactory.java | 3 - .../nacos/util/NacosNamingServiceUtils.java | 3 +- dubbo-registry/dubbo-registry-redis/pom.xml | 1 + .../dubbo-registry-zookeeper/pom.xml | 1 + .../registry/zookeeper/ZookeeperRegistry.java | 2 - .../zookeeper/ZookeeperServiceDiscovery.java | 37 ++++ .../zookeeper/ZookeeperRegistryTest.java | 3 +- .../ZookeeperServiceDiscoveryTest.java | 2 + dubbo-registry/pom.xml | 1 + dubbo-remoting/dubbo-remoting-api/pom.xml | 1 + .../remoting/PerformanceClientFixedTest.java | 2 +- .../remoting/transport/AbstractCodecTest.java | 5 +- dubbo-remoting/dubbo-remoting-etcd3/pom.xml | 1 + dubbo-remoting/dubbo-remoting-grizzly/pom.xml | 1 + dubbo-remoting/dubbo-remoting-http/pom.xml | 1 + dubbo-remoting/dubbo-remoting-mina/pom.xml | 1 + dubbo-remoting/dubbo-remoting-netty/pom.xml | 1 + dubbo-remoting/dubbo-remoting-netty4/pom.xml | 1 + dubbo-remoting/dubbo-remoting-p2p/pom.xml | 1 + .../dubbo-remoting-zookeeper/pom.xml | 1 + .../curator/CuratorZookeeperClient.java | 5 + dubbo-remoting/pom.xml | 1 + dubbo-rpc/dubbo-rpc-api/pom.xml | 1 + .../dubbo/rpc/filter/AccessLogFilterTest.java | 7 +- .../dubbo/rpc/support/BlockMyInvoker.java | 2 +- .../dubbo/rpc/support/MockInvokerTest.java | 13 +- .../apache/dubbo/rpc/support/MyInvoker.java | 2 +- .../dubbo/rpc/support/RpcUtilsTest.java | 4 +- dubbo-rpc/dubbo-rpc-dubbo/pom.xml | 1 + .../rpc/protocol/dubbo/DubboProtocol.java | 2 +- .../dubbo/ReferenceCountExchangeClient.java | 3 + dubbo-rpc/dubbo-rpc-hessian/pom.xml | 1 + .../rpc/protocol/hessian/HessianProtocol.java | 4 +- dubbo-rpc/dubbo-rpc-http/pom.xml | 1 + dubbo-rpc/dubbo-rpc-injvm/pom.xml | 1 + dubbo-rpc/dubbo-rpc-jsonrpc/pom.xml | 1 + dubbo-rpc/dubbo-rpc-memcached/pom.xml | 1 + dubbo-rpc/dubbo-rpc-native-thrift/pom.xml | 1 + dubbo-rpc/dubbo-rpc-redis/pom.xml | 1 + dubbo-rpc/dubbo-rpc-rest/pom.xml | 1 + .../DubboSwaggerApiListingResourceTest.java | 4 +- dubbo-rpc/dubbo-rpc-rmi/pom.xml | 1 + .../rpc/protocol/rmi/RmiProtocolTest.java | 4 +- dubbo-rpc/dubbo-rpc-thrift/pom.xml | 1 + dubbo-rpc/dubbo-rpc-webservice/pom.xml | 1 + dubbo-rpc/dubbo-rpc-xml/pom.xml | 1 + .../rpc/protocol/xmlrpc/XmlRpcProtocol.java | 2 +- dubbo-rpc/pom.xml | 1 + .../dubbo-serialization-api/pom.xml | 1 + .../dubbo-serialization-avro/pom.xml | 1 + .../serialize/avro/AvroObjectInput.java | 3 +- .../serialize/avro/AvroObjectOutput.java | 3 +- .../dubbo-serialization-fastjson/pom.xml | 1 + .../dubbo-serialization-fst/pom.xml | 1 + .../dubbo-serialization-gson/pom.xml | 1 + .../dubbo-serialization-hessian2/pom.xml | 1 + .../dubbo-serialization-jdk/pom.xml | 1 + .../dubbo-serialization-kryo/pom.xml | 1 + .../pom.xml | 3 +- .../dubbo-serialization-protobuf-json/pom.xml | 3 +- .../dubbo-serialization-protostuff/pom.xml | 3 +- .../protostuff/utils/WrapperUtils.java | 2 +- .../dubbo-serialization-test/pom.xml | 3 +- .../hessian2/Hessian2PersonOkTest.java | 1 + .../GenericProtobufObjectOutputTest.java | 1 + .../ProtostuffObjectOutputTest.java | 10 +- .../SerializableClassRegistryTest.java | 3 +- dubbo-serialization/pom.xml | 1 + 229 files changed, 1535 insertions(+), 1922 deletions(-) create mode 100644 dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/AbstractDynamicConfiguration.java delete mode 100644 dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboComponentScanRegistrarTest.java delete mode 100644 dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboConfigBindingRegistrarTest.java delete mode 100644 dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboConfigBindingsRegistrarTest.java delete mode 100644 dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboConfigConfigurationTest.java delete mode 100644 dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/EnableDubboConfigTest.java delete mode 100644 dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/EnableDubboTest.java delete mode 100644 dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/consumer/ConsumerConfiguration.java delete mode 100644 dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/consumer/test/TestConsumerConfiguration.java delete mode 100644 dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/DemoServiceImpl.java delete mode 100644 dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/HelloServiceImpl.java delete mode 100644 dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/ProviderConfiguration.java delete mode 100644 dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/properties/DefaultDubboConfigBinderTest.java delete mode 100644 dubbo-configcenter/dubbo-configcenter-api/src/test/java/org/apache/dubbo/configcenter/support/nop/NopDynamicConfigurationTest.java create mode 100644 dubbo-metadata/dubbo-metadata-api/src/test/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory create mode 100644 dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/CompositeMetadataServiceURLBuilder.java create mode 100644 dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/SpringCloudMetadataServiceURLBuilder.java create mode 100644 dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/StandardMetadataServiceURLBuilder.java delete mode 100644 dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.metadata.MetadataServiceProxyFactory create mode 100644 dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/services/org.apache.dubbo.registry.client.metadata.MetadataServiceURLBuilder rename dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/DefaultHelloService.java => dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/event/listener/CustomizableServiceInstanceListenerTest.java (53%) create mode 100644 dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/event/listener/LoggingEventListenerTest.java create mode 100644 dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/event/listener/ServiceInstancesChangedListenerTest.java create mode 100644 dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/metadata/MetadataServiceURLBuilderTest.java create mode 100644 dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/metadata/SpringCloudMetadataServiceURLBuilderTest.java diff --git a/.travis.yml b/.travis.yml index a0bacc78df..dedcc15d9a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ cache: install: true script: - - travis_wait 30 ./mvnw clean install -DskipTests=false -Dcheckstyle.skip=false -Drat.skip=false -Dmaven.javadoc.skip=true + - travis_wait 30 ./mvnw --quiet clean install -DskipTests=false -Dcheckstyle.skip=false -Drat.skip=false -Dmaven.javadoc.skip=true after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/dubbo-bom/pom.xml b/dubbo-bom/pom.xml index 175a9cfa70..0b0bd1a3ff 100644 --- a/dubbo-bom/pom.xml +++ b/dubbo-bom/pom.xml @@ -23,6 +23,7 @@ org.apache.dubbo dubbo-parent ${revision} + ../pom.xml dubbo-bom diff --git a/dubbo-bootstrap/pom.xml b/dubbo-bootstrap/pom.xml index 77af3e21b8..17df1344ef 100644 --- a/dubbo-bootstrap/pom.xml +++ b/dubbo-bootstrap/pom.xml @@ -26,14 +26,7 @@ - - - org.apache.dubbo - dubbo-configcenter-zookeeper - ${project.parent.version} - test - - + org.apache.dubbo dubbo-registry-zookeeper @@ -48,29 +41,13 @@ test - org.apache.dubbo - dubbo-registry-etcd3 - ${project.parent.version} - - - - - org.apache.dubbo - dubbo-metadata-report-etcd + dubbo-configcenter-zookeeper ${project.parent.version} test - - org.apache.dubbo - dubbo-configcenter-etcd - ${project.parent.version} - test - - - org.apache.dubbo @@ -113,17 +90,6 @@ test - - - - - - - org.apache.curator - curator-test - test - - - + \ No newline at end of file diff --git a/dubbo-bootstrap/src/main/java/org/apache/dubbo/bootstrap/DubboBootstrap.java b/dubbo-bootstrap/src/main/java/org/apache/dubbo/bootstrap/DubboBootstrap.java index 394e34510a..ab20a6fbfe 100644 --- a/dubbo-bootstrap/src/main/java/org/apache/dubbo/bootstrap/DubboBootstrap.java +++ b/dubbo-bootstrap/src/main/java/org/apache/dubbo/bootstrap/DubboBootstrap.java @@ -57,7 +57,6 @@ import org.apache.dubbo.registry.support.ServiceOrientedRegistry; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -77,7 +76,6 @@ import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; import static org.apache.dubbo.common.utils.StringUtils.isNotEmpty; import static org.apache.dubbo.config.context.ConfigManager.getInstance; import static org.apache.dubbo.registry.support.AbstractRegistryFactory.getRegistries; -import static org.apache.dubbo.remoting.Constants.CLIENT_KEY; /** * The bootstrap class of Dubbo @@ -114,19 +112,14 @@ public class DubboBootstrap { private final ConfigManager configManager = getInstance(); - /** - * Is provider or not - */ - private boolean isProvider; + private volatile boolean initialized = false; - private boolean initialized = false; - - private boolean started = false; + private volatile boolean started = false; /** * Only Provider Register */ - private boolean onlyRegisterProvider = false; + private volatile boolean onlyRegisterProvider = false; private ServiceInstance serviceInstance; @@ -155,6 +148,7 @@ public class DubboBootstrap { return this; } + // {@link ApplicationConfig} correlative methods /** @@ -193,6 +187,7 @@ public class DubboBootstrap { return this; } + // {@link RegistryConfig} correlative methods /** @@ -240,8 +235,8 @@ public class DubboBootstrap { return this; } - // {@link ProtocolConfig} correlative methods + // {@link ProtocolConfig} correlative methods public DubboBootstrap protocol(Consumer consumerBuilder) { return protocol(DEFAULT_PROTOCOL_ID, consumerBuilder); } @@ -261,8 +256,8 @@ public class DubboBootstrap { return this; } - // {@link ServiceConfig} correlative methods + // {@link ServiceConfig} correlative methods public DubboBootstrap service(Consumer> consumerBuilder) { return service(DEFAULT_SERVICE_ID, consumerBuilder); } @@ -278,8 +273,8 @@ public class DubboBootstrap { return this; } - // {@link Reference} correlative methods + // {@link Reference} correlative methods public DubboBootstrap reference(Consumer> consumerBuilder) { return reference(DEFAULT_REFERENCE_ID, consumerBuilder); } @@ -295,8 +290,8 @@ public class DubboBootstrap { return this; } - // {@link ProviderConfig} correlative methods + // {@link ProviderConfig} correlative methods public DubboBootstrap provider(Consumer builderConsumer) { return provider(DEFAULT_PROVIDER_ID, builderConsumer); } @@ -316,8 +311,8 @@ public class DubboBootstrap { return this; } - // {@link ConsumerConfig} correlative methods + // {@link ConsumerConfig} correlative methods public DubboBootstrap consumer(Consumer builderConsumer) { return consumer(DEFAULT_CONSUMER_ID, builderConsumer); } @@ -338,6 +333,7 @@ public class DubboBootstrap { } // {@link ConfigCenterConfig} correlative methods + public DubboBootstrap configCenter(ConfigCenterConfig configCenterConfig) { return configCenter(asList(configCenterConfig)); } @@ -424,13 +420,8 @@ public class DubboBootstrap { String id = "config-center-" + protocol + "-" + registryConfig.getPort(); ConfigCenterConfig cc = new ConfigCenterConfig(); cc.setId(id); - cc.setParameters(registryConfig.getParameters() == null ? - new HashMap<>() : - new HashMap<>(registryConfig.getParameters())); - cc.getParameters().put(CLIENT_KEY,registryConfig.getClient()); - cc.setProtocol(registryConfig.getProtocol()); + cc.setProtocol(protocol); cc.setAddress(registryConfig.getAddress()); - cc.setNamespace(registryConfig.getGroup()); cc.setHighestPriority(false); configManager.addConfigCenter(cc); }); @@ -463,7 +454,6 @@ public class DubboBootstrap { /** * export {@link MetadataService} */ - // TODO, only export to default registry? List exportedURLs = exportMetadataService( configManager.getApplication().orElseThrow(() -> new IllegalStateException("ApplicationConfig cannot be null")), configManager.getRegistries(), @@ -541,6 +531,7 @@ public class DubboBootstrap { /* serve for builder apis, begin */ + private ApplicationBuilder createApplicationBuilder(String name) { return new ApplicationBuilder().name(name); } @@ -569,8 +560,8 @@ public class DubboBootstrap { return new ConsumerBuilder().id(id); } - /* serve for builder apis, end */ + /* serve for builder apis, end */ private void startMetadataReport() { ApplicationConfig applicationConfig = configManager.getApplication().orElseThrow(() -> new IllegalStateException("There's no ApplicationConfig specified.")); @@ -612,15 +603,14 @@ public class DubboBootstrap { return null; } DynamicConfiguration dynamicConfiguration = getDynamicConfiguration(configCenter.toUrl()); - String configContent = dynamicConfiguration.getProperties(configCenter.getConfigFile(), configCenter.getGroup()); + String configContent = dynamicConfiguration.getRule(configCenter.getConfigFile(), configCenter.getGroup()); String appGroup = configManager.getApplication().orElse(new ApplicationConfig()).getName(); String appConfigContent = null; if (isNotEmpty(appGroup)) { - appConfigContent = dynamicConfiguration.getProperties - (isNotEmpty(configCenter.getAppConfigFile()) ? configCenter.getAppConfigFile() : configCenter.getConfigFile(), - appGroup - ); + appConfigContent = dynamicConfiguration.getConfig(isNotEmpty(configCenter.getAppConfigFile()) ? + configCenter.getAppConfigFile() : configCenter.getConfigFile(), appGroup + ); } try { Environment.getInstance().setConfigCenterFirst(configCenter.isHighestPriority()); @@ -663,6 +653,10 @@ public class DubboBootstrap { serviceConfig.export(); } + public boolean isOnlyRegisterProvider() { + return onlyRegisterProvider; + } + private void registerServiceInstance(List exportedURLs) { exportedURLs diff --git a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java index d88dcc38d0..191b233313 100644 --- a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java +++ b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java @@ -19,7 +19,6 @@ package org.apache.dubbo.bootstrap; import org.apache.dubbo.config.ReferenceConfig; import org.apache.dubbo.config.context.ConfigManager; - /** * Dubbo Provider Bootstrap * diff --git a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java index 019a61a443..1ed573f0ae 100644 --- a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java +++ b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java @@ -30,7 +30,6 @@ public class DubboServiceProviderBootstrap { .registry("zookeeper", builder -> builder.address("zookeeper://127.0.0.1:2181?registry-type=service")) // 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()) .protocol(builder -> builder.port(-1).name("dubbo")) .service(builder -> builder.id("test").interfaceClass(EchoService.class).ref(new EchoServiceImpl())) .start() diff --git a/dubbo-cluster/pom.xml b/dubbo-cluster/pom.xml index 864e7ccc77..bd6297430b 100644 --- a/dubbo-cluster/pom.xml +++ b/dubbo-cluster/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-parent ${revision} + ../pom.xml dubbo-cluster jar diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ListenableRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ListenableRouter.java index 2615ea3cd3..6d3276aa3c 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ListenableRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ListenableRouter.java @@ -119,7 +119,7 @@ public abstract class ListenableRouter extends AbstractRouter implements Configu } String routerKey = ruleKey + RULE_SUFFIX; configuration.addListener(routerKey, this); - String rule = configuration.getRule(routerKey, DynamicConfiguration.DEFAULT_GROUP); + String rule = configuration.getConfig(routerKey, DynamicConfiguration.DEFAULT_GROUP); if (StringUtils.isNotEmpty(rule)) { this.process(new ConfigChangeEvent(routerKey, rule)); } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java index 9e5d86314b..00ce099f0f 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java @@ -249,7 +249,7 @@ public class TagRouter extends AbstractRouter implements ConfigurationListener { String key = providerApplication + RULE_SUFFIX; configuration.addListener(key, this); application = providerApplication; - String rawRule = configuration.getRule(key, DynamicConfiguration.DEFAULT_GROUP); + String rawRule = configuration.getConfig(key, DynamicConfiguration.DEFAULT_GROUP); if (StringUtils.isNotEmpty(rawRule)) { this.process(new ConfigChangeEvent(key, rawRule)); } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java index 46e3a162bc..2a59ac97cc 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java @@ -32,8 +32,8 @@ import org.apache.dubbo.rpc.support.MockInvoker; import java.util.List; -import static org.apache.dubbo.rpc.cluster.Constants.INVOCATION_NEED_MOCK; import static org.apache.dubbo.rpc.Constants.MOCK_KEY; +import static org.apache.dubbo.rpc.cluster.Constants.INVOCATION_NEED_MOCK; public class MockClusterInvoker implements Invoker { diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/TagRouterTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/TagRouterTest.java index 829208da27..0981719d47 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/TagRouterTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/TagRouterTest.java @@ -16,11 +16,12 @@ */ package org.apache.dubbo.rpc.cluster.router; +import org.apache.dubbo.rpc.cluster.router.tag.model.TagRouterRule; +import org.apache.dubbo.rpc.cluster.router.tag.model.TagRuleParser; + import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.retry.ExponentialBackoffRetry; -import org.apache.dubbo.rpc.cluster.router.tag.model.TagRouterRule; -import org.apache.dubbo.rpc.cluster.router.tag.model.TagRuleParser; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvokerTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvokerTest.java index 4ee3a863f6..c8b806bfc1 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvokerTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvokerTest.java @@ -47,10 +47,10 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; +import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY; import static org.apache.dubbo.rpc.cluster.Constants.CLUSTER_AVAILABLE_CHECK_KEY; import static org.apache.dubbo.rpc.cluster.Constants.INVOCATION_NEED_MOCK; import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY; -import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; diff --git a/dubbo-common/pom.xml b/dubbo-common/pom.xml index dabf4bb47e..d988195730 100644 --- a/dubbo-common/pom.xml +++ b/dubbo-common/pom.xml @@ -21,6 +21,7 @@ org.apache.dubbo dubbo-parent ${revision} + ../pom.xml dubbo-common jar diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/Configuration.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/Configuration.java index 6fa15bde11..94ff25f10b 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/Configuration.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/Configuration.java @@ -127,6 +127,4 @@ public interface Configuration { return cls.cast(obj); } - - } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/AbstractDynamicConfiguration.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/AbstractDynamicConfiguration.java new file mode 100644 index 0000000000..604be99884 --- /dev/null +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/AbstractDynamicConfiguration.java @@ -0,0 +1,182 @@ +/* + * 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; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.NamedThreadFactory; + +import java.util.concurrent.Callable; +import java.util.concurrent.Future; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +import static java.util.concurrent.Executors.newFixedThreadPool; + +/** + * The abstract implementation of {@link DynamicConfiguration} + * + * @since 2.7.4 + */ +public abstract class AbstractDynamicConfiguration implements DynamicConfiguration { + + public static final String PARAM_NAME_PREFIX = "dubbo.config-center."; + + public static final String THREAD_POOL_PREFIX_PARAM_NAME = PARAM_NAME_PREFIX + "thread-pool.prefix"; + + public static final String THREAD_POOL_SIZE_PARAM_NAME = PARAM_NAME_PREFIX + "thread-pool.size"; + + public static final String DEFAULT_THREAD_POOL_PREFIX = PARAM_NAME_PREFIX + "workers"; + + public static final String DEFAULT_THREAD_POOL_SIZE = "1"; + + /** + * Logger + */ + protected final Logger logger = LoggerFactory.getLogger(getClass()); + + /** + * The thread pool for workers who executes the tasks + */ + private final ThreadPoolExecutor workersThreadPool; + + public AbstractDynamicConfiguration(URL url) { + this.workersThreadPool = initWorkersThreadPool(url); + } + + @Override + public void addListener(String key, String group, ConfigurationListener listener) { + + } + + @Override + public void removeListener(String key, String group, ConfigurationListener listener) { + + } + + @Override + public final String getConfig(String key, String group, long timeout) throws IllegalStateException { + return execute(() -> doGetConfig(key, group), timeout); + } + + @Override + public String getRule(String key, String group, long timeout) throws IllegalStateException { + return getConfig(key, group, timeout); + } + + @Override + public Object getInternalProperty(String key) { + return null; + } + + @Override + public final void close() throws Exception { + try { + doClose(); + } finally { + doFinally(); + } + } + + /** + * Get the content of configuration in the specified key and group + * + * @param key the key + * @param group the group + * @return if found, return the content of configuration + * @throws IllegalStateException + */ + protected abstract String doGetConfig(String key, String group) throws IllegalStateException; + + /** + * Close the resources if necessary + * + * @throws Exception If met with some problems + */ + protected abstract void doClose() throws Exception; + + /** + * Executes the {@link Runnable} with the specified timeout + * + * @param task the {@link Runnable task} + * @param timeout timeout in milliseconds + */ + protected final void execute(Runnable task, long timeout) { + execute(() -> { + task.run(); + return null; + }, timeout); + } + + /** + * Executes the {@link Callable} with the specified timeout + * + * @param task the {@link Callable task} + * @param timeout timeout in milliseconds + * @param the type of computing result + * @return the computing result + */ + protected final V execute(Callable task, long timeout) { + V value = null; + try { + + if (timeout < 1) { // less or equal 0 + value = task.call(); + } else { + Future future = workersThreadPool.submit(task); + value = future.get(timeout, TimeUnit.MILLISECONDS); + } + } catch (Exception e) { + if (logger.isErrorEnabled()) { + logger.error(e.getMessage(), e); + } + } + return value; + } + + private void doFinally() { + shutdownWorkersThreadPool(); + } + + private void shutdownWorkersThreadPool() { + if (!workersThreadPool.isShutdown()) { + workersThreadPool.shutdown(); + } + } + + protected ThreadPoolExecutor initWorkersThreadPool(URL url) { + int size = getThreadPoolSize(url); + String name = getThreadPoolPrefixName(url); + return (ThreadPoolExecutor) newFixedThreadPool(size, new NamedThreadFactory(name)); + } + + protected static String getThreadPoolPrefixName(URL url) { + return getParameter(url, THREAD_POOL_PREFIX_PARAM_NAME, DEFAULT_THREAD_POOL_PREFIX); + } + + protected static int getThreadPoolSize(URL url) { + return Integer.parseInt(getParameter(url, THREAD_POOL_SIZE_PARAM_NAME, DEFAULT_THREAD_POOL_SIZE)); + } + + protected static String getParameter(URL url, String name, String defaultValue) { + if (url != null) { + return url.getParameter(name, defaultValue); + } + return defaultValue; + } +} diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/DynamicConfiguration.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/DynamicConfiguration.java index b160398373..852ec62612 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/DynamicConfiguration.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/DynamicConfiguration.java @@ -21,10 +21,11 @@ import org.apache.dubbo.common.config.Configuration; import org.apache.dubbo.common.config.Environment; import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.SortedMap; +import java.util.SortedSet; +import java.util.TreeMap; import static org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory.getDynamicConfigurationFactory; import static org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoader; @@ -33,12 +34,13 @@ import static org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoad * Dynamic Configuration *
* From the use scenario internally inside framework, there're mainly three kinds of methods: - *
    - *
  • 1. getRule, get governance rules.
  • - *
  • 2. getProperties, get configuration file from Config Center at start up.
  • - *
  • 3. addListener/removeListener, add or remove listeners for governance rules or config items that need to watch.
  • - *
  • 4. getProperty, get a single config item.
  • - *
+ *
    + *
  1. {@link #getRule(String, String, long)}, get governance rules.
  2. + *
  3. {@link #getProperties(String, String, long)}, get configuration file from Config Center at start up.
  4. + *
  5. {@link #addListener(String, String, ConfigurationListener)}/ {@link #removeListener(String, String, ConfigurationListener)} + * , add or remove listeners for governance rules or config items that need to watch.
  6. + *
  7. {@link #getProperty(String, Object)}, get a single config item.
  8. + *
*/ public interface DynamicConfiguration extends Configuration, AutoCloseable { @@ -86,12 +88,52 @@ public interface DynamicConfiguration extends Configuration, AutoCloseable { */ void removeListener(String key, String group, ConfigurationListener listener); + /** + * Get the configuration mapped to the given key and the given group + * + * @param key the key to represent a configuration + * @param group the group where the key belongs to + * @return target configuration mapped to the given key and the given group + */ + default String getConfig(String key, String group) { + return getConfig(key, group, -1L); + } + + /** + * Get the configuration mapped to the given key and the given group. If the + * configuration fails to fetch after timeout exceeds, IllegalStateException will be thrown. + * + * @param key the key to represent a configuration + * @param group the group where the key belongs to + * @param timeout timeout value for fetching the target config + * @return target configuration mapped to the given key and the given group, IllegalStateException will be thrown + * if timeout exceeds. + */ + String getConfig(String key, String group, long timeout) throws IllegalStateException; + + /** + * This method are mostly used to get a compound config file, such as a complete dubbo.properties file. + */ + default String getProperties(String key, String group) throws IllegalStateException { + return getProperties(key, group, -1L); + } + + /** + * This method are mostly used to get a compound config file, such as a complete dubbo.properties file. + * + * @revision 2.7.4 + */ + default String getProperties(String key, String group, long timeout) throws IllegalStateException { + return getConfig(key, group, timeout); + } + /** * Get the governance rule mapped to the given key and the given group * * @param key the key to represent a configuration * @param group the group where the key belongs to * @return target configuration mapped to the given key and the given group + * @since 2.7.3 */ default String getRule(String key, String group) { return getRule(key, group, -1L); @@ -106,22 +148,10 @@ public interface DynamicConfiguration extends Configuration, AutoCloseable { * @param timeout timeout value for fetching the target config * @return target configuration mapped to the given key and the given group, IllegalStateException will be thrown * if timeout exceeds. + * @since 2.7.3 */ String getRule(String key, String group, long timeout) throws IllegalStateException; - /** - * This method are mostly used to get a compound config file, such as a complete dubbo.properties file. - */ - default String getProperties(String key, String group) throws IllegalStateException { - return getProperties(key, group, -1L); - } - - /** - * This method are mostly used to get a compound config file, such as a complete dubbo.properties file. - */ - String getProperties(String key, String group, long timeout) throws IllegalStateException; - - /** * Publish Config mapped to the given key under the {@link #DEFAULT_GROUP default group} * @@ -189,42 +219,42 @@ public interface DynamicConfiguration extends Configuration, AutoCloseable { * Get the config keys by the specified group * * @param group the specified group - * @return the read-only non-null {@link Set set} of config keys + * @return the read-only non-null sorted {@link Set set} of config keys * @throws UnsupportedOperationException If the under layer does not support * @since 2.7.4 */ - default Set getConfigKeys(String group) throws UnsupportedOperationException { + default SortedSet getConfigKeys(String group) throws UnsupportedOperationException { throw new UnsupportedOperationException("No support"); } /** - * Get the {@link Map} with with config keys and contents value by the specified group + * Get the {@link SortedMap} with with config keys and contents value by the specified group * * @param group the specified group - * @return the read-only non-null {@link Map map} + * @return the read-only non-null sorted {@link SortedMap map} * @throws UnsupportedOperationException If the under layer does not support * @since 2.7.4 */ - default Map getConfigs(String group) throws UnsupportedOperationException { + default SortedMap getConfigs(String group) throws UnsupportedOperationException { return getConfigs(group, -1); } /** - * Get the {@link Map} with with config keys and content value by the specified group + * Get the {@link SortedMap} with with config keys and content value by the specified group * * @param group the specified group * @param timeout the millisecond for timeout - * @return the read-only non-null {@link Map map} + * @return the read-only non-null sorted {@link SortedMap map} * @throws UnsupportedOperationException If the under layer does not support * @throws IllegalStateException If timeout exceeds * @since 2.7.4 */ - default Map getConfigs(String group, long timeout) throws UnsupportedOperationException, + default SortedMap getConfigs(String group, long timeout) throws UnsupportedOperationException, IllegalStateException { - Map configs = new LinkedHashMap<>(); - Set configKeys = getConfigKeys(group); + SortedMap configs = new TreeMap<>(); + SortedSet configKeys = getConfigKeys(group); configKeys.forEach(key -> configs.put(key, getString(key))); - return Collections.unmodifiableMap(configs); + return Collections.unmodifiableSortedMap(configs); } /** @@ -263,12 +293,12 @@ public interface DynamicConfiguration extends Configuration, AutoCloseable { return factory.getDynamicConfiguration(connectionURL); } - /** + /** * The format is '{interfaceName}:[version]:[group]' * * @return */ - static String getRuleKey(URL url) { + static String getRuleKey(URL url) { return url.getColonSeparatedKey(); } } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfiguration.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfiguration.java index 65d4f5057b..5b37c34826 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfiguration.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfiguration.java @@ -47,6 +47,9 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.SortedMap; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.concurrent.Callable; import java.util.concurrent.Future; import java.util.concurrent.SynchronousQueue; @@ -228,6 +231,12 @@ public class FileSystemDynamicConfiguration implements DynamicConfiguration { }); } + @Override + public String getConfig(String key, String group, long timeout) throws IllegalStateException { + File configFile = configFile(key, group); + return getConfig(configFile, timeout); + } + protected File configDirectory(String group) { String actualGroup = isBlank(group) ? DEFAULT_GROUP : group; return new File(rootDirectory, actualGroup); @@ -341,8 +350,7 @@ public class FileSystemDynamicConfiguration implements DynamicConfiguration { @Override public String getRule(String key, String group, long timeout) throws IllegalStateException { - File configFile = configFile(key, group); - return getConfig(configFile, timeout); + return getConfig(key, group, timeout); } protected String getConfig(File configFile, long timeout) { @@ -353,11 +361,6 @@ public class FileSystemDynamicConfiguration implements DynamicConfiguration { return file.exists() && file.canRead(); } - @Override - public String getProperties(String key, String group, long timeout) throws IllegalStateException { - return getRule(key, group, timeout); - } - @Override public Object getInternalProperty(String key) { return null; @@ -451,10 +454,10 @@ public class FileSystemDynamicConfiguration implements DynamicConfiguration { } @Override - public Set getConfigKeys(String group) { + public SortedSet getConfigKeys(String group) { return Stream.of(configDirectory(group).listFiles(File::isFile)) .map(File::getName) - .collect(Collectors.toSet()); + .collect(TreeSet::new, Set::add, Set::addAll); } @@ -467,7 +470,7 @@ public class FileSystemDynamicConfiguration implements DynamicConfiguration { } @Override - public Map getConfigs(String group) throws UnsupportedOperationException { + public SortedMap getConfigs(String group) throws UnsupportedOperationException { return getConfigs(group, -1); } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/nop/NopDynamicConfiguration.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/nop/NopDynamicConfiguration.java index 9337b05b8c..79401010e2 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/nop/NopDynamicConfiguration.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/nop/NopDynamicConfiguration.java @@ -51,12 +51,14 @@ public class NopDynamicConfiguration implements DynamicConfiguration { } @Override - public String getRule(String key, String group, long timeout) throws IllegalStateException { + public String getConfig(String key, String group, long timeout) throws IllegalStateException { + // no-op return null; } @Override - public String getProperties(String key, String group, long timeout) throws IllegalStateException { + public String getRule(String key, String group, long timeout) throws IllegalStateException { + // no-op return null; } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/wrapper/CompositeDynamicConfiguration.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/wrapper/CompositeDynamicConfiguration.java index 700a724862..528130d0a6 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/wrapper/CompositeDynamicConfiguration.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/wrapper/CompositeDynamicConfiguration.java @@ -49,6 +49,11 @@ public class CompositeDynamicConfiguration implements DynamicConfiguration { iterateListenerOperation(configuration -> configuration.removeListener(key, group, listener)); } + @Override + public String getConfig(String key, String group, long timeout) throws IllegalStateException { + return (String) iterateConfigOperation(configuration -> configuration.getConfig(key, group, timeout)); + } + @Override public String getRule(String key, String group, long timeout) throws IllegalStateException { return (String) iterateConfigOperation(configuration -> configuration.getRule(key, group, timeout)); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java index 120b6fb8ed..517df71a23 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java @@ -165,7 +165,7 @@ public interface CommonConstants { String METADATA_KEY = "metadata"; - String METADATA_DEFAULT = "local"; + String METADATA_DEFAULT = "default"; String METADATA_REMOTE = "remote"; diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/AdaptiveClassCodeGenerator.java b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/AdaptiveClassCodeGenerator.java index 610534fcb7..b68bd2d110 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/AdaptiveClassCodeGenerator.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/AdaptiveClassCodeGenerator.java @@ -16,17 +16,17 @@ */ package org.apache.dubbo.common.extension; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.StringUtils; + import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.stream.Collectors; import java.util.stream.IntStream; -import org.apache.dubbo.common.URL; -import org.apache.dubbo.common.logger.Logger; -import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.common.utils.StringUtils; - /** * Code generator for Adaptive class */ diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/bytecode/MixinTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/bytecode/MixinTest.java index 954ea51fda..544c9c6fed 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/bytecode/MixinTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/bytecode/MixinTest.java @@ -18,7 +18,6 @@ package org.apache.dubbo.common.bytecode; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; public class MixinTest { diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/config/InmemoryConfigurationTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/config/InmemoryConfigurationTest.java index b577631d36..bdb371a1dc 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/config/InmemoryConfigurationTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/config/InmemoryConfigurationTest.java @@ -16,14 +16,14 @@ */ package org.apache.dubbo.common.config; -import java.util.HashMap; -import java.util.Map; - import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.HashMap; +import java.util.Map; + /** * The type Inmemory configuration test. */ diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/threadlocal/InternalThreadLocalTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/threadlocal/InternalThreadLocalTest.java index 8c63ec0aec..df0b908a6c 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/threadlocal/InternalThreadLocalTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/threadlocal/InternalThreadLocalTest.java @@ -20,7 +20,6 @@ package org.apache.dubbo.common.threadlocal; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.util.Objects; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/PojoUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/PojoUtilsTest.java index 91773e4dd9..b395731f9e 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/PojoUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/PojoUtilsTest.java @@ -24,6 +24,7 @@ import org.apache.dubbo.common.model.person.FullAddress; import org.apache.dubbo.common.model.person.PersonInfo; import org.apache.dubbo.common.model.person.PersonStatus; import org.apache.dubbo.common.model.person.Phone; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -34,20 +35,20 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; -import java.util.HashSet; import java.util.Map; import java.util.UUID; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertSame; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; public class PojoUtilsTest { diff --git a/dubbo-compatible/pom.xml b/dubbo-compatible/pom.xml index 3826189591..b96623a137 100644 --- a/dubbo-compatible/pom.xml +++ b/dubbo-compatible/pom.xml @@ -21,6 +21,7 @@ org.apache.dubbo dubbo-parent ${revision} + ../pom.xml dubbo-compatible jar diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/FutureAdapter.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/FutureAdapter.java index 3306abb0a3..5b9711e6c5 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/FutureAdapter.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/FutureAdapter.java @@ -17,14 +17,14 @@ package com.alibaba.dubbo.rpc.protocol.dubbo; +import org.apache.dubbo.rpc.AppResponse; +import org.apache.dubbo.rpc.Result; + import com.alibaba.dubbo.remoting.RemotingException; import com.alibaba.dubbo.remoting.exchange.ResponseCallback; import com.alibaba.dubbo.remoting.exchange.ResponseFuture; import com.alibaba.dubbo.rpc.RpcException; -import org.apache.dubbo.rpc.AppResponse; -import org.apache.dubbo.rpc.Result; - import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; import java.util.concurrent.ExecutionException; diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/config/MethodConfigTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/config/MethodConfigTest.java index e45ef73783..f43cda8cf6 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/config/MethodConfigTest.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/config/MethodConfigTest.java @@ -43,7 +43,6 @@ import static org.hamcrest.Matchers.hasKey; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; public class MethodConfigTest { @Test diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/filter/LegacyInvoker.java b/dubbo-compatible/src/test/java/org/apache/dubbo/filter/LegacyInvoker.java index f77e0a523d..b1d19b57c3 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/filter/LegacyInvoker.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/filter/LegacyInvoker.java @@ -59,7 +59,7 @@ public class LegacyInvoker implements Invoker { public Result invoke(Invocation invocation) throws RpcException { AppResponse result = new AppResponse(); - if (hasException == false) { + if (!hasException) { result.setValue("alibaba"); } else { result.setException(new RuntimeException("mocked exception")); diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/RpcContextTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/RpcContextTest.java index 4a8d61e62c..d3b521ec94 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/RpcContextTest.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/rpc/RpcContextTest.java @@ -17,10 +17,12 @@ package org.apache.dubbo.rpc; +import com.alibaba.dubbo.rpc.RpcContext; +import org.junit.jupiter.api.Test; + import java.util.concurrent.CompletableFuture; import java.util.concurrent.Future; -import org.junit.jupiter.api.Test; -import com.alibaba.dubbo.rpc.RpcContext; + import static org.junit.jupiter.api.Assertions.assertEquals; public class RpcContextTest { diff --git a/dubbo-config/dubbo-config-api/pom.xml b/dubbo-config/dubbo-config-api/pom.xml index 6e66e49d18..7710bf6415 100644 --- a/dubbo-config/dubbo-config-api/pom.xml +++ b/dubbo-config/dubbo-config-api/pom.xml @@ -21,6 +21,7 @@ org.apache.dubbo dubbo-config ${revision} + ../pom.xml dubbo-config-api jar diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java index 19583727bf..535a182910 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java @@ -435,5 +435,4 @@ public class ApplicationConfig extends AbstractConfig { } parameters.put(key, value); } - } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java index 13ec542767..b9e0eb9cc0 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java @@ -194,13 +194,13 @@ public class ReferenceConfig extends AbstractReferenceConfig { if (!ReferenceConfig.this.destroyed) { logger.warn("ReferenceConfig(" + url + ") is not DESTROYED when FINALIZE"); - /* don't destroy for now - try { - ReferenceConfig.this.destroy(); - } catch (Throwable t) { - logger.warn("Unexpected err when destroy invoker of ReferenceConfig(" + url + ") in finalize method!", t); - } - */ + /* don't destroy for now + try { + ReferenceConfig.this.destroy(); + } catch (Throwable t) { + logger.warn("Unexpected err when destroy invoker of ReferenceConfig(" + url + ") in finalize method!", t); + } + */ } } }; diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryConfig.java index 22974b83d5..77bef4f6df 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryConfig.java @@ -183,10 +183,12 @@ public class RegistryConfig extends AbstractConfig { if (address != null) { try { URL url = URL.valueOf(address); - this.updateIdIfAbsent(url.getProtocol()); - this.updateProtocolIfAbsent(url.getProtocol()); - this.updatePortIfAbsent(url.getPort()); - this.updateParameters(url.getParameters()); + setUsername(url.getUsername()); + setPassword(url.getPassword()); + updateIdIfAbsent(url.getProtocol()); + updateProtocolIfAbsent(url.getProtocol()); + updatePortIfAbsent(url.getPort()); + setParameters(url.getParameters()); } catch (Exception ignored) { } } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java index d44fe1c102..192b558837 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java @@ -1,4 +1,3 @@ - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -767,7 +766,7 @@ public class ServiceConfig extends AbstractServiceConfig { if (portToBind == null || portToBind == 0) { portToBind = defaultPort; } - if (portToBind <= 0) { + if (portToBind == null || portToBind <= 0) { portToBind = getRandomPort(name); if (portToBind == null || portToBind < 0) { portToBind = getAvailablePort(defaultPort); @@ -1060,4 +1059,4 @@ public class ServiceConfig extends AbstractServiceConfig { protected void dispatch(Event event) { eventDispatcher.dispatch(event); } -} +} \ No newline at end of file diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java index cb4d7fdfa0..7f995435a7 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java @@ -177,10 +177,10 @@ public class ReferenceConfigTest { Assertions.assertEquals(3, (int)((MethodConfig)referenceConfig.getMethods().get(0)).getActives()); Assertions.assertEquals(5, (int)((MethodConfig)referenceConfig.getMethods().get(0)).getExecutes()); Assertions.assertTrue(((MethodConfig) referenceConfig.getMethods().get(0)).isAsync()); - assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getOninvoke(), "i"); - assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getOnreturn(), "r"); - assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getOnthrow(), "t"); - assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getCache(), "c"); + Assertions.assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getOninvoke(), "i"); + Assertions.assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getOnreturn(), "r"); + Assertions.assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getOnthrow(), "t"); + Assertions.assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getCache(), "c"); } diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/metadata/ConfigurableMetadataServiceExporterTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/metadata/ConfigurableMetadataServiceExporterTest.java index 43331e996d..c53eb7df27 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/metadata/ConfigurableMetadataServiceExporterTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/metadata/ConfigurableMetadataServiceExporterTest.java @@ -22,7 +22,6 @@ import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.context.ConfigManager; import org.apache.dubbo.metadata.MetadataService; -import org.apache.dubbo.metadata.MetadataServiceExporter; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -44,6 +43,7 @@ public class ConfigurableMetadataServiceExporterTest { @BeforeAll public static void init() { ConfigManager configManager = ConfigManager.getInstance(); + configManager.clear(); ApplicationConfig applicationConfig = new ApplicationConfig(); applicationConfig.setName("test"); configManager.setApplication(applicationConfig); @@ -69,7 +69,8 @@ public class ConfigurableMetadataServiceExporterTest { @Test public void testExportAndUnexport() { - MetadataServiceExporter exporter = new ConfigurableMetadataServiceExporter(); + ConfigurableMetadataServiceExporter exporter = new ConfigurableMetadataServiceExporter(); + exporter.setApplicationConfig(ConfigManager.getInstance().getApplication().get()); List urls = exporter.export(); assertEquals(1, urls.size()); diff --git a/dubbo-config/dubbo-config-spring/pom.xml b/dubbo-config/dubbo-config-spring/pom.xml index 405b29e323..9d94fa9189 100644 --- a/dubbo-config/dubbo-config-spring/pom.xml +++ b/dubbo-config/dubbo-config-spring/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-config ${revision} + ../pom.xml dubbo-config-spring jar diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceBeanBuilder.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceBeanBuilder.java index 2054473587..e17f519b1b 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceBeanBuilder.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceBeanBuilder.java @@ -57,6 +57,15 @@ class ReferenceBeanBuilder extends AnnotatedInterfaceConfigBeanBuilder serviceInterfaceClass = resolveServiceInterfaceClass(attributes, interfaceClass); diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java index 06deb57fdd..ce8b1965e3 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java @@ -19,6 +19,8 @@ package org.apache.dubbo.config.spring.beans.factory.annotation; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.ArrayUtils; +import org.apache.dubbo.config.MethodConfig; +import org.apache.dubbo.config.annotation.Method; import org.apache.dubbo.config.annotation.Service; import org.apache.dubbo.config.spring.ServiceBean; import org.apache.dubbo.config.spring.context.annotation.DubboClassPathBeanDefinitionScanner; @@ -54,6 +56,7 @@ import org.springframework.util.StringUtils; import java.lang.annotation.Annotation; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; @@ -387,6 +390,11 @@ public class ServiceAnnotationBeanPostProcessor implements BeanDefinitionRegistr builder.addPropertyValue("interface", interfaceClass.getName()); // Convert parameters into map builder.addPropertyValue("parameters", convertParameters(serviceAnnotationAttributes.getStringArray("parameters"))); + // Add methods parameters + List methodConfigs = convertMethodConfigs(serviceAnnotationAttributes.get("methods")); + if (!methodConfigs.isEmpty()) { + builder.addPropertyValue("methods", methodConfigs); + } /** * Add {@link org.apache.dubbo.config.ProviderConfig} Bean reference @@ -447,6 +455,12 @@ public class ServiceAnnotationBeanPostProcessor implements BeanDefinitionRegistr } + private List convertMethodConfigs(Object methodsAnnotation) { + if (methodsAnnotation == null){ + return Collections.EMPTY_LIST; + } + return MethodConfig.constructMethodConfig((Method[])methodsAnnotation); + } private ManagedList toRuntimeBeanReferences(String... beanNames) { diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/AnnotationUtils.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/AnnotationUtils.java index 19ced2b306..1e69cec4b2 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/AnnotationUtils.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/AnnotationUtils.java @@ -93,6 +93,14 @@ public class AnnotationUtils { * @throws IllegalStateException if interface name was not found */ public static String resolveInterfaceName(AnnotationAttributes attributes, Class defaultInterfaceClass) { + Boolean generic = getAttribute(attributes, "generic"); + if (generic != null && generic) { + // it's a generic reference + String interfaceClassName = getAttribute(attributes, "interfaceName"); + Assert.hasText(interfaceClassName, + "@Reference interfaceName() must be present when reference a generic service!"); + return interfaceClassName; + } return resolveServiceInterfaceClass(attributes, defaultInterfaceClass).getName(); } @@ -343,21 +351,9 @@ public class AnnotationUtils { if (ignoreDefaultValue && nullSafeEquals(attributeValue, getDefaultValue(annotation, attributeName))) { continue; } - - /** - * @since 2.7.1 - * ignore annotation member - */ - if (attributeValue.getClass().isAnnotation()) { - continue; - } - if (attributeValue.getClass().isArray() && attributeValue.getClass().getComponentType().isAnnotation()) { - continue; - } actualAttributes.put(attributeName, attributeValue); } - return resolvePlaceholders(actualAttributes, propertyResolver, ignoreAttributeNames); } 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 56fd2970b2..d1a695f8d3 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 @@ -16,6 +16,7 @@ */ package org.apache.dubbo.config.spring.beans.factory.annotation; +import org.apache.dubbo.config.annotation.Method; import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.config.spring.ReferenceBean; import org.apache.dubbo.config.spring.api.DemoService; @@ -47,14 +48,14 @@ import static org.junit.Assert.assertTrue; */ @RunWith(SpringRunner.class) @ContextConfiguration( - classes = { - ServiceAnnotationTestConfiguration.class, - ReferenceAnnotationBeanPostProcessorTest.class - }) + classes = { + ServiceAnnotationTestConfiguration.class, + ReferenceAnnotationBeanPostProcessorTest.class + }) @TestPropertySource(properties = { - "packagesToScan = org.apache.dubbo.config.spring.context.annotation.provider", - "consumer.version = ${demo.service.version}", - "consumer.url = dubbo://127.0.0.1:12345?version=2.5.7", + "packagesToScan = org.apache.dubbo.config.spring.context.annotation.provider", + "consumer.version = ${demo.service.version}", + "consumer.url = dubbo://127.0.0.1:12345?version=2.5.7", }) public class ReferenceAnnotationBeanPostProcessorTest { @@ -79,7 +80,7 @@ public class ReferenceAnnotationBeanPostProcessorTest { @Qualifier("helloServiceImpl") private HelloService helloServiceImpl; - @Reference(id = "helloService") + @Reference(id = "helloService", methods = @Method(name = "sayName", timeout = 100)) private HelloService helloService; @Test @@ -131,7 +132,7 @@ public class ReferenceAnnotationBeanPostProcessorTest { public void testGetReferenceBeans() { ReferenceAnnotationBeanPostProcessor beanPostProcessor = context.getBean(BEAN_NAME, - ReferenceAnnotationBeanPostProcessor.class); + ReferenceAnnotationBeanPostProcessor.class); Collection> referenceBeans = beanPostProcessor.getReferenceBeans(); @@ -139,8 +140,6 @@ public class ReferenceAnnotationBeanPostProcessorTest { ReferenceBean referenceBean = referenceBeans.iterator().next(); - TestBean testBean = context.getBean(TestBean.class); - Assert.assertNotNull(referenceBean.get()); } @@ -149,11 +148,10 @@ public class ReferenceAnnotationBeanPostProcessorTest { public void testGetInjectedFieldReferenceBeanMap() { ReferenceAnnotationBeanPostProcessor beanPostProcessor = context.getBean(BEAN_NAME, - ReferenceAnnotationBeanPostProcessor.class); - + ReferenceAnnotationBeanPostProcessor.class); Map> referenceBeanMap = - beanPostProcessor.getInjectedFieldReferenceBeanMap(); + beanPostProcessor.getInjectedFieldReferenceBeanMap(); Assert.assertEquals(2, referenceBeanMap.size()); @@ -162,7 +160,7 @@ public class ReferenceAnnotationBeanPostProcessorTest { InjectionMetadata.InjectedElement injectedElement = entry.getKey(); Assert.assertEquals("org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor$AnnotatedFieldElement", - injectedElement.getClass().getName()); + injectedElement.getClass().getName()); } @@ -172,11 +170,10 @@ public class ReferenceAnnotationBeanPostProcessorTest { public void testGetInjectedMethodReferenceBeanMap() { ReferenceAnnotationBeanPostProcessor beanPostProcessor = context.getBean(BEAN_NAME, - ReferenceAnnotationBeanPostProcessor.class); - + ReferenceAnnotationBeanPostProcessor.class); Map> referenceBeanMap = - beanPostProcessor.getInjectedMethodReferenceBeanMap(); + beanPostProcessor.getInjectedMethodReferenceBeanMap(); Assert.assertEquals(2, referenceBeanMap.size()); @@ -185,33 +182,32 @@ public class ReferenceAnnotationBeanPostProcessorTest { InjectionMetadata.InjectedElement injectedElement = entry.getKey(); Assert.assertEquals("org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor$AnnotatedMethodElement", - injectedElement.getClass().getName()); + injectedElement.getClass().getName()); } } -// @Test -// public void testModuleInfo() { -// -// ReferenceAnnotationBeanPostProcessor beanPostProcessor = context.getBean(BEAN_NAME, -// ReferenceAnnotationBeanPostProcessor.class); -// -// -// Map> referenceBeanMap = -// beanPostProcessor.getInjectedMethodReferenceBeanMap(); -// -// for (Map.Entry> entry : referenceBeanMap.entrySet()) { -// ReferenceBean referenceBean = entry.getValue(); -// -// assertThat(referenceBean.getModule().getName(), is("defaultModule")); -// assertThat(referenceBean.getMonitor(), not(nullValue())); -// } -// } + // @Test + // public void testModuleInfo() { + // + // ReferenceAnnotationBeanPostProcessor beanPostProcessor = context.getBean(BEAN_NAME, + // ReferenceAnnotationBeanPostProcessor.class); + // + // + // Map> referenceBeanMap = + // beanPostProcessor.getInjectedMethodReferenceBeanMap(); + // + // for (Map.Entry> entry : referenceBeanMap.entrySet()) { + // ReferenceBean referenceBean = entry.getValue(); + // + // assertThat(referenceBean.getModule().getName(), is("defaultModule")); + // assertThat(referenceBean.getMonitor(), not(nullValue())); + // } + // } private static class AncestorBean { - private DemoService demoServiceFromAncestor; @Autowired @@ -232,7 +228,6 @@ public class ReferenceAnnotationBeanPostProcessorTest { } - private static class ParentBean extends AncestorBean { @Reference(version = "${consumer.version}", url = "${consumer.url}") @@ -242,7 +237,6 @@ public class ReferenceAnnotationBeanPostProcessorTest { return demoServiceFromParent; } - } static class TestBean extends ParentBean { @@ -265,4 +259,21 @@ public class ReferenceAnnotationBeanPostProcessorTest { } } + @Test + public void testReferenceBeansMethodAnnotation() { + + ReferenceAnnotationBeanPostProcessor beanPostProcessor = context.getBean(BEAN_NAME, + ReferenceAnnotationBeanPostProcessor.class); + + Collection> referenceBeans = beanPostProcessor.getReferenceBeans(); + + Assert.assertEquals(2, referenceBeans.size()); + + ReferenceBean referenceBean = referenceBeans.iterator().next(); + + if ("helloService".equals(referenceBean.getId())) { + Assert.assertNotNull(referenceBean.getMethods()); + } + } + } \ No newline at end of file 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 22325d96eb..a509b43f41 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 @@ -79,4 +79,17 @@ public class ServiceAnnotationBeanPostProcessorTest { } + @Test + public void testMethodAnnotation() { + + Map serviceBeansMap = beanFactory.getBeansOfType(ServiceBean.class); + + Assert.assertEquals(2, serviceBeansMap.size()); + + ServiceBean demoServiceBean = serviceBeansMap.get("ServiceBean:org.apache.dubbo.config.spring.api.DemoService:2.5.7"); + + Assert.assertNotNull(demoServiceBean.getMethods()); + + } + } diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboConfigTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboConfigTest.java index b611c06019..559553e740 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboConfigTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboConfigTest.java @@ -24,11 +24,14 @@ import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.ProviderConfig; import org.apache.dubbo.config.RegistryConfig; +import org.junit.Assert; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.PropertySource; +import java.util.Map; + /** * {@link EnableDubboConfig} Test * @@ -92,6 +95,14 @@ public class EnableDubboConfigTest { ApplicationConfig applicationBean3 = context.getBean("applicationBean3", ApplicationConfig.class); Assertions.assertEquals("dubbo-demo-application3", applicationBean3.getName()); + Map protocolConfigs = context.getBeansOfType(ProtocolConfig.class); + + for (Map.Entry entry : protocolConfigs.entrySet()) { + String beanName = entry.getKey(); + ProtocolConfig protocol = entry.getValue(); + Assert.assertEquals(beanName, protocol.getName()); + } + } @EnableDubboConfig diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/provider/DemoServiceImpl.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/provider/DemoServiceImpl.java index 3aa1e86f4e..8ee2a8a09f 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/provider/DemoServiceImpl.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/provider/DemoServiceImpl.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.config.spring.context.annotation.provider; +import org.apache.dubbo.config.annotation.Method; import org.apache.dubbo.config.spring.api.Box; import org.apache.dubbo.config.spring.api.DemoService; @@ -32,7 +33,8 @@ import org.springframework.transaction.annotation.Transactional; version = "2.5.7", application = "${demo.service.application}", protocol = "${demo.service.protocol}", - registry = "${demo.service.registry}" + registry = "${demo.service.registry}", + methods = @Method(timeout = 100,name = "sayName") ) @Service @Transactional diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboComponentScanRegistrarTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboComponentScanRegistrarTest.java deleted file mode 100644 index 6ed8a85752..0000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboComponentScanRegistrarTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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.config.spring.context.context.annotation; - -import org.apache.dubbo.config.spring.api.DemoService; -import org.apache.dubbo.config.spring.context.annotation.DubboComponentScanRegistrar; -import org.apache.dubbo.config.spring.context.annotation.consumer.ConsumerConfiguration; -import org.apache.dubbo.config.spring.context.annotation.provider.DemoServiceImpl; -import org.apache.dubbo.config.spring.context.annotation.provider.ProviderConfiguration; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.springframework.aop.support.AopUtils; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.transaction.annotation.Transactional; - -import static org.springframework.core.annotation.AnnotationUtils.findAnnotation; - -/** - * {@link DubboComponentScanRegistrar} Test - * - * @since 2.5.8 - */ -public class DubboComponentScanRegistrarTest { - - @Test - public void test() { - - AnnotationConfigApplicationContext providerContext = new AnnotationConfigApplicationContext(); - - providerContext.register(ProviderConfiguration.class); - - providerContext.refresh(); - - DemoService demoService = providerContext.getBean(DemoService.class); - - String value = demoService.sayName("Mercy"); - - Assertions.assertEquals("Hello,Mercy", value); - - Class beanClass = AopUtils.getTargetClass(demoService); - - // DemoServiceImpl with @Transactional - Assertions.assertEquals(DemoServiceImpl.class, beanClass); - - // Test @Transactional is present or not - Assertions.assertNotNull(findAnnotation(beanClass, Transactional.class)); - - AnnotationConfigApplicationContext consumerContext = new AnnotationConfigApplicationContext(); - - consumerContext.register(ConsumerConfiguration.class); - - consumerContext.refresh(); - - ConsumerConfiguration consumerConfiguration = consumerContext.getBean(ConsumerConfiguration.class); - - demoService = consumerConfiguration.getDemoService(); - - value = demoService.sayName("Mercy"); - - Assertions.assertEquals("Hello,Mercy", value); - - ConsumerConfiguration.Child child = consumerContext.getBean(ConsumerConfiguration.Child.class); - - // From Child - - demoService = child.getDemoServiceFromChild(); - - Assertions.assertNotNull(demoService); - - value = demoService.sayName("Mercy"); - - Assertions.assertEquals("Hello,Mercy", value); - - Assertions.assertEquals("Hello,Mercy", child.getDemoService().sayName("Mercy")); - - // From Parent - - demoService = child.getDemoServiceFromParent(); - - Assertions.assertNotNull(demoService); - - value = demoService.sayName("Mercy"); - - Assertions.assertEquals("Hello,Mercy", value); - - // From Ancestor - - demoService = child.getDemoServiceFromAncestor(); - - Assertions.assertNotNull(demoService); - - value = demoService.sayName("Mercy"); - - Assertions.assertEquals("Hello,Mercy", value); - - providerContext.close(); - consumerContext.close(); - - - } - - -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboConfigBindingRegistrarTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboConfigBindingRegistrarTest.java deleted file mode 100644 index 48c06d4b47..0000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboConfigBindingRegistrarTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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.config.spring.context.context.annotation; - -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.spring.context.annotation.DubboConfigBindingRegistrar; -import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfigBinding; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.PropertySource; - -/** - * {@link DubboConfigBindingRegistrar} - * - * @since 2.5.8 - */ -public class DubboConfigBindingRegistrarTest { - - @Test - public void testRegisterBeanDefinitionsForSingle() { - - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - - context.register(TestApplicationConfig.class); - - context.refresh(); - - ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class); - - Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName()); - - - } - - @Test - public void testRegisterBeanDefinitionsForMultiple() { - - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - - context.register(TestMultipleApplicationConfig.class); - - context.refresh(); - - ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class); - - Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName()); - - applicationConfig = context.getBean("applicationBean2", ApplicationConfig.class); - - Assertions.assertEquals("dubbo-demo-application2", applicationConfig.getName()); - - applicationConfig = context.getBean("applicationBean3", ApplicationConfig.class); - - Assertions.assertEquals("dubbo-demo-application3", applicationConfig.getName()); - - - } - - @EnableDubboConfigBinding(prefix = "${application.prefixes}", type = ApplicationConfig.class, multiple = true) - @PropertySource("META-INF/config.properties") - private static class TestMultipleApplicationConfig { - - } - - @EnableDubboConfigBinding(prefix = "${application.prefix}", type = ApplicationConfig.class) - @PropertySource("META-INF/config.properties") - private static class TestApplicationConfig { - - } - - -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboConfigBindingsRegistrarTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboConfigBindingsRegistrarTest.java deleted file mode 100644 index f09782913d..0000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboConfigBindingsRegistrarTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.config.spring.context.context.annotation; - -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.spring.context.annotation.DubboConfigBindingsRegistrar; -import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfigBinding; -import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfigBindings; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.PropertySource; - -/** - * {@link DubboConfigBindingsRegistrar} Test - * - * @since DubboConfigBindingsRegistrar - */ -public class DubboConfigBindingsRegistrarTest { - - @Test - public void test() { - - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - - context.register(TestConfig.class); - - context.refresh(); - - ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class); - - Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName()); - - Assertions.assertEquals(2, context.getBeansOfType(ApplicationConfig.class).size()); - - } - - - @EnableDubboConfigBindings({ - @EnableDubboConfigBinding(prefix = "${application.prefix}", type = ApplicationConfig.class), - @EnableDubboConfigBinding(prefix = "dubbo.applications.applicationBean", type = ApplicationConfig.class) - }) - @PropertySource("META-INF/config.properties") - private static class TestConfig { - - } - -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboConfigConfigurationTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboConfigConfigurationTest.java deleted file mode 100644 index d4f28aae30..0000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/DubboConfigConfigurationTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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.config.spring.context.context.annotation; - -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.ModuleConfig; -import org.apache.dubbo.config.ProtocolConfig; -import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.spring.context.annotation.DubboConfigConfiguration; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.core.io.support.ResourcePropertySource; - -import java.io.IOException; - -/** - * {@link DubboConfigConfiguration} Test - * - * @since 2.5.8 - */ -public class DubboConfigConfigurationTest { - - private AnnotationConfigApplicationContext context; - - @BeforeEach - public void before() throws IOException { - - context = new AnnotationConfigApplicationContext(); - ResourcePropertySource propertySource = new ResourcePropertySource("META-INF/config.properties"); - context.getEnvironment().getPropertySources().addFirst(propertySource); - - } - - @AfterEach - public void after() { - context.close(); - } - - @Test - public void testSingle() throws IOException { - - context.register(DubboConfigConfiguration.Single.class); - context.refresh(); - - // application - ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class); - Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName()); - - // module - ModuleConfig moduleConfig = context.getBean("moduleBean", ModuleConfig.class); - Assertions.assertEquals("dubbo-demo-module", moduleConfig.getName()); - - // registry - RegistryConfig registryConfig = context.getBean(RegistryConfig.class); - Assertions.assertEquals("zookeeper://192.168.99.100:32770", registryConfig.getAddress()); - - // protocol - ProtocolConfig protocolConfig = context.getBean(ProtocolConfig.class); - Assertions.assertEquals("dubbo", protocolConfig.getName()); - Assertions.assertEquals(Integer.valueOf(20880), protocolConfig.getPort()); - } - - @Test - public void testMultiple() { - - context.register(DubboConfigConfiguration.Multiple.class); - context.refresh(); - - // application - ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class); - Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName()); - - ApplicationConfig applicationBean2 = context.getBean("applicationBean2", ApplicationConfig.class); - Assertions.assertEquals("dubbo-demo-application2", applicationBean2.getName()); - - ApplicationConfig applicationBean3 = context.getBean("applicationBean3", ApplicationConfig.class); - Assertions.assertEquals("dubbo-demo-application3", applicationBean3.getName()); - - } - -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/EnableDubboConfigTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/EnableDubboConfigTest.java deleted file mode 100644 index 691f251dac..0000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/EnableDubboConfigTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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.config.spring.context.context.annotation; - -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.ConsumerConfig; -import org.apache.dubbo.config.ModuleConfig; -import org.apache.dubbo.config.MonitorConfig; -import org.apache.dubbo.config.ProtocolConfig; -import org.apache.dubbo.config.ProviderConfig; -import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig; - -import org.junit.Assert; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.PropertySource; - -import java.util.Map; - -/** - * {@link EnableDubboConfig} Test - * - * @since 2.5.8 - */ -public class EnableDubboConfigTest { - - @Test - public void testSingle() { - - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - context.register(TestConfig.class); - context.refresh(); - - // application - ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class); - Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName()); - - // module - ModuleConfig moduleConfig = context.getBean("moduleBean", ModuleConfig.class); - Assertions.assertEquals("dubbo-demo-module", moduleConfig.getName()); - - // registry - RegistryConfig registryConfig = context.getBean(RegistryConfig.class); - Assertions.assertEquals("zookeeper://192.168.99.100:32770", registryConfig.getAddress()); - - // protocol - ProtocolConfig protocolConfig = context.getBean(ProtocolConfig.class); - Assertions.assertEquals("dubbo", protocolConfig.getName()); - Assertions.assertEquals(Integer.valueOf(20880), protocolConfig.getPort()); - - // monitor - MonitorConfig monitorConfig = context.getBean(MonitorConfig.class); - Assertions.assertEquals("zookeeper://127.0.0.1:32770", monitorConfig.getAddress()); - - // provider - ProviderConfig providerConfig = context.getBean(ProviderConfig.class); - Assertions.assertEquals("127.0.0.1", providerConfig.getHost()); - - - // consumer - ConsumerConfig consumerConfig = context.getBean(ConsumerConfig.class); - Assertions.assertEquals("netty", consumerConfig.getClient()); - - } - - @Test - public void testMultiple() { - - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - context.register(TestMultipleConfig.class); - context.refresh(); - - // application - ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class); - Assertions.assertEquals("dubbo-demo-application", applicationConfig.getName()); - - ApplicationConfig applicationBean2 = context.getBean("applicationBean2", ApplicationConfig.class); - Assertions.assertEquals("dubbo-demo-application2", applicationBean2.getName()); - - ApplicationConfig applicationBean3 = context.getBean("applicationBean3", ApplicationConfig.class); - Assertions.assertEquals("dubbo-demo-application3", applicationBean3.getName()); - - Map protocolConfigs = context.getBeansOfType(ProtocolConfig.class); - - for (Map.Entry entry : protocolConfigs.entrySet()) { - String beanName = entry.getKey(); - ProtocolConfig protocol = entry.getValue(); - Assert.assertEquals(beanName, protocol.getName()); - } - - } - - @EnableDubboConfig - @PropertySource("META-INF/config.properties") - private static class TestMultipleConfig { - - } - - @EnableDubboConfig(multiple = false) - @PropertySource("META-INF/config.properties") - private static class TestConfig { - - } -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/EnableDubboTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/EnableDubboTest.java deleted file mode 100644 index 1366a35d25..0000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/EnableDubboTest.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * 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.config.spring.context.context.annotation; - -import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.spring.api.DemoService; -import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; -import org.apache.dubbo.config.spring.context.annotation.consumer.test.TestConsumerConfiguration; -import org.apache.dubbo.config.spring.context.annotation.provider.DemoServiceImpl; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.aop.support.AopUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Primary; -import org.springframework.context.annotation.PropertySource; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.TransactionDefinition; -import org.springframework.transaction.TransactionException; -import org.springframework.transaction.TransactionStatus; -import org.springframework.transaction.annotation.EnableTransactionManagement; -import org.springframework.transaction.annotation.Transactional; - -import static org.springframework.core.annotation.AnnotationUtils.findAnnotation; - -/** - * {@link EnableDubbo} Test - * - * @since 2.5.8 - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {EnableDubboTest.class}) -@TestPropertySource(locations = "classpath:/META-INF/dubbb-provider.properties", - properties = "demo.service.version = 2.5.7") -@EnableDubbo(scanBasePackages = "org.apache.dubbo.config.spring.context.annotation.provider") -@ComponentScan(basePackages = "org.apache.dubbo.config.spring.context.annotation.provider") -@EnableTransactionManagement -public class EnableDubboTest { - - @Autowired - private ApplicationContext providerContext; - - @Test - public void test() { - - DemoService demoService = providerContext.getBean(DemoService.class); - - String value = demoService.sayName("Mercy"); - - Assert.assertEquals("Hello,Mercy", value); - - Class beanClass = AopUtils.getTargetClass(demoService); - - // DemoServiceImpl with @Transactional - Assert.assertEquals(DemoServiceImpl.class, beanClass); - - // Test @Transactional is present or not - Assert.assertNotNull(findAnnotation(beanClass, Transactional.class)); - - AnnotationConfigApplicationContext consumerContext = new AnnotationConfigApplicationContext(TestConsumerConfiguration.class); - - TestConsumerConfiguration consumerConfiguration = consumerContext.getBean(TestConsumerConfiguration.class); - - demoService = consumerConfiguration.getDemoService(); - - value = demoService.sayName("Mercy"); - - Assert.assertEquals("Hello,Mercy", value); - - TestConsumerConfiguration.Child child = consumerContext.getBean(TestConsumerConfiguration.Child.class); - - // From Child - - demoService = child.getDemoServiceFromChild(); - - Assert.assertNotNull(demoService); - - value = demoService.sayName("Mercy"); - - Assert.assertEquals("Hello,Mercy", value); - - // From Parent - - demoService = child.getDemoServiceFromParent(); - - Assert.assertNotNull(demoService); - - value = demoService.sayName("Mercy"); - - Assert.assertEquals("Hello,Mercy", value); - - // From Ancestor - - demoService = child.getDemoServiceFromAncestor(); - - Assert.assertNotNull(demoService); - - value = demoService.sayName("Mercy"); - - Assert.assertEquals("Hello,Mercy", value); - - // Test my-registry2 bean presentation - RegistryConfig registryConfig = consumerContext.getBean("my-registry2", RegistryConfig.class); - - // Test multiple binding - Assert.assertEquals("N/A", registryConfig.getAddress()); - - } - - @EnableDubbo(scanBasePackages = "org.apache.dubbo.config.spring.context.annotation.provider") - @ComponentScan(basePackages = "org.apache.dubbo.config.spring.context.annotation.provider") - @PropertySource("classpath:/META-INF/dubbb-provider.properties") - @EnableTransactionManagement - public static class TestProviderConfiguration { - - @Primary - @Bean - public PlatformTransactionManager platformTransactionManager() { - return new PlatformTransactionManager() { - - @Override - public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException { - return null; - } - - @Override - public void commit(TransactionStatus status) throws TransactionException { - - } - - @Override - public void rollback(TransactionStatus status) throws TransactionException { - - } - }; - } - } - - -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/consumer/ConsumerConfiguration.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/consumer/ConsumerConfiguration.java deleted file mode 100644 index 0486698619..0000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/consumer/ConsumerConfiguration.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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.config.spring.context.context.annotation.consumer; - -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.annotation.Reference; -import org.apache.dubbo.config.spring.api.DemoService; -import org.apache.dubbo.config.spring.context.annotation.DubboComponentScan; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; - -@Configuration("consumerConfiguration") -@DubboComponentScan( - basePackageClasses = ConsumerConfiguration.class -) -@PropertySource("META-INF/default.properties") -public class ConsumerConfiguration { - - /** - * Current application configuration, to replace XML config: - * - * <dubbo:application name="dubbo-demo-application"/> - * - * - * @return {@link ApplicationConfig} Bean - */ - @Bean("dubbo-demo-application") - public ApplicationConfig applicationConfig() { - ApplicationConfig applicationConfig = new ApplicationConfig(); - applicationConfig.setName("dubbo-demo-application"); - return applicationConfig; - } - - /** - * Current registry center configuration, to replace XML config: - * - * <dubbo:registry address="N/A"/> - * - * - * @return {@link RegistryConfig} Bean - */ - @Bean - public RegistryConfig registryConfig() { - RegistryConfig registryConfig = new RegistryConfig(); - registryConfig.setAddress("N/A"); - return registryConfig; - } - - @Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345") - private DemoService demoService; - - public DemoService getDemoService() { - return demoService; - } - - public void setDemoService(DemoService demoService) { - this.demoService = demoService; - } - - - @Bean - public Child c() { - return new Child(); - } - - public static abstract class Ancestor { - - @Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345") - private DemoService demoServiceFromAncestor; - - public DemoService getDemoServiceFromAncestor() { - return demoServiceFromAncestor; - } - - public void setDemoServiceFromAncestor(DemoService demoServiceFromAncestor) { - this.demoServiceFromAncestor = demoServiceFromAncestor; - } - } - - public static abstract class Parent extends Ancestor { - - private DemoService demoServiceFromParent; - - public DemoService getDemoServiceFromParent() { - return demoServiceFromParent; - } - - @Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345") - public void setDemoServiceFromParent(DemoService demoServiceFromParent) { - this.demoServiceFromParent = demoServiceFromParent; - } - - } - - public static class Child extends Parent { - - @Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345") - private DemoService demoServiceFromChild; - - public DemoService getDemoServiceFromChild() { - return demoServiceFromChild; - } - - public void setDemoServiceFromChild(DemoService demoServiceFromChild) { - this.demoServiceFromChild = demoServiceFromChild; - } - } - -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/consumer/test/TestConsumerConfiguration.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/consumer/test/TestConsumerConfiguration.java deleted file mode 100644 index dc41c614cd..0000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/consumer/test/TestConsumerConfiguration.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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.config.spring.context.context.annotation.consumer.test; - -import org.apache.dubbo.config.annotation.Reference; -import org.apache.dubbo.config.spring.api.DemoService; -import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.PropertySource; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -/** - * Test Consumer Configuration - * - * @since 2.5.7 - */ -@EnableDubbo(scanBasePackageClasses = TestConsumerConfiguration.class, multipleConfig = true) -@PropertySource("META-INF/dubbb-consumer.properties") -@EnableTransactionManagement -public class TestConsumerConfiguration { - - @Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345", application = "dubbo-demo-application") - private DemoService demoService; - - public DemoService getDemoService() { - return demoService; - } - - public void setDemoService(DemoService demoService) { - this.demoService = demoService; - } - - - @Bean - public TestConsumerConfiguration.Child c() { - return new TestConsumerConfiguration.Child(); - } - - public static abstract class Ancestor { - - @Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345", application = "dubbo-demo-application") - private DemoService demoServiceFromAncestor; - - public DemoService getDemoServiceFromAncestor() { - return demoServiceFromAncestor; - } - - public void setDemoServiceFromAncestor(DemoService demoServiceFromAncestor) { - this.demoServiceFromAncestor = demoServiceFromAncestor; - } - } - - public static abstract class Parent extends TestConsumerConfiguration.Ancestor { - - private DemoService demoServiceFromParent; - - public DemoService getDemoServiceFromParent() { - return demoServiceFromParent; - } - - @Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345", application = "dubbo-demo-application") - public void setDemoServiceFromParent(DemoService demoServiceFromParent) { - this.demoServiceFromParent = demoServiceFromParent; - } - - } - - public static class Child extends TestConsumerConfiguration.Parent { - - @Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345", application = "dubbo-demo-application") - private DemoService demoServiceFromChild; - - public DemoService getDemoServiceFromChild() { - return demoServiceFromChild; - } - - public void setDemoServiceFromChild(DemoService demoServiceFromChild) { - this.demoServiceFromChild = demoServiceFromChild; - } - } -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/DemoServiceImpl.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/DemoServiceImpl.java deleted file mode 100644 index 155bd2a553..0000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/DemoServiceImpl.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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.config.spring.context.context.annotation.provider; - -import org.apache.dubbo.config.spring.api.Box; -import org.apache.dubbo.config.spring.api.DemoService; - -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - - -/** - * {@link DemoService} Service implementation - * - * @since 2.5.8 - */ -@org.apache.dubbo.config.annotation.Service( - version = "${demo.service.version}", - application = "${demo.service.application}", - protocol = "${demo.service.protocol}", - registry = "${demo.service.registry}" -) -@Service -@Transactional -public class DemoServiceImpl implements DemoService { - - @Override - public String sayName(String name) { - return "Hello," + name; - } - - @Override - public Box getBox() { - return new Box() { - @Override - public String getName() { - return "MyBox"; - } - }; - } -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/HelloServiceImpl.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/HelloServiceImpl.java deleted file mode 100644 index 10b00a8f5b..0000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/HelloServiceImpl.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.config.spring.context.context.annotation.provider; - -import org.apache.dubbo.config.annotation.Service; -import org.apache.dubbo.config.spring.api.HelloService; - -/** - * {@link HelloService} Implementation just annotating Dubbo's {@link Service} - * - * @since 2.5.9 - */ -@Service(interfaceName = "org.apache.dubbo.config.spring.api.HelloService") -public class HelloServiceImpl implements HelloService { - - @Override - public String sayHello(String name) { - return "Hello, " + name; - } -} diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/ProviderConfiguration.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/ProviderConfiguration.java deleted file mode 100644 index 9c45d7134a..0000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/ProviderConfiguration.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * 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.config.spring.context.context.annotation.provider; - -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.ProtocolConfig; -import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.spring.context.annotation.DubboComponentScan; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Primary; -import org.springframework.context.annotation.PropertySource; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.TransactionDefinition; -import org.springframework.transaction.TransactionException; -import org.springframework.transaction.TransactionStatus; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -@DubboComponentScan(basePackages = "org.apache.dubbo") -@ComponentScan(basePackages = "org.apache.dubbo") -@PropertySource("META-INF/default.properties") -@EnableTransactionManagement -public class ProviderConfiguration { - - /** - * Current application configuration, to replace XML config: - * - * <dubbo:application name="dubbo-demo-application"/> - * - * - * @return {@link ApplicationConfig} Bean - */ - @Bean("dubbo-demo-application") - public ApplicationConfig applicationConfig() { - ApplicationConfig applicationConfig = new ApplicationConfig(); - applicationConfig.setName("dubbo-demo-application"); - return applicationConfig; - } - - /** - * Current registry center configuration, to replace XML config: - * - * <dubbo:registry id="my-registry" address="N/A"/> - * - * - * @return {@link RegistryConfig} Bean - */ - @Bean("my-registry") - public RegistryConfig registryConfig() { - RegistryConfig registryConfig = new RegistryConfig(); - registryConfig.setAddress("N/A"); - return registryConfig; - } - - /** - * Current protocol configuration, to replace XML config: - * - * <dubbo:protocol name="dubbo" port="12345"/> - * - * - * @return {@link ProtocolConfig} Bean - */ - @Bean("dubbo") - public ProtocolConfig protocolConfig() { - ProtocolConfig protocolConfig = new ProtocolConfig(); - protocolConfig.setName("dubbo"); - protocolConfig.setPort(12345); - return protocolConfig; - } - - @Primary - @Bean - public PlatformTransactionManager platformTransactionManager() { - return new PlatformTransactionManager() { - - @Override - public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException { - return null; - } - - @Override - public void commit(TransactionStatus status) throws TransactionException { - - } - - @Override - public void rollback(TransactionStatus status) throws TransactionException { - - } - }; - } - -} - diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/properties/DefaultDubboConfigBinderTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/properties/DefaultDubboConfigBinderTest.java deleted file mode 100644 index 1caddb0b31..0000000000 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/properties/DefaultDubboConfigBinderTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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.config.spring.context.context.properties; - - -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.ConsumerConfig; -import org.apache.dubbo.config.ProtocolConfig; -import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.spring.beans.factory.config.YamlPropertySourceFactory; -import org.apache.dubbo.config.spring.context.properties.DefaultDubboConfigBinder; -import org.apache.dubbo.config.spring.context.properties.DubboConfigBinder; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@TestPropertySource(locations = "classpath:/dubbo.properties") -@PropertySource(name = "yaml-source", value = {"classpath:/META-INF/dubbo.yml"}, factory = YamlPropertySourceFactory.class) -@Configuration -@ContextConfiguration(classes = {DefaultDubboConfigBinder.class, DefaultDubboConfigBinderTest.class}) -public class DefaultDubboConfigBinderTest { - - @Autowired - private DubboConfigBinder dubboConfigBinder; - - @Value("${dubbo.consumer.default}") - private Boolean isDefault; - - @Value("${dubbo.consumer.client}") - private String client; - - @Value("${dubbo.consumer.threadpool}") - private String threadPool; - - @Value("${dubbo.consumer.corethreads}") - private Integer coreThreads; - - @Value("${dubbo.consumer.threads}") - private Integer threads; - - @Value("${dubbo.consumer.queues}") - private Integer queues; - - @Test - public void testBinder() { - - ApplicationConfig applicationConfig = new ApplicationConfig(); - dubboConfigBinder.bind("dubbo.application", applicationConfig); - Assert.assertEquals("hello", applicationConfig.getName()); - Assert.assertEquals("world", applicationConfig.getOwner()); - - RegistryConfig registryConfig = new RegistryConfig(); - dubboConfigBinder.bind("dubbo.registry", registryConfig); - Assert.assertEquals("10.20.153.17", registryConfig.getAddress()); - - ProtocolConfig protocolConfig = new ProtocolConfig(); - dubboConfigBinder.bind("dubbo.protocol", protocolConfig); - Assert.assertEquals(Integer.valueOf(20881), protocolConfig.getPort()); - - ConsumerConfig consumerConfig = new ConsumerConfig(); - dubboConfigBinder.bind("dubbo.consumer", consumerConfig); - - Assert.assertEquals(isDefault, consumerConfig.isDefault()); - Assert.assertEquals(client, consumerConfig.getClient()); - Assert.assertEquals(threadPool, consumerConfig.getThreadpool()); - Assert.assertEquals(coreThreads, consumerConfig.getCorethreads()); - Assert.assertEquals(threads, consumerConfig.getThreads()); - Assert.assertEquals(queues, consumerConfig.getQueues()); - } -} - diff --git a/dubbo-config/pom.xml b/dubbo-config/pom.xml index bb8518fea9..69fcbc81aa 100644 --- a/dubbo-config/pom.xml +++ b/dubbo-config/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-parent ${revision} + ../pom.xml dubbo-config pom diff --git a/dubbo-configcenter/dubbo-configcenter-api/src/test/java/org/apache/dubbo/configcenter/support/nop/NopDynamicConfigurationTest.java b/dubbo-configcenter/dubbo-configcenter-api/src/test/java/org/apache/dubbo/configcenter/support/nop/NopDynamicConfigurationTest.java deleted file mode 100644 index a5158769df..0000000000 --- a/dubbo-configcenter/dubbo-configcenter-api/src/test/java/org/apache/dubbo/configcenter/support/nop/NopDynamicConfigurationTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.configcenter.support.nop; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * {@link NopDynamicConfiguration} Test - * - * @since 2.7.4 - */ -public class NopDynamicConfigurationTest { - - private NopDynamicConfiguration configuration = new NopDynamicConfiguration(null); - - @Test - public void testGetInternalProperty() { - assertNull(configuration.getInternalProperty(null)); - } - - @Test - public void testGetConfig() { - assertNull(configuration.getConfig(null, null, -1)); - } - - - @Test - public void testGetConfigs() { - assertNull(configuration.getConfigs(null, null, -1)); - } - - @Test - public void testAddListener() { - configuration.addListener(null, null, null); - } - - @Test - public void testRemoveListener() { - configuration.removeListener(null, null, null); - } - - @Test - public void testPublishConfig() { - assertTrue(configuration.publishConfig(null, null, null)); - } - - @Test - public void testGetConfigKeys() { - assertTrue(configuration.getConfigKeys(null).isEmpty()); - } - - -} diff --git a/dubbo-configcenter/dubbo-configcenter-apollo/pom.xml b/dubbo-configcenter/dubbo-configcenter-apollo/pom.xml index 6f3d8de8b1..4d19aa88f9 100644 --- a/dubbo-configcenter/dubbo-configcenter-apollo/pom.xml +++ b/dubbo-configcenter/dubbo-configcenter-apollo/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-configcenter ${revision} + ../pom.xml dubbo-configcenter-apollo jar diff --git a/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java index 810527cc9c..cd20dc20ab 100644 --- a/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java +++ b/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java @@ -97,11 +97,11 @@ public class ApolloDynamicConfiguration implements DynamicConfiguration { } } - private String getAddressWithProtocolPrefix (URL url) { + private String getAddressWithProtocolPrefix(URL url) { String address = url.getBackupAddress(); if (StringUtils.isNotEmpty(address)) { address = Arrays.stream(COMMA_SPLIT_PATTERN.split(address)) - .map(addr -> { + .map(addr -> { if (addr.startsWith(APOLLO_PROTOCOL_PREFIX)) { return addr; } @@ -135,7 +135,7 @@ public class ApolloDynamicConfiguration implements DynamicConfiguration { } @Override - public String getRule(String key, String group, long timeout) throws IllegalStateException { + public String getConfig(String key, String group, long timeout) throws IllegalStateException { if (StringUtils.isNotEmpty(group)) { if (group.equals(url.getParameter(APPLICATION_KEY))) { return ConfigService.getAppConfig().getProperty(key, null); @@ -147,8 +147,8 @@ public class ApolloDynamicConfiguration implements DynamicConfiguration { } @Override - public String getProperties(String key, String group, long timeout) throws IllegalStateException { - if(StringUtils.isEmpty(group)) { + public String getRule(String key, String group, long timeout) throws IllegalStateException { + if (StringUtils.isEmpty(group)) { return dubboConfigFile.getContent(); } if (group.equals(url.getParameter(APPLICATION_KEY))) { diff --git a/dubbo-configcenter/dubbo-configcenter-consul/pom.xml b/dubbo-configcenter/dubbo-configcenter-consul/pom.xml index 830c6bd71b..fa444feeb8 100644 --- a/dubbo-configcenter/dubbo-configcenter-consul/pom.xml +++ b/dubbo-configcenter/dubbo-configcenter-consul/pom.xml @@ -18,9 +18,10 @@ - dubbo-configcenter org.apache.dubbo + dubbo-configcenter ${revision} + ../pom.xml 4.0.0 diff --git a/dubbo-configcenter/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfiguration.java index b098ffa458..9a698a3bd9 100644 --- a/dubbo-configcenter/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfiguration.java +++ b/dubbo-configcenter/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfiguration.java @@ -93,16 +93,16 @@ public class ConsulDynamicConfiguration implements DynamicConfiguration { } @Override - public String getRule(String key, String group, long timeout) throws IllegalStateException { + public String getConfig(String key, String group, long timeout) throws IllegalStateException { return (String) getInternalProperty(convertKey(group, key)); } @Override - public String getProperties(String key, String group, long timeout) throws IllegalStateException { + public String getRule(String key, String group, long timeout) throws IllegalStateException { if (StringUtils.isEmpty(group)) { group = DEFAULT_GROUP; } - return (String) getInternalProperty(convertKey(group, key)); + return getConfig(key, group, timeout); } @Override diff --git a/dubbo-configcenter/dubbo-configcenter-etcd/pom.xml b/dubbo-configcenter/dubbo-configcenter-etcd/pom.xml index 76eaeb3a36..c16fd8ab93 100644 --- a/dubbo-configcenter/dubbo-configcenter-etcd/pom.xml +++ b/dubbo-configcenter/dubbo-configcenter-etcd/pom.xml @@ -20,9 +20,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - dubbo-configcenter org.apache.dubbo + dubbo-configcenter ${revision} + ../pom.xml 4.0.0 diff --git a/dubbo-configcenter/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfiguration.java index 6208d4ddb5..c5b48b7cde 100644 --- a/dubbo-configcenter/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfiguration.java +++ b/dubbo-configcenter/dubbo-configcenter-etcd/src/main/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfiguration.java @@ -22,7 +22,6 @@ import org.apache.dubbo.common.config.configcenter.ConfigChangeEvent; import org.apache.dubbo.common.config.configcenter.ConfigChangeType; import org.apache.dubbo.common.config.configcenter.ConfigurationListener; import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; -import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.remoting.etcd.StateListener; import org.apache.dubbo.remoting.etcd.jetcd.JEtcdClient; @@ -95,18 +94,23 @@ public class EtcdDynamicConfiguration implements DynamicConfiguration { } @Override - public String getRule(String key, String group, long timeout) throws IllegalStateException { + public String getConfig(String key, String group, long timeout) throws IllegalStateException { return (String) getInternalProperty(convertKey(group, key)); } @Override - public String getProperties(String key, String group, long timeout) throws IllegalStateException { - if (StringUtils.isEmpty(group)) { - group = DEFAULT_GROUP; - } - return (String) getInternalProperty(convertKey(group, key)); + public String getRule(String key, String group, long timeout) throws IllegalStateException { + return getConfig(key, group, timeout); } +// @Override +// public String getConfigs(String key, String group, long timeout) throws IllegalStateException { +// if (StringUtils.isEmpty(group)) { +// group = DEFAULT_GROUP; +// } +// return (String) getInternalProperty(convertKey(group, key)); +// } + @Override public Object getInternalProperty(String key) { return etcdClient.getKVValue(key); @@ -118,7 +122,7 @@ public class EtcdDynamicConfiguration implements DynamicConfiguration { } private void recover() { - for (EtcdConfigWatcher watcher: watchListenerMap.values()) { + for (EtcdConfigWatcher watcher : watchListenerMap.values()) { watcher.watch(); } } diff --git a/dubbo-configcenter/dubbo-configcenter-nacos/pom.xml b/dubbo-configcenter/dubbo-configcenter-nacos/pom.xml index 68dc27150f..b54dfc6bce 100644 --- a/dubbo-configcenter/dubbo-configcenter-nacos/pom.xml +++ b/dubbo-configcenter/dubbo-configcenter-nacos/pom.xml @@ -20,9 +20,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - dubbo-configcenter org.apache.dubbo + dubbo-configcenter ${revision} + ../pom.xml 4.0.0 diff --git a/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java index 468c5cbd07..bc3f900cf5 100644 --- a/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java +++ b/dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java @@ -185,9 +185,9 @@ public class NacosDynamicConfiguration implements DynamicConfiguration { } @Override - public String getRule(String key, String group, long timeout) throws IllegalStateException { + public String getConfig(String key, String group, long timeout) throws IllegalStateException { try { - long nacosTimeout = timeout < 0 ? DEFAULT_TIMEOUT : timeout; + long nacosTimeout = timeout < 0 ? DEFAULT_TIMEOUT : timeout; if (StringUtils.isEmpty(group)) { group = DEFAULT_GROUP; } @@ -199,8 +199,8 @@ public class NacosDynamicConfiguration implements DynamicConfiguration { } @Override - public String getProperties(String key, String group, long timeout) throws IllegalStateException { - return getRule(key, group, timeout); + public String getRule(String key, String group, long timeout) throws IllegalStateException { + return getConfig(key, group, timeout); } @Override diff --git a/dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java b/dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java index df3f5e2bec..a5ed3e7589 100644 --- a/dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java +++ b/dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java @@ -59,9 +59,9 @@ public class NacosDynamicConfigurationTest { Thread.sleep(200); put("org.apache.dubbo.demo.DemoService:1.0.0.test:xxxx.configurators", "helloworld"); Thread.sleep(200); - Assertions.assertEquals("hello", config.getRule("org.apache.dubbo.nacos.testService.configurators", DynamicConfiguration.DEFAULT_GROUP)); - Assertions.assertEquals("aaa=bbb", config.getRule("dubbo.properties", "test")); - Assertions.assertEquals("helloworld", config.getRule("org.apache.dubbo.demo.DemoService:1.0.0.test:xxxx.configurators", DynamicConfiguration.DEFAULT_GROUP)); + Assertions.assertEquals("hello", config.getConfig("org.apache.dubbo.nacos.testService.configurators", DynamicConfiguration.DEFAULT_GROUP)); + Assertions.assertEquals("aaa=bbb", config.getConfig("dubbo.properties", "test")); + Assertions.assertEquals("helloworld", config.getConfig("org.apache.dubbo.demo.DemoService:1.0.0.test:xxxx.configurators", DynamicConfiguration.DEFAULT_GROUP)); } @Test diff --git a/dubbo-configcenter/dubbo-configcenter-zookeeper/pom.xml b/dubbo-configcenter/dubbo-configcenter-zookeeper/pom.xml index 54977b8954..c06de98f0e 100644 --- a/dubbo-configcenter/dubbo-configcenter-zookeeper/pom.xml +++ b/dubbo-configcenter/dubbo-configcenter-zookeeper/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-configcenter ${revision} + ../pom.xml dubbo-configcenter-zookeeper jar diff --git a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java index 7010ab4a89..a346ecc5d0 100644 --- a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java +++ b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java @@ -106,22 +106,23 @@ public class ZookeeperDynamicConfiguration implements DynamicConfiguration { } @Override - public String getRule(String key, String group, long timeout) throws IllegalStateException { + public String getConfig(String key, String group, long timeout) throws IllegalStateException { return (String) getInternalProperty(getPathKey(group, key)); } + @Override + public String getRule(String key, String group, long timeout) throws IllegalStateException { + return getConfig(key, group, timeout); + } + @Override public String getProperties(String key, String group, long timeout) throws IllegalStateException { - // use global group 'dubbo' if no group specified - if (StringUtils.isEmpty(group)) { - group = DEFAULT_GROUP; - } - return (String) getInternalProperty(getPathKey(group, key)); + return getConfig(key, group, timeout); } @Override public boolean publishConfig(String key, String group, String content) { - String path = buildPath(key, group); + String path = getPathKey(key, group); zkClient.create(path, content, true); return true; } @@ -133,41 +134,46 @@ public class ZookeeperDynamicConfiguration implements DynamicConfiguration { return isEmpty(nodes) ? emptySortedSet() : unmodifiableSortedSet(new TreeSet<>(nodes)); } + private String buildPath(String group) { + String actualGroup = StringUtils.isEmpty(group) ? DEFAULT_GROUP : group; + return rootPath + PATH_SEPARATOR + actualGroup; + } + private String getPathKey(String group, String key) { - return rootPath + PATH_SEPARATOR + group + PATH_SEPARATOR + key; + return buildPath(group) + PATH_SEPARATOR + key; } - /** - * Build the config node path by the specified key and group - * - * @param key the key to represent a configuration - * @param group the group where the key belongs to - * @return - */ - protected String buildPath(String key, String group) { - String path = null; - /** - * when group is not null, we are getting startup configs from Config Center, for example: - * group=dubbo, key=dubbo.properties - */ - if (StringUtils.isNotEmpty(group)) { - path = group + "/" + key; - } - /** - * when group is null, we are fetching governance rules, for example: - * 1. key=org.apache.dubbo.DemoService.configurators - * 2. key = org.apache.dubbo.DemoService.condition-router - */ - else { - int i = key.lastIndexOf("."); - path = key.substring(0, i) + "/" + key.substring(i + 1); - } - return buildPath(path); - } - - protected String buildPath(String relativePath) { - String path = rootPath + "/" + relativePath; - return path; - } +// /** +// * Build the config node path by the specified key and group +// * +// * @param key the key to represent a configuration +// * @param group the group where the key belongs to +// * @return +// */ +// protected String buildPath(String key, String group) { +// String path = null; +// /** +// * when group is not null, we are getting startup configs from Config Center, for example: +// * group=dubbo, key=dubbo.properties +// */ +// if (StringUtils.isNotEmpty(group)) { +// path = group + "/" + key; +// } +// /** +// * when group is null, we are fetching governance rules, for example: +// * 1. key=org.apache.dubbo.DemoService.configurators +// * 2. key = org.apache.dubbo.DemoService.condition-router +// */ +// else { +// int i = key.lastIndexOf("."); +// path = key.substring(0, i) + "/" + key.substring(i + 1); +// } +// return buildPath(path); +// } +// +// protected String buildPath(String relativePath) { +// String path = rootPath + "/" + relativePath; +// return path; +// } } diff --git a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/test/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationTest.java b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/test/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationTest.java index 0d8b4d4df7..b2d03fc31f 100644 --- a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/test/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationTest.java +++ b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/test/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfigurationTest.java @@ -92,7 +92,7 @@ public class ZookeeperDynamicConfigurationTest { @Test public void testGetConfig() throws Exception { - Assertions.assertEquals("The content from dubbo.properties", configuration.getProperties("dubbo.properties", "dubbo")); + Assertions.assertEquals("The content from dubbo.properties", configuration.getConfig("dubbo.properties", "dubbo")); } @Test diff --git a/dubbo-configcenter/pom.xml b/dubbo-configcenter/pom.xml index 312fc3cbc3..869611cb62 100644 --- a/dubbo-configcenter/pom.xml +++ b/dubbo-configcenter/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-parent ${revision} + ../pom.xml dubbo-configcenter pom diff --git a/dubbo-container/dubbo-container-api/pom.xml b/dubbo-container/dubbo-container-api/pom.xml index 0014da4c2a..00e2fc3e45 100644 --- a/dubbo-container/dubbo-container-api/pom.xml +++ b/dubbo-container/dubbo-container-api/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-container ${revision} + ../pom.xml dubbo-container-api jar diff --git a/dubbo-container/dubbo-container-log4j/pom.xml b/dubbo-container/dubbo-container-log4j/pom.xml index d4503df1c8..949615f73e 100644 --- a/dubbo-container/dubbo-container-log4j/pom.xml +++ b/dubbo-container/dubbo-container-log4j/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-container ${revision} + ../pom.xml dubbo-container-log4j jar diff --git a/dubbo-container/dubbo-container-logback/pom.xml b/dubbo-container/dubbo-container-logback/pom.xml index a6f70145fa..0af3164a8b 100644 --- a/dubbo-container/dubbo-container-logback/pom.xml +++ b/dubbo-container/dubbo-container-logback/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-container ${revision} + ../pom.xml dubbo-container-logback jar diff --git a/dubbo-container/dubbo-container-spring/pom.xml b/dubbo-container/dubbo-container-spring/pom.xml index c7762cd418..ea11ebfe63 100644 --- a/dubbo-container/dubbo-container-spring/pom.xml +++ b/dubbo-container/dubbo-container-spring/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-container ${revision} + ../pom.xml dubbo-container-spring jar diff --git a/dubbo-container/pom.xml b/dubbo-container/pom.xml index b61d3cf1b9..d088993ff4 100644 --- a/dubbo-container/pom.xml +++ b/dubbo-container/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-parent ${revision} + ../pom.xml dubbo-container pom diff --git a/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-consumer/pom.xml b/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-consumer/pom.xml index 8dc62d85fc..6dd31d2942 100644 --- a/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-consumer/pom.xml +++ b/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-consumer/pom.xml @@ -20,9 +20,10 @@ - dubbo-demo-annotation org.apache.dubbo + dubbo-demo-annotation ${revision} + ../pom.xml 4.0.0 diff --git a/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-consumer/src/main/resources/spring/dubbo-consumer.properties b/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-consumer/src/main/resources/spring/dubbo-consumer.properties index 5ec658ba92..bda13add46 100644 --- a/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-consumer/src/main/resources/spring/dubbo-consumer.properties +++ b/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-consumer/src/main/resources/spring/dubbo-consumer.properties @@ -18,4 +18,4 @@ # dubbo.application.name=dubbo-demo-annotation-consumer -dubbo.registry.address=multicast://224.5.6.7:1234 +dubbo.registry.address=zookeeper://127.0.0.1:2181 diff --git a/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-provider/pom.xml b/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-provider/pom.xml index 4a3e720d88..27186ea7be 100644 --- a/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-provider/pom.xml +++ b/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-provider/pom.xml @@ -20,9 +20,10 @@ - dubbo-demo-annotation org.apache.dubbo + dubbo-demo-annotation ${revision} + ../pom.xml 4.0.0 diff --git a/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java b/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java index b848865dee..737b10ea8f 100644 --- a/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java +++ b/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java @@ -27,10 +27,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; public class Application { - /** - * In order to make sure multicast registry works, need to specify '-Djava.net.preferIPv4Stack=true' before - * launch the application - */ public static void main(String[] args) throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProviderConfiguration.class); context.start(); @@ -44,7 +40,7 @@ public class Application { @Bean public RegistryConfig registryConfig() { RegistryConfig registryConfig = new RegistryConfig(); - registryConfig.setAddress("multicast://224.5.6.7:1234"); + registryConfig.setAddress("zookeeper://127.0.0.1:2181"); return registryConfig; } } diff --git a/dubbo-demo/dubbo-demo-api/dubbo-demo-api-consumer/pom.xml b/dubbo-demo/dubbo-demo-api/dubbo-demo-api-consumer/pom.xml index e273e31373..055e06d655 100644 --- a/dubbo-demo/dubbo-demo-api/dubbo-demo-api-consumer/pom.xml +++ b/dubbo-demo/dubbo-demo-api/dubbo-demo-api-consumer/pom.xml @@ -20,9 +20,10 @@ - dubbo-demo-api org.apache.dubbo + dubbo-demo-api ${revision} + ../pom.xml 4.0.0 diff --git a/dubbo-demo/dubbo-demo-api/dubbo-demo-api-consumer/src/main/java/org/apache/dubbo/demo/consumer/Application.java b/dubbo-demo/dubbo-demo-api/dubbo-demo-api-consumer/src/main/java/org/apache/dubbo/demo/consumer/Application.java index b062d6e65f..9591a69b7a 100644 --- a/dubbo-demo/dubbo-demo-api/dubbo-demo-api-consumer/src/main/java/org/apache/dubbo/demo/consumer/Application.java +++ b/dubbo-demo/dubbo-demo-api/dubbo-demo-api-consumer/src/main/java/org/apache/dubbo/demo/consumer/Application.java @@ -24,14 +24,10 @@ import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.demo.DemoService; public class Application { - /** - * In order to make sure multicast registry works, need to specify '-Djava.net.preferIPv4Stack=true' before - * launch the application - */ public static void main(String[] args) { ReferenceConfig reference = new ReferenceConfig<>(); reference.setApplication(new ApplicationConfig("dubbo-demo-api-consumer")); - reference.setRegistry(new RegistryConfig("multicast://224.5.6.7:1234")); + reference.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181")); reference.setInterface(DemoService.class); DemoService service = reference.get(); String message = service.sayHello("dubbo"); diff --git a/dubbo-demo/dubbo-demo-api/dubbo-demo-api-provider/pom.xml b/dubbo-demo/dubbo-demo-api/dubbo-demo-api-provider/pom.xml index 04a2ae29ff..29e2bc7e90 100644 --- a/dubbo-demo/dubbo-demo-api/dubbo-demo-api-provider/pom.xml +++ b/dubbo-demo/dubbo-demo-api/dubbo-demo-api-provider/pom.xml @@ -21,9 +21,10 @@ - dubbo-demo-api org.apache.dubbo + dubbo-demo-api ${revision} + ../pom.xml 4.0.0 diff --git a/dubbo-demo/dubbo-demo-api/dubbo-demo-api-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java b/dubbo-demo/dubbo-demo-api/dubbo-demo-api-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java index 857e03f116..5990d75063 100644 --- a/dubbo-demo/dubbo-demo-api/dubbo-demo-api-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java +++ b/dubbo-demo/dubbo-demo-api/dubbo-demo-api-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java @@ -24,14 +24,10 @@ import org.apache.dubbo.config.ServiceConfig; import org.apache.dubbo.demo.DemoService; public class Application { - /** - * In order to make sure multicast registry works, need to specify '-Djava.net.preferIPv4Stack=true' before - * launch the application - */ public static void main(String[] args) throws Exception { ServiceConfig service = new ServiceConfig<>(); service.setApplication(new ApplicationConfig("dubbo-demo-api-provider")); - service.setRegistry(new RegistryConfig("multicast://224.5.6.7:1234")); + service.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181")); service.setInterface(DemoService.class); service.setRef(new DemoServiceImpl()); service.export(); diff --git a/dubbo-demo/dubbo-demo-api/pom.xml b/dubbo-demo/dubbo-demo-api/pom.xml index e78c2ca4e8..9db630de2e 100644 --- a/dubbo-demo/dubbo-demo-api/pom.xml +++ b/dubbo-demo/dubbo-demo-api/pom.xml @@ -21,9 +21,10 @@ - dubbo-demo org.apache.dubbo + dubbo-demo ${revision} + ../pom.xml 4.0.0 pom diff --git a/dubbo-demo/dubbo-demo-interface/pom.xml b/dubbo-demo/dubbo-demo-interface/pom.xml index a5c4b0517d..97aa7bf41c 100644 --- a/dubbo-demo/dubbo-demo-interface/pom.xml +++ b/dubbo-demo/dubbo-demo-interface/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-demo ${revision} + ../pom.xml dubbo-demo-interface jar diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/pom.xml b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/pom.xml index 69e1c8f670..63ed1b82eb 100644 --- a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/pom.xml +++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-demo-xml ${revision} + ../pom.xml dubbo-demo-xml-consumer jar diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/java/org/apache/dubbo/demo/consumer/Application.java b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/java/org/apache/dubbo/demo/consumer/Application.java index 90ed7c0b6a..f448a184a5 100644 --- a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/java/org/apache/dubbo/demo/consumer/Application.java +++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/java/org/apache/dubbo/demo/consumer/Application.java @@ -21,10 +21,6 @@ import org.apache.dubbo.demo.DemoService; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Application { - /** - * In order to make sure multicast registry works, need to specify '-Djava.net.preferIPv4Stack=true' before - * launch the application - */ public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-consumer.xml"); context.start(); diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/resources/spring/dubbo-consumer.xml b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/resources/spring/dubbo-consumer.xml index 6b5efc32f0..742195fcf2 100644 --- a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/resources/spring/dubbo-consumer.xml +++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/src/main/resources/spring/dubbo-consumer.xml @@ -23,10 +23,8 @@ - + - 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 99bd30bcf7..e00dcb916a 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 @@ -14,12 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. --> - + 4.0.0 org.apache.dubbo dubbo-demo-xml ${revision} + ../pom.xml dubbo-demo-xml-provider jar diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java index 25a9dd4be0..d1ab5be748 100644 --- a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java +++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java @@ -19,10 +19,6 @@ package org.apache.dubbo.demo.provider; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Application { - /** - * In order to make sure multicast registry works, need to specify '-Djava.net.preferIPv4Stack=true' before - * launch the application - */ public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-provider.xml"); context.start(); diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/resources/spring/dubbo-provider.xml b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/resources/spring/dubbo-provider.xml index 95e730682d..56a07cd2b0 100644 --- a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/resources/spring/dubbo-provider.xml +++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/src/main/resources/spring/dubbo-provider.xml @@ -21,18 +21,14 @@ 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"> - - + - - - diff --git a/dubbo-demo/dubbo-demo-xml/pom.xml b/dubbo-demo/dubbo-demo-xml/pom.xml index f75b2eca75..858d3597ed 100644 --- a/dubbo-demo/dubbo-demo-xml/pom.xml +++ b/dubbo-demo/dubbo-demo-xml/pom.xml @@ -20,9 +20,10 @@ - dubbo-demo org.apache.dubbo + dubbo-demo ${revision} + ../pom.xml 4.0.0 pom diff --git a/dubbo-demo/pom.xml b/dubbo-demo/pom.xml index d46e2d99df..e636a2305a 100644 --- a/dubbo-demo/pom.xml +++ b/dubbo-demo/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-parent ${revision} + ../pom.xml dubbo-demo pom diff --git a/dubbo-dependencies/pom.xml b/dubbo-dependencies/pom.xml index 27cea95f42..5d0ca46516 100644 --- a/dubbo-dependencies/pom.xml +++ b/dubbo-dependencies/pom.xml @@ -17,9 +17,10 @@ - dubbo-parent org.apache.dubbo + dubbo-parent ${revision} + ../pom.xml 4.0.0 diff --git a/dubbo-distribution/pom.xml b/dubbo-distribution/pom.xml index 41cef658d2..5b18042087 100644 --- a/dubbo-distribution/pom.xml +++ b/dubbo-distribution/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-parent ${revision} + ../pom.xml dubbo-distribution pom diff --git a/dubbo-filter/dubbo-filter-cache/pom.xml b/dubbo-filter/dubbo-filter-cache/pom.xml index 8241d23f45..22c905c579 100644 --- a/dubbo-filter/dubbo-filter-cache/pom.xml +++ b/dubbo-filter/dubbo-filter-cache/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-filter ${revision} + ../pom.xml dubbo-filter-cache jar diff --git a/dubbo-filter/dubbo-filter-validation/pom.xml b/dubbo-filter/dubbo-filter-validation/pom.xml index 51d70aead1..164653e52c 100644 --- a/dubbo-filter/dubbo-filter-validation/pom.xml +++ b/dubbo-filter/dubbo-filter-validation/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-filter ${revision} + ../pom.xml dubbo-filter-validation jar diff --git a/dubbo-filter/pom.xml b/dubbo-filter/pom.xml index efb95ab8cb..9b588c52d0 100644 --- a/dubbo-filter/pom.xml +++ b/dubbo-filter/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-parent ${revision} + ../pom.xml dubbo-filter pom diff --git a/dubbo-metadata-report/dubbo-metadata-definition-protobuf/pom.xml b/dubbo-metadata-report/dubbo-metadata-definition-protobuf/pom.xml index 219694abed..099fc56ddb 100644 --- a/dubbo-metadata-report/dubbo-metadata-definition-protobuf/pom.xml +++ b/dubbo-metadata-report/dubbo-metadata-definition-protobuf/pom.xml @@ -16,9 +16,10 @@ --> - dubbo-metadata-report org.apache.dubbo + dubbo-metadata ${revision} + ../pom.xml 4.0.0 dubbo-metadata-definition-protobuf diff --git a/dubbo-metadata/dubbo-metadata-api/pom.xml b/dubbo-metadata/dubbo-metadata-api/pom.xml index 3f5665a091..8c9a80c80d 100644 --- a/dubbo-metadata/dubbo-metadata-api/pom.xml +++ b/dubbo-metadata/dubbo-metadata-api/pom.xml @@ -44,6 +44,7 @@ dubbo-cluster ${project.parent.version} + com.google.code.gson gson diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMapping.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMapping.java index 287ba734c5..db22c6cf9f 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMapping.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMapping.java @@ -70,7 +70,6 @@ public class DynamicConfigurationServiceNameMapping implements ServiceNameMappin DynamicConfiguration dynamicConfiguration = DynamicConfiguration.getDynamicConfiguration(); - String key = ApplicationModel.getApplication(); Set serviceNames = new LinkedHashSet<>(); execute(() -> { Set keys = dynamicConfiguration.getConfigKeys(buildGroup(serviceInterface, group, version, protocol)); @@ -80,11 +79,13 @@ public class DynamicConfigurationServiceNameMapping implements ServiceNameMappin } protected static String buildGroup(String serviceInterface, String group, String version, String protocol) { - StringBuilder groupBuilder = new StringBuilder(serviceInterface) - .append(SEPARATOR).append(defaultString(group)) - .append(SEPARATOR).append(defaultString(version)) - .append(SEPARATOR).append(defaultString(protocol)); - return groupBuilder.toString(); + // the issue : https://github.com/apache/dubbo/issues/4671 + // StringBuilder groupBuilder = new StringBuilder(serviceInterface) + // .append(SEPARATOR).append(defaultString(group)) + // .append(SEPARATOR).append(defaultString(version)) + // .append(SEPARATOR).append(defaultString(protocol)); + // return groupBuilder.toString(); + return serviceInterface; } private static String defaultString(String value) { diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataService.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataService.java index 9e81778506..71b48d3aa8 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataService.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/MetadataService.java @@ -19,8 +19,14 @@ package org.apache.dubbo.metadata; import org.apache.dubbo.common.URL; import java.util.List; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.stream.Collectors; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; +import static java.util.Collections.unmodifiableSortedSet; import static java.util.stream.StreamSupport.stream; /** @@ -37,6 +43,7 @@ import static java.util.stream.StreamSupport.stream; */ public interface MetadataService { + /** * The value of all service names */ @@ -47,6 +54,11 @@ public interface MetadataService { */ String ALL_SERVICE_INTERFACES = "*"; + /** + * The service interface name of {@link MetadataService} + */ + String SERVICE_INTERFACE_NAME = MetadataService.class.getName(); + /** * The contract version of {@link MetadataService}, the future update must make sure compatible. */ @@ -72,82 +84,103 @@ public interface MetadataService { /** * the list of String that presents all Dubbo subscribed {@link URL urls} * - * @return non-null read-only {@link List} + * @return the non-null read-only {@link SortedSet sorted set} of {@link URL#toFullString() strings} presenting the {@link URL URLs} + * @see #toSortedStrings(Stream) + * @see URL#toFullString() */ - List getSubscribedURLs(); + SortedSet getSubscribedURLs(); /** - * Get the list of String that presents all Dubbo exported {@link URL urls} + * Get the {@link SortedSet sorted set} of String that presents all Dubbo exported {@link URL urls} * - * @return non-null read-only {@link List} + * @return the non-null read-only {@link SortedSet sorted set} of {@link URL#toFullString() strings} presenting the {@link URL URLs} + * @see #toSortedStrings(Stream) + * @see URL#toFullString() */ - default List getExportedURLs() { + default SortedSet getExportedURLs() { return getExportedURLs(ALL_SERVICE_INTERFACES); } /** - * Get the list of String that presents the specified Dubbo exported {@link URL urls} by the serviceInterface + * Get the {@link SortedSet sorted set} of String that presents the specified Dubbo exported {@link URL urls} by the serviceInterface * * @param serviceInterface The class name of Dubbo service interface - * @return non-null read-only {@link List} - * @see URL + * @return the non-null read-only {@link SortedSet sorted set} of {@link URL#toFullString() strings} presenting the {@link URL URLs} + * @see #toSortedStrings(Stream) + * @see URL#toFullString() */ - default List getExportedURLs(String serviceInterface) { + default SortedSet getExportedURLs(String serviceInterface) { return getExportedURLs(serviceInterface, null); } /** - * Get the list of String that presents the specified Dubbo exported {@link URL urls} by the + * Get the {@link SortedSet sorted set} of String that presents the specified Dubbo exported {@link URL urls} by the * serviceInterface and group * * @param serviceInterface The class name of Dubbo service interface * @param group the Dubbo Service Group (optional) - * @return non-null read-only {@link List} - * @see URL + * @return the non-null read-only {@link SortedSet sorted set} of {@link URL#toFullString() strings} presenting the {@link URL URLs} + * @see #toSortedStrings(Stream) + * @see URL#toFullString() */ - default List getExportedURLs(String serviceInterface, String group) { + default SortedSet getExportedURLs(String serviceInterface, String group) { return getExportedURLs(serviceInterface, group, null); } /** - * Get the list of String that presents the specified Dubbo exported {@link URL urls} by the + * Get the {@link SortedSet sorted set} of String that presents the specified Dubbo exported {@link URL urls} by the * serviceInterface, group and version * * @param serviceInterface The class name of Dubbo service interface * @param group the Dubbo Service Group (optional) * @param version the Dubbo Service Version (optional) - * @return non-null read-only {@link List} - * @see URL + * @return the non-null read-only {@link SortedSet sorted set} of {@link URL#toFullString() strings} presenting the {@link URL URLs} + * @see #toSortedStrings(Stream) + * @see URL#toFullString() */ - default List getExportedURLs(String serviceInterface, String group, String version) { + default SortedSet getExportedURLs(String serviceInterface, String group, String version) { return getExportedURLs(serviceInterface, group, version, null); } /** - * Get the list of String that presents the specified Dubbo exported {@link URL urls} by the + * Get the sorted set of String that presents the specified Dubbo exported {@link URL urls} by the * serviceInterface, group, version and protocol * * @param serviceInterface The class name of Dubbo service interface * @param group the Dubbo Service Group (optional) * @param version the Dubbo Service Version (optional) * @param protocol the Dubbo Service Protocol (optional) - * @return non-null read-only {@link List} - * @see URL + * @return the non-null read-only {@link SortedSet sorted set} of {@link URL#toFullString() strings} presenting the {@link URL URLs} + * @see #toSortedStrings(Stream) + * @see URL#toFullString() */ - List getExportedURLs(String serviceInterface, String group, String version, String protocol); + SortedSet getExportedURLs(String serviceInterface, String group, String version, String protocol); /** * Interface definition. + * * @return */ String getServiceDefinition(String interfaceName, String version, String group); /** * Interface definition. + * * @return */ String getServiceDefinition(String serviceKey); + /** + * Is the {@link URL} for the {@link MetadataService} or not? + * + * @param url {@link URL url} + * @return + */ + static boolean isMetadataServiceURL(URL url) { + String serviceInterface = url.getServiceInterface(); + return SERVICE_INTERFACE_NAME.equals(serviceInterface); + } + /** * Convert the multiple {@link URL urls} to a {@link List list} of {@link URL urls} * @@ -159,4 +192,28 @@ public interface MetadataService { .map(URL::valueOf) .collect(Collectors.toList()); } + + /** + * Convert the specified {@link Iterable} of {@link URL URLs} to be the {@link URL#toFullString() strings} presenting + * the {@link URL URLs} + * + * @param iterable {@link Iterable} of {@link URL} + * @return the non-null read-only {@link SortedSet sorted set} of {@link URL#toFullString() strings} presenting + * @see URL#toFullString() + */ + static SortedSet toSortedStrings(Iterable iterable) { + return toSortedStrings(StreamSupport.stream(iterable.spliterator(), false)); + } + + /** + * Convert the specified {@link Stream} of {@link URL URLs} to be the {@link URL#toFullString() strings} presenting + * the {@link URL URLs} + * + * @param stream {@link Stream} of {@link URL} + * @return the non-null read-only {@link SortedSet sorted set} of {@link URL#toFullString() strings} presenting + * @see URL#toFullString() + */ + static SortedSet toSortedStrings(Stream stream) { + return unmodifiableSortedSet(stream.map(URL::toFullString).collect(TreeSet::new, Set::add, Set::addAll)); + } } diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/WritableMetadataService.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/WritableMetadataService.java index f1a1ea40ae..0af21637d2 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/WritableMetadataService.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/WritableMetadataService.java @@ -30,7 +30,7 @@ import static org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoad * * @since 2.7.4 */ -@SPI("local") +@SPI("default") public interface WritableMetadataService extends MetadataService { /** diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java index 932af2bd64..36356216c8 100755 --- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java @@ -19,6 +19,7 @@ package org.apache.dubbo.metadata.definition.model; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import java.util.Objects; /** @@ -29,11 +30,19 @@ public class MethodDefinition implements Serializable { private String name; private String[] parameterTypes; private String returnType; + private List parameters; public String getName() { return name; } + public List getParameters() { + if (parameters == null) { + parameters = new ArrayList<>(); + } + return parameters; + } + public String[] getParameterTypes() { return parameterTypes; } @@ -46,6 +55,10 @@ public class MethodDefinition implements Serializable { this.name = name; } + public void setParameters(List parameters) { + this.parameters = parameters; + } + public void setParameterTypes(String[] parameterTypes) { this.parameterTypes = parameterTypes; } @@ -71,12 +84,13 @@ public class MethodDefinition implements Serializable { MethodDefinition that = (MethodDefinition) o; return Objects.equals(getName(), that.getName()) && Arrays.equals(getParameterTypes(), that.getParameterTypes()) && - Objects.equals(getReturnType(), that.getReturnType()); + Objects.equals(getReturnType(), that.getReturnType()) && + Objects.equals(getParameters(), that.getParameters()); } @Override public int hashCode() { - int result = Objects.hash(getName(), getReturnType()); + int result = Objects.hash(getName(), getReturnType(), getParameters()); result = 31 * result + Arrays.hashCode(getParameterTypes()); return result; } diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/store/InMemoryWritableMetadataService.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/store/InMemoryWritableMetadataService.java index 6b3d815f2d..44881d55a3 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/store/InMemoryWritableMetadataService.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/store/InMemoryWritableMetadataService.java @@ -28,18 +28,18 @@ import org.apache.dubbo.metadata.definition.model.ServiceDefinition; import com.google.gson.Gson; import java.util.Collection; -import java.util.LinkedList; -import java.util.List; +import java.util.Comparator; import java.util.Map; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.concurrent.Callable; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ConcurrentNavigableMap; +import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; -import java.util.stream.Collectors; -import static java.util.Collections.emptyList; -import static java.util.Collections.unmodifiableList; +import static java.util.Collections.emptySortedSet; +import static java.util.Collections.unmodifiableSortedSet; import static org.apache.dubbo.common.URL.buildKey; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; @@ -55,11 +55,6 @@ import static org.apache.dubbo.common.utils.CollectionUtils.isEmpty; */ public class InMemoryWritableMetadataService implements WritableMetadataService { - /** - * The class name of {@link MetadataService} - */ - static final String METADATA_SERVICE_CLASS_NAME = MetadataService.class.getName(); - private final Logger logger = LoggerFactory.getLogger(getClass()); private final Lock lock = new ReentrantLock(); @@ -68,9 +63,9 @@ public class InMemoryWritableMetadataService implements WritableMetadataService /** * All exported {@link URL urls} {@link Map} whose key is the return value of {@link URL#getServiceKey()} method - * and value is the {@link List} of the {@link URL URLs} + * and value is the {@link SortedSet sorted set} of the {@link URL URLs} */ - private ConcurrentMap> exportedServiceURLs = new ConcurrentHashMap<>(); + private ConcurrentNavigableMap> exportedServiceURLs = new ConcurrentSkipListMap<>(); // ==================================================================================== // @@ -78,42 +73,36 @@ public class InMemoryWritableMetadataService implements WritableMetadataService /** * The subscribed {@link URL urls} {@link Map} of {@link MetadataService}, - * whose key is the return value of {@link URL#getServiceKey()} method and value is the {@link List} of - * the {@link URL URLs} + * whose key is the return value of {@link URL#getServiceKey()} method and value is + * the {@link SortedSet sorted set} of the {@link URL URLs} */ - private final ConcurrentMap> subscribedServiceURLs = new ConcurrentHashMap<>(); + private final ConcurrentNavigableMap> subscribedServiceURLs = new ConcurrentSkipListMap<>(); - private final ConcurrentHashMap serviceDefinitions = new ConcurrentHashMap<>(); + private final ConcurrentNavigableMap serviceDefinitions = new ConcurrentSkipListMap<>(); // ==================================================================================== // @Override - public List getSubscribedURLs() { + public SortedSet getSubscribedURLs() { return getAllUnmodifiableServiceURLs(subscribedServiceURLs); } @Override - public List getExportedURLs(String serviceInterface, String group, String version, String protocol) { + public SortedSet getExportedURLs(String serviceInterface, String group, String version, String protocol) { if (ALL_SERVICE_INTERFACES.equals(serviceInterface)) { return getAllUnmodifiableServiceURLs(exportedServiceURLs); } String serviceKey = buildKey(serviceInterface, group, version); - return unmodifiableList(getServiceURLs(exportedServiceURLs, serviceKey, protocol)); + return unmodifiableSortedSet(getServiceURLs(exportedServiceURLs, serviceKey, protocol)); } @Override public boolean exportURL(URL url) { -// if (isMetadataServiceURL(url)) { // ignore MetadataService in the export phase -// return true; -// } return addURL(exportedServiceURLs, url); } @Override public boolean unexportURL(URL url) { -// if (isMetadataServiceURL(url)) { // ignore MetadataService in the export phase -// return true; -// } return removeURL(exportedServiceURLs, url); } @@ -156,22 +145,20 @@ public class InMemoryWritableMetadataService implements WritableMetadataService return serviceDefinitions.get(serviceKey); } - private boolean addURL(Map> serviceURLs, URL url) { + private boolean addURL(Map> serviceURLs, URL url) { return executeMutually(() -> { - List urls = serviceURLs.computeIfAbsent(url.getServiceKey(), s -> new LinkedList()); - if (!urls.contains(url)) { - return urls.add(url); - } - return false; + SortedSet urls = serviceURLs.computeIfAbsent(url.getServiceKey(), this::newSortedURLs); + return urls.add(url); }); } - private boolean removeURL(Map> serviceURLs, URL url) { + private SortedSet newSortedURLs(String serviceKey) { + return new TreeSet<>(URLComparator.INSTANCE); + } + + private boolean removeURL(Map> serviceURLs, URL url) { return executeMutually(() -> { - List urls = serviceURLs.get(url.getServiceKey()); - if (isEmpty(urls)) { - return false; - } + SortedSet urls = serviceURLs.getOrDefault(url.getServiceKey(), emptySortedSet()); return urls.remove(url); }); } @@ -193,19 +180,16 @@ public class InMemoryWritableMetadataService implements WritableMetadataService return success; } - private static List getServiceURLs(Map> exportedServiceURLs, String serviceKey, - String protocol) { - List serviceURLs = exportedServiceURLs.get(serviceKey); + private static SortedSet getServiceURLs(Map> exportedServiceURLs, String serviceKey, + String protocol) { + + SortedSet serviceURLs = exportedServiceURLs.get(serviceKey); if (isEmpty(serviceURLs)) { - return emptyList(); + return emptySortedSet(); } - return serviceURLs - .stream() - .filter(url -> isAcceptableProtocol(protocol, url)) - .map(URL::toFullString) - .collect(Collectors.toList()); + return MetadataService.toSortedStrings(serviceURLs.stream().filter(url -> isAcceptableProtocol(protocol, url))); } private static boolean isAcceptableProtocol(String protocol, URL url) { @@ -214,18 +198,17 @@ public class InMemoryWritableMetadataService implements WritableMetadataService || protocol.equals(url.getProtocol()); } -// private static boolean isMetadataServiceURL(URL url) { -// String serviceInterface = url.getServiceInterface(); -// return METADATA_SERVICE_CLASS_NAME.equals(serviceInterface); -// } + private static SortedSet getAllUnmodifiableServiceURLs(Map> serviceURLs) { + return MetadataService.toSortedStrings(serviceURLs.values().stream().flatMap(Collection::stream)); + } - private static List getAllUnmodifiableServiceURLs(Map> serviceURLs) { - return unmodifiableList( - serviceURLs - .values() - .stream() - .flatMap(Collection::stream) - .map(URL::toFullString) - .collect(Collectors.toList())); + private static class URLComparator implements Comparator { + + public static final URLComparator INSTANCE = new URLComparator(); + + @Override + public int compare(URL o1, URL o2) { + return o1.toFullString().compareTo(o2.toFullString()); + } } } diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/store/RemoteWritableMetadataService.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/store/RemoteWritableMetadataService.java index c52f5c8aa1..f31e936940 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/store/RemoteWritableMetadataService.java +++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/store/RemoteWritableMetadataService.java @@ -33,7 +33,10 @@ import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier; import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.rpc.RpcException; -import java.util.List; +import java.util.Collection; +import java.util.Collections; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.function.Consumer; import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; @@ -57,7 +60,8 @@ public class RemoteWritableMetadataService implements WritableMetadataService { private MetadataReportFactory metadataReportFactory = ExtensionLoader.getExtensionLoader(MetadataReportFactory.class).getAdaptiveExtension(); private MetadataReport metadataReport; - public RemoteWritableMetadataService() {} + public RemoteWritableMetadataService() { + } public void initMetadataReport(URL metadataReportURL) { if (METADATA_REPORT_KEY.equals(metadataReportURL.getProtocol())) { @@ -148,14 +152,18 @@ public class RemoteWritableMetadataService implements WritableMetadataService { } @Override - public List getSubscribedURLs() { - return metadataReport.getSubscribedURLs(); + public SortedSet getSubscribedURLs() { + return toSortedStrings(metadataReport.getSubscribedURLs()); } // TODO, protocol should be used @Override - public List getExportedURLs(String serviceInterface, String group, String version, String protocol) { - return metadataReport.getExportedURLs(new MetadataIdentifier(serviceInterface, group, version, null, null)); + public SortedSet getExportedURLs(String serviceInterface, String group, String version, String protocol) { + return toSortedStrings(metadataReport.getExportedURLs(new MetadataIdentifier(serviceInterface, group, version, null, null))); + } + + private static SortedSet toSortedStrings(Collection values) { + return Collections.unmodifiableSortedSet(new TreeSet<>(values)); } @Override diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.WritableMetadataService b/dubbo-metadata/dubbo-metadata-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.WritableMetadataService index 26bc942e70..cbf9324508 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.WritableMetadataService +++ b/dubbo-metadata/dubbo-metadata-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.WritableMetadataService @@ -1,2 +1,2 @@ -local=org.apache.dubbo.metadata.store.InMemoryWritableMetadataService +default=org.apache.dubbo.metadata.store.InMemoryWritableMetadataService remote=org.apache.dubbo.metadata.store.RemoteWritableMetadataService \ No newline at end of file diff --git a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMappingTest.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMappingTest.java index 8b2743f968..8afbeed998 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMappingTest.java +++ b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/DynamicConfigurationServiceNameMappingTest.java @@ -16,18 +16,11 @@ */ package org.apache.dubbo.metadata; -import org.apache.dubbo.common.URL; import org.apache.dubbo.common.config.Environment; import org.apache.dubbo.common.config.configcenter.DynamicConfiguration; import org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory; -import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.rpc.model.ApplicationModel; -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.CuratorFrameworkFactory; -import org.apache.curator.retry.ExponentialBackoffRetry; -import org.apache.curator.test.TestingServer; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -47,44 +40,25 @@ import static org.junit.jupiter.api.Assertions.assertEquals; */ public class DynamicConfigurationServiceNameMappingTest { - private static CuratorFramework client; - - private static URL configUrl; - private static int zkServerPort = NetUtils.getAvailablePort(); - private static TestingServer zkServer; private final ServiceNameMapping serviceNameMapping = getDefaultExtension(); @BeforeAll public static void setUp() throws Exception { - zkServer = new TestingServer(zkServerPort, true); - - client = CuratorFrameworkFactory.newClient("localhost:" + zkServerPort, 60 * 1000, 60 * 1000, - new ExponentialBackoffRetry(1000, 3)); - - client.start(); - - configUrl = URL.valueOf("zookeeper://localhost:" + zkServerPort); - DynamicConfiguration configuration = getExtensionLoader(DynamicConfigurationFactory.class) - .getExtension(configUrl.getProtocol()) - .getDynamicConfiguration(configUrl); + .getDefaultExtension() + .getDynamicConfiguration(null); Environment.getInstance().setDynamicConfiguration(configuration); } - @AfterAll - public static void tearDown() throws Exception { - zkServer.stop(); - } - @Test public void testBuildGroup() { - assertEquals("test:::", buildGroup("test", null, null, null)); - assertEquals("test:default::", buildGroup("test", "default", null, null)); - assertEquals("test:default:1.0.0:", buildGroup("test", "default", "1.0.0", null)); - assertEquals("test:default:1.0.0:dubbo", buildGroup("test", "default", "1.0.0", "dubbo")); + assertEquals("test", buildGroup("test", null, null, null)); + assertEquals("test", buildGroup("test", "default", null, null)); + assertEquals("test", buildGroup("test", "default", "1.0.0", null)); + assertEquals("test", buildGroup("test", "default", "1.0.0", "dubbo")); } @Test diff --git a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/InMemoryWritableMetadataServiceTest.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/InMemoryWritableMetadataServiceTest.java index 64771b0f57..c5b319129d 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/InMemoryWritableMetadataServiceTest.java +++ b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/InMemoryWritableMetadataServiceTest.java @@ -23,9 +23,12 @@ import org.apache.dubbo.rpc.model.ApplicationModel; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.util.List; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableSortedSet; import static org.apache.dubbo.common.URL.valueOf; import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; @@ -71,9 +74,9 @@ public class InMemoryWritableMetadataServiceTest { public void testGetExportedURLs() { assertTrue(metadataService.exportURL(BASE_URL)); - List exportedURLs = metadataService.getExportedURLs(TEST_SERVICE); + Set exportedURLs = metadataService.getExportedURLs(TEST_SERVICE); assertEquals(1, exportedURLs.size()); - assertEquals(asList(BASE_URL.toFullString()), exportedURLs); + assertEquals(asSortedSet(BASE_URL.toFullString()), exportedURLs); assertTrue(metadataService.unexportURL(BASE_URL)); assertTrue(metadataService.exportURL(BASE_URL)); @@ -83,21 +86,21 @@ public class InMemoryWritableMetadataServiceTest { assertTrue(metadataService.exportURL(BASE_URL_GROUP_AND_VERSION)); exportedURLs = metadataService.getExportedURLs(TEST_SERVICE); - assertEquals(asList(BASE_URL.toFullString()), exportedURLs); - assertEquals(asList( + assertEquals(asSortedSet(BASE_URL.toFullString()), exportedURLs); + assertEquals(asSortedSet( BASE_URL.toFullString(), BASE_URL_GROUP.toFullString(), BASE_URL_GROUP_AND_VERSION.toFullString()), metadataService.getExportedURLs()); assertTrue(metadataService.exportURL(REST_BASE_URL)); exportedURLs = metadataService.getExportedURLs(TEST_SERVICE); - assertEquals(asList(BASE_URL.toFullString(), REST_BASE_URL.toFullString()), exportedURLs); + assertEquals(asSortedSet(BASE_URL.toFullString(), REST_BASE_URL.toFullString()), exportedURLs); metadataService.exportURL(BASE_URL_GROUP_AND_VERSION_AND_PROTOCOL); exportedURLs = metadataService.getExportedURLs(TEST_SERVICE, "test", "1.0.0", "rest"); - assertEquals(asList(BASE_URL_GROUP_AND_VERSION_AND_PROTOCOL.toFullString()), exportedURLs); + assertEquals(asSortedSet(BASE_URL_GROUP_AND_VERSION_AND_PROTOCOL.toFullString()), exportedURLs); } @Test @@ -109,9 +112,9 @@ public class InMemoryWritableMetadataServiceTest { assertTrue(metadataService.subscribeURL(BASE_URL_GROUP_AND_VERSION)); assertTrue(metadataService.subscribeURL(REST_BASE_URL)); - List subscribedURLs = metadataService.getSubscribedURLs(); + Set subscribedURLs = metadataService.getSubscribedURLs(); assertEquals(4, subscribedURLs.size()); - assertEquals(asList( + assertEquals(asSortedSet( BASE_URL.toFullString(), REST_BASE_URL.toFullString(), BASE_URL_GROUP.toFullString(), @@ -120,7 +123,7 @@ public class InMemoryWritableMetadataServiceTest { assertTrue(metadataService.unsubscribeURL(REST_BASE_URL)); subscribedURLs = metadataService.getSubscribedURLs(); assertEquals(3, subscribedURLs.size()); - assertEquals(asList( + assertEquals(asSortedSet( BASE_URL.toFullString(), BASE_URL_GROUP.toFullString(), BASE_URL_GROUP_AND_VERSION.toFullString()), subscribedURLs); @@ -128,14 +131,19 @@ public class InMemoryWritableMetadataServiceTest { assertTrue(metadataService.unsubscribeURL(BASE_URL_GROUP)); subscribedURLs = metadataService.getSubscribedURLs(); assertEquals(2, subscribedURLs.size()); - assertEquals(asList( + assertEquals(asSortedSet( BASE_URL.toFullString(), BASE_URL_GROUP_AND_VERSION.toFullString()), subscribedURLs); assertTrue(metadataService.unsubscribeURL(BASE_URL_GROUP_AND_VERSION)); subscribedURLs = metadataService.getSubscribedURLs(); assertEquals(1, subscribedURLs.size()); - assertEquals(asList( + assertEquals(asSortedSet( BASE_URL.toFullString()), subscribedURLs); } + + private static > SortedSet asSortedSet(T... values) { + return unmodifiableSortedSet(new TreeSet<>(asList(values))); + } + } \ No newline at end of file diff --git a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifierTest.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifierTest.java index c104c76c1c..3d2823f1b3 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifierTest.java +++ b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifierTest.java @@ -42,7 +42,7 @@ public class MetadataIdentifierTest { (version == null ? "" : (version + PATH_SEPARATOR)) + (group == null ? "" : (group + PATH_SEPARATOR)) + PROVIDER_SIDE + PATH_SEPARATOR + application); - Assertions.assertEquals(providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), + Assertions.assertEquals(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY), interfaceName + MetadataIdentifier.SEPARATOR + (version == null ? "" : version) + MetadataIdentifier.SEPARATOR + (group == null ? "" : group) + MetadataIdentifier.SEPARATOR diff --git a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReportTest.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReportTest.java index e20258e0ce..bef9c856a4 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReportTest.java +++ b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReportTest.java @@ -64,7 +64,7 @@ public class AbstractMetadataReportTest { @Test public void testStoreProviderUsual() throws ClassNotFoundException, InterruptedException { - String interfaceName = "org.apache.dubbo.metadata.integration.InterfaceNameTestService"; + String interfaceName = "org.apache.dubbo.metadata.store.InterfaceNameTestService"; String version = "1.0.0"; String group = null; String application = "vic"; @@ -75,7 +75,7 @@ public class AbstractMetadataReportTest { @Test public void testStoreProviderSync() throws ClassNotFoundException, InterruptedException { - String interfaceName = "org.apache.dubbo.metadata.integration.InterfaceNameTestService"; + String interfaceName = "org.apache.dubbo.metadata.store.InterfaceNameTestService"; String version = "1.0.0"; String group = null; String application = "vic"; @@ -87,12 +87,12 @@ public class AbstractMetadataReportTest { @Test public void testFileExistAfterPut() throws InterruptedException, ClassNotFoundException { //just for one method - URL singleUrl = URL.valueOf("redis://" + NetUtils.getLocalAddress().getHostName() + ":4444/org.apache.dubbo.metadata.integration.InterfaceNameTestService?version=1.0.0&application=singleTest"); + URL singleUrl = URL.valueOf("redis://" + NetUtils.getLocalAddress().getHostName() + ":4444/org.apache.dubbo.metadata.store.InterfaceNameTestService?version=1.0.0&application=singleTest"); NewMetadataReport singleMetadataReport = new NewMetadataReport(singleUrl); Assertions.assertFalse(singleMetadataReport.file.exists()); - String interfaceName = "org.apache.dubbo.metadata.integration.InterfaceNameTestService"; + String interfaceName = "org.apache.dubbo.metadata.store.InterfaceNameTestService"; String version = "1.0.0"; String group = null; String application = "vic"; @@ -105,7 +105,7 @@ public class AbstractMetadataReportTest { @Test public void testRetry() throws InterruptedException, ClassNotFoundException { - String interfaceName = "org.apache.dubbo.metadata.integration.RetryTestService"; + String interfaceName = "org.apache.dubbo.metadata.store.RetryTestService"; String version = "1.0.0.retry"; String group = null; String application = "vic.retry"; @@ -134,7 +134,7 @@ public class AbstractMetadataReportTest { @Test public void testRetryCancel() throws InterruptedException, ClassNotFoundException { - String interfaceName = "org.apache.dubbo.metadata.integration.RetryTestService"; + String interfaceName = "org.apache.dubbo.metadata.store.RetryTestService"; String version = "1.0.0.retrycancel"; String group = null; String application = "vic.retry"; @@ -184,7 +184,7 @@ public class AbstractMetadataReportTest { Assertions.assertTrue(abstractMetadataReport.store.isEmpty()); Assertions.assertTrue(abstractMetadataReport.allMetadataReports.isEmpty()); - String interfaceName = "org.apache.dubbo.metadata.integration.InterfaceNameTestService"; + String interfaceName = "org.apache.dubbo.metadata.store.InterfaceNameTestService"; String version = "1.0.0"; String group = null; String application = "vic"; diff --git a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/store/RemoteWritableMeatadataServiceTest.java b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/store/RemoteWritableMeatadataServiceTest.java index 64867a0d63..18e8b70598 100644 --- a/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/store/RemoteWritableMeatadataServiceTest.java +++ b/dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/store/RemoteWritableMeatadataServiceTest.java @@ -81,7 +81,7 @@ public class RemoteWritableMeatadataServiceTest { @Test public void testPublishProviderContainInterface() throws InterruptedException { - URL publishUrl = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostName() + ":4444/org.apache.dubbo.TestService?version=1.0.3&application=vicpubp&interface=org.apache.dubbo.metadata.integration.InterfaceNameTestService&side=provider"); + URL publishUrl = URL.valueOf("dubbo://" + NetUtils.getLocalAddress().getHostName() + ":4444/org.apache.dubbo.TestService?version=1.0.3&application=vicpubp&interface=org.apache.dubbo.metadata.store.InterfaceNameTestService&side=provider"); metadataReportService1.publishProvider(publishUrl); Thread.sleep(300); @@ -95,7 +95,7 @@ public class RemoteWritableMeatadataServiceTest { Map map = fullServiceDefinition.getParameters(); Assertions.assertEquals(map.get("application"), "vicpubp"); Assertions.assertEquals(map.get("version"), "1.0.3"); - Assertions.assertEquals(map.get("interface"), "org.apache.dubbo.metadata.integration.InterfaceNameTestService"); + Assertions.assertEquals(map.get("interface"), "org.apache.dubbo.metadata.store.InterfaceNameTestService"); } @Test diff --git a/dubbo-metadata/dubbo-metadata-api/src/test/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory b/dubbo-metadata/dubbo-metadata-api/src/test/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory new file mode 100644 index 0000000000..2354eff212 --- /dev/null +++ b/dubbo-metadata/dubbo-metadata-api/src/test/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory @@ -0,0 +1 @@ +JTest=org.apache.dubbo.metadata.test.JTestMetadataReportFactory4Test \ No newline at end of file diff --git a/dubbo-metadata/dubbo-metadata-report-consul/pom.xml b/dubbo-metadata/dubbo-metadata-report-consul/pom.xml index 028d8979fa..b30001a8b0 100644 --- a/dubbo-metadata/dubbo-metadata-report-consul/pom.xml +++ b/dubbo-metadata/dubbo-metadata-report-consul/pom.xml @@ -18,9 +18,10 @@ - dubbo-metadata org.apache.dubbo + dubbo-metadata ${revision} + ../pom.xml 4.0.0 diff --git a/dubbo-metadata/dubbo-metadata-report-etcd/pom.xml b/dubbo-metadata/dubbo-metadata-report-etcd/pom.xml index 2fc66fd0a2..bb1dd818d7 100644 --- a/dubbo-metadata/dubbo-metadata-report-etcd/pom.xml +++ b/dubbo-metadata/dubbo-metadata-report-etcd/pom.xml @@ -20,9 +20,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - dubbo-metadata org.apache.dubbo + dubbo-metadata ${revision} + ../pom.xml 4.0.0 diff --git a/dubbo-metadata/dubbo-metadata-report-nacos/pom.xml b/dubbo-metadata/dubbo-metadata-report-nacos/pom.xml index 076f75d851..db76cae7d4 100644 --- a/dubbo-metadata/dubbo-metadata-report-nacos/pom.xml +++ b/dubbo-metadata/dubbo-metadata-report-nacos/pom.xml @@ -18,9 +18,10 @@ - dubbo-metadata org.apache.dubbo + dubbo-metadata ${revision} + ../pom.xml 4.0.0 diff --git a/dubbo-metadata/dubbo-metadata-report-redis/pom.xml b/dubbo-metadata/dubbo-metadata-report-redis/pom.xml index 20cf97a19a..f7a5b07b66 100644 --- a/dubbo-metadata/dubbo-metadata-report-redis/pom.xml +++ b/dubbo-metadata/dubbo-metadata-report-redis/pom.xml @@ -16,9 +16,10 @@ --> - dubbo-metadata org.apache.dubbo + dubbo-metadata ${revision} + ../pom.xml 4.0.0 diff --git a/dubbo-metadata/dubbo-metadata-report-zookeeper/pom.xml b/dubbo-metadata/dubbo-metadata-report-zookeeper/pom.xml index e93a39a7e1..89a5f9c3df 100644 --- a/dubbo-metadata/dubbo-metadata-report-zookeeper/pom.xml +++ b/dubbo-metadata/dubbo-metadata-report-zookeeper/pom.xml @@ -14,11 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. --> - + dubbo-metadata org.apache.dubbo ${revision} + ../pom.xml 4.0.0 diff --git a/dubbo-metadata/pom.xml b/dubbo-metadata/pom.xml index 36cc61a7d7..2c8bb6b5aa 100644 --- a/dubbo-metadata/pom.xml +++ b/dubbo-metadata/pom.xml @@ -31,7 +31,6 @@ dubbo-metadata-api dubbo-metadata-report-zookeeper dubbo-metadata-report-redis - dubbo-metadata-report-consul dubbo-metadata-report-etcd dubbo-metadata-report-nacos diff --git a/dubbo-monitor/dubbo-monitor-api/pom.xml b/dubbo-monitor/dubbo-monitor-api/pom.xml index 6147bff6c1..9f1405a3fd 100644 --- a/dubbo-monitor/dubbo-monitor-api/pom.xml +++ b/dubbo-monitor/dubbo-monitor-api/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-monitor ${revision} + ../pom.xml dubbo-monitor-api jar diff --git a/dubbo-monitor/dubbo-monitor-default/pom.xml b/dubbo-monitor/dubbo-monitor-default/pom.xml index 08a967529a..68a1bac9d1 100644 --- a/dubbo-monitor/dubbo-monitor-default/pom.xml +++ b/dubbo-monitor/dubbo-monitor-default/pom.xml @@ -21,6 +21,7 @@ org.apache.dubbo dubbo-monitor ${revision} + ../pom.xml dubbo-monitor-default jar diff --git a/dubbo-monitor/dubbo-monitor-default/src/test/java/org/apache/dubbo/monitor/dubbo/MetricsFilterTest.java b/dubbo-monitor/dubbo-monitor-default/src/test/java/org/apache/dubbo/monitor/dubbo/MetricsFilterTest.java index c31bd4a1ed..9037af091a 100644 --- a/dubbo-monitor/dubbo-monitor-default/src/test/java/org/apache/dubbo/monitor/dubbo/MetricsFilterTest.java +++ b/dubbo-monitor/dubbo-monitor-default/src/test/java/org/apache/dubbo/monitor/dubbo/MetricsFilterTest.java @@ -38,7 +38,6 @@ import com.alibaba.metrics.MetricName; import com.alibaba.metrics.common.MetricObject; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -60,7 +59,6 @@ import static org.apache.dubbo.monitor.Constants.DUBBO_PROVIDER; import static org.apache.dubbo.monitor.Constants.DUBBO_PROVIDER_METHOD; import static org.apache.dubbo.monitor.Constants.METHOD; import static org.apache.dubbo.monitor.Constants.SERVICE; - import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; diff --git a/dubbo-monitor/pom.xml b/dubbo-monitor/pom.xml index a6d21a0a55..4e3b53ca39 100644 --- a/dubbo-monitor/pom.xml +++ b/dubbo-monitor/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-parent ${revision} + ../pom.xml dubbo-monitor pom diff --git a/dubbo-plugin/dubbo-qos/pom.xml b/dubbo-plugin/dubbo-qos/pom.xml index 0df5abb8c6..b10199f176 100644 --- a/dubbo-plugin/dubbo-qos/pom.xml +++ b/dubbo-plugin/dubbo-qos/pom.xml @@ -19,6 +19,7 @@ org.apache.dubbo dubbo-plugin ${revision} + ../pom.xml 4.0.0 diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/util/CommandHelperTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/util/CommandHelperTest.java index 8f6ebc5bb9..b7db62e9d7 100644 --- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/util/CommandHelperTest.java +++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/util/CommandHelperTest.java @@ -22,15 +22,16 @@ import org.apache.dubbo.qos.command.impl.Ls; import org.apache.dubbo.qos.command.impl.Offline; import org.apache.dubbo.qos.command.impl.Online; import org.apache.dubbo.qos.command.impl.Quit; + import org.junit.jupiter.api.Test; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; public class CommandHelperTest { diff --git a/dubbo-plugin/pom.xml b/dubbo-plugin/pom.xml index 44b6fe0daf..5945b659e7 100644 --- a/dubbo-plugin/pom.xml +++ b/dubbo-plugin/pom.xml @@ -16,9 +16,10 @@ --> - dubbo-parent org.apache.dubbo + dubbo-parent ${revision} + ../pom.xml 4.0.0 diff --git a/dubbo-registry/dubbo-registry-api/pom.xml b/dubbo-registry/dubbo-registry-api/pom.xml index 86583e2ae7..db0c17586e 100644 --- a/dubbo-registry/dubbo-registry-api/pom.xml +++ b/dubbo-registry/dubbo-registry-api/pom.xml @@ -21,6 +21,7 @@ org.apache.dubbo dubbo-registry ${revision} + ../pom.xml dubbo-registry-api jar diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceInstance.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceInstance.java index 9949bab20d..251372d033 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceInstance.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceInstance.java @@ -16,19 +16,8 @@ */ package org.apache.dubbo.registry.client; -import org.apache.dubbo.common.URL; -import org.apache.dubbo.common.URLBuilder; -import org.apache.dubbo.metadata.MetadataService; - -import java.util.ArrayList; -import java.util.List; import java.util.Map; -import static java.lang.String.valueOf; -import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getMetadataServiceURLsParams; -import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getProviderHost; -import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getProviderPort; - /** * The model class of an instance of a service, which is used for service registration and discovery. *

@@ -103,36 +92,4 @@ public interface ServiceInstance { */ boolean equals(Object another); - /** - * Build the {@link URL urls} from {@link ServiceInstance#getMetadata() the metadata} of {@link ServiceInstance} - * - * @param serviceInstance {@link ServiceInstance} - * @return the not-null {@link List} - */ - static List toUrls(ServiceInstance serviceInstance) { - - Map> paramsMap = getMetadataServiceURLsParams(serviceInstance); - - List urls = new ArrayList<>(paramsMap.size()); - - for (Map.Entry> entry : paramsMap.entrySet()) { - - URLBuilder urlBuilder = new URLBuilder(); - String protocol = entry.getKey(); - Map urlParams = entry.getValue(); - String host = getProviderHost(urlParams); - Integer port = getProviderPort(urlParams); - urlBuilder.setHost(host) - .setPort(port) - .setProtocol(protocol) - .setPath(MetadataService.class.getName()); - - // add parameters - entry.getValue().forEach((name, value) -> urlBuilder.addParameter(name, valueOf(value))); - - urls.add(urlBuilder.build()); - } - - return urls; - } } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/CompositeMetadataServiceURLBuilder.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/CompositeMetadataServiceURLBuilder.java new file mode 100644 index 0000000000..9ced03aed3 --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/CompositeMetadataServiceURLBuilder.java @@ -0,0 +1,81 @@ +/* + * 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.registry.client.metadata; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.metadata.MetadataService; +import org.apache.dubbo.registry.client.ServiceInstance; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.ServiceLoader; + +import static java.util.Collections.emptyList; +import static java.util.Collections.unmodifiableList; +import static java.util.ServiceLoader.load; +import static org.apache.dubbo.common.utils.CollectionUtils.isNotEmpty; + +/** + * The implementation of {@link MetadataServiceURLBuilder} composites the multiple {@link MetadataServiceURLBuilder} + * instances are loaded by Java standard {@link ServiceLoader} will aggregate {@link URL URLs} for + * {@link MetadataServiceProxy} + * + * @see MetadataServiceURLBuilder + * @see MetadataServiceProxy + * @see MetadataService + * @see URL + * @see ServiceLoader + * @since 2.7.4 + */ +class CompositeMetadataServiceURLBuilder implements MetadataServiceURLBuilder { + + private final Class builderClass; + + private final Iterator builders; + + private final ClassLoader classLoader; + + public CompositeMetadataServiceURLBuilder() { + this.builderClass = MetadataServiceURLBuilder.class; + this.classLoader = getClass().getClassLoader(); + this.builders = initBuilders(); + } + + private Iterator initBuilders() { + return load(builderClass, classLoader).iterator(); + } + + @Override + public List build(ServiceInstance serviceInstance) { + if (serviceInstance == null) { + return emptyList(); + } + + List allURLs = new LinkedList<>(); + + while (builders.hasNext()) { + MetadataServiceURLBuilder builder = builders.next(); + List urls = builder.build(serviceInstance); + if (isNotEmpty(urls)) { + allURLs.addAll(urls); + } + } + + return unmodifiableList(allURLs); + } +} diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ExportedServicesRevisionMetadataCustomizer.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ExportedServicesRevisionMetadataCustomizer.java index 920096a00b..188312edab 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ExportedServicesRevisionMetadataCustomizer.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ExportedServicesRevisionMetadataCustomizer.java @@ -25,7 +25,7 @@ import org.apache.dubbo.registry.client.ServiceInstanceMetadataCustomizer; import java.util.Arrays; import java.util.Collection; -import java.util.List; +import java.util.SortedSet; import static java.lang.String.valueOf; import static java.util.Objects.hash; @@ -48,7 +48,7 @@ public class ExportedServicesRevisionMetadataCustomizer extends ServiceInstanceM @Override protected String buildMetadataValue(ServiceInstance serviceInstance) { WritableMetadataService writableMetadataService = WritableMetadataService.getDefaultExtension(); - List exportedURLs = writableMetadataService.getExportedURLs(); + SortedSet exportedURLs = writableMetadataService.getExportedURLs(); Object[] data = exportedURLs.stream() .map(URL::valueOf) // String to URL .map(URL::getServiceInterface) // get the service interface diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceProxy.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceProxy.java index e22b2b80bb..45ce42a041 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceProxy.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceProxy.java @@ -27,10 +27,11 @@ import org.apache.dubbo.rpc.proxy.InvokerInvocationHandler; import java.util.Iterator; import java.util.List; +import java.util.SortedSet; import java.util.function.Function; import static java.lang.reflect.Proxy.newProxyInstance; -import static org.apache.dubbo.registry.client.metadata.MetadataServiceURLBuilder.INSTANCE; +import static org.apache.dubbo.registry.client.metadata.MetadataServiceURLBuilder.composite; /** * The Proxy object for the {@link MetadataService} whose {@link ServiceInstance} providers may export multiple @@ -49,7 +50,7 @@ class MetadataServiceProxy implements MetadataService { private final Protocol protocol; public MetadataServiceProxy(ServiceInstance serviceInstance, Protocol protocol) { - this(INSTANCE.build(serviceInstance), protocol); + this(composite().build(serviceInstance), protocol); } public MetadataServiceProxy(List urls, Protocol protocol) { @@ -63,12 +64,12 @@ class MetadataServiceProxy implements MetadataService { } @Override - public List getSubscribedURLs() { + public SortedSet getSubscribedURLs() { return doInMetadataService(MetadataService::getSubscribedURLs); } @Override - public List getExportedURLs(String serviceInterface, String group, String version, String protocol) { + public SortedSet getExportedURLs(String serviceInterface, String group, String version, String protocol) { return doInMetadataService(metadataService -> metadataService.getExportedURLs(serviceInterface, group, version, protocol)); } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceURLBuilder.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceURLBuilder.java index 896cd4845f..f96f725fd2 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceURLBuilder.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceURLBuilder.java @@ -17,65 +17,37 @@ package org.apache.dubbo.registry.client.metadata; import org.apache.dubbo.common.URL; -import org.apache.dubbo.common.URLBuilder; import org.apache.dubbo.metadata.MetadataService; import org.apache.dubbo.registry.client.ServiceInstance; -import java.util.ArrayList; import java.util.List; -import java.util.Map; - -import static java.lang.String.valueOf; -import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getMetadataServiceURLsParams; -import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getProviderHost; -import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getProviderPort; +import java.util.ServiceLoader; /** - * The {@link URL} builder for {@link MetadataService} + * The builder interface of {@link MetadataService} to build {@link URL URLs}, the multiple implementations + * will be loaded by Java standard {@link ServiceLoader} and {@link #composite() composited}, + * whose building {@link URL URLs} will be aggregated * - * @see MetadataService + * @see CompositeMetadataServiceURLBuilder * @since 2.7.4 */ -class MetadataServiceURLBuilder { +public interface MetadataServiceURLBuilder { /** - * The singleton instance of {@link MetadataServiceURLBuilder} - */ - public static final MetadataServiceURLBuilder INSTANCE = new MetadataServiceURLBuilder(); - - private MetadataServiceURLBuilder() { - } - - /** - * Build the {@link URL urls} from {@link ServiceInstance#getMetadata() the metadata} of {@link ServiceInstance} + * Build the {@link URL URLs} from the specified {@link ServiceInstance} * * @param serviceInstance {@link ServiceInstance} - * @return the not-null {@link List} + * @return non-null */ - public List build(ServiceInstance serviceInstance) { + List build(ServiceInstance serviceInstance); - Map> paramsMap = getMetadataServiceURLsParams(serviceInstance); - - List urls = new ArrayList<>(paramsMap.size()); - - for (Map.Entry> entry : paramsMap.entrySet()) { - - URLBuilder urlBuilder = new URLBuilder(); - String protocol = entry.getKey(); - Map urlParams = entry.getValue(); - String host = getProviderHost(urlParams); - Integer port = getProviderPort(urlParams); - urlBuilder.setHost(host) - .setPort(port) - .setProtocol(protocol) - .setPath(MetadataService.class.getName()); - - // add parameters - entry.getValue().forEach((name, value) -> urlBuilder.addParameter(name, valueOf(value))); - - urls.add(urlBuilder.build()); - } - - return urls; + /** + * Get the composite implementation of {@link MetadataServiceURLBuilder} + * + * @return the instance of {@link CompositeMetadataServiceURLBuilder} + * @see CompositeMetadataServiceURLBuilder + */ + static MetadataServiceURLBuilder composite() { + return new CompositeMetadataServiceURLBuilder(); } } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceURLParamsMetadataCustomizer.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceURLParamsMetadataCustomizer.java index 754a275168..fadc9c46a8 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceURLParamsMetadataCustomizer.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceURLParamsMetadataCustomizer.java @@ -22,7 +22,7 @@ import org.apache.dubbo.metadata.WritableMetadataService; import org.apache.dubbo.registry.client.ServiceInstance; import org.apache.dubbo.registry.client.ServiceInstanceMetadataCustomizer; -import java.util.List; +import java.util.SortedSet; import static org.apache.dubbo.metadata.MetadataService.toURLs; import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.METADATA_SERVICE_URL_PARAMS_KEY; @@ -53,7 +53,7 @@ public class MetadataServiceURLParamsMetadataCustomizer extends ServiceInstanceM String version = MetadataService.VERSION; - List urls = writableMetadataService.getExportedURLs(serviceInterface, group, version); + SortedSet urls = writableMetadataService.getExportedURLs(serviceInterface, group, version); return getMetadataServiceParameter(toURLs(urls)); } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtils.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtils.java index 5a9dd6a4a6..dcebcec42d 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtils.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtils.java @@ -42,10 +42,22 @@ import static org.apache.dubbo.registry.integration.RegistryProtocol.DEFAULT_REG */ public class ServiceInstanceMetadataUtils { + /** + * The prefix of {@link MetadataService} : "dubbo.metadata-service." + */ + public static final String DUBBO_METADATA_SERVICE_PREFIX = "dubbo.metadata-service."; + /** * The key of metadata JSON of {@link MetadataService}'s {@link URL} */ - public static String METADATA_SERVICE_URL_PARAMS_KEY = "dubbo.metadata-service.url-params"; + public static String METADATA_SERVICE_URL_PARAMS_KEY = DUBBO_METADATA_SERVICE_PREFIX + "url-params"; + + /** + * The {@link URL URLs} property name of {@link MetadataService} : + * "dubbo.metadata-service.urls", which is used to be compatible with Dubbo Spring Cloud and + * discovery the metadata of instance + */ + public static final String DUBBO_METADATA_SERVICE_URLS_PROPERTY_NAME = DUBBO_METADATA_SERVICE_PREFIX + "urls"; /** * The key of The revision for all exported Dubbo services. diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/SpringCloudMetadataServiceURLBuilder.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/SpringCloudMetadataServiceURLBuilder.java new file mode 100644 index 0000000000..7eb3664d1c --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/SpringCloudMetadataServiceURLBuilder.java @@ -0,0 +1,49 @@ +/* + * 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.registry.client.metadata; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.registry.client.ServiceInstance; + +import com.alibaba.fastjson.JSON; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.DUBBO_METADATA_SERVICE_URLS_PROPERTY_NAME; + +/** + * The {@link MetadataServiceURLBuilder} implementation for The standard Dubbo scenario + * + * @since 2.7.4 + */ +public class SpringCloudMetadataServiceURLBuilder implements MetadataServiceURLBuilder { + + @Override + public List build(ServiceInstance serviceInstance) { + Map metadata = serviceInstance.getMetadata(); + String dubboURLsJSON = metadata.get(DUBBO_METADATA_SERVICE_URLS_PROPERTY_NAME); + if (StringUtils.isBlank(dubboURLsJSON)) { + return Collections.emptyList(); + } + List urlStrings = JSON.parseArray(dubboURLsJSON, String.class); + return urlStrings.stream().map(URL::valueOf).collect(Collectors.toList()); + } +} diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/StandardMetadataServiceURLBuilder.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/StandardMetadataServiceURLBuilder.java new file mode 100644 index 0000000000..48022af20a --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/StandardMetadataServiceURLBuilder.java @@ -0,0 +1,74 @@ +/* + * 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.registry.client.metadata; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.URLBuilder; +import org.apache.dubbo.metadata.MetadataService; +import org.apache.dubbo.registry.client.ServiceInstance; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import static java.lang.String.valueOf; +import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getMetadataServiceURLsParams; +import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getProviderHost; +import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getProviderPort; + +/** + * The {@link MetadataServiceURLBuilder} implementation for The standard Dubbo scenario + * + * @see MetadataService + * @since 2.7.4 + */ +public class StandardMetadataServiceURLBuilder implements MetadataServiceURLBuilder { + + /** + * Build the {@link URL urls} from {@link ServiceInstance#getMetadata() the metadata} of {@link ServiceInstance} + * + * @param serviceInstance {@link ServiceInstance} + * @return the not-null {@link List} + */ + @Override + public List build(ServiceInstance serviceInstance) { + + Map> paramsMap = getMetadataServiceURLsParams(serviceInstance); + + List urls = new ArrayList<>(paramsMap.size()); + + for (Map.Entry> entry : paramsMap.entrySet()) { + + URLBuilder urlBuilder = new URLBuilder(); + String protocol = entry.getKey(); + Map urlParams = entry.getValue(); + String host = getProviderHost(urlParams); + Integer port = getProviderPort(urlParams); + urlBuilder.setHost(host) + .setPort(port) + .setProtocol(protocol) + .setPath(MetadataService.class.getName()); + + // add parameters + entry.getValue().forEach((name, value) -> urlBuilder.addParameter(name, valueOf(value))); + + urls.add(urlBuilder.build()); + } + + return urls; + } +} diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/DefaultMetadataServiceProxyFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/DefaultMetadataServiceProxyFactory.java index 2e5840b7ec..06248f9700 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/DefaultMetadataServiceProxyFactory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/DefaultMetadataServiceProxyFactory.java @@ -27,20 +27,21 @@ import org.apache.dubbo.rpc.cluster.Cluster; import org.apache.dubbo.rpc.cluster.directory.StaticDirectory; import org.apache.dubbo.rpc.cluster.support.AvailableCluster; -import java.lang.reflect.Proxy; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import static org.apache.dubbo.registry.client.metadata.MetadataServiceURLBuilder.composite; + /** - * The factory of {@link MetadataService}'s {@link Proxy} + * The default {@link MetadataServiceProxyFactory} to get the proxy of {@link MetadataService} * * @since 2.7.4 */ public class DefaultMetadataServiceProxyFactory implements MetadataServiceProxyFactory { - private final Map proxys = new HashMap<>(); + private final Map proxies = new HashMap<>(); private ProxyFactory proxyFactory; @@ -58,11 +59,11 @@ public class DefaultMetadataServiceProxyFactory implements MetadataServiceProxyF @Override public MetadataService getProxy(ServiceInstance serviceInstance) { - return proxys.computeIfAbsent(serviceInstance.getId(), id -> createProxy(serviceInstance)); + return proxies.computeIfAbsent(serviceInstance.getId(), id -> createProxy(serviceInstance)); } protected MetadataService createProxy(ServiceInstance serviceInstance) { - List urls = ServiceInstance.toUrls(serviceInstance); + List urls = composite().build(serviceInstance); List> invokers = urls.stream() .map(url -> protocol.refer(MetadataService.class, url)) .collect(Collectors.toList()); diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/MetadataServiceProxyFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/MetadataServiceProxyFactory.java index ffc097244c..fd55bb776f 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/MetadataServiceProxyFactory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/MetadataServiceProxyFactory.java @@ -29,7 +29,7 @@ import static org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoad * @see MetadataService * @since 2.7.4 */ -@SPI("local") +@SPI("default") public interface MetadataServiceProxyFactory { /** diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ServiceOrientedRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ServiceOrientedRegistry.java index 8018effc71..9d388c8759 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ServiceOrientedRegistry.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ServiceOrientedRegistry.java @@ -40,6 +40,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.SortedSet; import java.util.stream.Collectors; import static java.lang.String.format; @@ -139,10 +140,15 @@ public class ServiceOrientedRegistry extends FailbackRegistry { } @Override - public void doRegister(URL url) { + public final void register(URL url) { if (!shouldRegister(url)) { // Should Not Register return; } + super.register(url); + } + + @Override + public void doRegister(URL url) { if (writableMetadataService.exportURL(url)) { if (logger.isInfoEnabled()) { logger.info(format("The URL[%s] registered successfully.", url.toString())); @@ -155,10 +161,15 @@ public class ServiceOrientedRegistry extends FailbackRegistry { } @Override - public void doUnregister(URL url) { + public final void unregister(URL url) { if (!shouldRegister(url)) { return; } + super.unregister(url); + } + + @Override + public void doUnregister(URL url) { if (writableMetadataService.unexportURL(url)) { if (logger.isInfoEnabled()) { logger.info(format("The URL[%s] deregistered successfully.", url.toString())); @@ -171,13 +182,26 @@ public class ServiceOrientedRegistry extends FailbackRegistry { } @Override - public void doSubscribe(URL url, NotifyListener listener) { + public final void subscribe(URL url, NotifyListener listener) { if (!shouldSubscribe(url)) { // Should Not Subscribe return; } + super.subscribe(url, listener); + } + + @Override + public void doSubscribe(URL url, NotifyListener listener) { subscribeURLs(url, listener); } + @Override + public final void unsubscribe(URL url, NotifyListener listener) { + if (!shouldSubscribe(url)) { // Should Not Subscribe + return; + } + super.unsubscribe(url, listener); + } + @Override public void doUnsubscribe(URL url, NotifyListener listener) { writableMetadataService.unsubscribeURL(url); @@ -401,7 +425,7 @@ public class ServiceOrientedRegistry extends FailbackRegistry { try { MetadataService metadataService = metadataServiceProxyFactory.getProxy(providerInstance); - List urls = metadataService.getExportedURLs(serviceInterface, group, version, protocol); + SortedSet urls = metadataService.getExportedURLs(serviceInterface, group, version, protocol); exportedURLs = urls.stream().map(URL::valueOf).collect(Collectors.toList()); } catch (Throwable e) { if (logger.isErrorEnabled()) { diff --git a/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.metadata.MetadataServiceProxyFactory b/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.metadata.MetadataServiceProxyFactory deleted file mode 100644 index 4886058702..0000000000 --- a/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.metadata.MetadataServiceProxyFactory +++ /dev/null @@ -1 +0,0 @@ -default=org.apache.dubbo.registry.client.metadata.DefaultMetadataServiceProxyFactory \ No newline at end of file diff --git a/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.metadata.proxy.MetadataServiceProxyFactory b/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.metadata.proxy.MetadataServiceProxyFactory index d9283dec44..359dbe8b9b 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.metadata.proxy.MetadataServiceProxyFactory +++ b/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.metadata.proxy.MetadataServiceProxyFactory @@ -1,2 +1,2 @@ -local=org.apache.dubbo.registry.client.metadata.proxy.DefaultMetadataServiceProxyFactory +default=org.apache.dubbo.registry.client.metadata.proxy.DefaultMetadataServiceProxyFactory remote=org.apache.dubbo.registry.client.metadata.proxy.RemoteMetadataServiceProxyFactory \ No newline at end of file diff --git a/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/services/org.apache.dubbo.registry.client.metadata.MetadataServiceURLBuilder b/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/services/org.apache.dubbo.registry.client.metadata.MetadataServiceURLBuilder new file mode 100644 index 0000000000..418ebb7d92 --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/services/org.apache.dubbo.registry.client.metadata.MetadataServiceURLBuilder @@ -0,0 +1,2 @@ +org.apache.dubbo.registry.client.metadata.StandardMetadataServiceURLBuilder +org.apache.dubbo.registry.client.metadata.SpringCloudMetadataServiceURLBuilder \ No newline at end of file diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/DefaultServiceInstanceTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/DefaultServiceInstanceTest.java index 38739f18b9..c48bfa9758 100644 --- a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/DefaultServiceInstanceTest.java +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/DefaultServiceInstanceTest.java @@ -30,31 +30,37 @@ import static org.junit.jupiter.api.Assertions.assertTrue; */ public class DefaultServiceInstanceTest { - public static DefaultServiceInstance INSTANCE = - new DefaultServiceInstance("A", "127.0.0.1", 8080); + public DefaultServiceInstance instance; + + public static DefaultServiceInstance createInstance() { + DefaultServiceInstance instance = new DefaultServiceInstance("A", "127.0.0.1", 8080); + instance.getMetadata().put("dubbo.metadata-service.urls", "[ \"dubbo://192.168.0.102:20881/com.alibaba.cloud.dubbo.service.DubboMetadataService?anyhost=true&application=spring-cloud-alibaba-dubbo-provider&bind.ip=192.168.0.102&bind.port=20881&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&group=spring-cloud-alibaba-dubbo-provider&interface=com.alibaba.cloud.dubbo.service.DubboMetadataService&methods=getAllServiceKeys,getServiceRestMetadata,getExportedURLs,getAllExportedURLs&pid=17134&qos.enable=false®ister=true&release=2.7.3&revision=1.0.0&side=provider×tamp=1564826098503&version=1.0.0\" ]"); + instance.getMetadata().put("dubbo.metadata-service.url-params", "{\"dubbo\":{\"application\":\"dubbo-provider-demo\",\"deprecated\":\"false\",\"group\":\"dubbo-provider-demo\",\"version\":\"1.0.0\",\"timestamp\":\"1564845042651\",\"dubbo\":\"2.0.2\",\"provider.host\":\"192.168.0.102\",\"provider.port\":\"20880\"}}"); + return instance; + } @BeforeEach public void init() { - INSTANCE = new DefaultServiceInstance("A", "127.0.0.1", 8080); + instance = createInstance(); } @Test public void testDefaultValues() { - assertTrue(INSTANCE.isEnabled()); - assertTrue(INSTANCE.isHealthy()); - assertTrue(INSTANCE.getMetadata().isEmpty()); + assertTrue(instance.isEnabled()); + assertTrue(instance.isHealthy()); + assertFalse(instance.getMetadata().isEmpty()); } @Test public void testSetAndGetValues() { - INSTANCE.setEnabled(false); - INSTANCE.setHealthy(false); + instance.setEnabled(false); + instance.setHealthy(false); - assertEquals("A", INSTANCE.getServiceName()); - assertEquals("127.0.0.1", INSTANCE.getHost()); - assertEquals(8080, INSTANCE.getPort()); - assertFalse(INSTANCE.isEnabled()); - assertFalse(INSTANCE.isHealthy()); - assertTrue(INSTANCE.getMetadata().isEmpty()); + assertEquals("A", instance.getServiceName()); + assertEquals("127.0.0.1", instance.getHost()); + assertEquals(8080, instance.getPort()); + assertFalse(instance.isEnabled()); + assertFalse(instance.isHealthy()); + assertFalse(instance.getMetadata().isEmpty()); } } diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/DefaultHelloService.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/event/listener/CustomizableServiceInstanceListenerTest.java similarity index 53% rename from dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/DefaultHelloService.java rename to dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/event/listener/CustomizableServiceInstanceListenerTest.java index 8277bc9b4e..0b022b0c1b 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/context/annotation/provider/DefaultHelloService.java +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/event/listener/CustomizableServiceInstanceListenerTest.java @@ -14,27 +14,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.config.spring.context.context.annotation.provider; +package org.apache.dubbo.registry.client.event.listener; -import org.apache.dubbo.config.spring.annotation.merged.MergedService; -import org.apache.dubbo.config.spring.api.HelloService; +import org.apache.dubbo.registry.client.DefaultServiceInstanceTest; +import org.apache.dubbo.registry.client.event.ServiceInstancePreRegisteredEvent; -import org.springframework.stereotype.Service; +import org.junit.jupiter.api.Test; /** - * Default {@link HelloService} annotation with Spring's {@link Service} - * and Dubbo's {@link org.apache.dubbo.config.annotation.Service} + * {@link CustomizableServiceInstanceListener} Test * - * @since TODO + * @since 2.7.4 */ -@Service -//@org.apache.dubbo.config.annotation.Service -@MergedService -public class DefaultHelloService implements HelloService { +public class CustomizableServiceInstanceListenerTest { - @Override - public String sayHello(String name) { - return "Greeting, " + name; + private CustomizableServiceInstanceListener listener = new CustomizableServiceInstanceListener(); + + @Test + public void testOnEvent() { + ServiceInstancePreRegisteredEvent event = new ServiceInstancePreRegisteredEvent(this, DefaultServiceInstanceTest.createInstance()); + // breaking test + listener.onEvent(event); } - } diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/event/listener/LoggingEventListenerTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/event/listener/LoggingEventListenerTest.java new file mode 100644 index 0000000000..ddd3aecd08 --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/event/listener/LoggingEventListenerTest.java @@ -0,0 +1,85 @@ +/* + * 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.registry.client.event.listener; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.registry.client.FileSystemServiceDiscovery; +import org.apache.dubbo.registry.client.ServiceDiscovery; +import org.apache.dubbo.registry.client.event.ServiceDiscoveryStartedEvent; +import org.apache.dubbo.registry.client.event.ServiceDiscoveryStartingEvent; +import org.apache.dubbo.registry.client.event.ServiceDiscoveryStoppedEvent; +import org.apache.dubbo.registry.client.event.ServiceDiscoveryStoppingEvent; +import org.apache.dubbo.registry.client.event.ServiceInstancePreRegisteredEvent; +import org.apache.dubbo.registry.client.event.ServiceInstancePreUnregisteredEvent; +import org.apache.dubbo.registry.client.event.ServiceInstanceRegisteredEvent; +import org.apache.dubbo.registry.client.event.ServiceInstanceUnregisteredEvent; +import org.apache.dubbo.registry.client.event.ServiceInstancesChangedEvent; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static java.util.Collections.singleton; +import static org.apache.dubbo.registry.client.DefaultServiceInstanceTest.createInstance; + +/** + * {@link LoggingEventListener} Test + * + * @since 2.7.4 + */ +public class LoggingEventListenerTest { + + private LoggingEventListener listener; + + @BeforeEach + public void init() { + listener = new LoggingEventListener(); + } + + @Test + public void testOnEvent() { + + URL connectionURL = URL.valueOf("file:///Users/Home"); + ServiceDiscovery serviceDiscovery = new FileSystemServiceDiscovery(connectionURL); + + // ServiceDiscoveryStartingEvent + listener.onEvent(new ServiceDiscoveryStartingEvent(serviceDiscovery)); + + // ServiceDiscoveryStartedEvent + listener.onEvent(new ServiceDiscoveryStartedEvent(serviceDiscovery)); + + // ServiceInstancePreRegisteredEvent + listener.onEvent(new ServiceInstancePreRegisteredEvent(serviceDiscovery, createInstance())); + + // ServiceInstanceRegisteredEvent + listener.onEvent(new ServiceInstanceRegisteredEvent(serviceDiscovery, createInstance())); + + // ServiceInstancesChangedEvent + listener.onEvent(new ServiceInstancesChangedEvent("test", singleton(createInstance()))); + + // ServiceInstancePreUnregisteredEvent + listener.onEvent(new ServiceInstancePreUnregisteredEvent(serviceDiscovery, createInstance())); + + // ServiceInstanceUnregisteredEvent + listener.onEvent(new ServiceInstanceUnregisteredEvent(serviceDiscovery, createInstance())); + + // ServiceDiscoveryStoppingEvent + listener.onEvent(new ServiceDiscoveryStoppingEvent(serviceDiscovery)); + + // ServiceDiscoveryStoppedEvent + listener.onEvent(new ServiceDiscoveryStoppedEvent(serviceDiscovery)); + } +} diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/event/listener/ServiceInstancesChangedListenerTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/event/listener/ServiceInstancesChangedListenerTest.java new file mode 100644 index 0000000000..898e732405 --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/event/listener/ServiceInstancesChangedListenerTest.java @@ -0,0 +1,54 @@ +/* + * 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.registry.client.event.listener; + +import org.apache.dubbo.event.Event; +import org.apache.dubbo.event.EventDispatcher; +import org.apache.dubbo.registry.client.event.ServiceInstancesChangedEvent; + +import org.junit.jupiter.api.Test; + +import java.util.concurrent.atomic.AtomicReference; + +import static java.util.Collections.emptyList; +import static org.apache.dubbo.event.EventDispatcher.getDefaultExtension; +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * {@link ServiceInstancesChangedListener} Test + * + * @since 2.7.4 + */ +public class ServiceInstancesChangedListenerTest { + + @Test + public void testOnEvent() { + + EventDispatcher eventDispatcher = getDefaultExtension(); + + Event event = new ServiceInstancesChangedEvent("test", emptyList()); + + AtomicReference eventRef = new AtomicReference<>(); + + eventDispatcher.addEventListener((ServiceInstancesChangedListener) eventRef::set); + + // Dispatch a ServiceInstancesChangedEvent + eventDispatcher.dispatch(event); + + assertEquals(eventRef.get(), event); + } +} diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/metadata/MetadataServiceURLBuilderTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/metadata/MetadataServiceURLBuilderTest.java new file mode 100644 index 0000000000..5c905779d2 --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/metadata/MetadataServiceURLBuilderTest.java @@ -0,0 +1,53 @@ +/* + * 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.registry.client.metadata; + +import org.apache.dubbo.registry.client.DefaultServiceInstance; +import org.apache.dubbo.registry.client.ServiceInstance; + +import org.junit.jupiter.api.Test; + +import static org.apache.dubbo.registry.client.metadata.MetadataServiceURLBuilder.composite; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * {@link MetadataServiceURLBuilder} Test + * + * @since 2.7.4 + */ +public class MetadataServiceURLBuilderTest { + + static ServiceInstance serviceInstance = new DefaultServiceInstance("127.0.0.1", "test", 8080); + + static { + serviceInstance.getMetadata().put("dubbo.metadata-service.urls", "[ \"dubbo://192.168.0.102:20881/com.alibaba.cloud.dubbo.service.DubboMetadataService?anyhost=true&application=spring-cloud-alibaba-dubbo-provider&bind.ip=192.168.0.102&bind.port=20881&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&group=spring-cloud-alibaba-dubbo-provider&interface=com.alibaba.cloud.dubbo.service.DubboMetadataService&methods=getAllServiceKeys,getServiceRestMetadata,getExportedURLs,getAllExportedURLs&pid=17134&qos.enable=false®ister=true&release=2.7.3&revision=1.0.0&side=provider×tamp=1564826098503&version=1.0.0\" ]"); + serviceInstance.getMetadata().put("dubbo.metadata-service.url-params", "{\"dubbo\":{\"application\":\"dubbo-provider-demo\",\"deprecated\":\"false\",\"group\":\"dubbo-provider-demo\",\"version\":\"1.0.0\",\"timestamp\":\"1564845042651\",\"dubbo\":\"2.0.2\",\"provider.host\":\"192.168.0.102\",\"provider.port\":\"20880\"}}"); + } + + @Test + public void testComposite() { + assertEquals(CompositeMetadataServiceURLBuilder.class, composite().getClass()); + } + + @Test + public void testBuild() { + assertTrue(composite().build(null).isEmpty()); + assertTrue(composite().build(new DefaultServiceInstance("127.0.0.1", "test", 8080)).isEmpty()); + assertEquals(2, composite().build(serviceInstance).size()); + } +} diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtilsTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtilsTest.java index 1fc056653e..6f88b8a813 100644 --- a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtilsTest.java +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/metadata/ServiceInstanceMetadataUtilsTest.java @@ -18,10 +18,13 @@ package org.apache.dubbo.registry.client.metadata; import org.apache.dubbo.common.URL; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.List; +import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -35,7 +38,7 @@ public class ServiceInstanceMetadataUtilsTest { private static URL url = URL.valueOf("dubbo://192.168.0.102:20880/org.apache.dubbo.metadata.MetadataService?&anyhost=true&application=spring-cloud-alibaba-dubbo-provider&bind.ip=192.168.0.102&bind.port=20880&default.deprecated=false&default.dynamic=false&default.register=true&deprecated=false&dubbo=2.0.2&dynamic=false&generic=false&group=spring-cloud-alibaba-dubbo-provider&interface=org.apache.dubbo.metadata.MetadataService&methods=getAllServiceKeys,getServiceRestMetadata,getExportedURLs,getAllExportedURLs&pid=58350®ister=true&release=2.7.1&revision=1.0.0&side=provider×tamp=1557928573174&version=1.0.0"); private static URL url2 = URL.valueOf("rest://192.168.0.102:20880/org.apache.dubbo.metadata.MetadataService?&anyhost=true&application=spring-cloud-alibaba-dubbo-provider&bind.ip=192.168.0.102&bind.port=20880&default.deprecated=false&default.dynamic=false&default.register=true&deprecated=false&dubbo=2.0.2&dynamic=false&generic=false&group=spring-cloud-alibaba-dubbo-provider&interface=org.apache.dubbo.metadata.MetadataService&methods=getAllServiceKeys,getServiceRestMetadata,getExportedURLs,getAllExportedURLs&pid=58350®ister=true&release=2.7.1&revision=1.0.0&side=provider×tamp=1557928573174&version=1.0.0"); - private static final String VALUE = "{\"rest\":{\"application\":\"spring-cloud-alibaba-dubbo-provider\",\"bind.ip\":\"192.168.0.102\",\"bind.port\":\"20880\",\"dubbo\":\"2.0.2\",\"release\":\"2.7.1\",\"side\":\"provider\",\"version\":\"1.0.0\"},\"dubbo\":{\"application\":\"spring-cloud-alibaba-dubbo-provider\",\"bind.ip\":\"192.168.0.102\",\"bind.port\":\"20880\",\"dubbo\":\"2.0.2\",\"release\":\"2.7.1\",\"side\":\"provider\",\"version\":\"1.0.0\"}}"; + private static final String VALUE = "{\"rest\":{\"application\":\"spring-cloud-alibaba-dubbo-provider\",\"deprecated\":\"false\",\"group\":\"spring-cloud-alibaba-dubbo-provider\",\"version\":\"1.0.0\",\"timestamp\":\"1557928573174\",\"dubbo\":\"2.0.2\",\"release\":\"2.7.1\",\"provider.host\":\"192.168.0.102\",\"provider.port\":\"20880\"},\"dubbo\":{\"application\":\"spring-cloud-alibaba-dubbo-provider\",\"deprecated\":\"false\",\"group\":\"spring-cloud-alibaba-dubbo-provider\",\"version\":\"1.0.0\",\"timestamp\":\"1557928573174\",\"dubbo\":\"2.0.2\",\"release\":\"2.7.1\",\"provider.host\":\"192.168.0.102\",\"provider.port\":\"20880\"}}"; @Test public void testMetadataServiceURLParameters() { @@ -44,6 +47,18 @@ public class ServiceInstanceMetadataUtilsTest { String parameter = ServiceInstanceMetadataUtils.getMetadataServiceParameter(urls); + JSONObject jsonObject = JSON.parseObject(parameter); + + urls.forEach(url -> { + JSONObject map = jsonObject.getJSONObject(url.getProtocol()); + for (Map.Entry param : url.getParameters().entrySet()) { + String value = map.getString(param.getKey()); + if (value != null) { + assertEquals(param.getValue(), value); + } + } + }); + assertEquals(VALUE, parameter); } diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/metadata/SpringCloudMetadataServiceURLBuilderTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/metadata/SpringCloudMetadataServiceURLBuilderTest.java new file mode 100644 index 0000000000..0a2b9f4a46 --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/metadata/SpringCloudMetadataServiceURLBuilderTest.java @@ -0,0 +1,51 @@ +/* + * 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.registry.client.metadata; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.registry.client.DefaultServiceInstance; + +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.apache.dubbo.registry.client.metadata.MetadataServiceURLBuilderTest.serviceInstance; +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * {@link SpringCloudMetadataServiceURLBuilder} Test + * + * @since 2.7.4 + */ +public class SpringCloudMetadataServiceURLBuilderTest { + + private SpringCloudMetadataServiceURLBuilder builder = new SpringCloudMetadataServiceURLBuilder(); + + @Test + public void testBuild() { + List urls = builder.build(new DefaultServiceInstance("127.0.0.1", "test", 8080)); + assertEquals(0, urls.size()); + + urls = builder.build(serviceInstance); + assertEquals(1, urls.size()); + URL url = urls.get(0); + assertEquals("192.168.0.102", url.getHost()); + assertEquals(20881, url.getPort()); + assertEquals("com.alibaba.cloud.dubbo.service.DubboMetadataService", url.getServiceInterface()); + } + +} diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/ServiceOrientedRegistryTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/ServiceOrientedRegistryTest.java index 9840a255f8..ec40682284 100644 --- a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/ServiceOrientedRegistryTest.java +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/ServiceOrientedRegistryTest.java @@ -25,8 +25,11 @@ import org.junit.jupiter.api.Test; import java.util.LinkedList; import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; -import static java.util.Collections.emptyList; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableSortedSet; import static org.apache.dubbo.common.URL.valueOf; import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_PROTOCOL; import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE; @@ -51,7 +54,7 @@ public class ServiceOrientedRegistryTest { private static final String SERVICE_INTERFACE = "org.apache.dubbo.metadata.MetadataService"; - private static final String GROUP = "spring-cloud-alibaba-dubbo-provider"; + private static final String GROUP = "dubbo-provider"; private static final String VERSION = "1.0.0"; @@ -94,11 +97,11 @@ public class ServiceOrientedRegistryTest { registry.register(url); - List urls = metadataService.getExportedURLs(); + SortedSet urls = metadataService.getExportedURLs(); - assertEquals(emptyList(), urls); - assertEquals(metadataService.getExportedURLs(SERVICE_INTERFACE), urls); - assertEquals(metadataService.getExportedURLs(SERVICE_INTERFACE, GROUP), urls); + assertTrue(urls.isEmpty()); + assertEquals(toSortedSet(), metadataService.getExportedURLs(SERVICE_INTERFACE)); + assertEquals(toSortedSet(), metadataService.getExportedURLs(SERVICE_INTERFACE, GROUP)); assertEquals(metadataService.getExportedURLs(SERVICE_INTERFACE, GROUP, VERSION), urls); assertEquals(metadataService.getExportedURLs(SERVICE_INTERFACE, GROUP, VERSION, DEFAULT_PROTOCOL), urls); @@ -110,8 +113,8 @@ public class ServiceOrientedRegistryTest { urls = metadataService.getExportedURLs(); - assertEquals(metadataService.getExportedURLs(serviceInterface, GROUP, VERSION), urls); - assertEquals(metadataService.getExportedURLs(serviceInterface, GROUP, VERSION, DEFAULT_PROTOCOL), urls); + assertEquals(metadataService.getExportedURLs(serviceInterface, GROUP, VERSION), toSortedSet(urls.first())); + assertEquals(metadataService.getExportedURLs(serviceInterface, GROUP, VERSION, DEFAULT_PROTOCOL), toSortedSet(urls.first())); } @@ -125,7 +128,7 @@ public class ServiceOrientedRegistryTest { // register registry.register(newURL); - List urls = metadataService.getExportedURLs(); + SortedSet urls = metadataService.getExportedURLs(); assertFalse(urls.isEmpty()); assertEquals(metadataService.getExportedURLs(serviceInterface, GROUP, VERSION), urls); @@ -136,7 +139,7 @@ public class ServiceOrientedRegistryTest { urls = metadataService.getExportedURLs(); - assertEquals(emptyList(), urls); + assertEquals(toSortedSet(), urls); assertEquals(metadataService.getExportedURLs(SERVICE_INTERFACE), urls); assertEquals(metadataService.getExportedURLs(SERVICE_INTERFACE, GROUP), urls); assertEquals(metadataService.getExportedURLs(SERVICE_INTERFACE, GROUP, VERSION), urls); @@ -148,10 +151,9 @@ public class ServiceOrientedRegistryTest { registry.subscribe(url, new MyNotifyListener()); - List urls = metadataService.getSubscribedURLs(); + SortedSet urls = metadataService.getSubscribedURLs(); - assertFalse(urls.isEmpty()); - assertEquals(url, urls.get(0)); + assertTrue(urls.isEmpty()); } @@ -170,4 +172,8 @@ public class ServiceOrientedRegistryTest { } } + private static > SortedSet toSortedSet(T... values) { + return unmodifiableSortedSet(new TreeSet<>(asList(values))); + } + } diff --git a/dubbo-registry/dubbo-registry-consul/pom.xml b/dubbo-registry/dubbo-registry-consul/pom.xml index 0b40fbf0b0..c2844abbdb 100644 --- a/dubbo-registry/dubbo-registry-consul/pom.xml +++ b/dubbo-registry/dubbo-registry-consul/pom.xml @@ -21,6 +21,7 @@ dubbo-registry org.apache.dubbo ${revision} + ../pom.xml 4.0.0 diff --git a/dubbo-registry/dubbo-registry-default/pom.xml b/dubbo-registry/dubbo-registry-default/pom.xml index 37df8f2ef7..b2eeecb1cb 100644 --- a/dubbo-registry/dubbo-registry-default/pom.xml +++ b/dubbo-registry/dubbo-registry-default/pom.xml @@ -21,6 +21,7 @@ org.apache.dubbo dubbo-registry ${revision} + ../pom.xml dubbo-registry-default jar diff --git a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryProtocolTest.java b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryProtocolTest.java index 5e84ece034..192ed588fa 100644 --- a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryProtocolTest.java +++ b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/RegistryProtocolTest.java @@ -41,8 +41,8 @@ import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; -import static org.apache.dubbo.rpc.cluster.Constants.EXPORT_KEY; import static org.apache.dubbo.registry.integration.RegistryProtocol.DEFAULT_REGISTER_PROVIDER_KEYS; +import static org.apache.dubbo.rpc.cluster.Constants.EXPORT_KEY; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; diff --git a/dubbo-registry/dubbo-registry-etcd3/pom.xml b/dubbo-registry/dubbo-registry-etcd3/pom.xml index 6d9d60cbd5..4464685274 100644 --- a/dubbo-registry/dubbo-registry-etcd3/pom.xml +++ b/dubbo-registry/dubbo-registry-etcd3/pom.xml @@ -22,6 +22,7 @@ dubbo-registry org.apache.dubbo ${revision} + ../pom.xml dubbo-registry-etcd3 diff --git a/dubbo-registry/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdServiceDiscovery.java b/dubbo-registry/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdServiceDiscovery.java index 4cce645ef1..f10a0b0dd5 100644 --- a/dubbo-registry/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdServiceDiscovery.java +++ b/dubbo-registry/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdServiceDiscovery.java @@ -38,8 +38,6 @@ import com.google.gson.Gson; import java.io.File; import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Optional; @@ -47,8 +45,6 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY; - /** * 2019-07-08 */ diff --git a/dubbo-registry/dubbo-registry-etcd3/src/test/java/org/apache/dubbo/registry/etcd/EtcdRegistryTest.java b/dubbo-registry/dubbo-registry-etcd3/src/test/java/org/apache/dubbo/registry/etcd/EtcdRegistryTest.java index f09ff804d1..079aadd789 100644 --- a/dubbo-registry/dubbo-registry-etcd3/src/test/java/org/apache/dubbo/registry/etcd/EtcdRegistryTest.java +++ b/dubbo-registry/dubbo-registry-etcd3/src/test/java/org/apache/dubbo/registry/etcd/EtcdRegistryTest.java @@ -79,12 +79,12 @@ import static org.apache.dubbo.common.constants.CommonConstants.ENABLED_KEY; import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; -import static org.apache.dubbo.registry.Constants.ADMIN_PROTOCOL; import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY; import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY; import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMERS_CATEGORY; import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDERS_CATEGORY; import static org.apache.dubbo.common.constants.RegistryConstants.ROUTERS_CATEGORY; +import static org.apache.dubbo.registry.Constants.ADMIN_PROTOCOL; @Disabled public class EtcdRegistryTest { diff --git a/dubbo-registry/dubbo-registry-multicast/pom.xml b/dubbo-registry/dubbo-registry-multicast/pom.xml index 643159bddd..8e03ce51d4 100644 --- a/dubbo-registry/dubbo-registry-multicast/pom.xml +++ b/dubbo-registry/dubbo-registry-multicast/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-registry ${revision} + ../pom.xml dubbo-registry-multicast jar diff --git a/dubbo-registry/dubbo-registry-multicast/src/main/java/org/apache/dubbo/registry/multicast/MulticastRegistry.java b/dubbo-registry/dubbo-registry-multicast/src/main/java/org/apache/dubbo/registry/multicast/MulticastRegistry.java index 0c2844552e..79e450fbdf 100644 --- a/dubbo-registry/dubbo-registry-multicast/src/main/java/org/apache/dubbo/registry/multicast/MulticastRegistry.java +++ b/dubbo-registry/dubbo-registry-multicast/src/main/java/org/apache/dubbo/registry/multicast/MulticastRegistry.java @@ -51,14 +51,14 @@ import java.util.concurrent.TimeUnit; import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT; import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; -import static org.apache.dubbo.registry.Constants.CONSUMER_PROTOCOL; -import static org.apache.dubbo.registry.Constants.DEFAULT_SESSION_TIMEOUT; import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY; import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL; import static org.apache.dubbo.common.constants.RegistryConstants.OVERRIDE_PROTOCOL; +import static org.apache.dubbo.common.constants.RegistryConstants.ROUTE_PROTOCOL; +import static org.apache.dubbo.registry.Constants.CONSUMER_PROTOCOL; +import static org.apache.dubbo.registry.Constants.DEFAULT_SESSION_TIMEOUT; import static org.apache.dubbo.registry.Constants.REGISTER; import static org.apache.dubbo.registry.Constants.REGISTER_KEY; -import static org.apache.dubbo.common.constants.RegistryConstants.ROUTE_PROTOCOL; import static org.apache.dubbo.registry.Constants.SESSION_TIMEOUT_KEY; import static org.apache.dubbo.registry.Constants.SUBSCRIBE; import static org.apache.dubbo.registry.Constants.UNREGISTER; diff --git a/dubbo-registry/dubbo-registry-multiple/pom.xml b/dubbo-registry/dubbo-registry-multiple/pom.xml index e62e2fe21b..aa7c1a2602 100644 --- a/dubbo-registry/dubbo-registry-multiple/pom.xml +++ b/dubbo-registry/dubbo-registry-multiple/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-registry ${revision} + ../pom.xml dubbo-registry-multiple jar diff --git a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistryFactory.java b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistryFactory.java index 4c3bc5c01e..721da52c14 100644 --- a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistryFactory.java +++ b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistryFactory.java @@ -21,9 +21,6 @@ import org.apache.dubbo.registry.Registry; import org.apache.dubbo.registry.RegistryFactory; import org.apache.dubbo.registry.support.AbstractRegistryFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import static org.apache.dubbo.registry.nacos.util.NacosNamingServiceUtils.createNamingService; /** diff --git a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/util/NacosNamingServiceUtils.java b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/util/NacosNamingServiceUtils.java index fd08d9ec85..98c9b5bbe1 100644 --- a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/util/NacosNamingServiceUtils.java +++ b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/util/NacosNamingServiceUtils.java @@ -1,4 +1,4 @@ -package org.apache.dubbo.registry.nacos.util;/* +/* * 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. @@ -14,6 +14,7 @@ package org.apache.dubbo.registry.nacos.util;/* * See the License for the specific language governing permissions and * limitations under the License. */ +package org.apache.dubbo.registry.nacos.util; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; diff --git a/dubbo-registry/dubbo-registry-redis/pom.xml b/dubbo-registry/dubbo-registry-redis/pom.xml index 8144089f35..e6e99b9d46 100644 --- a/dubbo-registry/dubbo-registry-redis/pom.xml +++ b/dubbo-registry/dubbo-registry-redis/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-registry ${revision} + ../pom.xml dubbo-registry-redis jar diff --git a/dubbo-registry/dubbo-registry-zookeeper/pom.xml b/dubbo-registry/dubbo-registry-zookeeper/pom.xml index cf3a1a90e1..2d810dbfdf 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/pom.xml +++ b/dubbo-registry/dubbo-registry-zookeeper/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-registry ${revision} + ../pom.xml dubbo-registry-zookeeper jar diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java index 4ddf1518e6..fbfc750bb9 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java @@ -60,8 +60,6 @@ public class ZookeeperRegistry extends FailbackRegistry { private final static Logger logger = LoggerFactory.getLogger(ZookeeperRegistry.class); - private final static int DEFAULT_ZOOKEEPER_PORT = 2181; - private final static String DEFAULT_ROOT = "dubbo"; private final String root; diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperServiceDiscovery.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperServiceDiscovery.java index 888972a82d..9ee5dde7cf 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperServiceDiscovery.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperServiceDiscovery.java @@ -21,6 +21,8 @@ import org.apache.dubbo.common.function.ThrowableConsumer; import org.apache.dubbo.common.function.ThrowableFunction; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.DefaultPage; +import org.apache.dubbo.common.utils.Page; import org.apache.dubbo.event.EventDispatcher; import org.apache.dubbo.event.EventListener; import org.apache.dubbo.registry.client.ServiceDiscovery; @@ -32,7 +34,9 @@ import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.api.CuratorWatcher; import org.apache.zookeeper.KeeperException; +import java.util.Iterator; import java.util.LinkedHashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -113,6 +117,39 @@ public class ZookeeperServiceDiscovery implements ServiceDiscovery, EventListene return doInServiceDiscovery(s -> build(s.queryForInstances(serviceName))); } + @Override + public Page getInstances(String serviceName, int offset, int pageSize, boolean healthyOnly) { + String path = buildServicePath(serviceName); + + return execute(path, p -> { + + List serviceInstances = new LinkedList<>(); + + List serviceIds = new LinkedList<>(curatorFramework.getChildren().forPath(p)); + + int totalSize = serviceIds.size(); + + Iterator iterator = serviceIds.iterator(); + + for (int i = 0; i < offset; i++) { + if (iterator.hasNext()) { // remove the elements from 0 to offset + iterator.next(); + iterator.remove(); + } + } + + for (int i = 0; i < pageSize; i++) { + if (iterator.hasNext()) { + String serviceId = iterator.next(); + ServiceInstance serviceInstance = build(serviceDiscovery.queryForInstance(serviceName, serviceId)); + serviceInstances.add(serviceInstance); + } + } + + return new DefaultPage<>(offset, pageSize, serviceInstances, totalSize); + }); + } + @Override public void addServiceInstancesChangedListener(String serviceName, ServiceInstancesChangedListener listener) throws NullPointerException, IllegalArgumentException { diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/test/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistryTest.java b/dubbo-registry/dubbo-registry-zookeeper/src/test/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistryTest.java index 80819ec4eb..d0b10f690d 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/test/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistryTest.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/test/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistryTest.java @@ -55,8 +55,9 @@ public class ZookeeperRegistryTest { public void setUp() throws Exception { int zkServerPort = NetUtils.getAvailablePort(); this.zkServer = new TestingServer(zkServerPort, true); - this.registryUrl = URL.valueOf("zookeeper://localhost:" + zkServerPort); + this.zkServer.start(); + this.registryUrl = URL.valueOf("zookeeper://localhost:" + zkServerPort); zookeeperRegistryFactory = new ZookeeperRegistryFactory(); zookeeperRegistryFactory.setZookeeperTransporter(new CuratorZookeeperTransporter()); this.zookeeperRegistry = (ZookeeperRegistry) zookeeperRegistryFactory.createRegistry(registryUrl); diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/test/java/org/apache/dubbo/registry/zookeeper/ZookeeperServiceDiscoveryTest.java b/dubbo-registry/dubbo-registry-zookeeper/src/test/java/org/apache/dubbo/registry/zookeeper/ZookeeperServiceDiscoveryTest.java index 61870224ca..5f14ec5849 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/test/java/org/apache/dubbo/registry/zookeeper/ZookeeperServiceDiscoveryTest.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/test/java/org/apache/dubbo/registry/zookeeper/ZookeeperServiceDiscoveryTest.java @@ -18,6 +18,7 @@ package org.apache.dubbo.registry.zookeeper; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.Page; +import org.apache.dubbo.event.EventDispatcher; import org.apache.dubbo.registry.client.DefaultServiceInstance; import org.apache.dubbo.registry.client.ServiceInstance; @@ -60,6 +61,7 @@ public class ZookeeperServiceDiscoveryTest { @BeforeEach public void init() throws Exception { + EventDispatcher.getDefaultExtension().removeAllEventListeners(); zkServerPort = getAvailablePort(); zkServer = new TestingServer(zkServerPort, true); zkServer.start(); diff --git a/dubbo-registry/pom.xml b/dubbo-registry/pom.xml index 32db5d495a..b32ad5e887 100644 --- a/dubbo-registry/pom.xml +++ b/dubbo-registry/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-parent ${revision} + ../pom.xml dubbo-registry pom diff --git a/dubbo-remoting/dubbo-remoting-api/pom.xml b/dubbo-remoting/dubbo-remoting-api/pom.xml index 6d35681d9f..69ed09499b 100644 --- a/dubbo-remoting/dubbo-remoting-api/pom.xml +++ b/dubbo-remoting/dubbo-remoting-api/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-remoting ${revision} + ../pom.xml dubbo-remoting-api jar diff --git a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceClientFixedTest.java b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceClientFixedTest.java index 93ccc76e51..8380f5a675 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceClientFixedTest.java +++ b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/PerformanceClientFixedTest.java @@ -80,7 +80,7 @@ public class PerformanceClientFixedTest { } catch (Throwable t) { t.printStackTrace(); } finally { - if (client != null && client.isConnected() == false) { + if (client != null && !client.isConnected()) { f++; System.out.println("open client failed, try again " + f); client.close(); diff --git a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/transport/AbstractCodecTest.java b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/transport/AbstractCodecTest.java index 44ea23338a..ed07ebb2d8 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/transport/AbstractCodecTest.java +++ b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/transport/AbstractCodecTest.java @@ -16,13 +16,14 @@ */ package org.apache.dubbo.remoting.transport; -import java.io.IOException; - import org.apache.dubbo.common.URL; import org.apache.dubbo.remoting.Channel; + import org.hamcrest.CoreMatchers; import org.mockito.internal.verification.VerificationModeFactory; +import java.io.IOException; + import static org.hamcrest.CoreMatchers.allOf; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.BDDMockito.given; diff --git a/dubbo-remoting/dubbo-remoting-etcd3/pom.xml b/dubbo-remoting/dubbo-remoting-etcd3/pom.xml index 73a2539bda..285854bda8 100644 --- a/dubbo-remoting/dubbo-remoting-etcd3/pom.xml +++ b/dubbo-remoting/dubbo-remoting-etcd3/pom.xml @@ -24,6 +24,7 @@ dubbo-remoting org.apache.dubbo ${revision} + ../pom.xml dubbo-remoting-etcd3 jar diff --git a/dubbo-remoting/dubbo-remoting-grizzly/pom.xml b/dubbo-remoting/dubbo-remoting-grizzly/pom.xml index cd185367fd..1d5a7f1017 100644 --- a/dubbo-remoting/dubbo-remoting-grizzly/pom.xml +++ b/dubbo-remoting/dubbo-remoting-grizzly/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-remoting ${revision} + ../pom.xml dubbo-remoting-grizzly jar diff --git a/dubbo-remoting/dubbo-remoting-http/pom.xml b/dubbo-remoting/dubbo-remoting-http/pom.xml index 19c8220e40..4c3cc99d48 100644 --- a/dubbo-remoting/dubbo-remoting-http/pom.xml +++ b/dubbo-remoting/dubbo-remoting-http/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-remoting ${revision} + ../pom.xml dubbo-remoting-http jar diff --git a/dubbo-remoting/dubbo-remoting-mina/pom.xml b/dubbo-remoting/dubbo-remoting-mina/pom.xml index 4808a1781c..76725e6a12 100644 --- a/dubbo-remoting/dubbo-remoting-mina/pom.xml +++ b/dubbo-remoting/dubbo-remoting-mina/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-remoting ${revision} + ../pom.xml dubbo-remoting-mina jar diff --git a/dubbo-remoting/dubbo-remoting-netty/pom.xml b/dubbo-remoting/dubbo-remoting-netty/pom.xml index 761d37b516..d048f5be1b 100644 --- a/dubbo-remoting/dubbo-remoting-netty/pom.xml +++ b/dubbo-remoting/dubbo-remoting-netty/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-remoting ${revision} + ../pom.xml dubbo-remoting-netty jar diff --git a/dubbo-remoting/dubbo-remoting-netty4/pom.xml b/dubbo-remoting/dubbo-remoting-netty4/pom.xml index 10d7f26fe1..99dd144996 100644 --- a/dubbo-remoting/dubbo-remoting-netty4/pom.xml +++ b/dubbo-remoting/dubbo-remoting-netty4/pom.xml @@ -19,6 +19,7 @@ dubbo-remoting org.apache.dubbo ${revision} + ../pom.xml 4.0.0 diff --git a/dubbo-remoting/dubbo-remoting-p2p/pom.xml b/dubbo-remoting/dubbo-remoting-p2p/pom.xml index f947606288..ff0bbee5e2 100644 --- a/dubbo-remoting/dubbo-remoting-p2p/pom.xml +++ b/dubbo-remoting/dubbo-remoting-p2p/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-remoting ${revision} + ../pom.xml dubbo-remoting-p2p jar diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/pom.xml b/dubbo-remoting/dubbo-remoting-zookeeper/pom.xml index bf4cffb389..d97f8486f0 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper/pom.xml +++ b/dubbo-remoting/dubbo-remoting-zookeeper/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-remoting ${revision} + ../pom.xml dubbo-remoting-zookeeper jar diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java index c142d00941..75aa256b55 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java @@ -46,6 +46,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executor; +import java.util.concurrent.TimeUnit; import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; @@ -84,6 +85,10 @@ public class CuratorZookeeperClient extends AbstractZookeeperClientorg.apache.dubbo dubbo-parent ${revision} + ../pom.xml dubbo-remoting pom diff --git a/dubbo-rpc/dubbo-rpc-api/pom.xml b/dubbo-rpc/dubbo-rpc-api/pom.xml index aae1c05b6e..d42cf3d13d 100644 --- a/dubbo-rpc/dubbo-rpc-api/pom.xml +++ b/dubbo-rpc/dubbo-rpc-api/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-rpc ${revision} + ../pom.xml dubbo-rpc-api jar diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/AccessLogFilterTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/AccessLogFilterTest.java index 3fc463fbad..5bfcb4b0dd 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/AccessLogFilterTest.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/AccessLogFilterTest.java @@ -16,9 +16,6 @@ */ package org.apache.dubbo.rpc.filter; -import java.lang.reflect.Field; -import java.util.Map; -import java.util.Set; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.LogUtil; import org.apache.dubbo.rpc.Filter; @@ -30,6 +27,10 @@ import org.apache.dubbo.rpc.support.MyInvoker; import org.junit.jupiter.api.Test; +import java.lang.reflect.Field; +import java.util.Map; +import java.util.Set; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/BlockMyInvoker.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/BlockMyInvoker.java index 7fec8d49fd..ee6e1bea9f 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/BlockMyInvoker.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/BlockMyInvoker.java @@ -40,7 +40,7 @@ public class BlockMyInvoker extends MyInvoker { @Override public Result invoke(Invocation invocation) throws RpcException { AppResponse result = new AppResponse(); - if (hasException == false) { + if (!hasException) { try { Thread.sleep(blockTime); } catch (InterruptedException e) { diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MockInvokerTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MockInvokerTest.java index f3e3f179d2..fcfa091630 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MockInvokerTest.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MockInvokerTest.java @@ -16,17 +16,18 @@ */ package org.apache.dubbo.rpc.support; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.RpcInvocation; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + import java.io.Serializable; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; -import org.apache.dubbo.common.URL; -import org.apache.dubbo.rpc.RpcException; -import org.apache.dubbo.rpc.RpcInvocation; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - import static org.apache.dubbo.rpc.Constants.MOCK_KEY; public class MockInvokerTest { diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MyInvoker.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MyInvoker.java index 57f1f1e6cc..ffccff64ea 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MyInvoker.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MyInvoker.java @@ -60,7 +60,7 @@ public class MyInvoker implements Invoker { public Result invoke(Invocation invocation) throws RpcException { AppResponse result = new AppResponse(); - if (hasException == false) { + if (!hasException) { result.setValue("alibaba"); } else { result.setException(new RuntimeException("mocked exception")); diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/RpcUtilsTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/RpcUtilsTest.java index dc51234652..a3153aff0c 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/RpcUtilsTest.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/RpcUtilsTest.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcInvocation; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -28,6 +29,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.apache.dubbo.rpc.Constants.AUTO_ATTACH_INVOCATIONID_KEY; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -35,8 +37,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; -import static org.apache.dubbo.rpc.Constants.AUTO_ATTACH_INVOCATIONID_KEY; - public class RpcUtilsTest { /** diff --git a/dubbo-rpc/dubbo-rpc-dubbo/pom.xml b/dubbo-rpc/dubbo-rpc-dubbo/pom.xml index 99fdf5a8b9..858b710728 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/pom.xml +++ b/dubbo-rpc/dubbo-rpc-dubbo/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-rpc ${revision} + ../pom.xml dubbo-rpc-dubbo jar diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java index 529ac47b29..5cce20964d 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java @@ -520,7 +520,7 @@ public class DubboProtocol extends AbstractProtocol { } /** - * Add client references in bulk + * Increase the reference Count if we create new invoker shares same connection, the connection will be closed without any reference. * * @param referenceCountExchangeClients */ diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/ReferenceCountExchangeClient.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/ReferenceCountExchangeClient.java index c7074aa9db..bda87cae7f 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/ReferenceCountExchangeClient.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/ReferenceCountExchangeClient.java @@ -192,6 +192,9 @@ final class ReferenceCountExchangeClient implements ExchangeClient { return client.isClosed(); } + /** + * The reference count of current ExchangeClient, connection will be closed if all invokers destroyed. + */ public void incrementAndGetCount() { referenceCount.incrementAndGet(); } diff --git a/dubbo-rpc/dubbo-rpc-hessian/pom.xml b/dubbo-rpc/dubbo-rpc-hessian/pom.xml index 99ef99da3c..5a0a8383e3 100644 --- a/dubbo-rpc/dubbo-rpc-hessian/pom.xml +++ b/dubbo-rpc/dubbo-rpc-hessian/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-rpc ${revision} + ../pom.xml dubbo-rpc-hessian jar diff --git a/dubbo-rpc/dubbo-rpc-hessian/src/main/java/org/apache/dubbo/rpc/protocol/hessian/HessianProtocol.java b/dubbo-rpc/dubbo-rpc-hessian/src/main/java/org/apache/dubbo/rpc/protocol/hessian/HessianProtocol.java index 9e30d0d033..8415157837 100644 --- a/dubbo-rpc/dubbo-rpc-hessian/src/main/java/org/apache/dubbo/rpc/protocol/hessian/HessianProtocol.java +++ b/dubbo-rpc/dubbo-rpc-hessian/src/main/java/org/apache/dubbo/rpc/protocol/hessian/HessianProtocol.java @@ -48,11 +48,11 @@ import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; import static org.apache.dubbo.remoting.Constants.CLIENT_KEY; import static org.apache.dubbo.remoting.Constants.DEFAULT_EXCHANGER; import static org.apache.dubbo.rpc.Constants.GENERIC_KEY; -import static org.apache.dubbo.rpc.protocol.hessian.Constants.HESSIAN2_REQUEST_KEY; import static org.apache.dubbo.rpc.protocol.hessian.Constants.DEFAULT_HESSIAN2_REQUEST; -import static org.apache.dubbo.rpc.protocol.hessian.Constants.HESSIAN_OVERLOAD_METHOD_KEY; import static org.apache.dubbo.rpc.protocol.hessian.Constants.DEFAULT_HESSIAN_OVERLOAD_METHOD; import static org.apache.dubbo.rpc.protocol.hessian.Constants.DEFAULT_HTTP_CLIENT; +import static org.apache.dubbo.rpc.protocol.hessian.Constants.HESSIAN2_REQUEST_KEY; +import static org.apache.dubbo.rpc.protocol.hessian.Constants.HESSIAN_OVERLOAD_METHOD_KEY; /** * http rpc support. diff --git a/dubbo-rpc/dubbo-rpc-http/pom.xml b/dubbo-rpc/dubbo-rpc-http/pom.xml index 6681a9a632..76cf8ab92d 100644 --- a/dubbo-rpc/dubbo-rpc-http/pom.xml +++ b/dubbo-rpc/dubbo-rpc-http/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-rpc ${revision} + ../pom.xml dubbo-rpc-http jar diff --git a/dubbo-rpc/dubbo-rpc-injvm/pom.xml b/dubbo-rpc/dubbo-rpc-injvm/pom.xml index 53ed2ffb4e..b5562bd13c 100644 --- a/dubbo-rpc/dubbo-rpc-injvm/pom.xml +++ b/dubbo-rpc/dubbo-rpc-injvm/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-rpc ${revision} + ../pom.xml dubbo-rpc-injvm jar diff --git a/dubbo-rpc/dubbo-rpc-jsonrpc/pom.xml b/dubbo-rpc/dubbo-rpc-jsonrpc/pom.xml index c5b4e89038..0963763dd3 100644 --- a/dubbo-rpc/dubbo-rpc-jsonrpc/pom.xml +++ b/dubbo-rpc/dubbo-rpc-jsonrpc/pom.xml @@ -21,6 +21,7 @@ dubbo-rpc org.apache.dubbo ${revision} + ../pom.xml 4.0.0 diff --git a/dubbo-rpc/dubbo-rpc-memcached/pom.xml b/dubbo-rpc/dubbo-rpc-memcached/pom.xml index bcfeea67e6..1a055206f5 100644 --- a/dubbo-rpc/dubbo-rpc-memcached/pom.xml +++ b/dubbo-rpc/dubbo-rpc-memcached/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-rpc ${revision} + ../pom.xml dubbo-rpc-memcached jar diff --git a/dubbo-rpc/dubbo-rpc-native-thrift/pom.xml b/dubbo-rpc/dubbo-rpc-native-thrift/pom.xml index bcc3cf9ec8..4aa998c0e7 100644 --- a/dubbo-rpc/dubbo-rpc-native-thrift/pom.xml +++ b/dubbo-rpc/dubbo-rpc-native-thrift/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-rpc ${revision} + ../pom.xml dubbo-rpc-native-thrift jar diff --git a/dubbo-rpc/dubbo-rpc-redis/pom.xml b/dubbo-rpc/dubbo-rpc-redis/pom.xml index 123273215f..7734033451 100644 --- a/dubbo-rpc/dubbo-rpc-redis/pom.xml +++ b/dubbo-rpc/dubbo-rpc-redis/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-rpc ${revision} + ../pom.xml dubbo-rpc-redis jar diff --git a/dubbo-rpc/dubbo-rpc-rest/pom.xml b/dubbo-rpc/dubbo-rpc-rest/pom.xml index b162030fd8..d5a97e0242 100644 --- a/dubbo-rpc/dubbo-rpc-rest/pom.xml +++ b/dubbo-rpc/dubbo-rpc-rest/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-rpc ${revision} + ../pom.xml dubbo-rpc-rest jar diff --git a/dubbo-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/integration/swagger/DubboSwaggerApiListingResourceTest.java b/dubbo-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/integration/swagger/DubboSwaggerApiListingResourceTest.java index 64f8b5da1c..565ddf75d5 100644 --- a/dubbo-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/integration/swagger/DubboSwaggerApiListingResourceTest.java +++ b/dubbo-rpc/dubbo-rpc-rest/src/test/java/org/apache/dubbo/rpc/protocol/rest/integration/swagger/DubboSwaggerApiListingResourceTest.java @@ -25,12 +25,12 @@ import javax.servlet.ServletConfig; import javax.servlet.ServletContext; import javax.ws.rs.core.Application; import javax.ws.rs.core.Response; - import java.net.URI; import java.util.HashSet; import java.util.Set; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class DubboSwaggerApiListingResourceTest { diff --git a/dubbo-rpc/dubbo-rpc-rmi/pom.xml b/dubbo-rpc/dubbo-rpc-rmi/pom.xml index 7e560b2cb9..1c7d3273f3 100644 --- a/dubbo-rpc/dubbo-rpc-rmi/pom.xml +++ b/dubbo-rpc/dubbo-rpc-rmi/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-rpc ${revision} + ../pom.xml dubbo-rpc-rmi jar diff --git a/dubbo-rpc/dubbo-rpc-rmi/src/test/java/org/apache/dubbo/rpc/protocol/rmi/RmiProtocolTest.java b/dubbo-rpc/dubbo-rpc-rmi/src/test/java/org/apache/dubbo/rpc/protocol/rmi/RmiProtocolTest.java index 9f3cb332c3..dcb3f68a45 100644 --- a/dubbo-rpc/dubbo-rpc-rmi/src/test/java/org/apache/dubbo/rpc/protocol/rmi/RmiProtocolTest.java +++ b/dubbo-rpc/dubbo-rpc-rmi/src/test/java/org/apache/dubbo/rpc/protocol/rmi/RmiProtocolTest.java @@ -20,13 +20,13 @@ package org.apache.dubbo.rpc.protocol.rmi; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.rpc.Exporter; +import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Protocol; import org.apache.dubbo.rpc.ProxyFactory; import org.apache.dubbo.rpc.RpcException; -import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.service.EchoService; - import org.apache.dubbo.rpc.service.GenericService; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; diff --git a/dubbo-rpc/dubbo-rpc-thrift/pom.xml b/dubbo-rpc/dubbo-rpc-thrift/pom.xml index d6e20ed95e..e6c21304fe 100644 --- a/dubbo-rpc/dubbo-rpc-thrift/pom.xml +++ b/dubbo-rpc/dubbo-rpc-thrift/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-rpc ${revision} + ../pom.xml dubbo-rpc-thrift jar diff --git a/dubbo-rpc/dubbo-rpc-webservice/pom.xml b/dubbo-rpc/dubbo-rpc-webservice/pom.xml index 70078f8f1a..ff08b3804b 100644 --- a/dubbo-rpc/dubbo-rpc-webservice/pom.xml +++ b/dubbo-rpc/dubbo-rpc-webservice/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-rpc ${revision} + ../pom.xml dubbo-rpc-webservice jar diff --git a/dubbo-rpc/dubbo-rpc-xml/pom.xml b/dubbo-rpc/dubbo-rpc-xml/pom.xml index 9afede914b..bd45e0fe22 100644 --- a/dubbo-rpc/dubbo-rpc-xml/pom.xml +++ b/dubbo-rpc/dubbo-rpc-xml/pom.xml @@ -21,6 +21,7 @@ org.apache.dubbo dubbo-rpc ${revision} + ../pom.xml dubbo-rpc-xml diff --git a/dubbo-rpc/dubbo-rpc-xml/src/main/java/org/apache/dubbo/xml/rpc/protocol/xmlrpc/XmlRpcProtocol.java b/dubbo-rpc/dubbo-rpc-xml/src/main/java/org/apache/dubbo/xml/rpc/protocol/xmlrpc/XmlRpcProtocol.java index 83b36cd69d..5e5efbab9e 100644 --- a/dubbo-rpc/dubbo-rpc-xml/src/main/java/org/apache/dubbo/xml/rpc/protocol/xmlrpc/XmlRpcProtocol.java +++ b/dubbo-rpc/dubbo-rpc-xml/src/main/java/org/apache/dubbo/xml/rpc/protocol/xmlrpc/XmlRpcProtocol.java @@ -150,8 +150,8 @@ public class XmlRpcProtocol extends AbstractProxyProtocol { } @Override - @SuppressWarnings("unchecked") protected T doRefer(final Class serviceType, URL url) throws RpcException { + @SuppressWarnings("unchecked") XmlRpcProxyFactoryBean xmlRpcProxyFactoryBean = new XmlRpcProxyFactoryBean(); xmlRpcProxyFactoryBean.setServiceUrl(url.setProtocol("http").toIdentityString()); xmlRpcProxyFactoryBean.setServiceInterface(serviceType); diff --git a/dubbo-rpc/pom.xml b/dubbo-rpc/pom.xml index 44b064f697..1388b5018b 100644 --- a/dubbo-rpc/pom.xml +++ b/dubbo-rpc/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-parent ${revision} + ../pom.xml dubbo-rpc pom diff --git a/dubbo-serialization/dubbo-serialization-api/pom.xml b/dubbo-serialization/dubbo-serialization-api/pom.xml index 62cf6f3105..f76044ced2 100644 --- a/dubbo-serialization/dubbo-serialization-api/pom.xml +++ b/dubbo-serialization/dubbo-serialization-api/pom.xml @@ -21,6 +21,7 @@ limitations under the License. org.apache.dubbo dubbo-serialization ${revision} + ../pom.xml dubbo-serialization-api jar diff --git a/dubbo-serialization/dubbo-serialization-avro/pom.xml b/dubbo-serialization/dubbo-serialization-avro/pom.xml index 908c49eb2f..75bbff7799 100644 --- a/dubbo-serialization/dubbo-serialization-avro/pom.xml +++ b/dubbo-serialization/dubbo-serialization-avro/pom.xml @@ -21,6 +21,7 @@ org.apache.dubbo dubbo-serialization ${revision} + ../pom.xml dubbo-serialization-avro jar diff --git a/dubbo-serialization/dubbo-serialization-avro/src/main/java/org/apache/dubbo/common/serialize/avro/AvroObjectInput.java b/dubbo-serialization/dubbo-serialization-avro/src/main/java/org/apache/dubbo/common/serialize/avro/AvroObjectInput.java index 8dc8057727..0d85ec7b24 100644 --- a/dubbo-serialization/dubbo-serialization-avro/src/main/java/org/apache/dubbo/common/serialize/avro/AvroObjectInput.java +++ b/dubbo-serialization/dubbo-serialization-avro/src/main/java/org/apache/dubbo/common/serialize/avro/AvroObjectInput.java @@ -16,11 +16,12 @@ */ package org.apache.dubbo.common.serialize.avro; +import org.apache.dubbo.common.serialize.ObjectInput; + import org.apache.avro.io.BinaryDecoder; import org.apache.avro.io.DecoderFactory; import org.apache.avro.reflect.ReflectDatumReader; import org.apache.avro.util.Utf8; -import org.apache.dubbo.common.serialize.ObjectInput; import java.io.IOException; import java.io.InputStream; diff --git a/dubbo-serialization/dubbo-serialization-avro/src/main/java/org/apache/dubbo/common/serialize/avro/AvroObjectOutput.java b/dubbo-serialization/dubbo-serialization-avro/src/main/java/org/apache/dubbo/common/serialize/avro/AvroObjectOutput.java index e723063a4f..42a34e05f0 100644 --- a/dubbo-serialization/dubbo-serialization-avro/src/main/java/org/apache/dubbo/common/serialize/avro/AvroObjectOutput.java +++ b/dubbo-serialization/dubbo-serialization-avro/src/main/java/org/apache/dubbo/common/serialize/avro/AvroObjectOutput.java @@ -16,11 +16,12 @@ */ package org.apache.dubbo.common.serialize.avro; +import org.apache.dubbo.common.serialize.ObjectOutput; + import org.apache.avro.io.BinaryEncoder; import org.apache.avro.io.EncoderFactory; import org.apache.avro.reflect.ReflectDatumWriter; import org.apache.avro.util.Utf8; -import org.apache.dubbo.common.serialize.ObjectOutput; import java.io.IOException; import java.io.OutputStream; diff --git a/dubbo-serialization/dubbo-serialization-fastjson/pom.xml b/dubbo-serialization/dubbo-serialization-fastjson/pom.xml index 6553abd7ec..48bd0c6da7 100644 --- a/dubbo-serialization/dubbo-serialization-fastjson/pom.xml +++ b/dubbo-serialization/dubbo-serialization-fastjson/pom.xml @@ -21,6 +21,7 @@ limitations under the License. org.apache.dubbo dubbo-serialization ${revision} + ../pom.xml dubbo-serialization-fastjson jar diff --git a/dubbo-serialization/dubbo-serialization-fst/pom.xml b/dubbo-serialization/dubbo-serialization-fst/pom.xml index 1f2936e8dd..7bcaaf8d49 100644 --- a/dubbo-serialization/dubbo-serialization-fst/pom.xml +++ b/dubbo-serialization/dubbo-serialization-fst/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-serialization ${revision} + ../pom.xml dubbo-serialization-fst jar diff --git a/dubbo-serialization/dubbo-serialization-gson/pom.xml b/dubbo-serialization/dubbo-serialization-gson/pom.xml index 3822d37755..52e1588a17 100644 --- a/dubbo-serialization/dubbo-serialization-gson/pom.xml +++ b/dubbo-serialization/dubbo-serialization-gson/pom.xml @@ -20,6 +20,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more dubbo-serialization org.apache.dubbo ${revision} + ../pom.xml dubbo-serialization-gson jar diff --git a/dubbo-serialization/dubbo-serialization-hessian2/pom.xml b/dubbo-serialization/dubbo-serialization-hessian2/pom.xml index 9363daca43..99a966ca6c 100644 --- a/dubbo-serialization/dubbo-serialization-hessian2/pom.xml +++ b/dubbo-serialization/dubbo-serialization-hessian2/pom.xml @@ -21,6 +21,7 @@ limitations under the License. org.apache.dubbo dubbo-serialization ${revision} + ../pom.xml dubbo-serialization-hessian2 jar diff --git a/dubbo-serialization/dubbo-serialization-jdk/pom.xml b/dubbo-serialization/dubbo-serialization-jdk/pom.xml index 21df9f487e..7058dbde4a 100644 --- a/dubbo-serialization/dubbo-serialization-jdk/pom.xml +++ b/dubbo-serialization/dubbo-serialization-jdk/pom.xml @@ -21,6 +21,7 @@ limitations under the License. org.apache.dubbo dubbo-serialization ${revision} + ../pom.xml dubbo-serialization-jdk jar diff --git a/dubbo-serialization/dubbo-serialization-kryo/pom.xml b/dubbo-serialization/dubbo-serialization-kryo/pom.xml index 86b5083a06..9e22ed0b57 100644 --- a/dubbo-serialization/dubbo-serialization-kryo/pom.xml +++ b/dubbo-serialization/dubbo-serialization-kryo/pom.xml @@ -21,6 +21,7 @@ limitations under the License. org.apache.dubbo dubbo-serialization ${revision} + ../pom.xml dubbo-serialization-kryo jar diff --git a/dubbo-serialization/dubbo-serialization-native-hession/pom.xml b/dubbo-serialization/dubbo-serialization-native-hession/pom.xml index 8d641db13c..8c710f6e9e 100644 --- a/dubbo-serialization/dubbo-serialization-native-hession/pom.xml +++ b/dubbo-serialization/dubbo-serialization-native-hession/pom.xml @@ -17,9 +17,10 @@ limitations under the License. - dubbo-serialization org.apache.dubbo + dubbo-serialization ${revision} + ../pom.xml 4.0.0 diff --git a/dubbo-serialization/dubbo-serialization-protobuf-json/pom.xml b/dubbo-serialization/dubbo-serialization-protobuf-json/pom.xml index b0788e1872..c39e288f93 100644 --- a/dubbo-serialization/dubbo-serialization-protobuf-json/pom.xml +++ b/dubbo-serialization/dubbo-serialization-protobuf-json/pom.xml @@ -17,9 +17,10 @@ limitations under the License. 4.0.0 - dubbo-serialization org.apache.dubbo + dubbo-serialization ${revision} + ../pom.xml dubbo-serialization-protobuf-json jar diff --git a/dubbo-serialization/dubbo-serialization-protostuff/pom.xml b/dubbo-serialization/dubbo-serialization-protostuff/pom.xml index 7d9e2c8e87..1682cbb853 100644 --- a/dubbo-serialization/dubbo-serialization-protostuff/pom.xml +++ b/dubbo-serialization/dubbo-serialization-protostuff/pom.xml @@ -18,9 +18,10 @@ limitations under the License. 4.0.0 - dubbo-serialization org.apache.dubbo + dubbo-serialization ${revision} + ../pom.xml dubbo-serialization-protostuff diff --git a/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/utils/WrapperUtils.java b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/utils/WrapperUtils.java index 80a67efc92..321ed0dcbd 100644 --- a/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/utils/WrapperUtils.java +++ b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/utils/WrapperUtils.java @@ -20,10 +20,10 @@ package org.apache.dubbo.common.serialize.protostuff.utils; import org.apache.dubbo.common.serialize.protostuff.Wrapper; import org.apache.dubbo.common.serialize.protostuff.delegate.SqlDateDelegate; import org.apache.dubbo.common.serialize.protostuff.delegate.TimeDelegate; +import org.apache.dubbo.common.serialize.protostuff.delegate.TimestampDelegate; import io.protostuff.runtime.DefaultIdStrategy; import io.protostuff.runtime.RuntimeEnv; -import org.apache.dubbo.common.serialize.protostuff.delegate.TimestampDelegate; import java.math.BigDecimal; import java.sql.Time; diff --git a/dubbo-serialization/dubbo-serialization-test/pom.xml b/dubbo-serialization/dubbo-serialization-test/pom.xml index 60d0c5ff0f..6799a9cdf1 100644 --- a/dubbo-serialization/dubbo-serialization-test/pom.xml +++ b/dubbo-serialization/dubbo-serialization-test/pom.xml @@ -17,9 +17,10 @@ - dubbo-serialization org.apache.dubbo + dubbo-serialization ${revision} + ../pom.xml 4.0.0 diff --git a/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/hessian2/Hessian2PersonOkTest.java b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/hessian2/Hessian2PersonOkTest.java index 3d454b2c39..2abad1e852 100644 --- a/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/hessian2/Hessian2PersonOkTest.java +++ b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/hessian2/Hessian2PersonOkTest.java @@ -19,6 +19,7 @@ package org.apache.dubbo.common.serialize.hessian2; import org.apache.dubbo.common.serialize.ObjectInput; import org.apache.dubbo.common.serialize.ObjectOutput; import org.apache.dubbo.common.serialize.base.AbstractSerializationPersonOkTest; + import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; diff --git a/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutputTest.java b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutputTest.java index 8f9b08da96..2d7a86aa2e 100644 --- a/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutputTest.java +++ b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutputTest.java @@ -17,6 +17,7 @@ package org.apache.dubbo.common.serialize.protobuf.support; import org.apache.dubbo.common.serialize.protobuf.support.model.GooglePB; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutputTest.java b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutputTest.java index 52397920f0..0ae337a5cb 100644 --- a/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutputTest.java +++ b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutputTest.java @@ -16,9 +16,8 @@ */ package org.apache.dubbo.common.serialize.protostuff; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.nullValue; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -26,8 +25,9 @@ import java.io.IOException; import java.sql.Timestamp; import java.util.Date; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.nullValue; public class ProtostuffObjectOutputTest { diff --git a/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/support/SerializableClassRegistryTest.java b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/support/SerializableClassRegistryTest.java index 8f5a9de13f..35027b5c02 100644 --- a/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/support/SerializableClassRegistryTest.java +++ b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/support/SerializableClassRegistryTest.java @@ -18,12 +18,13 @@ package org.apache.dubbo.common.serialize.support; import org.apache.dubbo.common.serialize.model.SerializablePerson; import org.apache.dubbo.common.serialize.model.person.Phone; + import org.junit.jupiter.api.Test; import java.util.Map; -import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; public class SerializableClassRegistryTest { @Test diff --git a/dubbo-serialization/pom.xml b/dubbo-serialization/pom.xml index 448aa07862..31e4175d43 100644 --- a/dubbo-serialization/pom.xml +++ b/dubbo-serialization/pom.xml @@ -20,6 +20,7 @@ org.apache.dubbo dubbo-parent ${revision} + ../pom.xml dubbo-serialization pom