Search in sources :

Example 11 with Protocol

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

the class HessianProtocolTest method testHessianProtocol.

@Test
public void testHessianProtocol() {
    HessianServiceImpl server = new HessianServiceImpl();
    Assert.assertFalse(server.isCalled());
    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");
    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");
    Assert.assertTrue(server.isCalled());
    Assert.assertEquals("Hello, haha", result);
    invoker.destroy();
    exporter.unexport();
}
Also used : ProxyFactory(com.alibaba.dubbo.rpc.ProxyFactory) Protocol(com.alibaba.dubbo.rpc.Protocol) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 12 with Protocol

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

the class HessianProtocolTest method testCustomException.

@Test
public void testCustomException() {
    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");
    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.customException();
        fail();
    } catch (MyException expected) {
    }
    invoker.destroy();
    exporter.unexport();
}
Also used : MyException(com.alibaba.dubbo.rpc.protocol.hessian.HessianServiceImpl.MyException) ProxyFactory(com.alibaba.dubbo.rpc.ProxyFactory) Protocol(com.alibaba.dubbo.rpc.Protocol) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 13 with Protocol

use of com.alibaba.dubbo.rpc.Protocol 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 14 with Protocol

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

the class RegistryProtocolTest method destroyRegistryProtocol.

private void destroyRegistryProtocol() {
    Protocol registry = RegistryProtocol.getRegistryProtocol();
    registry.destroy();
}
Also used : DubboProtocol(com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol) RegistryProtocol(com.alibaba.dubbo.registry.integration.RegistryProtocol) Protocol(com.alibaba.dubbo.rpc.Protocol)

Example 15 with Protocol

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

the class RegistryProtocolTest method testExportUrlNull.

@Test(expected = IllegalArgumentException.class)
public void testExportUrlNull() {
    RegistryProtocol registryProtocol = new RegistryProtocol();
    registryProtocol.setCluster(new FailfastCluster());
    Protocol dubboProtocol = DubboProtocol.getDubboProtocol();
    registryProtocol.setProtocol(dubboProtocol);
    Invoker<DemoService> invoker = new DubboInvoker<DemoService>(DemoService.class, registryUrl, new ExchangeClient[] { new MockedClient("10.20.20.20", 2222, true) });
    registryProtocol.export(invoker);
}
Also used : FailfastCluster(com.alibaba.dubbo.rpc.cluster.support.FailfastCluster) RegistryProtocol(com.alibaba.dubbo.registry.integration.RegistryProtocol) DubboInvoker(com.alibaba.dubbo.rpc.protocol.dubbo.DubboInvoker) DubboProtocol(com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol) RegistryProtocol(com.alibaba.dubbo.registry.integration.RegistryProtocol) Protocol(com.alibaba.dubbo.rpc.Protocol) Test(org.junit.Test)

Aggregations

Protocol (com.alibaba.dubbo.rpc.Protocol)16 Test (org.junit.Test)13 URL (com.alibaba.dubbo.common.URL)11 ProxyFactory (com.alibaba.dubbo.rpc.ProxyFactory)6 Result (com.alibaba.dubbo.rpc.Result)4 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)4 MockProtocol (com.alibaba.dubbo.rpc.support.MockProtocol)4 RegistryProtocol (com.alibaba.dubbo.registry.integration.RegistryProtocol)3 DubboProtocol (com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol)3 FailfastCluster (com.alibaba.dubbo.rpc.cluster.support.FailfastCluster)2 DubboInvoker (com.alibaba.dubbo.rpc.protocol.dubbo.DubboInvoker)2 ReferenceBean (com.alibaba.dubbo.config.spring.ReferenceBean)1 ServiceBean (com.alibaba.dubbo.config.spring.ServiceBean)1 Monitor (com.alibaba.dubbo.monitor.Monitor)1 MonitorFactory (com.alibaba.dubbo.monitor.MonitorFactory)1 MonitorService (com.alibaba.dubbo.monitor.MonitorService)1 RpcException (com.alibaba.dubbo.rpc.RpcException)1 MyException (com.alibaba.dubbo.rpc.protocol.hessian.HessianServiceImpl.MyException)1 Method (java.lang.reflect.Method)1 HashSet (java.util.HashSet)1