Search in sources :

Example 11 with Protocol

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

the class HessianProtocolTest method testHttpClient.

@Test
public void testHttpClient() {
    HessianServiceImpl server = new HessianServiceImpl();
    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("hessian://127.0.0.1:" + port + "/" + HessianService.class.getName() + "?version=1.0.0&client=httpclient&hessian.overload.method=true");
    Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
    Invoker<HessianService> invoker = protocol.refer(HessianService.class, url);
    HessianService 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)

Example 12 with Protocol

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

the class HttpProtocolTest method testGenericInvoke.

@Test
public void testGenericInvoke() {
    HttpServiceImpl server = new HttpServiceImpl();
    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("http://127.0.0.1:" + port + "/" + HttpService.class.getName() + "?release=2.7.0");
    Exporter<HttpService> exporter = protocol.export(proxyFactory.getInvoker(server, HttpService.class, url));
    Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
    GenericService client = proxyFactory.getProxy(invoker, true);
    String result = (String) client.$invoke("sayHello", new String[] { "java.lang.String" }, new Object[] { "haha" });
    Assertions.assertTrue(server.isCalled());
    Assertions.assertEquals("Hello, haha", result);
    invoker.destroy();
    exporter.unexport();
}
Also used : GenericService(org.apache.dubbo.rpc.service.GenericService) ProxyFactory(org.apache.dubbo.rpc.ProxyFactory) Protocol(org.apache.dubbo.rpc.Protocol) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 13 with Protocol

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

the class HttpProtocolTest method testJsonrpcProtocol.

@Test
public void testJsonrpcProtocol() {
    HttpServiceImpl server = new HttpServiceImpl();
    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("http://127.0.0.1:" + port + "/" + HttpService.class.getName() + "?version=1.0.0");
    Exporter<HttpService> exporter = protocol.export(proxyFactory.getInvoker(server, HttpService.class, url));
    Invoker<HttpService> invoker = protocol.refer(HttpService.class, url);
    HttpService client = proxyFactory.getProxy(invoker);
    String result = client.sayHello("haha");
    assertTrue(server.isCalled());
    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)

Example 14 with Protocol

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

the class ProtocolTest method test_destroyWontCloseAllProtocol.

@Test
public void test_destroyWontCloseAllProtocol() throws Exception {
    Protocol autowireProtocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    Protocol InjvmProtocol = ExtensionLoader.getExtensionLoader(Protocol.class).getExtension("injvm");
    assertEquals(0, InjvmProtocol.getDefaultPort());
    InjvmProtocol.export(invoker);
    Invoker<IEcho> refer = InjvmProtocol.refer(IEcho.class, url);
    IEcho echoProxy = proxyFactory.getProxy(refer);
    assertEquals("ok", echoProxy.echo("ok"));
    try {
        autowireProtocol.destroy();
    } catch (UnsupportedOperationException expected) {
        assertThat(expected.getMessage(), containsString("of interface org.apache.dubbo.rpc.Protocol is not adaptive method!"));
    }
    assertEquals("ok2", echoProxy.echo("ok2"));
}
Also used : Protocol(org.apache.dubbo.rpc.Protocol) Test(org.junit.jupiter.api.Test)

Example 15 with Protocol

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

the class ThriftProtocolTest method testThriftProtocolMultipleServices.

@Test
public void testThriftProtocolMultipleServices() throws TException {
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    DemoServiceImpl server1 = new DemoServiceImpl();
    int port = NetUtils.getAvailablePort();
    URL url1 = URL.valueOf(org.apache.dubbo.rpc.protocol.nativethrift.ThriftProtocol.NAME + "://127.0.0.1:" + port + "/" + DemoService.Iface.class.getName() + "?version=1.0.0&nativethrift.overload.method=true");
    Exporter<DemoService.Iface> exporter1 = protocol.export(proxyFactory.getInvoker(server1, DemoService.Iface.class, url1));
    Invoker<DemoService.Iface> invoker1 = protocol.refer(DemoService.Iface.class, url1);
    DemoService.Iface client1 = proxyFactory.getProxy(invoker1);
    String result1 = client1.sayHello("haha");
    Assertions.assertTrue(server1.isCalled());
    Assertions.assertEquals("Hello, haha", result1);
    UserServiceImpl server2 = new UserServiceImpl();
    URL url2 = URL.valueOf(org.apache.dubbo.rpc.protocol.nativethrift.ThriftProtocol.NAME + "://127.0.0.1:" + NetUtils.getAvailablePort() + "/" + UserService.Iface.class.getName() + "?version=1.0.0&nativethrift.overload.method=true");
    Exporter<UserService.Iface> exporter2 = protocol.export(proxyFactory.getInvoker(server2, UserService.Iface.class, url2));
    Invoker<UserService.Iface> invoker2 = protocol.refer(UserService.Iface.class, url2);
    UserService.Iface client2 = proxyFactory.getProxy(invoker2);
    String result2 = client2.find(2);
    Assertions.assertEquals("KK2", result2);
    invoker1.destroy();
    exporter1.unexport();
    invoker2.destroy();
    exporter2.unexport();
}
Also used : ProxyFactory(org.apache.dubbo.rpc.ProxyFactory) URL(org.apache.dubbo.common.URL) Protocol(org.apache.dubbo.rpc.Protocol) 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