Search in sources :

Example 6 with EchoService

use of org.apache.dubbo.rpc.service.EchoService 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

EchoService (org.apache.dubbo.rpc.service.EchoService)6 Test (org.junit.jupiter.api.Test)6 DemoService (org.apache.dubbo.rpc.protocol.dubbo.support.DemoService)3 DemoServiceImpl (org.apache.dubbo.rpc.protocol.dubbo.support.DemoServiceImpl)3 HashMap (java.util.HashMap)2 URL (org.apache.dubbo.common.URL)2 Type (org.apache.dubbo.rpc.protocol.dubbo.support.Type)2 Disabled (org.junit.jupiter.api.Disabled)2 Protocol (org.apache.dubbo.rpc.Protocol)1 ProxyFactory (org.apache.dubbo.rpc.ProxyFactory)1 RemoteService (org.apache.dubbo.rpc.protocol.dubbo.support.RemoteService)1 RemoteServiceImpl (org.apache.dubbo.rpc.protocol.dubbo.support.RemoteServiceImpl)1 DemoService (org.apache.dubbo.service.DemoService)1 DemoServiceImpl (org.apache.dubbo.service.DemoServiceImpl)1