You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2018/07/09 06:17:18 UTC
[GitHub] lovepoem closed pull request #2041: [Dubbo-1696] Enhance the test
coverage part-17 : dubbo-rpc/dubbo-rpc-injvm module
lovepoem closed pull request #2041: [Dubbo-1696] Enhance the test coverage part-17 : dubbo-rpc/dubbo-rpc-injvm module
URL: https://github.com/apache/incubator-dubbo/pull/2041
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocol.java b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocol.java
index eff37b801b..290e208430 100644
--- a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocol.java
+++ b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocol.java
@@ -97,7 +97,7 @@ public boolean isInjvmRefer(URL url) {
// Since injvm protocol is configured explicitly, we don't need to set any extra flag, use normal refer process.
if (Constants.LOCAL_PROTOCOL.toString().equals(url.getProtocol())) {
isJvmRefer = false;
- } else if (Constants.SCOPE_LOCAL.equals(scope) || (url.getParameter("injvm", false))) {
+ } else if (Constants.SCOPE_LOCAL.equals(scope) || (url.getParameter(Constants.LOCAL_PROTOCOL, false))) {
// if it's declared as local reference
// 'scope=local' is equivalent to 'injvm=true', injvm will be deprecated in the future release
isJvmRefer = true;
diff --git a/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocolTest.java b/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocolTest.java
index 8d5c5d2eb8..c6c0bdb123 100644
--- a/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocolTest.java
+++ b/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocolTest.java
@@ -21,6 +21,7 @@
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.rpc.Exporter;
+import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.ProxyFactory;
@@ -28,9 +29,11 @@
import org.junit.Test;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
@@ -38,6 +41,11 @@
*/
public class InjvmProtocolTest {
+
+ static{
+ InjvmProtocol injvm = InjvmProtocol.getInjvmProtocol();
+ }
+
private Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
private ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
private List<Exporter<?>> exporters = new ArrayList<Exporter<?>>();
@@ -53,11 +61,17 @@ public void after() throws Exception {
@Test
public void testLocalProtocol() throws Exception {
DemoService service = new DemoServiceImpl();
- Exporter<?> exporter = protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("injvm://127.0.0.1/TestService").addParameter(Constants.INTERFACE_KEY, DemoService.class.getName())));
+ Invoker<?> invoker = proxy.getInvoker(service, DemoService.class, URL.valueOf("injvm://127.0.0.1/TestService").addParameter(Constants.INTERFACE_KEY, DemoService.class.getName()));
+ assertTrue(invoker.isAvailable());
+ Exporter<?> exporter = protocol.export(invoker);
exporters.add(exporter);
service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("injvm://127.0.0.1/TestService").addParameter(Constants.INTERFACE_KEY, DemoService.class.getName())));
assertEquals(service.getSize(new String[]{"", "", ""}), 3);
service.invoke("injvm://127.0.0.1/TestService", "invoke");
+
+ InjvmInvoker injvmInvoker = new InjvmInvoker(DemoService.class, URL.valueOf("injvm://127.0.0.1/TestService"),null,new HashMap<String, Exporter<?>>());
+ assertFalse(injvmInvoker.isAvailable());
+
}
@Test
@@ -74,6 +88,19 @@ public void testIsInjvmRefer() throws Exception {
url = url.addParameter(Constants.GROUP_KEY, "*")
.addParameter(Constants.VERSION_KEY, "*");
assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));
+
+ url = URL.valueOf("fake://127.0.0.1/TestService").addParameter(Constants.SCOPE_KEY, Constants.SCOPE_LOCAL);
+ assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));
+
+ url = URL.valueOf("fake://127.0.0.1/TestService").addParameter(Constants.LOCAL_PROTOCOL,true);
+ assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));
+
+ url = URL.valueOf("fake://127.0.0.1/TestService").addParameter(Constants.SCOPE_KEY, Constants.SCOPE_REMOTE);
+ assertFalse(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));
+
+ url = URL.valueOf("fake://127.0.0.1/TestService").addParameter(Constants.GENERIC_KEY, true);
+ assertFalse(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));
+
}
}
\ No newline at end of file
diff --git a/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/ProtocolTest.java b/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/ProtocolTest.java
index e68c4234ab..45ee265d3d 100644
--- a/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/ProtocolTest.java
+++ b/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/ProtocolTest.java
@@ -36,6 +36,10 @@ public String echo(String e) {
}
};
+ static{
+ InjvmProtocol injvm = InjvmProtocol.getInjvmProtocol();
+ }
+
ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getExtension("javassist");
URL url = URL.valueOf("injvm://localhost:0/org.apache.dubbo.rpc.support.IEcho?interface=org.apache.dubbo.rpc.support.IEcho");
@@ -48,6 +52,8 @@ public void test_destroyWontCloseAllProtocol() throws Exception {
Protocol InjvmProtocol = ExtensionLoader.getExtensionLoader(Protocol.class).getExtension("injvm");
+ assertEquals(0,InjvmProtocol.getDefaultPort());
+
InjvmProtocol.export(invoker);
Invoker<IEcho> refer = InjvmProtocol.refer(IEcho.class, url);
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org