### Question:
TimeoutFilter implements Filter { @Override public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { long start = System.currentTimeMillis(); Result result = invoker.invoke(invocation); long elapsed = System.currentTimeMillis() - start; if (invoker.getUrl() != null && elapsed > invoker.getUrl().getMethodParameter(invocation.getMethodName(), "timeout", Integer.MAX_VALUE)) { if (logger.isWarnEnabled()) { logger.warn("invoke time out. method: " + invocation.getMethodName() + " arguments: " + Arrays.toString(invocation.getArguments()) + " , url is " + invoker.getUrl() + ", invoke elapsed " + elapsed + " ms."); } } return result; }  @Override Result invoke(Invoker<?> invoker, Invocation invocation);  }### Answer:
@Test public void testInvokeWithoutTimeout() throws Exception { int timeout = 3000; Invoker invoker = Mockito.mock(Invoker.class); when(invoker.invoke(any(Invocation.class))).thenReturn(new RpcResult("result")); when(invoker.getUrl()).thenReturn(URL.valueOf("test: Invocation invocation = Mockito.mock(Invocation.class); when(invocation.getMethodName()).thenReturn("testInvokeWithoutTimeout"); Result result = timeoutFilter.invoke(invoker, invocation); Assertions.assertEquals("result", result.getValue()); }
@Test public void testInvokeWithTimeout() throws Exception { int timeout = 100; URL url = URL.valueOf("test: Invoker invoker = new BlockMyInvoker(url, (timeout + 100)); Invocation invocation = Mockito.mock(Invocation.class); when(invocation.getMethodName()).thenReturn("testInvokeWithTimeout"); Result result = timeoutFilter.invoke(invoker, invocation); Assertions.assertEquals("alibaba", result.getValue()); }