ConsumerContextFilter implements Filter { public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { RpcContext.getContext() .setInvoker(invoker) .setInvocation(invocation) .setLocalAddress(NetUtils.getLocalHost(), 0) .setRemoteAddress(invoker.getUrl().getHost(), invoker.getUrl().getPort()); if (invocation instanceof RpcInvocation) { ((RpcInvocation)invocation).setInvoker(invoker); } try { return invoker.invoke(invocation); } finally { RpcContext.getContext().clearAttachments(); } }  Result invoke(Invoker<?> invoker, Invocation invocation);  }
@Test public void testSetContext(){ URL url = URL.valueOf("test: 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()); }