TimeoutFilter implements Filter, Filter.Listener { @Override public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { return invoker.invoke(invocation); }  @Override Result invoke(Invoker<?> invoker, Invocation invocation); @Override void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation); @Override void onError(Throwable t, Invoker<?> invoker, Invocation invocation);  }
@Test public void testInvokeWithoutTimeout() throws Exception { int timeout = 3000; Invoker invoker = Mockito.mock(Invoker.class); when(invoker.invoke(any(Invocation.class))).thenReturn(new AppResponse("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("Dubbo", result.getValue()); }