@Test public void managedInvocationTest() { final CompletableFuture<Integer> future = managedService.asyncTask(1); LOGGER.info("You can do something else in the meantime and later get the future value"); try { assertEquals(3, future.get(200, TimeUnit.MILLISECONDS).intValue()); } catch (Exception e) { fail("Unexpected exception" + e); } }
public CompletableFuture<Integer> asyncTask(final int value) { LOGGER.info("Create asyncTask"); return CompletableFuture .supplyAsync(longTask(value, 100, null), executor) .thenApply(i -> i + 1); }
ManagedService { public CompletableFuture<Integer> asyncTask(final int value) { LOGGER.info("Create asyncTask"); return CompletableFuture .supplyAsync(longTask(value, 100, null), executor) .thenApply(i -> i + 1); } }
ManagedService { public CompletableFuture<Integer> asyncTask(final int value) { LOGGER.info("Create asyncTask"); return CompletableFuture .supplyAsync(longTask(value, 100, null), executor) .thenApply(i -> i + 1); }  }
ManagedService { public CompletableFuture<Integer> asyncTask(final int value) { LOGGER.info("Create asyncTask"); return CompletableFuture .supplyAsync(longTask(value, 100, null), executor) .thenApply(i -> i + 1); }  CompletableFuture<Integer> asyncTask(final int value); CompletableFuture<Integer> asyncTaskWithException(final int value); }
ManagedService { public CompletableFuture<Integer> asyncTask(final int value) { LOGGER.info("Create asyncTask"); return CompletableFuture .supplyAsync(longTask(value, 100, null), executor) .thenApply(i -> i + 1); }  CompletableFuture<Integer> asyncTask(final int value); CompletableFuture<Integer> asyncTaskWithException(final int value);  }