use of com.alibaba.dubbo.rpc.support.DemoService in project dubbo by alibaba.
the class ConsumerContextFilterTest method testSetContext.
@Test
public void testSetContext() {
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
Invoker<DemoService> invoker = new MyInvoker<DemoService>(url);
Invocation invocation = new MockInvocation();
consumerContextFilter.invoke(invoker, invocation);
assertEquals(invoker, RpcContext.getContext().getInvoker());
assertEquals(invocation, RpcContext.getContext().getInvocation());
assertEquals(NetUtils.getLocalHost() + ":0", RpcContext.getContext().getLocalAddressString());
assertEquals("test:11", RpcContext.getContext().getRemoteAddressString());
}
use of com.alibaba.dubbo.rpc.support.DemoService in project dubbo by alibaba.
the class ContextFilterTest method testWithAttachments.
@Test
public void testWithAttachments() {
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
Invoker<DemoService> invoker = new MyInvoker<DemoService>(url);
Invocation invocation = new MockInvocation();
Result result = contextFilter.invoke(invoker, invocation);
assertNull(RpcContext.getContext().getInvoker());
}
use of com.alibaba.dubbo.rpc.support.DemoService in project dubbo by alibaba.
the class DeprecatedFilterTest method testDeprecatedFilter.
@Test
public void testDeprecatedFilter() {
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1&echo." + Constants.DEPRECATED_KEY + "=true");
LogUtil.start();
deprecatedFilter.invoke(new MyInvoker<DemoService>(url), new MockInvocation());
assertEquals(1, LogUtil.findMessage("The service method com.alibaba.dubbo.rpc.support.DemoService.echo(String) is DEPRECATED"));
LogUtil.stop();
}
use of com.alibaba.dubbo.rpc.support.DemoService in project dubbo by alibaba.
the class EchoFilterTest method testEcho.
@SuppressWarnings("unchecked")
@Test
public void testEcho() {
Invocation invocation = EasyMock.createMock(Invocation.class);
EasyMock.expect(invocation.getMethodName()).andReturn("$echo").anyTimes();
EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Enum.class }).anyTimes();
EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
EasyMock.expect(invocation.getAttachments()).andReturn(null).anyTimes();
EasyMock.replay(invocation);
Invoker<DemoService> invoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
RpcResult result = new RpcResult();
result.setValue("High");
EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
EasyMock.replay(invoker);
Result filterResult = echoFilter.invoke(invoker, invocation);
assertEquals("hello", filterResult.getValue());
}
use of com.alibaba.dubbo.rpc.support.DemoService in project dubbo by alibaba.
the class ExceptionFilterTest method testRpcException.
@SuppressWarnings("unchecked")
@Test
public void testRpcException() {
Logger logger = EasyMock.createMock(Logger.class);
RpcContext.getContext().setRemoteAddress("127.0.0.1", 1234);
RpcException exception = new RpcException("TestRpcException");
logger.error(EasyMock.eq("Got unchecked and undeclared exception which called by 127.0.0.1. service: " + DemoService.class.getName() + ", method: sayHello, exception: " + RpcException.class.getName() + ": TestRpcException"), EasyMock.eq(exception));
ExceptionFilter exceptionFilter = new ExceptionFilter(logger);
RpcInvocation invocation = new RpcInvocation("sayHello", new Class<?>[] { String.class }, new Object[] { "world" });
Invoker<DemoService> invoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class);
EasyMock.expect(invoker.invoke(EasyMock.eq(invocation))).andThrow(exception);
EasyMock.replay(logger, invoker);
try {
exceptionFilter.invoke(invoker, invocation);
} catch (RpcException e) {
assertEquals("TestRpcException", e.getMessage());
}
EasyMock.verify(logger, invoker);
RpcContext.removeContext();
}
Aggregations