@Test public void forEachXWithEvents() { List<Integer> list = new ArrayList<>(); LazyFutureStream<Integer> stream = LazyFutureStream.of( () -> 1, () -> 2, () -> 3, (Supplier<Integer>) () -> { throw new RuntimeException(); }) .map(Supplier::get); Subscription s = stream.forEachXEvents(2, i -> list.add(i), e -> error = e, () -> complete = true); assertThat(list, hasItems(1, 2)); assertThat(list.size(), equalTo(2)); System.out.println("first batch"); s.request(1); assertFalse(complete); assertThat(list, hasItems(1, 2, 3)); assertThat(list.size(), equalTo(3)); assertThat(error, nullValue()); s.request(2); assertThat(error, instanceOf(RuntimeException.class)); assertTrue(complete); }
@Test public void forEachWithEvents() { List<Integer> list = new ArrayList<>(); assertFalse(complete); assertThat(error, nullValue()); LazyFutureStream<Integer> stream = LazyFutureStream.of( () -> 1, () -> 2, () -> 3, (Supplier<Integer>) () -> { throw new RuntimeException(); }) .map(Supplier::get); stream.forEachEvent(i -> list.add(i), e -> error = e, () -> complete = true); assertThat(list, hasItems(1, 2, 3)); assertThat(list.size(), equalTo(3)); assertThat(error, instanceOf(RuntimeException.class)); assertTrue(complete); }
@Test public void forEachWithErrorsAsync() { List<Integer> list = new ArrayList<>(); assertThat(error, nullValue()); LazyFutureStream<Integer> stream = LazyFutureStream.of( () -> 1, () -> 2, () -> 3, (Supplier<Integer>) () -> { throw new RuntimeException(); }, () -> 4, () -> 5) .async() .map(Supplier::get); stream.forEachWithError(i -> list.add(i), e -> error = e); ExceptionSoftener.softenRunnable(() -> Thread.sleep(100)).run(); assertThat(list, hasItems(1, 2, 3, 4, 5)); assertThat(list.size(), equalTo(5)); assertThat(list, hasItems(1, 2, 3, 4, 5)); assertThat(list.size(), equalTo(5)); assertThat(error, instanceOf(RuntimeException.class)); }
@Test public void forEachX() { Subscription s = LazyFutureStream.of(1, 2, 3).forEachX(2, System.out::println); System.out.println("first batch"); s.request(1); }
@Test public void forEachXTest() { List<Integer> list = new ArrayList<>(); Subscription s = LazyFutureStream.of(1, 2, 3).forEachX(2, i -> list.add(i)); assertThat(list, hasItems(1, 2)); assertThat(list.size(), equalTo(2)); s.request(1); assertThat(list, hasItems(1, 2, 3)); assertThat(list.size(), equalTo(3)); }