Skip to content
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

[DUBBO-3137]: step3 - start to use RpcConstants #4038

Merged
merged 6 commits into from
May 13, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static org.apache.dubbo.common.Constants.FORCE_USE_TAG;
import static org.apache.dubbo.common.constants.RpcConstants.FORCE_USE_TAG;
import static org.apache.dubbo.common.Constants.TAG_KEY;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.common.constants.RpcConstants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.common.constants.RpcConstants.REFERENCE_FILTER_KEY;
import static org.apache.dubbo.common.constants.RpcConstants.INVOKER_LISTENER_KEY;
import static org.apache.dubbo.common.constants.RpcConstants.ASYNC_KEY;

/**
* ClusterUtils
Expand Down Expand Up @@ -78,13 +82,13 @@ public static URL mergeUrl(URL remoteUrl, Map<String, String> localMap) {
map.remove(RemotingConstants.TRANSPORTER_KEY);
map.remove(DEFAULT_KEY_PREFIX + RemotingConstants.TRANSPORTER_KEY);

map.remove(Constants.ASYNC_KEY);
map.remove(DEFAULT_KEY_PREFIX + Constants.ASYNC_KEY);
map.remove(ASYNC_KEY);
map.remove(DEFAULT_KEY_PREFIX + ASYNC_KEY);

// remove method async entry.
Set<String> methodAsyncKey = new HashSet<>();
for (String key : map.keySet()) {
if (key != null && key.endsWith("." + Constants.ASYNC_KEY)) {
if (key != null && key.endsWith("." + ASYNC_KEY)) {
methodAsyncKey.add(key);
}
}
Expand All @@ -111,7 +115,7 @@ public static URL mergeUrl(URL remoteUrl, Map<String, String> localMap) {
}
if (remoteMap != null && remoteMap.size() > 0) {
// Use version passed from provider side
reserveRemoteValue(Constants.DUBBO_VERSION_KEY, map, remoteMap);
reserveRemoteValue(DUBBO_VERSION_KEY, map, remoteMap);
reserveRemoteValue(VERSION_KEY, map, remoteMap);
reserveRemoteValue(METHODS_KEY, map, remoteMap);
reserveRemoteValue(TIMESTAMP_KEY, map, remoteMap);
Expand All @@ -121,17 +125,17 @@ public static URL mergeUrl(URL remoteUrl, Map<String, String> localMap) {
map.put(REMOTE_APPLICATION_KEY, remoteMap.get(APPLICATION_KEY));

// Combine filters and listeners on Provider and Consumer
String remoteFilter = remoteMap.get(Constants.REFERENCE_FILTER_KEY);
String localFilter = localMap.get(Constants.REFERENCE_FILTER_KEY);
String remoteFilter = remoteMap.get(REFERENCE_FILTER_KEY);
String localFilter = localMap.get(REFERENCE_FILTER_KEY);
if (remoteFilter != null && remoteFilter.length() > 0
&& localFilter != null && localFilter.length() > 0) {
localMap.put(Constants.REFERENCE_FILTER_KEY, remoteFilter + "," + localFilter);
localMap.put(REFERENCE_FILTER_KEY, remoteFilter + "," + localFilter);
}
String remoteListener = remoteMap.get(Constants.INVOKER_LISTENER_KEY);
String localListener = localMap.get(Constants.INVOKER_LISTENER_KEY);
String remoteListener = remoteMap.get(INVOKER_LISTENER_KEY);
String localListener = localMap.get(INVOKER_LISTENER_KEY);
if (remoteListener != null && remoteListener.length() > 0
&& localListener != null && localListener.length() > 0) {
localMap.put(Constants.INVOKER_LISTENER_KEY, remoteListener + "," + localListener);
localMap.put(INVOKER_LISTENER_KEY, remoteListener + "," + localListener);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.dubbo.rpc.cluster.support;

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.logger.Logger;
Expand Down Expand Up @@ -50,6 +49,7 @@
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
import static org.apache.dubbo.common.constants.RpcConstants.MERGER_KEY;

@SuppressWarnings("unchecked")
public class MergeableClusterInvoker<T> extends AbstractClusterInvoker<T> {
Expand All @@ -64,7 +64,7 @@ public MergeableClusterInvoker(Directory<T> directory) {
@Override
protected Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
checkInvokers(invokers, invocation);
String merger = getUrl().getMethodParameter(invocation.getMethodName(), Constants.MERGER_KEY);
String merger = getUrl().getMethodParameter(invocation.getMethodName(), MERGER_KEY);
if (ConfigUtils.isEmpty(merger)) { // If a method doesn't have a merger, only invoke one Group
for (final Invoker<T> invoker : invokers) {
if (invoker.isAvailable()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.apache.dubbo.rpc.cluster.Directory;
import org.apache.dubbo.rpc.support.MockInvoker;

import static org.apache.dubbo.common.constants.RpcConstants.MOCK_KEY;

import java.util.List;

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

String value = directory.getUrl().getMethodParameter(invocation.getMethodName(), Constants.MOCK_KEY, Boolean.FALSE.toString()).trim();
String value = directory.getUrl().getMethodParameter(invocation.getMethodName(), MOCK_KEY, Boolean.FALSE.toString()).trim();
if (value.length() == 0 || value.equalsIgnoreCase("false")) {
//no mock
result = this.invoker.invoke(invocation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.dubbo.rpc.cluster.directory;

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;

Expand All @@ -27,6 +26,8 @@
import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.common.constants.RpcConstants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.common.constants.RpcConstants.TOKEN_KEY;

/**
* MockInvocation.java
Expand All @@ -50,8 +51,8 @@ public Map<String, String> getAttachments() {
attachments.put(PATH_KEY, "dubbo");
attachments.put(GROUP_KEY, "dubbo");
attachments.put(VERSION_KEY, "1.0.0");
attachments.put(Constants.DUBBO_VERSION_KEY, "1.0.0");
attachments.put(Constants.TOKEN_KEY, "sfag");
attachments.put(DUBBO_VERSION_KEY, "1.0.0");
attachments.put(TOKEN_KEY, "sfag");
attachments.put(TIMEOUT_KEY, "1000");
return attachments;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.common.constants.RpcConstants.DUBBO_VERSION_KEY;

public class ClusterUtilsTest {

Expand All @@ -46,7 +47,7 @@ public void testMergeUrl() throws Exception {
providerURL = URLBuilder.from(providerURL)
.addParameter(GROUP_KEY, "dubbo")
.addParameter(VERSION_KEY, "1.2.3")
.addParameter(Constants.DUBBO_VERSION_KEY, "2.3.7")
.addParameter(DUBBO_VERSION_KEY, "2.3.7")
.addParameter(THREADPOOL_KEY, "fixed")
.addParameter(THREADS_KEY, Integer.MAX_VALUE)
.addParameter(THREAD_NAME_KEY, "test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.dubbo.rpc.cluster.support;

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
Expand All @@ -39,6 +38,7 @@
import java.util.Map;

import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.RpcConstants.MERGER_KEY;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -101,7 +101,7 @@ public void setUp() throws Exception {
public void testGetMenuSuccessfully() throws Exception {

// setup
url = url.addParameter(Constants.MERGER_KEY, ".merge");
url = url.addParameter(MERGER_KEY, ".merge");

given(invocation.getMethodName()).willReturn("getMenu");
given(invocation.getParameterTypes()).willReturn(new Class<?>[]{});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import java.util.Arrays;
import java.util.List;

import static org.apache.dubbo.common.constants.RpcConstants.MOCK_KEY;

public class MockClusterInvokerTest {

List<Invoker<IHelloService>> invokers = new ArrayList<Invoker<IHelloService>>();
Expand All @@ -54,7 +56,7 @@ public void beforeMethod() {
@Test
public void testMockInvokerInvoke_normal() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName());
url = url.addParameter(Constants.MOCK_KEY, "fail");
url = url.addParameter(MOCK_KEY, "fail");
Invoker<IHelloService> cluster = getClusterInvoker(url);
URL mockUrl = URL.valueOf("mock://localhost/" + IHelloService.class.getName()
+ "?getSomething.mock=return aa");
Expand Down Expand Up @@ -82,7 +84,7 @@ public void testMockInvokerInvoke_normal() {
@Test
public void testMockInvokerInvoke_failmock() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName())
.addParameter(Constants.MOCK_KEY, "fail:return null")
.addParameter(MOCK_KEY, "fail:return null")
.addParameter("invoke_return_error", "true");
URL mockUrl = URL.valueOf("mock://localhost/" + IHelloService.class.getName()
+ "?getSomething.mock=return aa").addParameters(url.getParameters());
Expand Down Expand Up @@ -117,7 +119,7 @@ public void testMockInvokerInvoke_failmock() {
@Test
public void testMockInvokerInvoke_forcemock() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName());
url = url.addParameter(Constants.MOCK_KEY, "force:return null");
url = url.addParameter(MOCK_KEY, "force:return null");

URL mockUrl = URL.valueOf("mock://localhost/" + IHelloService.class.getName()
+ "?getSomething.mock=return aa&getSomething3xx.mock=return xx")
Expand Down Expand Up @@ -149,7 +151,7 @@ public void testMockInvokerInvoke_forcemock() {
@Test
public void testMockInvokerInvoke_forcemock_defaultreturn() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName());
url = url.addParameter(Constants.MOCK_KEY, "force");
url = url.addParameter(MOCK_KEY, "force");
Invoker<IHelloService> cluster = getClusterInvoker(url);
URL mockUrl = URL.valueOf("mock://localhost/" + IHelloService.class.getName()
+ "?getSomething.mock=return aa&getSomething3xx.mock=return xx&sayHello.mock=return ")
Expand Down
Loading