Search in sources :

Example 1 with Protocol

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

the class MockClusterInvokerTest method testMockInvokerInvoke_forcemock.

/**
	 * 测试mock策略是否正常-force-mork
	 */
@Test
public void testMockInvokerInvoke_forcemock() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName());
    url = url.addParameter(Constants.MOCK_KEY, "force:return null");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    URL mockUrl = URL.valueOf("mock://localhost/" + IHelloService.class.getName() + "?getSomething.mock=return aa&getSomething3xx.mock=return xx").addParameters(url.getParameters());
    Protocol protocol = new MockProtocol();
    Invoker<IHelloService> mInvoker1 = protocol.refer(IHelloService.class, mockUrl);
    invokers.add(mInvoker1);
    //方法配置了mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getSomething");
    Result ret = cluster.invoke(invocation);
    Assert.assertEquals("aa", ret.getValue());
    //如果没有配置mock,则直接返回null
    invocation = new RpcInvocation();
    invocation.setMethodName("getSomething2");
    ret = cluster.invoke(invocation);
    Assert.assertEquals(null, ret.getValue());
    //如果没有配置mock,则直接返回null
    invocation = new RpcInvocation();
    invocation.setMethodName("sayHello");
    ret = cluster.invoke(invocation);
    Assert.assertEquals(null, ret.getValue());
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) MockProtocol(com.alibaba.dubbo.rpc.support.MockProtocol) Protocol(com.alibaba.dubbo.rpc.Protocol) MockProtocol(com.alibaba.dubbo.rpc.support.MockProtocol) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result) Test(org.junit.Test)

Example 2 with Protocol

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

the class MockClusterInvokerTest method testMockInvokerInvoke_forcemock_defaultreturn.

@Test
public void testMockInvokerInvoke_forcemock_defaultreturn() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName());
    url = url.addParameter(Constants.MOCK_KEY, "force");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    URL mockUrl = URL.valueOf("mock://localhost/" + IHelloService.class.getName() + "?getSomething.mock=return aa&getSomething3xx.mock=return xx&sayHello.mock=return ").addParameters(url.getParameters());
    Protocol protocol = new MockProtocol();
    Invoker<IHelloService> mInvoker1 = protocol.refer(IHelloService.class, mockUrl);
    invokers.add(mInvoker1);
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("sayHello");
    Result ret = cluster.invoke(invocation);
    Assert.assertEquals(null, ret.getValue());
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) MockProtocol(com.alibaba.dubbo.rpc.support.MockProtocol) Protocol(com.alibaba.dubbo.rpc.Protocol) MockProtocol(com.alibaba.dubbo.rpc.support.MockProtocol) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result) Test(org.junit.Test)

Example 3 with Protocol

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

the class ProtocolConfig method destroyAll.

public static void destroyAll() {
    AbstractRegistryFactory.destroyAll();
    ExtensionLoader<Protocol> loader = ExtensionLoader.getExtensionLoader(Protocol.class);
    for (String protocolName : loader.getLoadedExtensions()) {
        try {
            Protocol protocol = loader.getLoadedExtension(protocolName);
            if (protocol != null) {
                protocol.destroy();
            }
        } catch (Throwable t) {
            logger.warn(t.getMessage(), t);
        }
    }
}
Also used : Protocol(com.alibaba.dubbo.rpc.Protocol)

Example 4 with Protocol

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

the class RegistryProtocolTest method testExport.

@Test
public void testExport() {
    RegistryProtocol registryProtocol = new RegistryProtocol();
    registryProtocol.setCluster(new FailfastCluster());
    registryProtocol.setRegistryFactory(ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension());
    Protocol dubboProtocol = DubboProtocol.getDubboProtocol();
    registryProtocol.setProtocol(dubboProtocol);
    URL newRegistryUrl = registryUrl.addParameter(Constants.EXPORT_KEY, serviceUrl);
    DubboInvoker<DemoService> invoker = new DubboInvoker<DemoService>(DemoService.class, newRegistryUrl, new ExchangeClient[] { new MockedClient("10.20.20.20", 2222, true) });
    Exporter<DemoService> exporter = registryProtocol.export(invoker);
    Exporter<DemoService> exporter2 = registryProtocol.export(invoker);
    //同一个invoker,多次export的exporter不同
    Assert.assertNotSame(exporter, exporter2);
    exporter.unexport();
    exporter2.unexport();
}
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) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 5 with Protocol

use of com.alibaba.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");
    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 com.alibaba.dubbo.rpc.Protocol is not adaptive method!"));
    }
    assertEquals("ok2", echoProxy.echo("ok2"));
}
Also used : Protocol(com.alibaba.dubbo.rpc.Protocol) Test(org.junit.Test)

Aggregations

Protocol (com.alibaba.dubbo.rpc.Protocol)15 Test (org.junit.Test)12 URL (com.alibaba.dubbo.common.URL)10 ProxyFactory (com.alibaba.dubbo.rpc.ProxyFactory)5 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 ConsumerConfig (com.alibaba.dubbo.config.ConsumerConfig)1 ProtocolConfig (com.alibaba.dubbo.config.ProtocolConfig)1 RegistryConfig (com.alibaba.dubbo.config.RegistryConfig)1 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