use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by alibaba.
the class HttpProtocolTest method testJsonrpcProtocol.
@Test
public void testJsonrpcProtocol() {
HttpServiceImpl server = new HttpServiceImpl();
assertFalse(server.isCalled());
ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
int port = NetUtils.getAvailablePort();
URL url = URL.valueOf("http://127.0.0.1:" + port + "/" + HttpService.class.getName() + "?version=1.0.0");
Exporter<HttpService> exporter = protocol.export(proxyFactory.getInvoker(server, HttpService.class, url));
Invoker<HttpService> invoker = protocol.refer(HttpService.class, url);
HttpService client = proxyFactory.getProxy(invoker);
String result = client.sayHello("haha");
assertTrue(server.isCalled());
assertEquals("Hello, haha", result);
invoker.destroy();
exporter.unexport();
}
use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by alibaba.
the class ThriftProtocolTest method testThriftProtocolMultipleServices.
@Test
public void testThriftProtocolMultipleServices() throws TException {
ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
DemoServiceImpl server1 = new DemoServiceImpl();
int port = NetUtils.getAvailablePort();
URL url1 = URL.valueOf(org.apache.dubbo.rpc.protocol.nativethrift.ThriftProtocol.NAME + "://127.0.0.1:" + port + "/" + DemoService.Iface.class.getName() + "?version=1.0.0&nativethrift.overload.method=true");
Exporter<DemoService.Iface> exporter1 = protocol.export(proxyFactory.getInvoker(server1, DemoService.Iface.class, url1));
Invoker<DemoService.Iface> invoker1 = protocol.refer(DemoService.Iface.class, url1);
DemoService.Iface client1 = proxyFactory.getProxy(invoker1);
String result1 = client1.sayHello("haha");
Assertions.assertTrue(server1.isCalled());
Assertions.assertEquals("Hello, haha", result1);
UserServiceImpl server2 = new UserServiceImpl();
URL url2 = URL.valueOf(org.apache.dubbo.rpc.protocol.nativethrift.ThriftProtocol.NAME + "://127.0.0.1:" + NetUtils.getAvailablePort() + "/" + UserService.Iface.class.getName() + "?version=1.0.0&nativethrift.overload.method=true");
Exporter<UserService.Iface> exporter2 = protocol.export(proxyFactory.getInvoker(server2, UserService.Iface.class, url2));
Invoker<UserService.Iface> invoker2 = protocol.refer(UserService.Iface.class, url2);
UserService.Iface client2 = proxyFactory.getProxy(invoker2);
String result2 = client2.find(2);
Assertions.assertEquals("KK2", result2);
invoker1.destroy();
exporter1.unexport();
invoker2.destroy();
exporter2.unexport();
}
use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by alibaba.
the class ThriftProtocolTest method testThriftProtocol.
@Test
public void testThriftProtocol() throws TException {
DemoServiceImpl server = new DemoServiceImpl();
ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
int port = NetUtils.getAvailablePort();
URL url = URL.valueOf(org.apache.dubbo.rpc.protocol.nativethrift.ThriftProtocol.NAME + "://127.0.0.1:" + port + "/" + DemoService.Iface.class.getName() + "?version=1.0.0&nativethrift.overload.method=true");
Exporter<DemoService.Iface> exporter = protocol.export(proxyFactory.getInvoker(server, DemoService.Iface.class, url));
Invoker<DemoService.Iface> invoker = protocol.refer(DemoService.Iface.class, url);
DemoService.Iface client = proxyFactory.getProxy(invoker);
String result = client.sayHello("haha");
Assertions.assertTrue(server.isCalled());
Assertions.assertEquals("Hello, haha", result);
invoker.destroy();
exporter.unexport();
}
use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by alibaba.
the class GenericServiceTest method testGeneric2.
@Test
public void testGeneric2() {
DemoService server = new DemoServiceImpl();
ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
URL url = URL.valueOf("dubbo://127.0.0.1:5342/" + DemoService.class.getName() + "?version=1.0.0&generic=true$timeout=3000");
Exporter<DemoService> exporter = protocol.export(proxyFactory.getInvoker(server, DemoService.class, url));
Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
GenericService client = proxyFactory.getProxy(invoker, true);
Object result = client.$invoke("sayHello", new String[] { "java.lang.String" }, new Object[] { "haha" });
Assertions.assertEquals("hello haha", result);
Invoker<DemoService> invoker2 = protocol.refer(DemoService.class, url);
GenericService client2 = (GenericService) proxyFactory.getProxy(invoker2, true);
Object result2 = client2.$invoke("sayHello", new String[] { "java.lang.String" }, new Object[] { "haha" });
Assertions.assertEquals("hello haha", result2);
invoker.destroy();
exporter.unexport();
}
use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by alibaba.
the class GenericServiceTest method testGenericCompatible.
@Test
public void testGenericCompatible() {
DemoService server = new DemoServiceImpl();
ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
URL url = URL.valueOf("dubbo://127.0.0.1:5342/" + DemoService.class.getName() + "?version=1.0.0&generic=true$timeout=3000");
Exporter<DemoService> exporter = protocol.export(proxyFactory.getInvoker(server, DemoService.class, url));
// simulate normal invoke
ReferenceConfig<com.alibaba.dubbo.rpc.service.GenericService> oldReferenceConfig = new ReferenceConfig<>();
oldReferenceConfig.setGeneric(true);
oldReferenceConfig.setInterface(DemoService.class.getName());
oldReferenceConfig.checkAndUpdateSubConfigs();
Invoker invoker = protocol.refer(oldReferenceConfig.getInterfaceClass(), url);
com.alibaba.dubbo.rpc.service.GenericService client = (com.alibaba.dubbo.rpc.service.GenericService) proxyFactory.getProxy(invoker, true);
Object result = client.$invoke("sayHello", new String[] { "java.lang.String" }, new Object[] { "haha" });
Assertions.assertEquals("hello haha", result);
invoker.destroy();
exporter.unexport();
}
Aggregations