Tasks { public static <I> Builder<I> foreach(Iterable<I> items) { return new Builder<>(items); } private  Tasks(); static Builder<I> foreach(Iterable<I> items); static Builder<I> foreach(I[] items);  }
@Test public void testFailNoStoppingSuppressed() throws Throwable { assertFailed(builder().suppressExceptions(), failingTask); failingTask.assertInvoked("Continued through operations", ITEM_COUNT); items.forEach(Item::assertCommittedOrFailed); }
@Test public void testFailedCallAbortSuppressed() throws Throwable { assertFailed(builder() .stopOnFailure() .suppressExceptions() .abortWith(aborter), failingTask); failingTask.assertInvokedAtLeast("success", FAILPOINT); if (!isParallel()) { aborter.assertInvokedAtLeast("abort", 1); items.stream().filter(i -> !i.committed) .map(Item::assertAborted); items.stream().filter(i -> i.committed) .forEach(i -> assertFalse(i.toString(), i.aborted)); } }
@Test public void testFailFastCallRevertSuppressed() throws Throwable { assertFailed(builder() .stopOnFailure() .revertWith(reverter) .abortWith(aborter) .suppressExceptions() .onFailure(failures), failingTask); failingTask.assertInvokedAtLeast("success", FAILPOINT); if (!isParallel()) { aborter.assertInvokedAtLeast("abort", 1); items.stream().filter(i -> !i.committed) .filter(i -> !i.failed) .forEach(Item::assertAborted); } items.stream().filter(i -> i.committed && !i.failed) .forEach(Item::assertReverted); items.stream().filter(i -> i.reverted) .forEach(Item::assertCommitted); failures.assertInvoked("failure event", 1); }
@Test public void testFailSlowCallRevertSuppressed() throws Throwable { assertFailed(builder() .suppressExceptions() .revertWith(reverter) .onFailure(failures), failingTask); failingTask.assertInvokedAtLeast("success", FAILPOINT); int failing = failures.getItem().id; items.stream() .filter(i -> i.id != failing) .filter(i -> i.committed) .forEach(Item::assertReverted); items.stream().filter(i -> i.reverted) .forEach(Item::assertCommitted); failures.assertInvoked("failure event", 1); }
@Test public void testFailSlowExceptions() throws Throwable { intercept(IOException.class, () -> builder() .run(failingTask)); failingTask.assertInvoked("continued through operations", ITEM_COUNT); items.forEach(Item::assertCommittedOrFailed); }
@Test public void testRevertAllSuppressed() throws Throwable { CounterTask failLast = new CounterTask("task", ITEM_COUNT, Item::commit); assertFailed(builder() .suppressExceptions() .stopOnFailure() .revertWith(reverter) .abortWith(aborter) .onFailure(failures), failLast); failLast.assertInvoked("success", ITEM_COUNT); int abCount = aborter.getCount(); int revCount = reverter.getCount(); assertEquals(ITEM_COUNT, 1 + abCount + revCount); int failing = failures.getItem().id; items.stream() .filter(i -> i.id != failing) .filter(i -> i.committed) .forEach(Item::assertReverted); items.stream() .filter(i -> i.id != failing) .filter(i -> !i.committed) .forEach(Item::assertAborted); items.stream().filter(i -> i.reverted) .forEach(Item::assertCommitted); failures.assertInvoked("failure event", 1); }