@Test public void flatMapFailureIntoThrownExceptionTest() throws InterruptedException { RuntimeException finalException = new RuntimeException(); ListenableFuture<?> lf = makeListenableFutureFactory().makeWithFailure(new Exception()); AtomicBoolean mapped = new AtomicBoolean(false); ListenableFuture<?> finalLF = lf.flatMapFailure(Exception.class, (t) -> { mapped.set(true); throw finalException; }); assertTrue(mapped.get()); assertTrue(finalLF != lf); verifyFailureConditionFuture(finalLF, finalException); }
@Test public void flatMapFailureIgnoredFailureTypeTest() { ListenableFuture<?> lf = makeListenableFutureFactory().makeWithFailure(new Exception()); AtomicBoolean mapped = new AtomicBoolean(false); ListenableFuture<?> finalLF = lf.flatMapFailure(RuntimeException.class, (t) -> { mapped.set(true); return FutureUtils.immediateResultFuture(null); }); assertFalse(mapped.get()); assertTrue(lf == finalLF); }
@Test public void flatMapFailureIgnoredTest() { ListenableFuture<Object> lf = makeListenableFutureFactory().makeWithResult(null); AtomicBoolean mapped = new AtomicBoolean(false); ListenableFuture<Object> finalLF = lf.flatMapFailure(Throwable.class, (t) -> { mapped.set(true); return FutureUtils.immediateResultFuture(new Object()); }); assertFalse(mapped.get()); assertTrue(lf == finalLF); }
@Test public void flatMapFailureTest() { // should be straight through ListenableFuture<Object> testFuture = new ImmediateResultListenableFuture<>(null); assertTrue(testFuture == testFuture.flatMapFailure(Exception.class, (t) -> FutureUtils.immediateFailureFuture(new RuntimeException()))); assertTrue(testFuture == testFuture.flatMapFailure(Exception.class, (t) -> FutureUtils.immediateFailureFuture(new RuntimeException()), SameThreadSubmitterExecutor.instance())); assertTrue(testFuture == testFuture.flatMapFailure(Exception.class, (t) -> FutureUtils.immediateFailureFuture(new RuntimeException()), SameThreadSubmitterExecutor.instance(), null)); }
@Test public void flatMapFailureIntoReturnedExceptionTest() throws InterruptedException { RuntimeException finalException = new RuntimeException(); ListenableFuture<Object> lf = makeListenableFutureFactory().makeWithFailure(new Exception()); AtomicBoolean mapped = new AtomicBoolean(false); ListenableFuture<Object> finalLF = lf.flatMapFailure(Exception.class, (t) -> { mapped.set(true); return FutureUtils.immediateFailureFuture(finalException); }); assertTrue(mapped.get()); assertTrue(finalLF != lf); verifyFailureConditionFuture(finalLF, finalException); }
@Test public void flatMapFailureIntoResultTest() throws InterruptedException, ExecutionException { ListenableFuture<?> lf = makeListenableFutureFactory().makeWithFailure(new Exception()); AtomicBoolean mapped = new AtomicBoolean(false); ListenableFuture<?> finalLF = lf.flatMapFailure(Exception.class, (t) -> { mapped.set(true); return FutureUtils.immediateResultFuture(null); }); assertTrue(finalLF.isDone()); assertTrue(mapped.get()); assertTrue(finalLF != lf); assertNull(finalLF.get()); }
@Test public void flatMapFailureWithExecutorIntoThrownExceptionTest() throws InterruptedException { TestableScheduler scheduler = new TestableScheduler(); RuntimeException finalException = new RuntimeException(); ListenableFuture<?> lf = makeListenableFutureFactory().makeWithFailure(new Exception()); AtomicBoolean mapped = new AtomicBoolean(false); ListenableFuture<?> finalLF = lf.flatMapFailure(Exception.class, (t) -> { mapped.set(true); throw finalException; }, scheduler); assertTrue(finalLF != lf); assertFalse(finalLF.isDone()); assertEquals(1, scheduler.tick()); assertTrue(finalLF.isDone()); assertTrue(mapped.get()); verifyFailureConditionFuture(finalLF, finalException); }
@Test public void flatMapFailureWithExecutorIntoReturnedExceptionTest() throws InterruptedException { TestableScheduler scheduler = new TestableScheduler(); RuntimeException finalException = new RuntimeException(); ListenableFuture<Object> lf = makeListenableFutureFactory().makeWithFailure(new Exception()); AtomicBoolean mapped = new AtomicBoolean(false); ListenableFuture<Object> finalLF = lf.flatMapFailure(Exception.class, (t) -> { mapped.set(true); return FutureUtils.immediateFailureFuture(finalException); }, scheduler); assertTrue(finalLF != lf); assertFalse(finalLF.isDone()); assertEquals(1, scheduler.tick()); assertTrue(finalLF.isDone()); assertTrue(mapped.get()); verifyFailureConditionFuture(finalLF, finalException); }
@Test public void flatMapFailureWithExecutorIgnoredTest() { TestableScheduler scheduler = new TestableScheduler(); ListenableFuture<Object> lf = makeListenableFutureFactory().makeWithResult(null); AtomicBoolean mapped = new AtomicBoolean(false); ListenableFuture<Object> finalLF = lf.flatMapFailure(Throwable.class, (t) -> { mapped.set(true); return FutureUtils.immediateResultFuture(new Object()); }, scheduler); assertTrue(finalLF != lf); assertFalse(finalLF.isDone()); assertEquals(1, scheduler.tick()); assertTrue(finalLF.isDone()); assertFalse(mapped.get()); assertTrue(finalLF.isDone()); }
@Test public void flatMapFailureWithExecutorIgnoredFailureTypeTest() { TestableScheduler scheduler = new TestableScheduler(); ListenableFuture<?> lf = makeListenableFutureFactory().makeWithFailure(new Exception()); AtomicBoolean mapped = new AtomicBoolean(false); ListenableFuture<?> finalLF = lf.flatMapFailure(RuntimeException.class, (t) -> { mapped.set(true); return FutureUtils.immediateResultFuture(null); }, scheduler); assertTrue(finalLF != lf); assertFalse(finalLF.isDone()); assertEquals(1, scheduler.tick()); assertTrue(finalLF.isDone()); assertFalse(mapped.get()); assertTrue(finalLF.isDone()); }
@Test public void flatMapFailureWithExecutorIntoResultTest() throws InterruptedException, ExecutionException { TestableScheduler scheduler = new TestableScheduler(); ListenableFuture<?> lf = makeListenableFutureFactory().makeWithFailure(new Exception()); AtomicBoolean mapped = new AtomicBoolean(false); ListenableFuture<?> finalLF = lf.flatMapFailure(Exception.class, (t) -> { mapped.set(true); return FutureUtils.immediateResultFuture(null); }, scheduler); assertTrue(finalLF != lf); assertFalse(finalLF.isDone()); assertEquals(1, scheduler.tick()); assertTrue(finalLF.isDone()); assertTrue(mapped.get()); assertNull(finalLF.get()); }