use of org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker in project dubbo by alibaba.
the class ConsumerContextClusterInterceptorTest method testBefore.
@Test
public void testBefore() {
AbstractClusterInvoker mockInvoker = Mockito.mock(AbstractClusterInvoker.class);
RpcContext serverContextBefore = RpcContext.getServerContext();
RpcInvocation rpcInvocation = new RpcInvocation();
interceptor.before(mockInvoker, rpcInvocation);
RpcContext serverContextAfter = RpcContext.getServerContext();
Assertions.assertNotSame(serverContextBefore, serverContextAfter);
Assertions.assertSame(mockInvoker, rpcInvocation.getInvoker());
}
use of org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker in project dubbo by alibaba.
the class MockClusterInvokerTest method getClusterInvokerMock.
private Invoker<IHelloService> getClusterInvokerMock(URL url, Invoker<IHelloService> mockInvoker) {
// As `javassist` have a strict restriction of argument types, request will fail if Invocation do not contains complete parameter type information
final URL durl = url.addParameter("proxy", "jdk");
invokers.clear();
ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getExtension("jdk");
Invoker<IHelloService> invoker1 = proxy.getInvoker(new HelloService(), IHelloService.class, durl);
invokers.add(invoker1);
if (mockInvoker != null) {
invokers.add(mockInvoker);
}
StaticDirectory<IHelloService> dic = new StaticDirectory<IHelloService>(durl, invokers, null);
dic.buildRouterChain();
AbstractClusterInvoker<IHelloService> cluster = new AbstractClusterInvoker(dic) {
@Override
protected Result doInvoke(Invocation invocation, List invokers, LoadBalance loadbalance) throws RpcException {
if (durl.getParameter("invoke_return_error", false)) {
throw new RpcException(RpcException.TIMEOUT_EXCEPTION, "test rpc exception");
} else {
return ((Invoker<?>) invokers.get(0)).invoke(invocation);
}
}
};
return new MockClusterInvoker<IHelloService>(dic, cluster);
}
use of org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker in project dubbo by alibaba.
the class MockProviderRpcExceptionTest method getClusterInvokerMock.
private Invoker<IHelloRpcService> getClusterInvokerMock(URL url, Invoker<IHelloRpcService> mockInvoker) {
// As `javassist` have a strict restriction of argument types, request will fail if Invocation do not contains complete parameter type information
final URL durl = url.addParameter("proxy", "jdk");
invokers.clear();
ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getExtension("jdk");
Invoker<IHelloRpcService> invoker1 = proxy.getInvoker(new HelloRpcService(), IHelloRpcService.class, durl);
invokers.add(invoker1);
if (mockInvoker != null) {
invokers.add(mockInvoker);
}
StaticDirectory<IHelloRpcService> dic = new StaticDirectory<IHelloRpcService>(durl, invokers, null);
dic.buildRouterChain();
AbstractClusterInvoker<IHelloRpcService> cluster = new AbstractClusterInvoker(dic) {
@Override
protected Result doInvoke(Invocation invocation, List invokers, LoadBalance loadbalance) throws RpcException {
if (durl.getParameter("invoke_return_error", false)) {
throw new RpcException(RpcException.TIMEOUT_EXCEPTION, "test rpc exception ");
} else {
return ((Invoker<?>) invokers.get(0)).invoke(invocation);
}
}
};
return new MockClusterInvoker<IHelloRpcService>(dic, cluster);
}
Aggregations