@Test public void testWithTimeout() throws Exception { RequestContext rc = mock(RequestContext.class); when(rc.proceed()).thenReturn(new Result(Status.OK)); Async async = mock(Async.class); when(async.timeout()).thenReturn(1l); when(async.unit()).thenReturn(TimeUnit.SECONDS); Result result = interceptor.call(async, rc); assertThat(result).isInstanceOf(AsyncResult.class); final int[] code = {0}; ManagedFutureTask<Result> r = executor.submit(((AsyncResult) result).callable()) .onSuccess(new ManagedFutureTask.SuccessCallback<Result>() { @Override public void onSuccess(ManagedFutureTask<Result> future, Result result) { code[0] = result.getStatusCode(); } }); Thread.sleep(100); assertThat(code[0]).isEqualTo(200); }
@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();  }