Search in sources :

Example 1 with DemoServiceImpl

use of org.apache.dubbo.service.DemoServiceImpl 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);
}
Also used : ServiceConfig(com.alibaba.dubbo.config.ServiceConfig) ReferenceConfig(com.alibaba.dubbo.config.ReferenceConfig) DemoService(org.apache.dubbo.service.DemoService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) DemoServiceImpl(org.apache.dubbo.service.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 2 with DemoServiceImpl

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

Example 3 with DemoServiceImpl

use of org.apache.dubbo.service.DemoServiceImpl 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();
}
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) Invoker(org.apache.dubbo.rpc.Invoker) ReferenceConfig(com.alibaba.dubbo.config.ReferenceConfig) 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 4 with DemoServiceImpl

use of org.apache.dubbo.service.DemoServiceImpl 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 5 with DemoServiceImpl

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

Aggregations

DemoService (org.apache.dubbo.service.DemoService)7 DemoServiceImpl (org.apache.dubbo.service.DemoServiceImpl)7 Test (org.junit.jupiter.api.Test)7 URL (org.apache.dubbo.common.URL)6 Protocol (org.apache.dubbo.rpc.Protocol)6 ProxyFactory (org.apache.dubbo.rpc.ProxyFactory)6 GenericService (org.apache.dubbo.rpc.service.GenericService)5 ComplexObject (org.apache.dubbo.service.ComplexObject)5 ReferenceConfig (com.alibaba.dubbo.config.ReferenceConfig)2 ServiceConfig (com.alibaba.dubbo.config.ServiceConfig)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)1 FullServiceDefinition (org.apache.dubbo.metadata.definition.model.FullServiceDefinition)1 MethodDefinition (org.apache.dubbo.metadata.definition.model.MethodDefinition)1 Invoker (org.apache.dubbo.rpc.Invoker)1 EchoService (org.apache.dubbo.rpc.service.EchoService)1