Skip to content

Commit e690864

Browse files
CrazyHZMbeiwei30
authored andcommitted
[DUBBO-3137]: step3 - start to use RpcConstants (#4038)
* constants step3 rpc * remove useless import * remove useless import * remove useless import * remove useless import
1 parent 805f7c7 commit e690864

File tree

98 files changed

+546
-682
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+546
-682
lines changed

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import java.util.function.Predicate;
4141
import java.util.stream.Collectors;
4242

43-
import static org.apache.dubbo.common.Constants.FORCE_USE_TAG;
43+
import static org.apache.dubbo.common.constants.RpcConstants.FORCE_USE_TAG;
4444
import static org.apache.dubbo.common.Constants.TAG_KEY;
4545

4646
/**

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/ClusterUtils.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
4141
import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY;
4242
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
43+
import static org.apache.dubbo.common.constants.RpcConstants.DUBBO_VERSION_KEY;
44+
import static org.apache.dubbo.common.constants.RpcConstants.REFERENCE_FILTER_KEY;
45+
import static org.apache.dubbo.common.constants.RpcConstants.INVOKER_LISTENER_KEY;
46+
import static org.apache.dubbo.common.constants.RpcConstants.ASYNC_KEY;
4347

4448
/**
4549
* ClusterUtils
@@ -78,13 +82,13 @@ public static URL mergeUrl(URL remoteUrl, Map<String, String> localMap) {
7882
map.remove(RemotingConstants.TRANSPORTER_KEY);
7983
map.remove(DEFAULT_KEY_PREFIX + RemotingConstants.TRANSPORTER_KEY);
8084

81-
map.remove(Constants.ASYNC_KEY);
82-
map.remove(DEFAULT_KEY_PREFIX + Constants.ASYNC_KEY);
85+
map.remove(ASYNC_KEY);
86+
map.remove(DEFAULT_KEY_PREFIX + ASYNC_KEY);
8387

8488
// remove method async entry.
8589
Set<String> methodAsyncKey = new HashSet<>();
8690
for (String key : map.keySet()) {
87-
if (key != null && key.endsWith("." + Constants.ASYNC_KEY)) {
91+
if (key != null && key.endsWith("." + ASYNC_KEY)) {
8892
methodAsyncKey.add(key);
8993
}
9094
}
@@ -111,7 +115,7 @@ public static URL mergeUrl(URL remoteUrl, Map<String, String> localMap) {
111115
}
112116
if (remoteMap != null && remoteMap.size() > 0) {
113117
// Use version passed from provider side
114-
reserveRemoteValue(Constants.DUBBO_VERSION_KEY, map, remoteMap);
118+
reserveRemoteValue(DUBBO_VERSION_KEY, map, remoteMap);
115119
reserveRemoteValue(VERSION_KEY, map, remoteMap);
116120
reserveRemoteValue(METHODS_KEY, map, remoteMap);
117121
reserveRemoteValue(TIMESTAMP_KEY, map, remoteMap);
@@ -121,17 +125,17 @@ public static URL mergeUrl(URL remoteUrl, Map<String, String> localMap) {
121125
map.put(REMOTE_APPLICATION_KEY, remoteMap.get(APPLICATION_KEY));
122126

123127
// Combine filters and listeners on Provider and Consumer
124-
String remoteFilter = remoteMap.get(Constants.REFERENCE_FILTER_KEY);
125-
String localFilter = localMap.get(Constants.REFERENCE_FILTER_KEY);
128+
String remoteFilter = remoteMap.get(REFERENCE_FILTER_KEY);
129+
String localFilter = localMap.get(REFERENCE_FILTER_KEY);
126130
if (remoteFilter != null && remoteFilter.length() > 0
127131
&& localFilter != null && localFilter.length() > 0) {
128-
localMap.put(Constants.REFERENCE_FILTER_KEY, remoteFilter + "," + localFilter);
132+
localMap.put(REFERENCE_FILTER_KEY, remoteFilter + "," + localFilter);
129133
}
130-
String remoteListener = remoteMap.get(Constants.INVOKER_LISTENER_KEY);
131-
String localListener = localMap.get(Constants.INVOKER_LISTENER_KEY);
134+
String remoteListener = remoteMap.get(INVOKER_LISTENER_KEY);
135+
String localListener = localMap.get(INVOKER_LISTENER_KEY);
132136
if (remoteListener != null && remoteListener.length() > 0
133137
&& localListener != null && localListener.length() > 0) {
134-
localMap.put(Constants.INVOKER_LISTENER_KEY, remoteListener + "," + localListener);
138+
localMap.put(INVOKER_LISTENER_KEY, remoteListener + "," + localListener);
135139
}
136140
}
137141

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/MergeableClusterInvoker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.apache.dubbo.rpc.cluster.support;
1818

19-
import org.apache.dubbo.common.Constants;
2019
import org.apache.dubbo.common.URL;
2120
import org.apache.dubbo.common.extension.ExtensionLoader;
2221
import org.apache.dubbo.common.logger.Logger;
@@ -50,6 +49,7 @@
5049
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
5150
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
5251
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
52+
import static org.apache.dubbo.common.constants.RpcConstants.MERGER_KEY;
5353

5454
@SuppressWarnings("unchecked")
5555
public class MergeableClusterInvoker<T> extends AbstractClusterInvoker<T> {
@@ -64,7 +64,7 @@ public MergeableClusterInvoker(Directory<T> directory) {
6464
@Override
6565
protected Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
6666
checkInvokers(invokers, invocation);
67-
String merger = getUrl().getMethodParameter(invocation.getMethodName(), Constants.MERGER_KEY);
67+
String merger = getUrl().getMethodParameter(invocation.getMethodName(), MERGER_KEY);
6868
if (ConfigUtils.isEmpty(merger)) { // If a method doesn't have a merger, only invoke one Group
6969
for (final Invoker<T> invoker : invokers) {
7070
if (invoker.isAvailable()) {

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import org.apache.dubbo.rpc.cluster.Directory;
3232
import org.apache.dubbo.rpc.support.MockInvoker;
3333

34+
import static org.apache.dubbo.common.constants.RpcConstants.MOCK_KEY;
35+
3436
import java.util.List;
3537

3638
public class MockClusterInvoker<T> implements Invoker<T> {
@@ -70,7 +72,7 @@ public Class<T> getInterface() {
7072
public Result invoke(Invocation invocation) throws RpcException {
7173
Result result = null;
7274

73-
String value = directory.getUrl().getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim();
75+
String value = directory.getUrl().getMethodParameter(invocation.getMethodName(), MOCK_KEY, Boolean.FALSE.toString()).trim();
7476
if (value.length() == 0 || value.equalsIgnoreCase("false")) {
7577
//no mock
7678
result = this.invoker.invoke(invocation);

dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/directory/MockDirInvocation.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.apache.dubbo.rpc.cluster.directory;
1818

19-
import org.apache.dubbo.common.Constants;
2019
import org.apache.dubbo.rpc.Invocation;
2120
import org.apache.dubbo.rpc.Invoker;
2221

@@ -27,6 +26,8 @@
2726
import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
2827
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
2928
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
29+
import static org.apache.dubbo.common.constants.RpcConstants.DUBBO_VERSION_KEY;
30+
import static org.apache.dubbo.common.constants.RpcConstants.TOKEN_KEY;
3031

3132
/**
3233
* MockInvocation.java
@@ -50,8 +51,8 @@ public Map<String, String> getAttachments() {
5051
attachments.put(PATH_KEY, "dubbo");
5152
attachments.put(GROUP_KEY, "dubbo");
5253
attachments.put(VERSION_KEY, "1.0.0");
53-
attachments.put(Constants.DUBBO_VERSION_KEY, "1.0.0");
54-
attachments.put(Constants.TOKEN_KEY, "sfag");
54+
attachments.put(DUBBO_VERSION_KEY, "1.0.0");
55+
attachments.put(TOKEN_KEY, "sfag");
5556
attachments.put(TIMEOUT_KEY, "1000");
5657
return attachments;
5758
}

dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/ClusterUtilsTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY;
3434
import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
3535
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
36+
import static org.apache.dubbo.common.constants.RpcConstants.DUBBO_VERSION_KEY;
3637

3738
public class ClusterUtilsTest {
3839

@@ -46,7 +47,7 @@ public void testMergeUrl() throws Exception {
4647
providerURL = URLBuilder.from(providerURL)
4748
.addParameter(GROUP_KEY, "dubbo")
4849
.addParameter(VERSION_KEY, "1.2.3")
49-
.addParameter(Constants.DUBBO_VERSION_KEY, "2.3.7")
50+
.addParameter(DUBBO_VERSION_KEY, "2.3.7")
5051
.addParameter(THREADPOOL_KEY, "fixed")
5152
.addParameter(THREADS_KEY, Integer.MAX_VALUE)
5253
.addParameter(THREAD_NAME_KEY, "test")

dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/MergeableClusterInvokerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.apache.dubbo.rpc.cluster.support;
1818

19-
import org.apache.dubbo.common.Constants;
2019
import org.apache.dubbo.common.URL;
2120
import org.apache.dubbo.rpc.Invocation;
2221
import org.apache.dubbo.rpc.Invoker;
@@ -39,6 +38,7 @@
3938
import java.util.Map;
4039

4140
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
41+
import static org.apache.dubbo.common.constants.RpcConstants.MERGER_KEY;
4242
import static org.junit.jupiter.api.Assertions.assertEquals;
4343
import static org.mockito.BDDMockito.given;
4444
import static org.mockito.Mockito.mock;
@@ -101,7 +101,7 @@ public void setUp() throws Exception {
101101
public void testGetMenuSuccessfully() throws Exception {
102102

103103
// setup
104-
url = url.addParameter(Constants.MERGER_KEY, ".merge");
104+
url = url.addParameter(MERGER_KEY, ".merge");
105105

106106
given(invocation.getMethodName()).willReturn("getMenu");
107107
given(invocation.getParameterTypes()).willReturn(new Class<?>[]{});

dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvokerTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import java.util.Arrays;
4040
import java.util.List;
4141

42+
import static org.apache.dubbo.common.constants.RpcConstants.MOCK_KEY;
43+
4244
public class MockClusterInvokerTest {
4345

4446
List<Invoker<IHelloService>> invokers = new ArrayList<Invoker<IHelloService>>();
@@ -54,7 +56,7 @@ public void beforeMethod() {
5456
@Test
5557
public void testMockInvokerInvoke_normal() {
5658
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName());
57-
url = url.addParameter(Constants.MOCK_KEY, "fail");
59+
url = url.addParameter(MOCK_KEY, "fail");
5860
Invoker<IHelloService> cluster = getClusterInvoker(url);
5961
URL mockUrl = URL.valueOf("mock://localhost/" + IHelloService.class.getName()
6062
+ "?getSomething.mock=return aa");
@@ -82,7 +84,7 @@ public void testMockInvokerInvoke_normal() {
8284
@Test
8385
public void testMockInvokerInvoke_failmock() {
8486
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName())
85-
.addParameter(Constants.MOCK_KEY, "fail:return null")
87+
.addParameter(MOCK_KEY, "fail:return null")
8688
.addParameter("invoke_return_error", "true");
8789
URL mockUrl = URL.valueOf("mock://localhost/" + IHelloService.class.getName()
8890
+ "?getSomething.mock=return aa").addParameters(url.getParameters());
@@ -117,7 +119,7 @@ public void testMockInvokerInvoke_failmock() {
117119
@Test
118120
public void testMockInvokerInvoke_forcemock() {
119121
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName());
120-
url = url.addParameter(Constants.MOCK_KEY, "force:return null");
122+
url = url.addParameter(MOCK_KEY, "force:return null");
121123

122124
URL mockUrl = URL.valueOf("mock://localhost/" + IHelloService.class.getName()
123125
+ "?getSomething.mock=return aa&getSomething3xx.mock=return xx")
@@ -149,7 +151,7 @@ public void testMockInvokerInvoke_forcemock() {
149151
@Test
150152
public void testMockInvokerInvoke_forcemock_defaultreturn() {
151153
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName());
152-
url = url.addParameter(Constants.MOCK_KEY, "force");
154+
url = url.addParameter(MOCK_KEY, "force");
153155
Invoker<IHelloService> cluster = getClusterInvoker(url);
154156
URL mockUrl = URL.valueOf("mock://localhost/" + IHelloService.class.getName()
155157
+ "?getSomething.mock=return aa&getSomething3xx.mock=return xx&sayHello.mock=return ")

0 commit comments

Comments
 (0)