Search in sources :

Example 36 with Protocol

use of org.apache.dubbo.rpc.Protocol 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)

Example 37 with Protocol

use of org.apache.dubbo.rpc.Protocol in project dubbo by alibaba.

the class XmlRpcProtocolTest method testXmlRpcProtocol.

@Test
public void testXmlRpcProtocol() {
    XmlRpcServiceImpl server = new XmlRpcServiceImpl();
    Assertions.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("xmlrpc://127.0.0.1:" + port + "/" + XmlRpcService.class.getName() + "?version=1.0.0");
    Exporter<XmlRpcService> exporter = protocol.export(proxyFactory.getInvoker(server, XmlRpcService.class, url));
    Invoker<XmlRpcService> invoker = protocol.refer(XmlRpcService.class, url);
    XmlRpcService client = proxyFactory.getProxy(invoker);
    String result = client.sayHello("haha");
    Assertions.assertTrue(server.isCalled());
    Assertions.assertEquals("Hello, haha", result);
    invoker.destroy();
    exporter.unexport();
}
Also used : ProxyFactory(org.apache.dubbo.rpc.ProxyFactory) Protocol(org.apache.dubbo.rpc.Protocol) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Aggregations

Protocol (org.apache.dubbo.rpc.Protocol)37 Test (org.junit.jupiter.api.Test)33 URL (org.apache.dubbo.common.URL)32 ProxyFactory (org.apache.dubbo.rpc.ProxyFactory)25 GenericService (org.apache.dubbo.rpc.service.GenericService)10 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)6 DemoService (org.apache.dubbo.service.DemoService)6 DemoServiceImpl (org.apache.dubbo.service.DemoServiceImpl)6 Result (org.apache.dubbo.rpc.Result)5 DubboProtocol (org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol)5 ComplexObject (org.apache.dubbo.service.ComplexObject)5 RpcException (org.apache.dubbo.rpc.RpcException)4 MockProtocol (org.apache.dubbo.rpc.support.MockProtocol)4 HashMap (java.util.HashMap)3 MetricsService (org.apache.dubbo.monitor.MetricsService)3 RegistryProtocol (org.apache.dubbo.registry.integration.RegistryProtocol)3 IMetricManager (com.alibaba.metrics.IMetricManager)2 MetricObject (com.alibaba.metrics.common.MetricObject)2 Gson (com.google.gson.Gson)2 TypeToken (com.google.gson.reflect.TypeToken)2