diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cfd2cb5..65ffdb2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ jobs: - name: Set up Maven Central Repository uses: actions/setup-java@v3 with: - java-version: '11' + java-version: '17' distribution: 'adopt' server-id: ossrh server-username: MAVEN_USERNAME diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index 3ab0719..0a6b2f6 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -4,6 +4,7 @@ on: branches: - dubbo-3.2.x - dubbo-2.x + - release/* jobs: check-snapshot: @@ -32,7 +33,7 @@ jobs: - name: Set up Maven Central Repository uses: actions/setup-java@v3 with: - java-version: '11' + java-version: '17' distribution: 'adopt' server-id: ossrh server-username: MAVEN_USERNAME diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 709f33f..8a7114a 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -4,16 +4,18 @@ on: branches: - dubbo-3.2.x - dubbo-2.x + - release/* pull_request: branches: - dubbo-3.2.x - dubbo-2.x + - release/* jobs: build: strategy: matrix: - java: [ 8 ] + java: [ 8, 17 ] os: [ 'windows-latest', 'ubuntu-latest' ] runs-on: ${{ matrix.os }} steps: diff --git a/dubbo-examples/pom.xml b/dubbo-examples/pom.xml index 2ecca29..4fa61df 100644 --- a/dubbo-examples/pom.xml +++ b/dubbo-examples/pom.xml @@ -54,19 +54,6 @@ log4j-slf4j-impl ${log4j2.version} - - - junit - junit - ${junit.version} - test - - - - org.springframework - spring-test - test - diff --git a/dubbo-plugins/dubbo-metadatareport-polaris/pom.xml b/dubbo-plugins/dubbo-metadatareport-polaris/pom.xml index 4fafe00..4f44bcf 100644 --- a/dubbo-plugins/dubbo-metadatareport-polaris/pom.xml +++ b/dubbo-plugins/dubbo-metadatareport-polaris/pom.xml @@ -18,11 +18,5 @@ polaris-adapter-dubbo ${project.version} - - junit - junit - 4.13.1 - test - \ No newline at end of file diff --git a/dubbo-plugins/dubbo-registry-polaris/pom.xml b/dubbo-plugins/dubbo-registry-polaris/pom.xml index 574425e..e4fe9d5 100644 --- a/dubbo-plugins/dubbo-registry-polaris/pom.xml +++ b/dubbo-plugins/dubbo-registry-polaris/pom.xml @@ -18,10 +18,5 @@ polaris-adapter-dubbo ${project.version} - - org.slf4j - slf4j-api - ${slf4j.version} - \ No newline at end of file diff --git a/polaris-adapter-dubbo/pom.xml b/polaris-adapter-dubbo/pom.xml index e31ea6c..bd0e33d 100644 --- a/polaris-adapter-dubbo/pom.xml +++ b/polaris-adapter-dubbo/pom.xml @@ -63,21 +63,10 @@ com.tencent.polaris polaris-all - - org.slf4j - slf4j-api - ${slf4j.version} - com.jayway.jsonpath json-path ${json_path_version} - - junit - junit - 4.13.1 - test - \ No newline at end of file diff --git a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/DubboUtils.java b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/DubboUtils.java index 84b6c0a..d73bad5 100644 --- a/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/DubboUtils.java +++ b/polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/DubboUtils.java @@ -17,6 +17,7 @@ package com.tencent.polaris.common.utils; +import com.tencent.polaris.api.utils.StringUtils; import com.tencent.polaris.common.registry.DubboServiceInfo; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.config.ConfigurationUtils; @@ -80,9 +81,13 @@ public static List analyzeRemoteDubboServiceInfo(Invoker serviceInfos = new ArrayList<>(2); URL providerUrl = invoker.getUrl(); + String service = providerUrl.getRemoteApplication(); + if (StringUtils.isBlank(service)) { + service = providerUrl.getHost(); + } if (checkIsApplicationMode(invoker)) { serviceInfos.add(DubboServiceInfo.builder() - .service(providerUrl.getRemoteApplication()) + .service(service) .interfaceName(providerUrl.getServiceInterface()) .methodName(invocation.getMethodName()) .build()); @@ -95,14 +100,14 @@ public static List analyzeRemoteDubboServiceInfo(Invoker boolean checkIsApplicationMode(Invoker invoker) { + static boolean checkIsApplicationMode(Invoker invoker) { URL providerUrl = invoker.getUrl(); if (providerUrl instanceof InstanceAddressURL) { return true; } if (providerUrl instanceof ServiceConfigURL) { ServiceConfigURL url = (ServiceConfigURL) providerUrl; - String registerMode = url.getParameter(RegistryConstants.REGISTER_MODE_KEY); + String registerMode = url.getParameter(RegistryConstants.REGISTER_MODE_KEY, RegistryConstants.DEFAULT_REGISTER_MODE_INSTANCE); switch (registerMode) { case RegistryConstants.DEFAULT_REGISTER_MODE_ALL: case RegistryConstants.DEFAULT_REGISTER_MODE_INSTANCE: diff --git a/polaris-adapter-dubbo/src/test/java/com/tencent/polaris/common/utils/DubboUtilsTest.java b/polaris-adapter-dubbo/src/test/java/com/tencent/polaris/common/utils/DubboUtilsTest.java new file mode 100644 index 0000000..8872593 --- /dev/null +++ b/polaris-adapter-dubbo/src/test/java/com/tencent/polaris/common/utils/DubboUtilsTest.java @@ -0,0 +1,98 @@ +/* + * Tencent is pleased to support the open source community by making dubbo-polaris-java available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * 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 com.tencent.polaris.common.utils; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.constants.RegistryConstants; +import org.apache.dubbo.common.url.component.ServiceConfigURL; +import org.apache.dubbo.registry.client.InstanceAddressURL; +import org.apache.dubbo.rpc.Invoker; +import org.junit.Test; +import org.mockito.Mockito; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; + +/** + * Test for {@link DubboUtils}. + * + * @author Haotian Zhang + */ +public class DubboUtilsTest { + + @Test + public void testCheckIsApplicationModeWithInstanceAddressURL() { + // 准备:创建InstanceAddressURL类型的mock Invoker + Invoker invoker = Mockito.mock(Invoker.class); + InstanceAddressURL url = Mockito.mock(InstanceAddressURL.class); + when(invoker.getUrl()).thenReturn(url); + + // 执行 & 验证:InstanceAddressURL应该返回true + assertThat(DubboUtils.checkIsApplicationMode(invoker)).isTrue(); + } + + @Test + public void testCheckIsApplicationModeWithServiceConfigURL_RegisterModeAll() { + // 准备:创建ServiceConfigURL类型的mock Invoker,设置registerMode为ALL + Invoker invoker = Mockito.mock(Invoker.class); + ServiceConfigURL url = Mockito.mock(ServiceConfigURL.class); + when(invoker.getUrl()).thenReturn(url); + when(url.getParameter(RegistryConstants.REGISTER_MODE_KEY, RegistryConstants.DEFAULT_REGISTER_MODE_INSTANCE)) + .thenReturn(RegistryConstants.DEFAULT_REGISTER_MODE_ALL); + + // 执行 & 验证:registerMode为ALL应该返回true + assertThat(DubboUtils.checkIsApplicationMode(invoker)).isTrue(); + } + + @Test + public void testCheckIsApplicationModeWithServiceConfigURL_RegisterModeInstance() { + // 准备:创建ServiceConfigURL类型的mock Invoker,设置registerMode为INSTANCE + Invoker invoker = Mockito.mock(Invoker.class); + ServiceConfigURL url = Mockito.mock(ServiceConfigURL.class); + when(invoker.getUrl()).thenReturn(url); + when(url.getParameter(RegistryConstants.REGISTER_MODE_KEY, RegistryConstants.DEFAULT_REGISTER_MODE_INSTANCE)) + .thenReturn(RegistryConstants.DEFAULT_REGISTER_MODE_INSTANCE); + + // 执行 & 验证:registerMode为INSTANCE应该返回true + assertThat(DubboUtils.checkIsApplicationMode(invoker)).isTrue(); + } + + @Test + public void testCheckIsApplicationModeWithServiceConfigURL_RegisterModeInterface() { + // 准备:创建ServiceConfigURL类型的mock Invoker,设置registerMode为INTERFACE + Invoker invoker = Mockito.mock(Invoker.class); + ServiceConfigURL url = Mockito.mock(ServiceConfigURL.class); + when(invoker.getUrl()).thenReturn(url); + when(url.getParameter(RegistryConstants.REGISTER_MODE_KEY, RegistryConstants.DEFAULT_REGISTER_MODE_INSTANCE)) + .thenReturn(RegistryConstants.DEFAULT_REGISTER_MODE_INTERFACE); + + // 执行 & 验证:registerMode为INTERFACE应该返回false + assertThat(DubboUtils.checkIsApplicationMode(invoker)).isFalse(); + } + + @Test + public void testCheckIsApplicationModeWithOtherURL() { + // 准备:创建普通URL类型的mock Invoker + Invoker invoker = Mockito.mock(Invoker.class); + URL url = Mockito.mock(URL.class); + when(invoker.getUrl()).thenReturn(url); + + // 执行 & 验证:普通URL类型应该返回false + assertThat(DubboUtils.checkIsApplicationMode(invoker)).isFalse(); + } +} diff --git a/pom.xml b/pom.xml index 01532aa..5122cbd 100644 --- a/pom.xml +++ b/pom.xml @@ -43,10 +43,16 @@ 2.0.1.0 - ${maven.build.timestamp} + 3.2.7 + 1.7.25 + 2.8.0 + 4.13.1 + 1.14.19 + 4.9.0 + 3.16.1 + + yyyy-MM-dd HH:mm - UTF-8 - UTF-8 UTF-8 1.8 1.8 @@ -56,9 +62,11 @@ 3.0.1 3.0.0-M1 1.2.5 - 3.2.7 - 1.7.25 - 2.8.0 + 3.1.0 + + ${maven.build.timestamp} + UTF-8 + UTF-8 @@ -74,11 +82,6 @@ polaris-all ${polaris.version} - - org.slf4j - slf4j-api - ${slf4j.version} - com.jayway.jsonpath json-path @@ -87,8 +90,63 @@ + + + + org.slf4j + slf4j-api + ${slf4j.version} + provided + + + junit + junit + ${junit.version} + test + + + net.bytebuddy + byte-buddy + ${byte-buddy.version} + test + + + net.bytebuddy + byte-buddy-agent + ${byte-buddy.version} + test + + + org.mockito + mockito-inline + ${mockito.version} + test + + + org.assertj + assertj-core + ${assertj.version} + test + + + + + org.apache.maven.plugins + maven-clean-plugin + ${maven.clean.plugin.version} + + + + ${project.basedir} + + dependency-reduced-pom.xml + + + + + org.apache.maven.plugins maven-checkstyle-plugin