use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by alibaba.
the class DubboMonitorTest method testMonitorFactory.
@Test
public void testMonitorFactory() throws Exception {
MockMonitorService monitorService = new MockMonitorService();
URL statistics = new URLBuilder(DUBBO_PROTOCOL, "10.20.153.10", 0).addParameter(MonitorService.APPLICATION, "morgan").addParameter(MonitorService.INTERFACE, "MemberService").addParameter(MonitorService.METHOD, "findPerson").addParameter(MonitorService.CONSUMER, "10.20.153.11").addParameter(MonitorService.SUCCESS, 1).addParameter(MonitorService.FAILURE, 0).addParameter(MonitorService.ELAPSED, 3).addParameter(MonitorService.MAX_ELAPSED, 3).addParameter(MonitorService.CONCURRENT, 1).addParameter(MonitorService.MAX_CONCURRENT, 1).build();
Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
MonitorFactory monitorFactory = ExtensionLoader.getExtensionLoader(MonitorFactory.class).getAdaptiveExtension();
Exporter<MonitorService> exporter = protocol.export(proxyFactory.getInvoker(monitorService, MonitorService.class, URL.valueOf("dubbo://127.0.0.1:17979/" + MonitorService.class.getName())));
try {
Monitor monitor = null;
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < 60000) {
monitor = monitorFactory.getMonitor(URL.valueOf("dubbo://127.0.0.1:17979?interval=10"));
if (monitor == null) {
continue;
}
try {
monitor.collect(statistics);
int i = 0;
while (monitorService.getStatistics() == null && i < 200) {
i++;
Thread.sleep(10);
}
URL result = monitorService.getStatistics();
Assertions.assertEquals(1, result.getParameter(MonitorService.SUCCESS, 0));
Assertions.assertEquals(3, result.getParameter(MonitorService.ELAPSED, 0));
} finally {
monitor.destroy();
}
break;
}
Assertions.assertNotNull(monitor);
} finally {
exporter.unexport();
}
}
use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by alibaba.
the class HessianProtocolTest method testCustomException.
@Test
public void testCustomException() {
HessianServiceImpl server = new HessianServiceImpl();
ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
int port = NetUtils.getAvailablePort();
URL url = URL.valueOf("hessian://127.0.0.1:" + port + "/" + HessianService.class.getName() + "?version=1.0.0");
Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
Invoker<HessianService> invoker = protocol.refer(HessianService.class, url);
HessianService client = proxyFactory.getProxy(invoker);
try {
client.customException();
fail();
} catch (HessianServiceImpl.MyException expected) {
}
invoker.destroy();
exporter.unexport();
}
use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by alibaba.
the class HttpProtocolTest method testJsonrpcProtocolForServerJetty.
@Test
public void testJsonrpcProtocolForServerJetty() {
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&server=jetty");
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 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 alibaba.
the class GenericServiceTest method testGenericComplexCompute4FullServiceMetadata.
@Test
public void testGenericComplexCompute4FullServiceMetadata() {
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;
FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(DemoService.class);
MethodDefinition methodDefinition = getMethod("complexCompute", fullServiceDefinition.getMethods());
Map mapObject = createComplexObject(fullServiceDefinition, var1, var2, l, var3, var4, testEnum);
ComplexObject complexObject = map2bean(mapObject);
Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
GenericService client = proxyFactory.getProxy(invoker, true);
Object result = client.$invoke(methodDefinition.getName(), methodDefinition.getParameterTypes(), new Object[] { "haha", mapObject });
Assertions.assertEquals("haha###" + complexObject.toString(), result);
Invoker<DemoService> invoker2 = protocol.refer(DemoService.class, url);
GenericService client2 = (GenericService) proxyFactory.getProxy(invoker2, true);
Object result2 = client2.$invoke("complexCompute", methodDefinition.getParameterTypes(), new Object[] { "haha2", mapObject });
Assertions.assertEquals("haha2###" + complexObject.toString(), result2);
invoker.destroy();
exporter.unexport();
}
Aggregations