From 18c1bd56790cdfa48f6f5812e56bd466ce8c0595 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Sun, 23 May 2021 16:47:29 +0800 Subject: [PATCH 1/3] Fix RpcUtilsTest Compilation Failure (#7832) * Fix RpcUtilsTest Compilation Failure * Fix Random port in WebserviceProtocolTest * Fix retry in ut --- .../store/redis/RedisMetadataReportTest.java | 2 + .../monitor/dubbo/MetricsFilterTest.java | 7 ++-- .../multiple/MultipleRegistry2S2RTest.java | 2 + .../registry/redis/RedisRegistryTest.java | 2 + .../dubbo/rpc/support/RpcUtilsTest.java | 39 +++++++++---------- .../rpc/protocol/redis/RedisProtocolTest.java | 2 + .../webservice/WebserviceProtocolTest.java | 16 ++++---- 7 files changed, 37 insertions(+), 33 deletions(-) diff --git a/dubbo-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java b/dubbo-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java index a4313bcfcab..adf6e97e3b5 100644 --- a/dubbo-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java +++ b/dubbo-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java @@ -74,7 +74,9 @@ public void constructor(final TestInfo testInfo) throws IOException { .settingIf(usesAuthentication, "requirepass " + REDIS_PASSWORD) .build(); this.redisServer.start(); + exception = null; } catch (IOException e) { + e.printStackTrace(); exception = e; } if (exception == null) { diff --git a/dubbo-monitor/dubbo-monitor-default/src/test/java/org/apache/dubbo/monitor/dubbo/MetricsFilterTest.java b/dubbo-monitor/dubbo-monitor-default/src/test/java/org/apache/dubbo/monitor/dubbo/MetricsFilterTest.java index 4576deb7f81..ada0e6f51c5 100644 --- a/dubbo-monitor/dubbo-monitor-default/src/test/java/org/apache/dubbo/monitor/dubbo/MetricsFilterTest.java +++ b/dubbo-monitor/dubbo-monitor-default/src/test/java/org/apache/dubbo/monitor/dubbo/MetricsFilterTest.java @@ -151,15 +151,14 @@ public void testAll() { try { setUp(); testcase.call(); + throwable = null; break; } catch (Throwable t) { + t.printStackTrace(); throwable = t; } } - if (throwable != null) { - throwable.printStackTrace(); - Assertions.fail(); - } + Assertions.assertNull(throwable); } } diff --git a/dubbo-registry/dubbo-registry-multiple/src/test/java/org/apache/dubbo/registry/multiple/MultipleRegistry2S2RTest.java b/dubbo-registry/dubbo-registry-multiple/src/test/java/org/apache/dubbo/registry/multiple/MultipleRegistry2S2RTest.java index 78ccedd706c..e526a967a73 100644 --- a/dubbo-registry/dubbo-registry-multiple/src/test/java/org/apache/dubbo/registry/multiple/MultipleRegistry2S2RTest.java +++ b/dubbo-registry/dubbo-registry-multiple/src/test/java/org/apache/dubbo/registry/multiple/MultipleRegistry2S2RTest.java @@ -82,7 +82,9 @@ public static void setUp() throws Exception { .settingIf(SystemUtils.IS_OS_WINDOWS, "maxheap 128mb") .build(); redisServer.start(); + exception = null; } catch (IOException e) { + e.printStackTrace(); exception = e; } if (exception == null) { diff --git a/dubbo-registry/dubbo-registry-redis/src/test/java/org/apache/dubbo/registry/redis/RedisRegistryTest.java b/dubbo-registry/dubbo-registry-redis/src/test/java/org/apache/dubbo/registry/redis/RedisRegistryTest.java index 60d21b39098..2feccc4c44b 100644 --- a/dubbo-registry/dubbo-registry-redis/src/test/java/org/apache/dubbo/registry/redis/RedisRegistryTest.java +++ b/dubbo-registry/dubbo-registry-redis/src/test/java/org/apache/dubbo/registry/redis/RedisRegistryTest.java @@ -64,7 +64,9 @@ public void setUp() throws Exception { .settingIf(SystemUtils.IS_OS_WINDOWS, "maxheap 128mb") .build(); this.redisServer.start(); + exception = null; } catch (IOException e) { + e.printStackTrace(); exception = e; } if (exception == null) { diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/RpcUtilsTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/RpcUtilsTest.java index b1d142716d1..8fc54b43bc1 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/RpcUtilsTest.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/RpcUtilsTest.java @@ -21,9 +21,9 @@ import org.apache.dubbo.rpc.InvokeMode; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcInvocation; - import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ServiceRepository; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -311,6 +311,23 @@ public void testIsOneway() { @Test public void testIsAsync() { + Object[] args = new Object[] {"hello", "dubbo", 520}; + Class demoServiceClass = DemoService.class; + String serviceName = demoServiceClass.getName(); + Invoker invoker = mock(Invoker.class); + + URL url = URL.valueOf( + "test://127.0.0.1:1/org.apache.dubbo.rpc.support.DemoService?interface=org.apache.dubbo.rpc.support.DemoService"); + + RpcInvocation inv = new RpcInvocation("test", serviceName, "", + new Class[] {String.class, String[].class, Object[].class}, + new Object[] {"method", new String[] {}, args}, + null, invoker, null); + + Assertions.assertFalse(RpcUtils.isAsync(url, inv)); + inv.setInvokeMode(InvokeMode.ASYNC); + Assertions.assertTrue(RpcUtils.isAsync(url, inv)); + URL url1 = URL.valueOf("dubbo://localhost/?test.async=true"); Invocation inv1 = new RpcInvocation("test", "DemoService", "", new Class[]{}, new String[]{}); inv1.setAttachment("test." + ASYNC_KEY, Boolean.FALSE.toString()); @@ -418,26 +435,6 @@ public void testGetMethodName(String methodName) { } } - @Test - public void testIsAsync() { - Object[] args = new Object[] {"hello", "dubbo", 520}; - Class demoServiceClass = DemoService.class; - String serviceName = demoServiceClass.getName(); - Invoker invoker = mock(Invoker.class); - - URL url = URL.valueOf( - "test://127.0.0.1:1/org.apache.dubbo.rpc.support.DemoService?interface=org.apache.dubbo.rpc.support.DemoService"); - - RpcInvocation inv = new RpcInvocation("test", serviceName, "", - new Class[] {String.class, String[].class, Object[].class}, - new Object[] {"method", new String[] {}, args}, - null, invoker, null); - - Assertions.assertFalse(RpcUtils.isAsync(url, inv)); - inv.setInvokeMode(InvokeMode.ASYNC); - Assertions.assertTrue(RpcUtils.isAsync(url, inv)); - } - @Test public void testIsGenericCall() { Assertions.assertTrue(RpcUtils.isGenericCall("Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;", "$invoke")); diff --git a/dubbo-rpc/dubbo-rpc-redis/src/test/java/org/apache/dubbo/rpc/protocol/redis/RedisProtocolTest.java b/dubbo-rpc/dubbo-rpc-redis/src/test/java/org/apache/dubbo/rpc/protocol/redis/RedisProtocolTest.java index 46583037205..c393143a2be 100644 --- a/dubbo-rpc/dubbo-rpc-redis/src/test/java/org/apache/dubbo/rpc/protocol/redis/RedisProtocolTest.java +++ b/dubbo-rpc/dubbo-rpc-redis/src/test/java/org/apache/dubbo/rpc/protocol/redis/RedisProtocolTest.java @@ -78,7 +78,9 @@ public void setUp(final TestInfo testInfo) throws IOException { .settingIf(usesAuthentication, "requirepass " + REDIS_PASSWORD) .build(); this.redisServer.start(); + exception = null; } catch (IOException e) { + e.printStackTrace(); exception = e; } if (exception == null) { diff --git a/dubbo-rpc/dubbo-rpc-webservice/src/test/java/org/apache/dubbo/rpc/protocol/webservice/WebserviceProtocolTest.java b/dubbo-rpc/dubbo-rpc-webservice/src/test/java/org/apache/dubbo/rpc/protocol/webservice/WebserviceProtocolTest.java index e3d15eb3ab5..540b1e74b06 100644 --- a/dubbo-rpc/dubbo-rpc-webservice/src/test/java/org/apache/dubbo/rpc/protocol/webservice/WebserviceProtocolTest.java +++ b/dubbo-rpc/dubbo-rpc-webservice/src/test/java/org/apache/dubbo/rpc/protocol/webservice/WebserviceProtocolTest.java @@ -16,10 +16,6 @@ */ package org.apache.dubbo.rpc.protocol.webservice; -import org.apache.catalina.Context; -import org.apache.catalina.LifecycleException; -import org.apache.catalina.connector.Connector; -import org.apache.catalina.startup.Tomcat; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.URLBuilder; import org.apache.dubbo.common.extension.ExtensionLoader; @@ -30,6 +26,10 @@ import org.apache.dubbo.rpc.Protocol; import org.apache.dubbo.rpc.ProxyFactory; +import org.apache.catalina.Context; +import org.apache.catalina.LifecycleException; +import org.apache.catalina.connector.Connector; +import org.apache.catalina.startup.Tomcat; import org.junit.jupiter.api.Test; import java.io.File; @@ -85,7 +85,7 @@ public void testWebserviceProtocol() throws Exception { @Test public void testWebserviceServlet() throws LifecycleException { - int port = 55065; + int port = NetUtils.getAvailablePort(); Tomcat tomcat = buildTomcat("/dubbo-webservice", "/services/*", port); DemoService service = new DemoServiceImpl(); @@ -96,7 +96,7 @@ public void testWebserviceServlet() throws LifecycleException { .setPort(port) .setPath("dubbo-webservice2/" + DemoService.class.getName()) .addParameter("server", "servlet") - .addParameter("bind.port", 55065) + .addParameter("bind.port", port) .addParameter("contextpath", "dubbo-webservice2") .addParameter(SERVICE_PATH_PREFIX, "dubbo-webservice/services") .addParameter("codec", "exchange") @@ -116,7 +116,7 @@ public void testWebserviceServlet() throws LifecycleException { public void testWebserviceJetty() throws LifecycleException { Tomcat tomcat = buildTomcat("/dubbo-webservice", "/services/*", 55065); DemoService service = new DemoServiceImpl(); - int port = 55066; + int port = NetUtils.getAvailablePort(); URLBuilder builder = new URLBuilder() .setProtocol("webservice") @@ -124,7 +124,7 @@ public void testWebserviceJetty() throws LifecycleException { .setPort(port) .setPath("dubbo-webservice3/" + DemoService.class.getName()) .addParameter("server", "jetty") - .addParameter("bind.port", 55066) + .addParameter("bind.port", port) .addParameter("contextpath", "dubbo-webservice2") .addParameter("codec", "exchange") .addParameter("timeout", 3000); From 0049c24e88ed2fef799ec0dfcc3fd106df26490c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=81=BC=E5=8D=8E?= <43363120+BurningCN@users.noreply.github.com> Date: Sun, 23 May 2021 21:18:18 +0800 Subject: [PATCH 2/3] Optimize the logic of obtaining the mock parameter value of the corresponding method in the MockInvoker#invoke method (#7840) --- .../java/org/apache/dubbo/rpc/support/MockInvoker.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/MockInvoker.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/MockInvoker.java index 156494cd649..4b826bb49c1 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/MockInvoker.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/MockInvoker.java @@ -99,13 +99,8 @@ public Result invoke(Invocation invocation) throws RpcException { if (invocation instanceof RpcInvocation) { ((RpcInvocation) invocation).setInvoker(this); } - String mock = null; - if (getUrl().hasMethodParameter(invocation.getMethodName())) { - mock = getUrl().getParameter(invocation.getMethodName() + "." + MOCK_KEY); - } - if (StringUtils.isBlank(mock)) { - mock = getUrl().getParameter(MOCK_KEY); - } + + String mock = getUrl().getMethodParameter(invocation.getMethodName(),MOCK_KEY); if (StringUtils.isBlank(mock)) { throw new RpcException(new IllegalAccessException("mock can not be null. url :" + url)); From 028153a19940d7a5f2d78d415c3cf5f93fdb8543 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Mon, 24 May 2021 10:28:45 +0800 Subject: [PATCH 3/3] Update Pull Request Template (#7828) --- PULL_REQUEST_TEMPLATE.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index a1384f243a0..e9247482436 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -10,9 +10,12 @@ +## Checklist - [x] Make sure there is a [GitHub_issue](https://github.com/apache/dubbo/issues) field for the change (usually before you start working on it). Trivial changes like typos do not require a GitHub issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue. -- [ ] Format the pull request title like `[Dubbo-XXX] Fix UnknownException when host config not exist #XXX`. Each commit in the pull request should have a meaningful subject line and body. +- [ ] Each commit in the pull request should have a meaningful subject line and body. - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. +- [ ] Check if is necessary to patch to Dubbo 3 if you are work on Dubbo 2.7 - [ ] Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add sample in [dubbo samples](https://github.com/apache/dubbo-samples) project. -- [ ] Run `mvn clean install -DskipTests=false` & `mvn clean test-compile failsafe:integration-test` to make sure unit-test and integration-test pass. +- [ ] Add some description to [dubbo-website](https://github.com/apache/dubbo-website) project if you are requesting to add a feature. +- [ ] GitHub Actions works fine on your own branch. - [ ] If this contribution is large, please follow the [Software Donation Guide](https://github.com/apache/dubbo/wiki/Software-donation-guide).