use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by alibaba.
the class XmlRpcProtocolTest method testXmlRpcProtocol.
@Test
public void testXmlRpcProtocol() {
XmlRpcServiceImpl server = new XmlRpcServiceImpl();
Assertions.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("xmlrpc://127.0.0.1:" + port + "/" + XmlRpcService.class.getName() + "?version=1.0.0");
Exporter<XmlRpcService> exporter = protocol.export(proxyFactory.getInvoker(server, XmlRpcService.class, url));
Invoker<XmlRpcService> invoker = protocol.refer(XmlRpcService.class, url);
XmlRpcService 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 apache.
the class MockClusterInvokerTest method getClusterInvokerMock.
private Invoker<IHelloService> getClusterInvokerMock(URL url, Invoker<IHelloService> mockInvoker) {
// As `javassist` have a strict restriction of argument types, request will fail if Invocation do not contains complete parameter type information
final URL durl = url.addParameter("proxy", "jdk");
invokers.clear();
ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getExtension("jdk");
Invoker<IHelloService> invoker1 = proxy.getInvoker(new HelloService(), IHelloService.class, durl);
invokers.add(invoker1);
if (mockInvoker != null) {
invokers.add(mockInvoker);
}
StaticDirectory<IHelloService> dic = new StaticDirectory<IHelloService>(durl, invokers, null);
dic.buildRouterChain();
AbstractClusterInvoker<IHelloService> cluster = new AbstractClusterInvoker(dic) {
@Override
protected Result doInvoke(Invocation invocation, List invokers, LoadBalance loadbalance) throws RpcException {
if (durl.getParameter("invoke_return_error", false)) {
throw new RpcException(RpcException.TIMEOUT_EXCEPTION, "test rpc exception");
} else {
return ((Invoker<?>) invokers.get(0)).invoke(invocation);
}
}
};
return new MockClusterInvoker<IHelloService>(dic, cluster);
}
use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by apache.
the class GenericServiceTest method testGenericFindComplexObject4FullServiceMetadata.
@Test
public void testGenericFindComplexObject4FullServiceMetadata() {
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));
String var1 = "v1";
int var2 = 234;
long l = 555;
String[] var3 = { "var31", "var32" };
List<Integer> var4 = Arrays.asList(2, 4, 8);
ComplexObject.TestEnum testEnum = ComplexObject.TestEnum.VALUE2;
// ComplexObject complexObject = createComplexObject(var1, var2, l, var3, var4, testEnum);
Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
GenericService client = proxyFactory.getProxy(invoker, true);
Object result = client.$invoke("findComplexObject", new String[] { "java.lang.String", "int", "long", "java.lang.String[]", "java.util.List", "org.apache.dubbo.service.ComplexObject$TestEnum" }, new Object[] { var1, var2, l, var3, var4, testEnum });
Assertions.assertNotNull(result);
ComplexObject r = map2bean((Map) result);
Assertions.assertEquals(r, createComplexObject(var1, var2, l, var3, var4, testEnum));
invoker.destroy();
exporter.unexport();
}
use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by apache.
the class GenericServiceTest method testGeneric.
@Test
public void testGeneric() {
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");
Exporter<DemoService> exporter = protocol.export(proxyFactory.getInvoker(server, DemoService.class, url));
Invoker<DemoService> invoker = protocol.refer(DemoService.class, url);
GenericService client = (GenericService) proxyFactory.getProxy(invoker, true);
Object result = client.$invoke("sayHello", new String[] { "java.lang.String" }, new Object[] { "haha" });
Assertions.assertEquals("hello haha", result);
org.apache.dubbo.rpc.service.GenericService newClient = (org.apache.dubbo.rpc.service.GenericService) proxyFactory.getProxy(invoker, true);
Object res = newClient.$invoke("sayHello", new String[] { "java.lang.String" }, new Object[] { "hehe" });
Assertions.assertEquals("hello hehe", res);
invoker.destroy();
exporter.unexport();
}
use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by apache.
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