本文整理汇总了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());
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}