当前位置: 首页>>代码示例>>Java>>正文


Java MockProtocol类代码示例

本文整理汇总了Java中com.alibaba.dubbo.rpc.support.MockProtocol的典型用法代码示例。如果您正苦于以下问题:Java MockProtocol类的具体用法?Java MockProtocol怎么用?Java MockProtocol使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MockProtocol类属于com.alibaba.dubbo.rpc.support包,在下文中一共展示了MockProtocol类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testMockInvokerInvoke_forcemock_defaultreturn

import com.alibaba.dubbo.rpc.support.MockProtocol; //导入依赖的package包/类
@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());
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:19,代码来源:MockClusterInvokerTest.java

示例2: testMockInvokerInvoke_forcemock_defaultreturn

import com.alibaba.dubbo.rpc.support.MockProtocol; //导入依赖的package包/类
@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());
}
 
开发者ID:l1325169021,项目名称:github-test,代码行数:19,代码来源:MockClusterInvokerTest.java

示例3: testMockInvokerInvoke_normal

import com.alibaba.dubbo.rpc.support.MockProtocol; //导入依赖的package包/类
/**
 * 测试mock策略是否正常-fail-mock
 */
@Test
public void testMockInvokerInvoke_normal(){
	URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName());
	url = url.addParameter(Constants.MOCK_KEY, "fail" );
	Invoker<IHelloService> cluster = getClusterInvoker(url);        
       URL mockUrl = URL.valueOf("mock://localhost/"+IHelloService.class.getName()
			+"?getSomething.mock=return aa");
	
	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("something", ret.getValue());
       
       //如果没有配置mock,则直接返回null
       invocation = new RpcInvocation();
	invocation.setMethodName("sayHello");
       ret = cluster.invoke(invocation);
       Assert.assertEquals(null, ret.getValue());
}
 
开发者ID:xingmima,项目名称:dubbos,代码行数:28,代码来源:MockClusterInvokerTest.java

示例4: testMockInvokerInvoke_normal

import com.alibaba.dubbo.rpc.support.MockProtocol; //导入依赖的package包/类
/**
 * 测试mock策略是否正常-fail-mock
 */
@Test
public void testMockInvokerInvoke_normal() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName());
    url = url.addParameter(Constants.MOCK_KEY, "fail");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    URL mockUrl = URL.valueOf("mock://localhost/" + IHelloService.class.getName()
            + "?getSomething.mock=return aa");

    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("something", ret.getValue());

    //如果没有配置mock,则直接返回null
    invocation = new RpcInvocation();
    invocation.setMethodName("sayHello");
    ret = cluster.invoke(invocation);
    Assert.assertEquals(null, ret.getValue());
}
 
开发者ID:hufeng,项目名称:dubbo2.js,代码行数:28,代码来源:MockClusterInvokerTest.java

示例5: testMockInvokerInvoke_failmock

import com.alibaba.dubbo.rpc.support.MockProtocol; //导入依赖的package包/类
/**
 * 测试mock策略是否正常-fail-mock
 */
@Test
public void testMockInvokerInvoke_failmock(){
	URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName())
			.addParameter(Constants.MOCK_KEY, "fail:return null" )
			.addParameter("invoke_return_error", "true" );
	Invoker<IHelloService> cluster = getClusterInvoker(url);        
       URL mockUrl = URL.valueOf("mock://localhost/"+IHelloService.class.getName()
			+"?getSomething.mock=return aa").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());
}
 
开发者ID:xingmima,项目名称:dubbos,代码行数:35,代码来源:MockClusterInvokerTest.java

示例6: testMockInvokerInvoke_forcemock

import com.alibaba.dubbo.rpc.support.MockProtocol; //导入依赖的package包/类
/**
 * 测试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());
}
 
开发者ID:xingmima,项目名称:dubbos,代码行数:35,代码来源:MockClusterInvokerTest.java


注:本文中的com.alibaba.dubbo.rpc.support.MockProtocol类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。