use of org.apache.dubbo.service.DemoService in project dubbo by alibaba.
the class ConfigTest method testConfig.
@Test
public void testConfig() {
com.alibaba.dubbo.config.ServiceConfig<DemoService> service = new ServiceConfig<>();
service.setApplication(applicationConfig);
service.setRegistry(registryConfig);
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
com.alibaba.dubbo.config.ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
reference.setApplication(applicationConfig);
reference.setRegistry(registryConfig);
reference.setInterface(DemoService.class);
DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(applicationConfig).registry(registryConfig).service(service).reference(reference).start();
DemoService demoService = bootstrap.getCache().get(reference);
String message = demoService.sayHello("dubbo");
Assertions.assertEquals("hello dubbo", message);
}
use of org.apache.dubbo.service.DemoService 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.service.DemoService 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();
}
use of org.apache.dubbo.service.DemoService in project dubbo by alibaba.
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.service.DemoService in project dubbo by alibaba.
the class EchoServiceTest method testEcho.
@Test
public void testEcho() {
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);
EchoService client = (EchoService) proxyFactory.getProxy(invoker);
Object result = client.$echo("haha");
Assertions.assertEquals("haha", result);
org.apache.dubbo.rpc.service.EchoService newClient = (org.apache.dubbo.rpc.service.EchoService) proxyFactory.getProxy(invoker);
Object res = newClient.$echo("hehe");
Assertions.assertEquals("hehe", res);
invoker.destroy();
exporter.unexport();
}
Aggregations