Skip to content

fix:fix check error when register mode is null. #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
branches:
- dubbo-3.2.x
- dubbo-2.x
- release/*

jobs:
check-snapshot:
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 0 additions & 13 deletions dubbo-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,6 @@
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
6 changes: 0 additions & 6 deletions dubbo-plugins/dubbo-metadatareport-polaris/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,5 @@
<artifactId>polaris-adapter-dubbo</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
5 changes: 0 additions & 5 deletions dubbo-plugins/dubbo-registry-polaris/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,5 @@
<artifactId>polaris-adapter-dubbo</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies>
</project>
11 changes: 0 additions & 11 deletions polaris-adapter-dubbo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,10 @@
<groupId>com.tencent.polaris</groupId>
<artifactId>polaris-all</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>${json_path_version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -80,9 +81,13 @@ public static <T> List<DubboServiceInfo> analyzeRemoteDubboServiceInfo(Invoker<T
List<DubboServiceInfo> 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());
Expand All @@ -95,14 +100,14 @@ public static <T> List<DubboServiceInfo> analyzeRemoteDubboServiceInfo(Invoker<T
return serviceInfos;
}

private static <T> boolean checkIsApplicationMode(Invoker<T> invoker) {
static <T> boolean checkIsApplicationMode(Invoker<T> 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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
80 changes: 69 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,16 @@
<!-- Polaris SDK version -->
<polaris.version>2.0.1.0</polaris.version>

<timestamp>${maven.build.timestamp}</timestamp>
<apache.dubbo.version>3.2.7</apache.dubbo.version>
<slf4j.version>1.7.25</slf4j.version>
<json_path_version>2.8.0</json_path_version>
<junit.version>4.13.1</junit.version>
<byte-buddy.version>1.14.19</byte-buddy.version>
<mockito.version>4.9.0</mockito.version>
<assertj.version>3.16.1</assertj.version>

<!-- Maven Plugin -->
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
Expand All @@ -56,9 +62,11 @@
<maven.gpg.plugin.version>3.0.1</maven.gpg.plugin.version>
<maven.deploy.plugin.version>3.0.0-M1</maven.deploy.plugin.version>
<maven.flatten.plugin.version>1.2.5</maven.flatten.plugin.version>
<apache.dubbo.version>3.2.7</apache.dubbo.version>
<slf4j.version>1.7.25</slf4j.version>
<json_path_version>2.8.0</json_path_version>
<maven.clean.plugin.version>3.1.0</maven.clean.plugin.version>

<timestamp>${maven.build.timestamp}</timestamp>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencyManagement>
Expand All @@ -74,11 +82,6 @@
<artifactId>polaris-all</artifactId>
<version>${polaris.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
Expand All @@ -87,8 +90,63 @@
</dependencies>
</dependencyManagement>

<dependencies>
<!--日志相关依赖-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>${byte-buddy.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
<version>${byte-buddy.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>${maven.clean.plugin.version}</version>
<configuration>
<filesets>
<fileset>
<directory>${project.basedir}</directory>
<includes>
<include>dependency-reduced-pom.xml</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
Expand Down