Search in sources :

Example 46 with ProxyFactory

use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by apache.

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 47 with ProxyFactory

use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by apache.

the class DubboMonitorTest method testMonitorFactory.

@Test
public void testMonitorFactory() throws Exception {
    MockMonitorService monitorService = new MockMonitorService();
    URL statistics = new URLBuilder(DUBBO_PROTOCOL, "10.20.153.10", 0).addParameter(MonitorService.APPLICATION, "morgan").addParameter(MonitorService.INTERFACE, "MemberService").addParameter(MonitorService.METHOD, "findPerson").addParameter(MonitorService.CONSUMER, "10.20.153.11").addParameter(MonitorService.SUCCESS, 1).addParameter(MonitorService.FAILURE, 0).addParameter(MonitorService.ELAPSED, 3).addParameter(MonitorService.MAX_ELAPSED, 3).addParameter(MonitorService.CONCURRENT, 1).addParameter(MonitorService.MAX_CONCURRENT, 1).build();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    MonitorFactory monitorFactory = ExtensionLoader.getExtensionLoader(MonitorFactory.class).getAdaptiveExtension();
    Exporter<MonitorService> exporter = protocol.export(proxyFactory.getInvoker(monitorService, MonitorService.class, URL.valueOf("dubbo://127.0.0.1:17979/" + MonitorService.class.getName())));
    try {
        Monitor monitor = null;
        long start = System.currentTimeMillis();
        while (System.currentTimeMillis() - start < 60000) {
            monitor = monitorFactory.getMonitor(URL.valueOf("dubbo://127.0.0.1:17979?interval=10"));
            if (monitor == null) {
                continue;
            }
            try {
                monitor.collect(statistics);
                int i = 0;
                while (monitorService.getStatistics() == null && i < 200) {
                    i++;
                    Thread.sleep(10);
                }
                URL result = monitorService.getStatistics();
                Assertions.assertEquals(1, result.getParameter(MonitorService.SUCCESS, 0));
                Assertions.assertEquals(3, result.getParameter(MonitorService.ELAPSED, 0));
            } finally {
                monitor.destroy();
            }
            break;
        }
        Assertions.assertNotNull(monitor);
    } finally {
        exporter.unexport();
    }
}
Also used : Monitor(org.apache.dubbo.monitor.Monitor) MonitorFactory(org.apache.dubbo.monitor.MonitorFactory) ProxyFactory(org.apache.dubbo.rpc.ProxyFactory) MonitorService(org.apache.dubbo.monitor.MonitorService) Protocol(org.apache.dubbo.rpc.Protocol) URL(org.apache.dubbo.common.URL) URLBuilder(org.apache.dubbo.common.URLBuilder) Test(org.junit.jupiter.api.Test)

Example 48 with ProxyFactory

use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by apache.

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)

Example 49 with ProxyFactory

use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by apache.

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 50 with ProxyFactory

use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by apache.

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)

Aggregations

URL (org.apache.dubbo.common.URL)54 ProxyFactory (org.apache.dubbo.rpc.ProxyFactory)54 Protocol (org.apache.dubbo.rpc.Protocol)50 Test (org.junit.jupiter.api.Test)50 GenericService (org.apache.dubbo.rpc.service.GenericService)20 DemoService (org.apache.dubbo.service.DemoService)12 DemoServiceImpl (org.apache.dubbo.service.DemoServiceImpl)12 ComplexObject (org.apache.dubbo.service.ComplexObject)10 Invoker (org.apache.dubbo.rpc.Invoker)6 RpcException (org.apache.dubbo.rpc.RpcException)6 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Invocation (org.apache.dubbo.rpc.Invocation)4 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)4 LoadBalance (org.apache.dubbo.rpc.cluster.LoadBalance)4 StaticDirectory (org.apache.dubbo.rpc.cluster.directory.StaticDirectory)4 AbstractClusterInvoker (org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker)4 ReferenceConfig (com.alibaba.dubbo.config.ReferenceConfig)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2