use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class RegistryDirectoryTest method testNotify_MockProviderOnly.
/**
* Test mock provider distribution
*/
@Test
public void testNotify_MockProviderOnly() {
RegistryDirectory registryDirectory = getRegistryDirectory();
List<URL> serviceUrls = new ArrayList<URL>();
serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1,getXXX2"));
serviceUrls.add(SERVICEURL.setProtocol(Constants.MOCK_PROTOCOL));
registryDirectory.notify(serviceUrls);
Assert.assertEquals(true, registryDirectory.isAvailable());
invocation = new RpcInvocation();
List invokers = registryDirectory.list(invocation);
Assert.assertEquals(2, invokers.size());
RpcInvocation mockinvocation = new RpcInvocation();
mockinvocation.setAttachment(Constants.INVOCATION_NEED_MOCK, "true");
invokers = registryDirectory.list(mockinvocation);
Assert.assertEquals(1, invokers.size());
}
use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_check_ListString.
@SuppressWarnings("unchecked")
@Test
public void testMockInvokerFromOverride_Invoke_check_ListString() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("getListString.mock", "force:return [\"hi\",\"hi2\"]").addParameter("invoke_return_error", "true");
Invoker<IHelloService> cluster = getClusterInvoker(url);
// Configured with mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getListString");
Result ret = cluster.invoke(invocation);
List<String> rl = (List<String>) ret.getValue();
Assert.assertEquals(2, rl.size());
Assert.assertEquals("hi", rl.get(0));
}
use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class MockClusterInvokerTest method testMockInvokerInvoke_forcemock.
/**
* Test if mock policy works fine: force-mock
*/
@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);
// Configured with mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getSomething");
Result ret = cluster.invoke(invocation);
Assert.assertEquals("aa", ret.getValue());
// If no mock was configured, return null directly
invocation = new RpcInvocation();
invocation.setMethodName("getSomething2");
ret = cluster.invoke(invocation);
Assert.assertEquals(null, ret.getValue());
// If no mock was configured, return null directly
invocation = new RpcInvocation();
invocation.setMethodName("sayHello");
ret = cluster.invoke(invocation);
Assert.assertEquals(null, ret.getValue());
}
use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_Fock_WithDefault.
/**
* Test if mock policy works fine: fail-mock
*/
@Test
public void testMockInvokerFromOverride_Invoke_Fock_WithDefault() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("mock", "fail:return null").addParameter("getSomething.mock", "fail:return x").addParameter("getSomething2.mock", "force:return y").addParameter("invoke_return_error", "true");
Invoker<IHelloService> cluster = getClusterInvoker(url);
// Configured with mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getSomething");
Result ret = cluster.invoke(invocation);
Assert.assertEquals("x", ret.getValue());
// If no mock was configured, return null directly
invocation = new RpcInvocation();
invocation.setMethodName("getSomething2");
ret = cluster.invoke(invocation);
Assert.assertEquals("y", ret.getValue());
// If no mock was configured, return null directly
invocation = new RpcInvocation();
invocation.setMethodName("getSomething3");
ret = cluster.invoke(invocation);
Assert.assertEquals(null, ret.getValue());
// If no mock was configured, return null directly
invocation = new RpcInvocation();
invocation.setMethodName("sayHello");
ret = cluster.invoke(invocation);
Assert.assertEquals(null, ret.getValue());
}
use of com.alibaba.dubbo.rpc.RpcInvocation 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());
}
Aggregations