Search in sources :

Example 6 with ProxyFactory

use of com.alibaba.dubbo.rpc.ProxyFactory in project dubbo by alibaba.

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();
    URL url = URL.valueOf("hessian://127.0.0.1:5342/" + 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) {
        Assert.assertEquals(true, expected.isTimeout());
    } finally {
        invoker.destroy();
        exporter.unexport();
    }
}
Also used : ProxyFactory(com.alibaba.dubbo.rpc.ProxyFactory) RpcException(com.alibaba.dubbo.rpc.RpcException) Protocol(com.alibaba.dubbo.rpc.Protocol) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 7 with ProxyFactory

use of com.alibaba.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 URL("dubbo", "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);
    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();
                Assert.assertEquals(1, result.getParameter(MonitorService.SUCCESS, 0));
                Assert.assertEquals(3, result.getParameter(MonitorService.ELAPSED, 0));
            } finally {
                monitor.destroy();
            }
            break;
        }
        Assert.assertNotNull(monitor);
    } finally {
        exporter.unexport();
    }
}
Also used : Monitor(com.alibaba.dubbo.monitor.Monitor) MonitorFactory(com.alibaba.dubbo.monitor.MonitorFactory) ProxyFactory(com.alibaba.dubbo.rpc.ProxyFactory) MonitorService(com.alibaba.dubbo.monitor.MonitorService) Protocol(com.alibaba.dubbo.rpc.Protocol) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Aggregations

URL (com.alibaba.dubbo.common.URL)7 ProxyFactory (com.alibaba.dubbo.rpc.ProxyFactory)7 Protocol (com.alibaba.dubbo.rpc.Protocol)6 Test (org.junit.Test)6 RpcException (com.alibaba.dubbo.rpc.RpcException)2 Monitor (com.alibaba.dubbo.monitor.Monitor)1 MonitorFactory (com.alibaba.dubbo.monitor.MonitorFactory)1 MonitorService (com.alibaba.dubbo.monitor.MonitorService)1 Invocation (com.alibaba.dubbo.rpc.Invocation)1 Invoker (com.alibaba.dubbo.rpc.Invoker)1 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)1 LoadBalance (com.alibaba.dubbo.rpc.cluster.LoadBalance)1 StaticDirectory (com.alibaba.dubbo.rpc.cluster.directory.StaticDirectory)1 AbstractClusterInvoker (com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker)1 MyException (com.alibaba.dubbo.rpc.protocol.hessian.HessianServiceImpl.MyException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1