@Test public void getFlatMappedRunningStackTraceTest() { ListenableFuture<Object> mappedFuture = slf.flatMap((o) -> FutureUtils.immediateResultFuture(o)) .flatMap((o) -> FutureUtils.immediateResultFuture(null)); assertNull(mappedFuture.getRunningStackTrace()); slf.setRunningThread(Thread.currentThread()); StackTraceElement[] stack = mappedFuture.getRunningStackTrace(); assertEquals(this.getClass().getName(), stack[4].getClassName()); slf.setResult(null); assertNull(mappedFuture.getRunningStackTrace()); }
@Test public void flatMapCancelationExceptionMessageTest() throws InterruptedException, TimeoutException { String msg = StringUtils.makeRandomString(5); SettableListenableFuture<Void> slf = new CancelMessageTestSettableListenableFuture(msg); ListenableFuture<Void> mappedFuture = slf.flatMap((v) -> FutureUtils.immediateResultFuture(null)); slf.cancel(false); verifyCancelationExceptionMessageOnGet(msg, mappedFuture); verifyCancelationExceptionMessageInCallback(msg, mappedFuture); }
@Test public void flatMapCancelationExceptionMessageAlreadyDoneTest() throws InterruptedException, TimeoutException { String msg = StringUtils.makeRandomString(5); SettableListenableFuture<Void> slf = new CancelMessageTestSettableListenableFuture(msg); slf.cancel(false); ListenableFuture<Void> mappedFuture = slf.flatMap((v) -> FutureUtils.immediateResultFuture(null)); verifyCancelationExceptionMessageOnGet(msg, mappedFuture); verifyCancelationExceptionMessageInCallback(msg, mappedFuture); }
@Test public void cancelFlatMappedAsyncFutureTest() { SettableListenableFuture<Void> asyncSLF = new SettableListenableFuture<>(); ListenableFuture<Void> mappedLF = slf.flatMap(asyncSLF); slf.setResult(null); // complete source future before cancel assertFalse(mappedLF.isDone()); assertTrue(mappedLF.cancel(false)); // no interrupt needed, delegate future not started assertTrue(asyncSLF.isCancelled()); }