Skip to content

Commit 8fad9e0

Browse files
fix:fix check error when register mode is null. (#79)
1 parent 9768a34 commit 8fad9e0

File tree

10 files changed

+181
-52
lines changed

10 files changed

+181
-52
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- name: Set up Maven Central Repository
1111
uses: actions/setup-java@v3
1212
with:
13-
java-version: '11'
13+
java-version: '17'
1414
distribution: 'adopt'
1515
server-id: ossrh
1616
server-username: MAVEN_USERNAME

.github/workflows/snapshot.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
branches:
55
- dubbo-3.2.x
66
- dubbo-2.x
7+
- release/*
78

89
jobs:
910
check-snapshot:
@@ -32,7 +33,7 @@ jobs:
3233
- name: Set up Maven Central Repository
3334
uses: actions/setup-java@v3
3435
with:
35-
java-version: '11'
36+
java-version: '17'
3637
distribution: 'adopt'
3738
server-id: ossrh
3839
server-username: MAVEN_USERNAME

.github/workflows/testing.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ on:
44
branches:
55
- dubbo-3.2.x
66
- dubbo-2.x
7+
- release/*
78
pull_request:
89
branches:
910
- dubbo-3.2.x
1011
- dubbo-2.x
12+
- release/*
1113

1214
jobs:
1315
build:
1416
strategy:
1517
matrix:
16-
java: [ 8 ]
18+
java: [ 8, 17 ]
1719
os: [ 'windows-latest', 'ubuntu-latest' ]
1820
runs-on: ${{ matrix.os }}
1921
steps:

dubbo-examples/pom.xml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,6 @@
5454
<artifactId>log4j-slf4j-impl</artifactId>
5555
<version>${log4j2.version}</version>
5656
</dependency>
57-
58-
<dependency>
59-
<groupId>junit</groupId>
60-
<artifactId>junit</artifactId>
61-
<version>${junit.version}</version>
62-
<scope>test</scope>
63-
</dependency>
64-
65-
<dependency>
66-
<groupId>org.springframework</groupId>
67-
<artifactId>spring-test</artifactId>
68-
<scope>test</scope>
69-
</dependency>
7057
</dependencies>
7158

7259
<profiles>

dubbo-plugins/dubbo-metadatareport-polaris/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,5 @@
1818
<artifactId>polaris-adapter-dubbo</artifactId>
1919
<version>${project.version}</version>
2020
</dependency>
21-
<dependency>
22-
<groupId>junit</groupId>
23-
<artifactId>junit</artifactId>
24-
<version>4.13.1</version>
25-
<scope>test</scope>
26-
</dependency>
2721
</dependencies>
2822
</project>

dubbo-plugins/dubbo-registry-polaris/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,5 @@
1818
<artifactId>polaris-adapter-dubbo</artifactId>
1919
<version>${project.version}</version>
2020
</dependency>
21-
<dependency>
22-
<groupId>org.slf4j</groupId>
23-
<artifactId>slf4j-api</artifactId>
24-
<version>${slf4j.version}</version>
25-
</dependency>
2621
</dependencies>
2722
</project>

polaris-adapter-dubbo/pom.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,10 @@
6363
<groupId>com.tencent.polaris</groupId>
6464
<artifactId>polaris-all</artifactId>
6565
</dependency>
66-
<dependency>
67-
<groupId>org.slf4j</groupId>
68-
<artifactId>slf4j-api</artifactId>
69-
<version>${slf4j.version}</version>
70-
</dependency>
7166
<dependency>
7267
<groupId>com.jayway.jsonpath</groupId>
7368
<artifactId>json-path</artifactId>
7469
<version>${json_path_version}</version>
7570
</dependency>
76-
<dependency>
77-
<groupId>junit</groupId>
78-
<artifactId>junit</artifactId>
79-
<version>4.13.1</version>
80-
<scope>test</scope>
81-
</dependency>
8271
</dependencies>
8372
</project>

polaris-adapter-dubbo/src/main/java/com/tencent/polaris/common/utils/DubboUtils.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.tencent.polaris.common.utils;
1919

20+
import com.tencent.polaris.api.utils.StringUtils;
2021
import com.tencent.polaris.common.registry.DubboServiceInfo;
2122
import org.apache.dubbo.common.URL;
2223
import org.apache.dubbo.common.config.ConfigurationUtils;
@@ -80,9 +81,13 @@ public static <T> List<DubboServiceInfo> analyzeRemoteDubboServiceInfo(Invoker<T
8081
List<DubboServiceInfo> serviceInfos = new ArrayList<>(2);
8182

8283
URL providerUrl = invoker.getUrl();
84+
String service = providerUrl.getRemoteApplication();
85+
if (StringUtils.isBlank(service)) {
86+
service = providerUrl.getHost();
87+
}
8388
if (checkIsApplicationMode(invoker)) {
8489
serviceInfos.add(DubboServiceInfo.builder()
85-
.service(providerUrl.getRemoteApplication())
90+
.service(service)
8691
.interfaceName(providerUrl.getServiceInterface())
8792
.methodName(invocation.getMethodName())
8893
.build());
@@ -95,14 +100,14 @@ public static <T> List<DubboServiceInfo> analyzeRemoteDubboServiceInfo(Invoker<T
95100
return serviceInfos;
96101
}
97102

98-
private static <T> boolean checkIsApplicationMode(Invoker<T> invoker) {
103+
static <T> boolean checkIsApplicationMode(Invoker<T> invoker) {
99104
URL providerUrl = invoker.getUrl();
100105
if (providerUrl instanceof InstanceAddressURL) {
101106
return true;
102107
}
103108
if (providerUrl instanceof ServiceConfigURL) {
104109
ServiceConfigURL url = (ServiceConfigURL) providerUrl;
105-
String registerMode = url.getParameter(RegistryConstants.REGISTER_MODE_KEY);
110+
String registerMode = url.getParameter(RegistryConstants.REGISTER_MODE_KEY, RegistryConstants.DEFAULT_REGISTER_MODE_INSTANCE);
106111
switch (registerMode) {
107112
case RegistryConstants.DEFAULT_REGISTER_MODE_ALL:
108113
case RegistryConstants.DEFAULT_REGISTER_MODE_INSTANCE:
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making dubbo-polaris-java available.
3+
*
4+
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
5+
*
6+
* Licensed under the BSD 3-Clause License (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://opensource.org/licenses/BSD-3-Clause
11+
*
12+
* Unless required by applicable law or agreed to in writing, software distributed
13+
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations under the License.
16+
*/
17+
18+
package com.tencent.polaris.common.utils;
19+
20+
import org.apache.dubbo.common.URL;
21+
import org.apache.dubbo.common.constants.RegistryConstants;
22+
import org.apache.dubbo.common.url.component.ServiceConfigURL;
23+
import org.apache.dubbo.registry.client.InstanceAddressURL;
24+
import org.apache.dubbo.rpc.Invoker;
25+
import org.junit.Test;
26+
import org.mockito.Mockito;
27+
28+
import static org.assertj.core.api.Assertions.assertThat;
29+
import static org.mockito.Mockito.when;
30+
31+
/**
32+
* Test for {@link DubboUtils}.
33+
*
34+
* @author Haotian Zhang
35+
*/
36+
public class DubboUtilsTest {
37+
38+
@Test
39+
public void testCheckIsApplicationModeWithInstanceAddressURL() {
40+
// 准备:创建InstanceAddressURL类型的mock Invoker
41+
Invoker<?> invoker = Mockito.mock(Invoker.class);
42+
InstanceAddressURL url = Mockito.mock(InstanceAddressURL.class);
43+
when(invoker.getUrl()).thenReturn(url);
44+
45+
// 执行 & 验证:InstanceAddressURL应该返回true
46+
assertThat(DubboUtils.checkIsApplicationMode(invoker)).isTrue();
47+
}
48+
49+
@Test
50+
public void testCheckIsApplicationModeWithServiceConfigURL_RegisterModeAll() {
51+
// 准备:创建ServiceConfigURL类型的mock Invoker,设置registerMode为ALL
52+
Invoker<?> invoker = Mockito.mock(Invoker.class);
53+
ServiceConfigURL url = Mockito.mock(ServiceConfigURL.class);
54+
when(invoker.getUrl()).thenReturn(url);
55+
when(url.getParameter(RegistryConstants.REGISTER_MODE_KEY, RegistryConstants.DEFAULT_REGISTER_MODE_INSTANCE))
56+
.thenReturn(RegistryConstants.DEFAULT_REGISTER_MODE_ALL);
57+
58+
// 执行 & 验证:registerMode为ALL应该返回true
59+
assertThat(DubboUtils.checkIsApplicationMode(invoker)).isTrue();
60+
}
61+
62+
@Test
63+
public void testCheckIsApplicationModeWithServiceConfigURL_RegisterModeInstance() {
64+
// 准备:创建ServiceConfigURL类型的mock Invoker,设置registerMode为INSTANCE
65+
Invoker<?> invoker = Mockito.mock(Invoker.class);
66+
ServiceConfigURL url = Mockito.mock(ServiceConfigURL.class);
67+
when(invoker.getUrl()).thenReturn(url);
68+
when(url.getParameter(RegistryConstants.REGISTER_MODE_KEY, RegistryConstants.DEFAULT_REGISTER_MODE_INSTANCE))
69+
.thenReturn(RegistryConstants.DEFAULT_REGISTER_MODE_INSTANCE);
70+
71+
// 执行 & 验证:registerMode为INSTANCE应该返回true
72+
assertThat(DubboUtils.checkIsApplicationMode(invoker)).isTrue();
73+
}
74+
75+
@Test
76+
public void testCheckIsApplicationModeWithServiceConfigURL_RegisterModeInterface() {
77+
// 准备:创建ServiceConfigURL类型的mock Invoker,设置registerMode为INTERFACE
78+
Invoker<?> invoker = Mockito.mock(Invoker.class);
79+
ServiceConfigURL url = Mockito.mock(ServiceConfigURL.class);
80+
when(invoker.getUrl()).thenReturn(url);
81+
when(url.getParameter(RegistryConstants.REGISTER_MODE_KEY, RegistryConstants.DEFAULT_REGISTER_MODE_INSTANCE))
82+
.thenReturn(RegistryConstants.DEFAULT_REGISTER_MODE_INTERFACE);
83+
84+
// 执行 & 验证:registerMode为INTERFACE应该返回false
85+
assertThat(DubboUtils.checkIsApplicationMode(invoker)).isFalse();
86+
}
87+
88+
@Test
89+
public void testCheckIsApplicationModeWithOtherURL() {
90+
// 准备:创建普通URL类型的mock Invoker
91+
Invoker<?> invoker = Mockito.mock(Invoker.class);
92+
URL url = Mockito.mock(URL.class);
93+
when(invoker.getUrl()).thenReturn(url);
94+
95+
// 执行 & 验证:普通URL类型应该返回false
96+
assertThat(DubboUtils.checkIsApplicationMode(invoker)).isFalse();
97+
}
98+
}

pom.xml

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,16 @@
4343
<!-- Polaris SDK version -->
4444
<polaris.version>2.0.1.0</polaris.version>
4545

46-
<timestamp>${maven.build.timestamp}</timestamp>
46+
<apache.dubbo.version>3.2.7</apache.dubbo.version>
47+
<slf4j.version>1.7.25</slf4j.version>
48+
<json_path_version>2.8.0</json_path_version>
49+
<junit.version>4.13.1</junit.version>
50+
<byte-buddy.version>1.14.19</byte-buddy.version>
51+
<mockito.version>4.9.0</mockito.version>
52+
<assertj.version>3.16.1</assertj.version>
53+
54+
<!-- Maven Plugin -->
4755
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
48-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
49-
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
5056
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
5157
<maven.compiler.source>1.8</maven.compiler.source>
5258
<maven.compiler.target>1.8</maven.compiler.target>
@@ -56,9 +62,11 @@
5662
<maven.gpg.plugin.version>3.0.1</maven.gpg.plugin.version>
5763
<maven.deploy.plugin.version>3.0.0-M1</maven.deploy.plugin.version>
5864
<maven.flatten.plugin.version>1.2.5</maven.flatten.plugin.version>
59-
<apache.dubbo.version>3.2.7</apache.dubbo.version>
60-
<slf4j.version>1.7.25</slf4j.version>
61-
<json_path_version>2.8.0</json_path_version>
65+
<maven.clean.plugin.version>3.1.0</maven.clean.plugin.version>
66+
67+
<timestamp>${maven.build.timestamp}</timestamp>
68+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
69+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
6270
</properties>
6371

6472
<dependencyManagement>
@@ -74,11 +82,6 @@
7482
<artifactId>polaris-all</artifactId>
7583
<version>${polaris.version}</version>
7684
</dependency>
77-
<dependency>
78-
<groupId>org.slf4j</groupId>
79-
<artifactId>slf4j-api</artifactId>
80-
<version>${slf4j.version}</version>
81-
</dependency>
8285
<dependency>
8386
<groupId>com.jayway.jsonpath</groupId>
8487
<artifactId>json-path</artifactId>
@@ -87,8 +90,63 @@
8790
</dependencies>
8891
</dependencyManagement>
8992

93+
<dependencies>
94+
<!--日志相关依赖-->
95+
<dependency>
96+
<groupId>org.slf4j</groupId>
97+
<artifactId>slf4j-api</artifactId>
98+
<version>${slf4j.version}</version>
99+
<scope>provided</scope>
100+
</dependency>
101+
<dependency>
102+
<groupId>junit</groupId>
103+
<artifactId>junit</artifactId>
104+
<version>${junit.version}</version>
105+
<scope>test</scope>
106+
</dependency>
107+
<dependency>
108+
<groupId>net.bytebuddy</groupId>
109+
<artifactId>byte-buddy</artifactId>
110+
<version>${byte-buddy.version}</version>
111+
<scope>test</scope>
112+
</dependency>
113+
<dependency>
114+
<groupId>net.bytebuddy</groupId>
115+
<artifactId>byte-buddy-agent</artifactId>
116+
<version>${byte-buddy.version}</version>
117+
<scope>test</scope>
118+
</dependency>
119+
<dependency>
120+
<groupId>org.mockito</groupId>
121+
<artifactId>mockito-inline</artifactId>
122+
<version>${mockito.version}</version>
123+
<scope>test</scope>
124+
</dependency>
125+
<dependency>
126+
<groupId>org.assertj</groupId>
127+
<artifactId>assertj-core</artifactId>
128+
<version>${assertj.version}</version>
129+
<scope>test</scope>
130+
</dependency>
131+
</dependencies>
132+
90133
<build>
91134
<plugins>
135+
<plugin>
136+
<groupId>org.apache.maven.plugins</groupId>
137+
<artifactId>maven-clean-plugin</artifactId>
138+
<version>${maven.clean.plugin.version}</version>
139+
<configuration>
140+
<filesets>
141+
<fileset>
142+
<directory>${project.basedir}</directory>
143+
<includes>
144+
<include>dependency-reduced-pom.xml</include>
145+
</includes>
146+
</fileset>
147+
</filesets>
148+
</configuration>
149+
</plugin>
92150
<plugin>
93151
<groupId>org.apache.maven.plugins</groupId>
94152
<artifactId>maven-checkstyle-plugin</artifactId>

0 commit comments

Comments
 (0)