@Test public void testWithTimeoutReached() throws Exception { RequestContext rc = mock(RequestContext.class); doAnswer(new Answer<Result>() { @Override public Result answer(InvocationOnMock invocation) throws Throwable { Thread.sleep(1000); return Results.ok("Done"); } }).when(rc).proceed(); Route route = mock(Route.class); when(route.getUrl()).thenReturn("/"); when(rc.route()).thenReturn(route); Async async = mock(Async.class); when(async.timeout()).thenReturn(10l); when(async.unit()).thenReturn(TimeUnit.MILLISECONDS); Result result = interceptor.call(async, rc); assertThat(result).isInstanceOf(AsyncResult.class); final Result[] retrieved = {null}; final Throwable[] errors = {null}; ManagedFutureTask<Result> r = executor.submit(((AsyncResult) result).callable()) .onSuccess(new ManagedFutureTask.SuccessCallback<Result>() { @Override public void onSuccess(ManagedFutureTask<Result> future, Result result) { retrieved[0] = result; } }) .onFailure(new ManagedFutureTask.FailureCallback() { @Override public void onFailure(ManagedFutureTask future, Throwable throwable) { errors[0] = throwable; } }); Thread.sleep(100); assertThat(retrieved[0]).isNull(); assertThat(errors[0]).isNotNull().isInstanceOf(HttpException.class); assertThat(errors[0].getMessage()) .contains("Request timeout"); }
@Override public Result call(final Async configuration, final RequestContext context) throws Exception { Callable<Result> callable; if (configuration.timeout() > 0) { callable = new ResultRetriever(context, configuration); } else { callable = new Callable<Result>() { @Override public Result call() throws Exception { return context.proceed(); } }; } return new AsyncResult(callable); }
AsyncInterceptor extends Interceptor<Async> { @Override public Result call(final Async configuration, final RequestContext context) throws Exception { Callable<Result> callable; if (configuration.timeout() > 0) { callable = new ResultRetriever(context, configuration); } else { callable = new Callable<Result>() { @Override public Result call() throws Exception { return context.proceed(); } }; } return new AsyncResult(callable); } }
AsyncInterceptor extends Interceptor<Async> { @Override public Result call(final Async configuration, final RequestContext context) throws Exception { Callable<Result> callable; if (configuration.timeout() > 0) { callable = new ResultRetriever(context, configuration); } else { callable = new Callable<Result>() { @Override public Result call() throws Exception { return context.proceed(); } }; } return new AsyncResult(callable); }  }
AsyncInterceptor extends Interceptor<Async> { @Override public Result call(final Async configuration, final RequestContext context) throws Exception { Callable<Result> callable; if (configuration.timeout() > 0) { callable = new ResultRetriever(context, configuration); } else { callable = new Callable<Result>() { @Override public Result call() throws Exception { return context.proceed(); } }; } return new AsyncResult(callable); }  @Override Result call(final Async configuration, final RequestContext context); @Override Class<Async> annotation(); }
AsyncInterceptor extends Interceptor<Async> { @Override public Result call(final Async configuration, final RequestContext context) throws Exception { Callable<Result> callable; if (configuration.timeout() > 0) { callable = new ResultRetriever(context, configuration); } else { callable = new Callable<Result>() { @Override public Result call() throws Exception { return context.proceed(); } }; } return new AsyncResult(callable); }  @Override Result call(final Async configuration, final RequestContext context); @Override Class<Async> annotation();  }