Search in sources :

Example 31 with ProxyFactory

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

the class HessianProtocolTest method testTimeOut.

@Test
public void testTimeOut() {
    HessianServiceImpl server = new HessianServiceImpl();
    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&timeout=10");
    Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
    Invoker<HessianService> invoker = protocol.refer(HessianService.class, url);
    HessianService client = proxyFactory.getProxy(invoker);
    try {
        client.timeOut(6000);
        fail();
    } catch (RpcException expected) {
        Assertions.assertTrue(expected.isTimeout());
    } finally {
        invoker.destroy();
        exporter.unexport();
    }
}
Also used : ProxyFactory(org.apache.dubbo.rpc.ProxyFactory) RpcException(org.apache.dubbo.rpc.RpcException) Protocol(org.apache.dubbo.rpc.Protocol) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 32 with ProxyFactory

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

the class MockProviderRpcExceptionTest method getClusterInvokerMock.

private Invoker<IHelloRpcService> getClusterInvokerMock(URL url, Invoker<IHelloRpcService> mockInvoker) {
    // As `javassist` have a strict restriction of argument types, request will fail if Invocation do not contains complete parameter type information
    final URL durl = url.addParameter("proxy", "jdk");
    invokers.clear();
    ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getExtension("jdk");
    Invoker<IHelloRpcService> invoker1 = proxy.getInvoker(new HelloRpcService(), IHelloRpcService.class, durl);
    invokers.add(invoker1);
    if (mockInvoker != null) {
        invokers.add(mockInvoker);
    }
    StaticDirectory<IHelloRpcService> dic = new StaticDirectory<IHelloRpcService>(durl, invokers, null);
    dic.buildRouterChain();
    AbstractClusterInvoker<IHelloRpcService> cluster = new AbstractClusterInvoker(dic) {

        @Override
        protected Result doInvoke(Invocation invocation, List invokers, LoadBalance loadbalance) throws RpcException {
            if (durl.getParameter("invoke_return_error", false)) {
                throw new RpcException(RpcException.TIMEOUT_EXCEPTION, "test rpc exception ");
            } else {
                return ((Invoker<?>) invokers.get(0)).invoke(invocation);
            }
        }
    };
    return new MockClusterInvoker<IHelloRpcService>(dic, cluster);
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) ProxyFactory(org.apache.dubbo.rpc.ProxyFactory) AbstractClusterInvoker(org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker) URL(org.apache.dubbo.common.URL) StaticDirectory(org.apache.dubbo.rpc.cluster.directory.StaticDirectory) Invoker(org.apache.dubbo.rpc.Invoker) AbstractClusterInvoker(org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker) LoadBalance(org.apache.dubbo.rpc.cluster.LoadBalance) RpcException(org.apache.dubbo.rpc.RpcException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 33 with ProxyFactory

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

the class MockClusterInvokerTest method getClusterInvokerMock.

private Invoker<IHelloService> getClusterInvokerMock(URL url, Invoker<IHelloService> mockInvoker) {
    // As `javassist` have a strict restriction of argument types, request will fail if Invocation do not contains complete parameter type information
    final URL durl = url.addParameter("proxy", "jdk");
    invokers.clear();
    ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getExtension("jdk");
    Invoker<IHelloService> invoker1 = proxy.getInvoker(new HelloService(), IHelloService.class, durl);
    invokers.add(invoker1);
    if (mockInvoker != null) {
        invokers.add(mockInvoker);
    }
    StaticDirectory<IHelloService> dic = new StaticDirectory<IHelloService>(durl, invokers, null);
    dic.buildRouterChain();
    AbstractClusterInvoker<IHelloService> cluster = new AbstractClusterInvoker(dic) {

        @Override
        protected Result doInvoke(Invocation invocation, List invokers, LoadBalance loadbalance) throws RpcException {
            if (durl.getParameter("invoke_return_error", false)) {
                throw new RpcException(RpcException.TIMEOUT_EXCEPTION, "test rpc exception");
            } else {
                return ((Invoker<?>) invokers.get(0)).invoke(invocation);
            }
        }
    };
    return new MockClusterInvoker<IHelloService>(dic, cluster);
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) ProxyFactory(org.apache.dubbo.rpc.ProxyFactory) AbstractClusterInvoker(org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker) URL(org.apache.dubbo.common.URL) StaticDirectory(org.apache.dubbo.rpc.cluster.directory.StaticDirectory) Invoker(org.apache.dubbo.rpc.Invoker) AbstractClusterInvoker(org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker) LoadBalance(org.apache.dubbo.rpc.cluster.LoadBalance) RpcException(org.apache.dubbo.rpc.RpcException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 34 with ProxyFactory

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

the class MockProviderRpcExceptionTest method getClusterInvokerMock.

private Invoker<IHelloRpcService> getClusterInvokerMock(URL url, Invoker<IHelloRpcService> mockInvoker) {
    // As `javassist` have a strict restriction of argument types, request will fail if Invocation do not contains complete parameter type information
    final URL durl = url.addParameter("proxy", "jdk");
    invokers.clear();
    ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getExtension("jdk");
    Invoker<IHelloRpcService> invoker1 = proxy.getInvoker(new HelloRpcService(), IHelloRpcService.class, durl);
    invokers.add(invoker1);
    if (mockInvoker != null) {
        invokers.add(mockInvoker);
    }
    StaticDirectory<IHelloRpcService> dic = new StaticDirectory<IHelloRpcService>(durl, invokers, null);
    dic.buildRouterChain();
    AbstractClusterInvoker<IHelloRpcService> cluster = new AbstractClusterInvoker(dic) {

        @Override
        protected Result doInvoke(Invocation invocation, List invokers, LoadBalance loadbalance) throws RpcException {
            if (durl.getParameter("invoke_return_error", false)) {
                throw new RpcException(RpcException.TIMEOUT_EXCEPTION, "test rpc exception ");
            } else {
                return ((Invoker<?>) invokers.get(0)).invoke(invocation);
            }
        }
    };
    return new MockClusterInvoker<IHelloRpcService>(dic, cluster);
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) ProxyFactory(org.apache.dubbo.rpc.ProxyFactory) AbstractClusterInvoker(org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker) URL(org.apache.dubbo.common.URL) StaticDirectory(org.apache.dubbo.rpc.cluster.directory.StaticDirectory) Invoker(org.apache.dubbo.rpc.Invoker) AbstractClusterInvoker(org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker) LoadBalance(org.apache.dubbo.rpc.cluster.LoadBalance) RpcException(org.apache.dubbo.rpc.RpcException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 35 with ProxyFactory

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

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)

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