Search in sources :

Example 1 with ComplexObject

use of org.apache.dubbo.service.ComplexObject 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();
}
Also used : GenericService(org.apache.dubbo.rpc.service.GenericService) ProxyFactory(org.apache.dubbo.rpc.ProxyFactory) DemoService(org.apache.dubbo.service.DemoService) URL(org.apache.dubbo.common.URL) ComplexObject(org.apache.dubbo.service.ComplexObject) ComplexObject(org.apache.dubbo.service.ComplexObject) Protocol(org.apache.dubbo.rpc.Protocol) DemoServiceImpl(org.apache.dubbo.service.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 2 with ComplexObject

use of org.apache.dubbo.service.ComplexObject 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();
}
Also used : GenericService(org.apache.dubbo.rpc.service.GenericService) ProxyFactory(org.apache.dubbo.rpc.ProxyFactory) DemoService(org.apache.dubbo.service.DemoService) URL(org.apache.dubbo.common.URL) FullServiceDefinition(org.apache.dubbo.metadata.definition.model.FullServiceDefinition) ComplexObject(org.apache.dubbo.service.ComplexObject) MethodDefinition(org.apache.dubbo.metadata.definition.model.MethodDefinition) ComplexObject(org.apache.dubbo.service.ComplexObject) Protocol(org.apache.dubbo.rpc.Protocol) HashMap(java.util.HashMap) Map(java.util.Map) DemoServiceImpl(org.apache.dubbo.service.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Aggregations

URL (org.apache.dubbo.common.URL)2 Protocol (org.apache.dubbo.rpc.Protocol)2 ProxyFactory (org.apache.dubbo.rpc.ProxyFactory)2 GenericService (org.apache.dubbo.rpc.service.GenericService)2 ComplexObject (org.apache.dubbo.service.ComplexObject)2 DemoService (org.apache.dubbo.service.DemoService)2 DemoServiceImpl (org.apache.dubbo.service.DemoServiceImpl)2 Test (org.junit.jupiter.api.Test)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 FullServiceDefinition (org.apache.dubbo.metadata.definition.model.FullServiceDefinition)1 MethodDefinition (org.apache.dubbo.metadata.definition.model.MethodDefinition)1