diff --git a/context-propagation/src/test/java/io/smallrye/mutiny/context/MultiContextPropagationTest.java b/context-propagation/src/test/java/io/smallrye/mutiny/context/MultiContextPropagationTest.java index 8ee1f517d..fa143297e 100644 --- a/context-propagation/src/test/java/io/smallrye/mutiny/context/MultiContextPropagationTest.java +++ b/context-propagation/src/test/java/io/smallrye/mutiny/context/MultiContextPropagationTest.java @@ -125,7 +125,7 @@ public void testDeferredWithMultipleItems() { } catch (Throwable t) { emitter.fail(t); } - }).start()).collectItems().asList(); + }).start()).collect().asList(); List result = latch.await().indefinitely(); assertThat(result).hasSize(3).allSatisfy(i -> assertThat(i).isEqualTo(2)); @@ -151,7 +151,7 @@ public void testGenerator() { return r; }); - int result = multi.collectItems().first().await().indefinitely(); + int result = multi.collect().first().await().indefinitely(); assertThat(result).isEqualTo(2); } diff --git a/documentation/README.md b/documentation/README.md index bdec9e10a..b27aba3f4 100644 --- a/documentation/README.md +++ b/documentation/README.md @@ -96,14 +96,14 @@ public class RepetitionsTest { // tag::distinct[] List list = multi .transform().byDroppingDuplicates() - .collectItems().asList() + .collect().asList() .await().indefinitely(); // end::distinct[] // tag::repetition[] List list2 = multi .transform().byDroppingRepetitions() - .collectItems().asList() + .collect().asList() .await().indefinitely(); // end::repetition[] assertThat(list).containsExactly(1, 2, 3, 4, 5, 6); diff --git a/documentation/src/main/jekyll/assets/images/collect-as-list.png b/documentation/src/main/jekyll/assets/images/collect-as-list.png index 80665c831..263f19e82 100644 Binary files a/documentation/src/main/jekyll/assets/images/collect-as-list.png and b/documentation/src/main/jekyll/assets/images/collect-as-list.png differ diff --git a/documentation/src/main/jekyll/guides/collecting-items.adoc b/documentation/src/main/jekyll/guides/collecting-items.adoc index 6f86188a3..a0d04c761 100644 --- a/documentation/src/main/jekyll/guides/collecting-items.adoc +++ b/documentation/src/main/jekyll/guides/collecting-items.adoc @@ -9,6 +9,7 @@ This is also called a _reduction_ in functional programming. The `Uni` fires its item when the `Multi` completes. Mutiny provides multiple operators to deal with that scenario. +They are available from the `collect()` group. For example, you can store the items in a list, emit the list on completion, or use a Java `Collector` to customize the aggregation. IMPORTANT: Don't collect items from infinite streams or you will likely end with an out-of-memory failure! @@ -78,7 +79,7 @@ include::{include_dir}/CollectingItemsTest.java[tag=collector] == Getting the first and last items -While they are not strictly speaking collecting items, the `collectItems().first()` and `collectItems().last()` allows retrieving the first and last item from a `Multi`: +While they are not strictly speaking collecting items, the `collect().first()` and `collect().last()` allows retrieving the first and last item from a `Multi`: [source, java, indent=0] ---- diff --git a/documentation/src/test/java/guides/CompletionStageTest.java b/documentation/src/test/java/guides/CompletionStageTest.java index 31957a096..27b0fd6ba 100644 --- a/documentation/src/test/java/guides/CompletionStageTest.java +++ b/documentation/src/test/java/guides/CompletionStageTest.java @@ -70,8 +70,8 @@ public void test() { .onItem().transform(String::toUpperCase); // end::create-multi[] - assertThat(multi1.collectItems().asList().await().indefinitely()).containsExactly("HELLO"); - assertThat(multi2.collectItems().asList().await().indefinitely()).containsExactly("HELLO"); + assertThat(multi1.collect().asList().await().indefinitely()).containsExactly("HELLO"); + assertThat(multi2.collect().asList().await().indefinitely()).containsExactly("HELLO"); } } diff --git a/documentation/src/test/java/guides/CreatingMultiTest.java b/documentation/src/test/java/guides/CreatingMultiTest.java index 7d39b16c9..d0a304703 100644 --- a/documentation/src/test/java/guides/CreatingMultiTest.java +++ b/documentation/src/test/java/guides/CreatingMultiTest.java @@ -54,8 +54,8 @@ public void creation() { Multi multiFromItems = Multi.createFrom().items(1, 2, 3, 4); Multi multiFromIterable = Multi.createFrom().iterable(Arrays.asList(1, 2, 3, 4, 5)); // end::simple[] - assertThat(multiFromItems.collectItems().asList().await().indefinitely()).containsExactly(1, 2, 3, 4); - assertThat(multiFromIterable.collectItems().asList().await().indefinitely()).containsExactly(1, 2, 3, 4, 5); + assertThat(multiFromItems.collect().asList().await().indefinitely()).containsExactly(1, 2, 3, 4); + assertThat(multiFromIterable.collect().asList().await().indefinitely()).containsExactly(1, 2, 3, 4, 5); } { @@ -64,9 +64,9 @@ public void creation() { Multi multi = Multi.createFrom().items(() -> IntStream.range(counter.getAndIncrement(), counter.get() * 2).boxed()); // end::supplier[] - assertThat(multi.collectItems().asList().await().indefinitely()).containsExactly(0, 1); - assertThat(multi.collectItems().asList().await().indefinitely()).containsExactly(1, 2, 3); - assertThat(multi.collectItems().asList().await().indefinitely()).containsExactly(2, 3, 4, 5); + assertThat(multi.collect().asList().await().indefinitely()).containsExactly(0, 1); + assertThat(multi.collect().asList().await().indefinitely()).containsExactly(1, 2, 3); + assertThat(multi.collect().asList().await().indefinitely()).containsExactly(2, 3, 4, 5); } { @@ -101,7 +101,7 @@ public void creation() { em.complete(); }); // end::emitter[] - assertThat(multi.collectItems().asList().await().indefinitely()).containsExactly(1, 2, 3); + assertThat(multi.collect().asList().await().indefinitely()).containsExactly(1, 2, 3); } { diff --git a/documentation/src/test/java/guides/HandlingFailuresTest.java b/documentation/src/test/java/guides/HandlingFailuresTest.java index 96f398293..0acc45b5d 100644 --- a/documentation/src/test/java/guides/HandlingFailuresTest.java +++ b/documentation/src/test/java/guides/HandlingFailuresTest.java @@ -26,7 +26,7 @@ public void testInvoke(SystemOut out) { .onFailure().invoke(failure -> log(failure)); // end::invoke[] assertThatThrownBy(() -> u.await().indefinitely()).hasMessageContaining("boom"); - assertThatThrownBy(() -> m.collectItems().asList() + assertThatThrownBy(() -> m.collect().asList() .await().indefinitely()).hasMessageContaining("boom"); assertThat(out.get()).contains("boom"); } @@ -64,7 +64,7 @@ public void testCompletionOnFailure() { Multi m = multi .onFailure().recoverWithCompletion(); // end::recover-completion[] - assertThat(m.collectItems().asList().await().indefinitely()).isEmpty(); + assertThat(m.collect().asList().await().indefinitely()).isEmpty(); } @Test @@ -79,7 +79,7 @@ public void testSwitch() { .onFailure().recoverWithMulti(f -> getFallbackMulti(f)); // end::recover-switch[] assertThat(u.await().indefinitely()).isEqualTo("hello"); - assertThat(m.collectItems().asList().await().indefinitely()).containsExactly("hey"); + assertThat(m.collect().asList().await().indefinitely()).containsExactly("hey"); } private Multi getFallbackMulti(Throwable f) { diff --git a/documentation/src/test/java/guides/RetryTest.java b/documentation/src/test/java/guides/RetryTest.java index 34a9435e7..73974a980 100644 --- a/documentation/src/test/java/guides/RetryTest.java +++ b/documentation/src/test/java/guides/RetryTest.java @@ -25,7 +25,7 @@ public void testRetryAtMost() { .onFailure().retry().atMost(3); // end::retry-at-most[] assertThatThrownBy(() -> u.await().indefinitely()).hasMessageContaining("boom"); - assertThatThrownBy(() -> m.collectItems().asList() + assertThatThrownBy(() -> m.collect().asList() .await().indefinitely()).hasMessageContaining("boom"); } diff --git a/documentation/src/test/java/guides/RxTest.java b/documentation/src/test/java/guides/RxTest.java index 4df05c13f..ba439fe5c 100644 --- a/documentation/src/test/java/guides/RxTest.java +++ b/documentation/src/test/java/guides/RxTest.java @@ -26,17 +26,17 @@ public void rx() { List list = multi .map(i -> i + 1) - .collectItems().asList() + .collect().asList() .await().indefinitely(); List list2 = multi .flatMap(i -> Multi.createFrom().items(i, i)) - .collectItems().asList() + .collect().asList() .await().indefinitely(); List list3 = multi .concatMap(i -> Multi.createFrom().items(i, i)) - .collectItems().asList() + .collect().asList() .await().indefinitely(); // end::rx[] @@ -68,31 +68,31 @@ public void mutiny() { List list = multi .onItem().transform(i -> i + 1) - .collectItems().asList() + .collect().asList() .await().indefinitely(); List list2 = multi .onItem().transformToMultiAndMerge(i -> Multi.createFrom().items(i, i)) - .collectItems().asList() + .collect().asList() .await().indefinitely(); // Equivalent to transformToMultiAndMerge but let you configure the flattening process, // failure management, concurrency... List list3 = multi .onItem().transformToMulti(i -> Multi.createFrom().items(i, i)).merge() - .collectItems().asList() + .collect().asList() .await().indefinitely(); List list4 = multi .onItem().transformToMultiAndConcatenate(i -> Multi.createFrom().items(i, i)) - .collectItems().asList() + .collect().asList() .await().indefinitely(); // Equivalent to transformToMultiAndConcatenate but let you configure the flattening process, // failure management... List list5 = multi .onItem().transformToMulti(i -> Multi.createFrom().items(i, i)).concatenate() - .collectItems().asList() + .collect().asList() .await().indefinitely(); diff --git a/documentation/src/test/java/guides/TransformItemsAsyncTest.java b/documentation/src/test/java/guides/TransformItemsAsyncTest.java index 48f504569..0ddfcb068 100644 --- a/documentation/src/test/java/guides/TransformItemsAsyncTest.java +++ b/documentation/src/test/java/guides/TransformItemsAsyncTest.java @@ -67,7 +67,7 @@ public void testUniToMulti(SystemOut out) { Multi result = uni .onItem().transformToMulti(item -> Multi.createFrom().items(item, item)); // end::uni-to-multi[] - assertThat(result.collectItems().asList().await().indefinitely()).containsExactly("Cameron", "Cameron"); + assertThat(result.collect().asList().await().indefinitely()).containsExactly("Cameron", "Cameron"); // tag::uni-to-multi-2[] uni @@ -90,8 +90,8 @@ public void testMergeAndConcatUni() { .onItem().transformToUniAndConcatenate(name -> invokeRemoteGreetingService(name)); // end::merge-concat[] - assertThat(merged.collectItems().asList().await().indefinitely()).containsExactly("a", "b"); - assertThat(concat.collectItems().asList().await().indefinitely()).containsExactly("a", "b"); + assertThat(merged.collect().asList().await().indefinitely()).containsExactly("a", "b"); + assertThat(concat.collect().asList().await().indefinitely()).containsExactly("a", "b"); } @Test @@ -106,8 +106,8 @@ public void testMergeAndConcatMulti() { .onItem().transformToMultiAndConcatenate(item -> someMulti(item)); // end::merge-concat-multi[] - assertThat(merged.collectItems().asList().await().indefinitely()).containsExactly("a", "b"); - assertThat(concat.collectItems().asList().await().indefinitely()).containsExactly("a", "b"); + assertThat(merged.collect().asList().await().indefinitely()).containsExactly("a", "b"); + assertThat(concat.collect().asList().await().indefinitely()).containsExactly("a", "b"); } private Multi someMulti(String item) { diff --git a/documentation/src/test/java/guides/TransformItemsTest.java b/documentation/src/test/java/guides/TransformItemsTest.java index fdcdfc44e..783f0eea3 100644 --- a/documentation/src/test/java/guides/TransformItemsTest.java +++ b/documentation/src/test/java/guides/TransformItemsTest.java @@ -32,7 +32,7 @@ public void testMultiTransform() { Multi m = multi .onItem().transform(i -> i.toUpperCase()); // end::multi-transform[] - assertThat(m.collectItems().asList().await().indefinitely()).containsExactly("A", "B", "C"); + assertThat(m.collect().asList().await().indefinitely()).containsExactly("A", "B", "C"); } @Test diff --git a/documentation/src/test/java/guides/integration/ReactorTest.java b/documentation/src/test/java/guides/integration/ReactorTest.java index 381372e26..30d3f42e1 100644 --- a/documentation/src/test/java/guides/integration/ReactorTest.java +++ b/documentation/src/test/java/guides/integration/ReactorTest.java @@ -27,12 +27,12 @@ public void testMultiCreation() { List list = multiFromFlux .onItem().transform(Object::toString) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly("a", "b", "c"); list = multiFromMono .onItem().transform(Object::toString) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly("a"); } diff --git a/documentation/src/test/java/guides/integration/RxJavaTest.java b/documentation/src/test/java/guides/integration/RxJavaTest.java index 0acc59301..3445740ce 100644 --- a/documentation/src/test/java/guides/integration/RxJavaTest.java +++ b/documentation/src/test/java/guides/integration/RxJavaTest.java @@ -33,12 +33,12 @@ public void testMultiCreation() { List list = multiFromObservable .onItem().transform(Object::toString) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly("a", "b", "c"); list = multiFromFlowable .onItem().transform(Object::toString) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly("a", "b", "c"); Completable completable = getCompletable(); @@ -59,22 +59,22 @@ public void testMultiCreation() { list = multiFromCompletable .onItem().transform(Object::toString) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).isEmpty(); list = multiFromSingle .onItem().transform(Object::toString) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly("a"); list = multiFromMaybe .onItem().transform(Object::toString) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly("a"); list = multiFromEmptyMaybe .onItem().transform(Object::toString) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).isEmpty(); } diff --git a/documentation/src/test/java/guides/operators/CollectingItemsTest.java b/documentation/src/test/java/guides/operators/CollectingItemsTest.java index b407d9f68..b48d62c53 100644 --- a/documentation/src/test/java/guides/operators/CollectingItemsTest.java +++ b/documentation/src/test/java/guides/operators/CollectingItemsTest.java @@ -21,14 +21,14 @@ public class CollectingItemsTest { public void testList() { // tag::list[] Multi multi = getMulti(); - Uni> uni = multi.collectItems().asList(); + Uni> uni = multi.collect().asList(); // end::list[] assertThat(uni.await().indefinitely()).containsExactly("a", "b", "c"); // tag::first[] - Uni first = multi.collectItems().first(); - Uni last = multi.collectItems().last(); + Uni first = multi.collect().first(); + Uni last = multi.collect().last(); // end::first[] assertThat(first.await().indefinitely()).isEqualTo("a"); @@ -40,7 +40,7 @@ public void testMap() { // tag::map[] Multi multi = getMulti(); Uni> uni = - multi.collectItems() + multi.collect() .asMap(item -> getUniqueKeyForItem(item)); // end::map[] @@ -52,7 +52,7 @@ public void testMultiMap() { // tag::multimap[] Multi multi = getMulti(); Uni>> uni = - multi.collectItems() + multi.collect() .asMultiMap(item -> getKeyForItem(item)); // end::multimap[] @@ -63,14 +63,14 @@ public void testMultiMap() { public void testCustomAccumulator() { // tag::accumulator[] Multi multi = getMulti(); - Uni uni = multi.collectItems() + Uni uni = multi.collect() .in(MyCollection::new, (col, item) -> col.add(item)); // end::accumulator[] assertThat(uni.await().indefinitely()).hasSize(3); // tag::collector[] - Uni count = multi.collectItems() + Uni count = multi.collect() .with(Collectors.counting()); // end::collector[] diff --git a/documentation/src/test/java/guides/operators/CombiningItemsTest.java b/documentation/src/test/java/guides/operators/CombiningItemsTest.java index eee04c3f8..caa07fd56 100644 --- a/documentation/src/test/java/guides/operators/CombiningItemsTest.java +++ b/documentation/src/test/java/guides/operators/CombiningItemsTest.java @@ -113,10 +113,10 @@ public void testCombineLast() { .latestItems().using(list -> combineItems(list)); // end::combine-last[] - List> list = multi1.collectItems().asList().await().indefinitely(); + List> list = multi1.collect().asList().await().indefinitely(); assertThat(list).hasSize(3); assertThat(list.toString()).contains("a3", "b1", "b2", "b3").doesNotContain("a1", "a2"); - List strings = multi2.collectItems().asList().await().indefinitely(); + List strings = multi2.collect().asList().await().indefinitely(); assertThat(strings).hasSize(3).containsExactly("a3b1", "a3b2", "a3b3"); } diff --git a/documentation/src/test/java/guides/operators/DelayTest.java b/documentation/src/test/java/guides/operators/DelayTest.java index 043e9266d..052004e8b 100644 --- a/documentation/src/test/java/guides/operators/DelayTest.java +++ b/documentation/src/test/java/guides/operators/DelayTest.java @@ -47,7 +47,7 @@ public void testDelayMulti() { Uni.createFrom().nullItem().onItem().delayIt().by(Duration.ofMillis(10)) ); // end::delay-multi[] - assertThat(delayed.collectItems().asList().await().indefinitely()).containsExactly(1, 2, 3, 4, 5); + assertThat(delayed.collect().asList().await().indefinitely()).containsExactly(1, 2, 3, 4, 5); } @Test @@ -60,7 +60,7 @@ public void testThrottling() { Multi delayed = Multi.createBy().combining().streams(ticks, multi) .using((x, item) -> item); // end::throttling-multi[] - assertThat(delayed.collectItems().asList().await().indefinitely()).containsExactly(1, 2, 3, 4, 5); + assertThat(delayed.collect().asList().await().indefinitely()).containsExactly(1, 2, 3, 4, 5); } @Test @@ -73,7 +73,7 @@ public void testDelayMultiRandom() { return Uni.createFrom().nullItem().onItem().delayIt().by(delay); }); // end::delay-multi-random[] - assertThat(delayed.collectItems().asList() + assertThat(delayed.collect().asList() .await().indefinitely()) .containsExactlyInAnyOrder(1, 2, 3, 4, 5); } diff --git a/documentation/src/test/java/guides/operators/EmitOnTest.java b/documentation/src/test/java/guides/operators/EmitOnTest.java index a4c3be909..c9398aa36 100644 --- a/documentation/src/test/java/guides/operators/EmitOnTest.java +++ b/documentation/src/test/java/guides/operators/EmitOnTest.java @@ -51,7 +51,7 @@ public void test(SystemOut out) { .onItem() .invoke(s -> System.out.println("Received item `" + s + "` on thread: " + Thread.currentThread().getName())) - .collectItems().first() + .collect().first() .await().indefinitely(); // end::code[] diff --git a/documentation/src/test/java/guides/operators/FilterTest.java b/documentation/src/test/java/guides/operators/FilterTest.java index 43b2b28ee..611e7807c 100644 --- a/documentation/src/test/java/guides/operators/FilterTest.java +++ b/documentation/src/test/java/guides/operators/FilterTest.java @@ -16,14 +16,14 @@ public void filter() { // tag::filter[] List list = multi .transform().byFilteringItemsWith(i -> i > 6) - .collectItems().asList() + .collect().asList() .await().indefinitely(); // end::filter[] // tag::test[] List list2 = multi .transform().byTestingItemsWith(i -> Uni.createFrom().item(i > 6)) - .collectItems().asList() + .collect().asList() .await().indefinitely(); // end::test[] @@ -37,17 +37,17 @@ public void take() { // tag::take[] List list = multi .transform().byTakingFirstItems(2) - .collectItems().asList() + .collect().asList() .await().indefinitely(); List list2 = multi .transform().byTakingItemsWhile(i -> i < 3) - .collectItems().asList() + .collect().asList() .await().indefinitely(); List list3 = multi .transform().byTakingLastItems(2) - .collectItems().asList() + .collect().asList() .await().indefinitely(); // end::take[] assertThat(list).containsExactly(1, 2); @@ -61,17 +61,17 @@ public void skip() { // tag::skip[] List list = multi .transform().bySkippingFirstItems(8) - .collectItems().asList() + .collect().asList() .await().indefinitely(); List list2 = multi .transform().bySkippingItemsWhile(i -> i < 9) - .collectItems().asList() + .collect().asList() .await().indefinitely(); List list3 = multi .transform().bySkippingLastItems(8) - .collectItems().asList() + .collect().asList() .await().indefinitely(); // end::skip[] assertThat(list).containsExactly(9, 10); @@ -85,14 +85,14 @@ public void distinct() { // tag::distinct[] List list = multi .transform().byDroppingDuplicates() - .collectItems().asList() + .collect().asList() .await().indefinitely(); // end::distinct[] // tag::repetition[] List list2 = multi .transform().byDroppingRepetitions() - .collectItems().asList() + .collect().asList() .await().indefinitely(); // end::repetition[] assertThat(list).containsExactly(1, 2, 3, 4, 5, 6); diff --git a/documentation/src/test/java/guides/operators/MergeConcatTest.java b/documentation/src/test/java/guides/operators/MergeConcatTest.java index 2905098e6..580404e7e 100644 --- a/documentation/src/test/java/guides/operators/MergeConcatTest.java +++ b/documentation/src/test/java/guides/operators/MergeConcatTest.java @@ -91,13 +91,13 @@ public void testConcatenateStrings(SystemOut out) { assertThat( Multi.createBy().concatenating().streams(first, second) - .collectItems().in(StringBuffer::new, StringBuffer::append) + .collect().in(StringBuffer::new, StringBuffer::append) .await().indefinitely() ).isEqualToIgnoringCase("A1A2A3B1B2B3"); assertThat( Multi.createBy().concatenating().streams(second, first) - .collectItems().in(StringBuffer::new, StringBuffer::append) + .collect().in(StringBuffer::new, StringBuffer::append) .await().indefinitely() ).isEqualToIgnoringCase("B1B2B3A1A2A3"); diff --git a/documentation/src/test/java/guides/operators/RepetitionsTest.java b/documentation/src/test/java/guides/operators/RepetitionsTest.java index b337943aa..e35a5fcf3 100644 --- a/documentation/src/test/java/guides/operators/RepetitionsTest.java +++ b/documentation/src/test/java/guides/operators/RepetitionsTest.java @@ -15,14 +15,14 @@ public void distinct() { // tag::distinct[] List list = multi .transform().byDroppingDuplicates() - .collectItems().asList() + .collect().asList() .await().indefinitely(); // end::distinct[] // tag::repetition[] List list2 = multi .transform().byDroppingRepetitions() - .collectItems().asList() + .collect().asList() .await().indefinitely(); // end::repetition[] assertThat(list).containsExactly(1, 2, 3, 4, 5, 6); diff --git a/documentation/src/test/java/guides/operators/TakeTest.java b/documentation/src/test/java/guides/operators/TakeTest.java index 1757e3597..ff210fad4 100644 --- a/documentation/src/test/java/guides/operators/TakeTest.java +++ b/documentation/src/test/java/guides/operators/TakeTest.java @@ -29,10 +29,10 @@ public void testTake() { Multi takeForDuration = multi.transform().byTakingItemsFor(Duration.ofSeconds(1)); // end::take-for[] - assertThat(firstThreeItems.collectItems().asList().await().indefinitely()).containsExactly(1, 2, 3); - assertThat(takeWhile.collectItems().asList().await().indefinitely()).containsExactly(1, 2, 3); - assertThat(lastThreeItems.collectItems().asList().await().indefinitely()).containsExactly(7, 8, 9); - assertThat(takeForDuration.collectItems().asList().await().indefinitely()).containsExactly(1, 2, 3, 4, 5, 6, 7, 8, 9); + assertThat(firstThreeItems.collect().asList().await().indefinitely()).containsExactly(1, 2, 3); + assertThat(takeWhile.collect().asList().await().indefinitely()).containsExactly(1, 2, 3); + assertThat(lastThreeItems.collect().asList().await().indefinitely()).containsExactly(7, 8, 9); + assertThat(takeForDuration.collect().asList().await().indefinitely()).containsExactly(1, 2, 3, 4, 5, 6, 7, 8, 9); } @@ -56,10 +56,10 @@ public void testSkip() { Multi skipForDuration = multi.transform().bySkippingItemsFor(Duration.ofSeconds(1)); // end::skip-for[] - assertThat(skipThreeItems.collectItems().asList().await().indefinitely()).containsExactly(4, 5, 6, 7, 8, 9); - assertThat(skipLastThreeItems.collectItems().asList().await().indefinitely()).containsExactly(1, 2, 3, 4 ,5, 6); - assertThat(skipWhile.collectItems().asList().await().indefinitely()).containsExactly(4, 5, 6, 7, 8, 9); - assertThat(skipForDuration.collectItems().asList().await().indefinitely()).isEmpty(); + assertThat(skipThreeItems.collect().asList().await().indefinitely()).containsExactly(4, 5, 6, 7, 8, 9); + assertThat(skipLastThreeItems.collect().asList().await().indefinitely()).containsExactly(1, 2, 3, 4 ,5, 6); + assertThat(skipWhile.collect().asList().await().indefinitely()).containsExactly(4, 5, 6, 7, 8, 9); + assertThat(skipForDuration.collect().asList().await().indefinitely()).isEmpty(); } } diff --git a/implementation/src/main/java/io/smallrye/mutiny/Multi.java b/implementation/src/main/java/io/smallrye/mutiny/Multi.java index 5f72495e1..cfceffdf8 100644 --- a/implementation/src/main/java/io/smallrye/mutiny/Multi.java +++ b/implementation/src/main/java/io/smallrye/mutiny/Multi.java @@ -140,7 +140,7 @@ default O stage(Function, O> stage) { /** * Configures the action to execute when the observed {@link Multi} sends a {@link Subscription}. * The downstream don't have a subscription yet. It will be passed once the configured action completes. - * + *

* For example: * *

@@ -190,15 +190,42 @@ default  O stage(Function, O> stage) {
     Multi cache();
 
     /**
-     * Produces {@link Multi} or {@link Uni} collecting items from this {@link Multi}. You can accumulate the items
-     * into a {@link java.util.List} ({@link MultiCollect#asList()}), {@link java.util.Map}
-     * ({@link MultiCollect#asMap(Function)}...
+     * Produces {@link Uni} collecting/aggregating items from this {@link Multi}.
+     * It allows accumulating the items emitted by this {@code multi} into a structure such as a into a
+     * {@link java.util.List} ({@link MultiCollect#asList()}), a {@link java.util.Map}
+     * ({@link MultiCollect#asMap(Function)}, or a custom collector.
+     * When this {@code multi} sends the completion signal, the structure is emitted by the returned {@link Uni}.
+     * 

+ * If this {@link Multi} emits a failure, the produced {@link Uni} produces the same failure and the aggregated items + * are discarded. + *

+ * You can also retrieve the first and last items using {@link MultiCollect#first()} and {@link MultiCollect#last()}. + * Be aware to not used method collecting items on unbounded / infinite {@link Multi}. + * + * @return the object to configure the collection process. + * @deprecated Use {@link #collect()} instead + */ + @Deprecated + default MultiCollect collectItems() { + return collect(); + } + + /** + * Produces {@link Uni} collecting/aggregating items from this {@link Multi}. + * It allows accumulating the items emitted by this {@code multi} into a structure such as a into a + * {@link java.util.List} ({@link MultiCollect#asList()}), a {@link java.util.Map} + * ({@link MultiCollect#asMap(Function)}, or a custom collector. + * When this {@code multi} sends the completion signal, the structure is emitted by the returned {@link Uni}. + *

+ * If this {@link Multi} emits a failure, the produced {@link Uni} produces the same failure and the aggregated items + * are discarded. *

- * You can also retrieve the first and list items using {@link MultiCollect#first()} and {@link MultiCollect#last()}. + * You can also retrieve the first and last items using {@link MultiCollect#first()} and {@link MultiCollect#last()}. + * Be aware to not used method collecting items on unbounded / infinite {@link Multi}. * * @return the object to configure the collection process. */ - MultiCollect collectItems(); + MultiCollect collect(); /** * Produces {@link Multi} grouping items from this {@link Multi} into various "form of chunks" (list, {@link Multi}). @@ -207,7 +234,20 @@ default O stage(Function, O> stage) { * * @return the object to configure the grouping. */ - MultiGroup groupItems(); + MultiGroup group(); + + /** + * Produces {@link Multi} grouping items from this {@link Multi} into various "form of chunks" (list, {@link Multi}). + * The grouping can be done linearly ({@link MultiGroup#intoLists()} and {@link MultiGroup#intoMultis()}, or based + * on a grouping function ({@link MultiGroup#by(Function)}) + * + * @return the object to configure the grouping. + * @deprecated Use {@link #group()} instead + */ + @Deprecated + default MultiGroup groupItems() { + return group(); + } /** * Produces a new {@link Multi} invoking the {@code onItem}, {@code onFailure} and {@code onCompletion} methods @@ -464,14 +504,14 @@ default Multi concatMap(Function onTermination(); /** * Configures actions when the subscriber cancels the subscription. - * + * * @return the object to configure the cancellation actions */ MultiOnCancel onCancellation(); diff --git a/implementation/src/main/java/io/smallrye/mutiny/groups/MultiCollect.java b/implementation/src/main/java/io/smallrye/mutiny/groups/MultiCollect.java index aacf72d51..9b211e43c 100644 --- a/implementation/src/main/java/io/smallrye/mutiny/groups/MultiCollect.java +++ b/implementation/src/main/java/io/smallrye/mutiny/groups/MultiCollect.java @@ -2,6 +2,7 @@ import static io.smallrye.mutiny.helpers.ParameterValidation.nonNull; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; @@ -9,10 +10,13 @@ import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collector; +import java.util.stream.Collectors; import io.smallrye.mutiny.Multi; import io.smallrye.mutiny.Uni; -import io.smallrye.mutiny.operators.MultiCollector; +import io.smallrye.mutiny.infrastructure.Infrastructure; +import io.smallrye.mutiny.operators.multi.MultiCollectorOp; +import io.smallrye.mutiny.operators.multi.MultiLastItemOp; /** * Collects / aggregates items from the upstream and send the resulting collection / structure when the @@ -39,7 +43,7 @@ public MultiCollect(Multi upstream) { * @return the produced uni */ public Uni first() { - return MultiCollector.first(upstream); + return Uni.createFrom().multi(upstream); } /** @@ -53,7 +57,7 @@ public Uni first() { * @return the produced uni */ public Uni last() { - return MultiCollector.last(upstream); + return Uni.createFrom().publisher(Infrastructure.onMultiCreation(new MultiLastItemOp<>(upstream))); } /** @@ -63,7 +67,7 @@ public Uni last() { * @return the {@link Uni} emitting the list of items from this {@link Multi}. */ public Uni> asList() { - return MultiCollector.list(upstream); + return collector(upstream, Collectors.toList(), false); } /** @@ -76,7 +80,7 @@ public Uni> asList() { * @return a {@link Uni} emitted the collected object as item, when the {@link Multi} completes */ public Uni with(Collector collector) { - return MultiCollector.collector(upstream, collector, true); + return collector(upstream, collector, true); } /** @@ -99,7 +103,9 @@ public Uni with(Collector collector) { * @return a {@link Uni} emitting the collected container as item when this {@link Multi} completes */ public Uni in(Supplier supplier, BiConsumer accumulator) { - return MultiCollector.collectInto(upstream, supplier, accumulator); + Collector collector = Collector.of(supplier, accumulator, (r, r2) -> r, + Collector.Characteristics.IDENTITY_FINISH); + return collector(upstream, collector, false); } /** @@ -138,9 +144,10 @@ public Uni> asMap(Function keyMapper) { * @return a {@link Uni} emitting an item with the collected {@link Map}. The uni emits the item when this * {@link Multi} completes */ - public Uni> asMap(Function keyMapper, + public Uni> asMap( + Function keyMapper, Function valueMapper) { - return MultiCollector.map(upstream, keyMapper, valueMapper); + return collector(upstream, Collectors.toMap(keyMapper, valueMapper), false); } /** @@ -161,9 +168,21 @@ public Uni> asMap(Function keyMapper, * @return a {@link Uni} emitting an item with the collected {@link Map}. The uni emits the item when this * {@link Multi} completes */ - public Uni>> asMultiMap(Function keyMapper, + public Uni>> asMultiMap( + Function keyMapper, Function valueMapper) { - return MultiCollector.multimap(upstream, keyMapper, valueMapper); + return collector(upstream, Collectors.toMap( + keyMapper, + res -> { + List list = new ArrayList<>(); + V mapped = valueMapper.apply(res); + list.add(mapped); + return list; + }, + (vs, vs2) -> { + vs.addAll(vs2); + return vs; + }), false); } /** @@ -181,7 +200,14 @@ public Uni>> asMultiMap(Function Uni>> asMultiMap(Function keyMapper) { - return MultiCollector.multimap(upstream, keyMapper, Function.identity()); + return asMultiMap(keyMapper, Function.identity()); + } + + private static Uni collector(Multi upstream, Collector collector, + boolean acceptNullAsInitialValue) { + Multi multi = Infrastructure + .onMultiCreation(new MultiCollectorOp<>(upstream, collector, acceptNullAsInitialValue)); + return Uni.createFrom().publisher(multi); } } diff --git a/implementation/src/main/java/io/smallrye/mutiny/groups/MultiGroupIntoLists.java b/implementation/src/main/java/io/smallrye/mutiny/groups/MultiGroupIntoLists.java index d575c7468..0274c3d0e 100644 --- a/implementation/src/main/java/io/smallrye/mutiny/groups/MultiGroupIntoLists.java +++ b/implementation/src/main/java/io/smallrye/mutiny/groups/MultiGroupIntoLists.java @@ -1,15 +1,14 @@ package io.smallrye.mutiny.groups; -import static io.smallrye.mutiny.helpers.ParameterValidation.nonNull; -import static io.smallrye.mutiny.helpers.ParameterValidation.positive; -import static io.smallrye.mutiny.helpers.ParameterValidation.validate; +import static io.smallrye.mutiny.helpers.ParameterValidation.*; import java.time.Duration; import java.util.List; import io.smallrye.mutiny.Multi; import io.smallrye.mutiny.infrastructure.Infrastructure; -import io.smallrye.mutiny.operators.MultiCollector; +import io.smallrye.mutiny.operators.multi.MultiBufferOp; +import io.smallrye.mutiny.operators.multi.MultiBufferWithTimeoutOp; public class MultiGroupIntoLists { @@ -37,7 +36,9 @@ public MultiGroupIntoLists(Multi upstream) { * window. */ public Multi> every(Duration duration) { - return Infrastructure.onMultiCreation(MultiCollector.list(upstream, validate(duration, "duration"))); + return Infrastructure.onMultiCreation(new MultiBufferWithTimeoutOp<>(upstream, Integer.MAX_VALUE, + validate(duration, "duration"), + Infrastructure.getDefaultWorkerPool())); } /** @@ -55,7 +56,7 @@ public Multi> every(Duration duration) { * @return a Multi emitting lists of at most {@code size} items from the upstream Multi. */ public Multi> of(int size) { - return Infrastructure.onMultiCreation(MultiCollector.list(upstream, positive(size, "size"))); + return Infrastructure.onMultiCreation(new MultiBufferOp<>(upstream, size, size)); } /** @@ -76,8 +77,8 @@ public Multi> of(int size) { * {@code size} items */ public Multi> of(int size, int skip) { - return Infrastructure.onMultiCreation( - MultiCollector.list(upstream, positive(size, "size"), positive(skip, "skip"))); + return Infrastructure.onMultiCreation(new MultiBufferOp<>(upstream, + positive(size, "size"), positive(skip, "skip"))); } /** @@ -101,7 +102,7 @@ public Multi> of(int size, int skip) { * @return a Multi emitting lists of at most {@code size} items from the upstream Multi. */ public Multi> of(int size, Duration maximumDelay) { - return upstream.groupItems().intoMultis().every(maximumDelay) - .flatMap(withTimeout -> withTimeout.groupItems().intoLists().of(size)); + return upstream.group().intoMultis().every(maximumDelay) + .flatMap(withTimeout -> withTimeout.group().intoLists().of(size)); } } diff --git a/implementation/src/main/java/io/smallrye/mutiny/operators/AbstractMulti.java b/implementation/src/main/java/io/smallrye/mutiny/operators/AbstractMulti.java index 3330cf38d..dbbcadf28 100644 --- a/implementation/src/main/java/io/smallrye/mutiny/operators/AbstractMulti.java +++ b/implementation/src/main/java/io/smallrye/mutiny/operators/AbstractMulti.java @@ -71,16 +71,6 @@ public Multi cache() { return Infrastructure.onMultiCreation(new MultiCacheOp<>(this)); } - @Override - public MultiCollect collectItems() { - return new MultiCollect<>(this); - } - - @Override - public MultiGroup groupItems() { - return new MultiGroup<>(this); - } - @Override public Multi emitOn(Executor executor) { return Infrastructure.onMultiCreation(new MultiEmitOnOp<>(this, nonNull(executor, "executor"))); @@ -136,4 +126,13 @@ public MultiOnRequest onRequest() { return new MultiOnRequest<>(this); } + @Override + public MultiCollect collect() { + return new MultiCollect<>(this); + } + + @Override + public MultiGroup group() { + return new MultiGroup<>(this); + } } diff --git a/implementation/src/main/java/io/smallrye/mutiny/operators/MultiCollector.java b/implementation/src/main/java/io/smallrye/mutiny/operators/MultiCollector.java deleted file mode 100644 index 20c44a5c2..000000000 --- a/implementation/src/main/java/io/smallrye/mutiny/operators/MultiCollector.java +++ /dev/null @@ -1,93 +0,0 @@ -package io.smallrye.mutiny.operators; - -import java.time.Duration; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.function.BiConsumer; -import java.util.function.BinaryOperator; -import java.util.function.Function; -import java.util.function.Supplier; -import java.util.stream.Collector; -import java.util.stream.Collectors; - -import io.smallrye.mutiny.Multi; -import io.smallrye.mutiny.Uni; -import io.smallrye.mutiny.infrastructure.Infrastructure; -import io.smallrye.mutiny.operators.multi.MultiBufferOp; -import io.smallrye.mutiny.operators.multi.MultiBufferWithTimeoutOp; -import io.smallrye.mutiny.operators.multi.MultiCollectorOp; -import io.smallrye.mutiny.operators.multi.MultiLastItemOp; - -public class MultiCollector { - - private MultiCollector() { - // avoid direct instantiation. - } - - public static Uni first(Multi upstream) { - return Uni.createFrom().multi(upstream); - } - - public static Uni last(Multi upstream) { - return Uni.createFrom().publisher(Infrastructure.onMultiCreation(new MultiLastItemOp<>(upstream))); - } - - public static Uni> list(Multi upstream) { - return collector(upstream, Collectors.toList(), false); - } - - public static Uni collector(Multi upstream, Collector collector, - boolean acceptNullAsInitialValue) { - Multi multi = Infrastructure.onMultiCreation(new MultiCollectorOp<>(upstream, collector, acceptNullAsInitialValue)); - return Uni.createFrom().publisher(multi); - } - - public static Uni collectInto(Multi upstream, Supplier producer, - BiConsumer combinator) { - Collector collector = Collector.of(producer, combinator, (BinaryOperator) (r, r2) -> r, - Collector.Characteristics.IDENTITY_FINISH); - return collector(upstream, collector, false); - } - - public static Uni> map(Multi upstream, Function keyMapper) { - return map(upstream, keyMapper, Function.identity()); - } - - public static Uni> map(Multi upstream, Function keyMapper, - Function valueMapper) { - return collector(upstream, Collectors.toMap(keyMapper, valueMapper), false); - } - - public static Uni>> multimap(Multi upstream, - Function keyMapper, - Function valueMapper) { - return collector(upstream, Collectors.toMap( - keyMapper, - res -> { - List list = new ArrayList<>(); - V mapped = valueMapper.apply(res); - list.add(mapped); - return list; - }, - (vs, vs2) -> { - vs.addAll(vs2); - return vs; - }), false); - } - - public static Multi> list(Multi upstream, Duration timeWindow) { - return Infrastructure.onMultiCreation(new MultiBufferWithTimeoutOp<>(upstream, Integer.MAX_VALUE, timeWindow, - Infrastructure.getDefaultWorkerPool())); - } - - public static Multi> list(Multi upstream, int size) { - return Infrastructure.onMultiCreation(new MultiBufferOp<>(upstream, size, size)); - } - - public static Multi> list(Multi upstream, int size, int skip) { - return Infrastructure.onMultiCreation(new MultiBufferOp<>(upstream, size, skip)); - } - -} diff --git a/implementation/src/test/java/io/smallrye/mutiny/MultiStageTest.java b/implementation/src/test/java/io/smallrye/mutiny/MultiStageTest.java index d2f2c0076..3f6d5eb35 100644 --- a/implementation/src/test/java/io/smallrye/mutiny/MultiStageTest.java +++ b/implementation/src/test/java/io/smallrye/mutiny/MultiStageTest.java @@ -21,7 +21,7 @@ public void testChainStage() { .onItem().transform(i -> i + 1) .onFailure().retry().indefinitely()) .stage(m -> m.onItem().transform(i -> Integer.toString(i))) - .stage(m -> m.collectItems().asList()) + .stage(m -> m.collect().asList()) .await().indefinitely(); assertThat(result).containsExactly("2", "3", "4"); } @@ -37,7 +37,7 @@ public void testChainWithDeprecatedThenAndApply() { .onItem().apply(i -> i + 1) .onFailure().retry().indefinitely()) .then(m -> m.onItem().apply(i -> Integer.toString(i))) - .then(m -> m.collectItems().asList()) + .then(m -> m.collect().asList()) .await().indefinitely(); assertThat(result).containsExactly("2", "3", "4"); } @@ -66,7 +66,7 @@ public void testThatFunctionCanReturnNullIfVoid() { .stage(self -> self.onItem().transformToUni(i -> Uni.createFrom().item(Integer.toString(i))) .concatenate()) .stage(self -> { - String r = self.collectItems().first().await().indefinitely(); + String r = self.collect().first().await().indefinitely(); result.set(r); return null; // void }); @@ -80,7 +80,7 @@ public void testChainingUni() { .stage(self -> self .onItem().transform(i -> i + 1) .onItem().transform(i -> Integer.toString(i))) - .stage(self -> self.collectItems().first()) + .stage(self -> self.collect().first()) .stage(self -> self.await().indefinitely()); assertThat(result).isEqualTo("24"); } @@ -91,7 +91,7 @@ public void testChainingUniWithDeprecatedApplyAndThen() { .then(self -> self .onItem().apply(i -> i + 1) .onItem().apply(i -> Integer.toString(i))) - .then(self -> self.collectItems().first()) + .then(self -> self.collect().first()) .then(self -> self.await().indefinitely()); assertThat(result).isEqualTo("24"); } diff --git a/implementation/src/test/java/io/smallrye/mutiny/UniStageTest.java b/implementation/src/test/java/io/smallrye/mutiny/UniStageTest.java index 4169afade..1a711800f 100644 --- a/implementation/src/test/java/io/smallrye/mutiny/UniStageTest.java +++ b/implementation/src/test/java/io/smallrye/mutiny/UniStageTest.java @@ -71,7 +71,7 @@ public void testChainingMulti() { .stage(self -> self .onItem().transform(i -> i + 1) .onItem().transform(i -> Integer.toString(i))) - .stage(self -> self.collectItems().first()) + .stage(self -> self.collect().first()) .stage(self -> self.await().indefinitely()); assertThat(result).isEqualTo("24"); } diff --git a/implementation/src/test/java/io/smallrye/mutiny/groups/MultiConvertTest.java b/implementation/src/test/java/io/smallrye/mutiny/groups/MultiConvertTest.java index a9a7da425..a9f362898 100644 --- a/implementation/src/test/java/io/smallrye/mutiny/groups/MultiConvertTest.java +++ b/implementation/src/test/java/io/smallrye/mutiny/groups/MultiConvertTest.java @@ -15,7 +15,7 @@ public class MultiConvertTest { @Test public void testMultiConvertWithCustomConverter() { Multi multi = Multi.createFrom().items(1, 2, 3).convert().with(m -> m.map(i -> Integer.toString(i))); - List list = multi.collectItems().asList().await().indefinitely(); + List list = multi.collect().asList().await().indefinitely(); assertThat(list).containsExactly("1", "2", "3"); } diff --git a/implementation/src/test/java/io/smallrye/mutiny/infrastructure/MutinySchedulerTest.java b/implementation/src/test/java/io/smallrye/mutiny/infrastructure/MutinySchedulerTest.java index f2123e17e..1a68a536a 100644 --- a/implementation/src/test/java/io/smallrye/mutiny/infrastructure/MutinySchedulerTest.java +++ b/implementation/src/test/java/io/smallrye/mutiny/infrastructure/MutinySchedulerTest.java @@ -104,7 +104,7 @@ public void testMultiRetry() { thread.set(Thread.currentThread().getName()); return s.toUpperCase(); }) - .collectItems().first() + .collect().first() .await().indefinitely(); assertThat(res).isEqualTo("HELLO"); @@ -128,7 +128,7 @@ public void testMultiRetryExpireIn() { thread.set(Thread.currentThread().getName()); return s.toUpperCase(); }) - .collectItems().first() + .collect().first() .await().indefinitely(); assertThat(res).isEqualTo("HELLO"); @@ -140,7 +140,7 @@ public void testTicks() { AtomicReference thread = new AtomicReference<>(); List list = Multi.createFrom().ticks().every(Duration.ofMillis(10)) .transform().byTakingFirstItems(5) - .collectItems().asList() + .collect().asList() .onItem().invoke(l -> thread.set(Thread.currentThread().getName())) .await().indefinitely(); @@ -152,9 +152,9 @@ public void testTicks() { public void testCollectionBasedOnDuration() { AtomicReference thread = new AtomicReference<>(); Multi.createFrom().ticks().every(Duration.ofMillis(10)) - .groupItems().intoLists().every(Duration.ofMillis(10)) + .group().intoLists().every(Duration.ofMillis(10)) .transform().byTakingFirstItems(5) - .collectItems().asList() + .collect().asList() .onItem().invoke(l -> thread.set(Thread.currentThread().getName())) .await().indefinitely(); assertThat(thread.get()).startsWith("my-thread-"); diff --git a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiCollectTest.java b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiCollectTest.java index 734cc142c..5187b0383 100644 --- a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiCollectTest.java +++ b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiCollectTest.java @@ -34,6 +34,23 @@ public class MultiCollectTest { @Test public void testCollectFirstAndLast() { + Multi items = Multi.createFrom().items(1, 2, 3); + items + .collect().first() + .subscribe().withSubscriber(UniAssertSubscriber.create()) + .await() + .assertItem(1); + + items + .collect().last() + .subscribe().withSubscriber(UniAssertSubscriber.create()) + .await() + .assertItem(3); + } + + @SuppressWarnings("deprecation") + @Test + public void testCollectFirstAndLastDeprecated() { Multi items = Multi.createFrom().items(1, 2, 3); items .collectItems().first() @@ -52,13 +69,13 @@ public void testCollectFirstAndLast() { public void testCollectWithEmpty() { Multi items = Multi.createFrom().empty(); items - .collectItems().first() + .collect().first() .subscribe().withSubscriber(UniAssertSubscriber.create()) .await() .assertItem(null); items - .collectItems().last() + .collect().last() .subscribe().withSubscriber(UniAssertSubscriber.create()) .await() .assertItem(null); @@ -68,13 +85,13 @@ public void testCollectWithEmpty() { public void testCollectFirstAndLastOnFailure() { Multi failing = Multi.createFrom().failure(new IOException("boom")); failing - .collectItems().first() + .collect().first() .subscribe().withSubscriber(UniAssertSubscriber.create()) .await() .assertFailedWith(IOException.class, "boom"); failing - .collectItems().last() + .collect().last() .subscribe().withSubscriber(UniAssertSubscriber.create()) .await() .assertFailedWith(IOException.class, "boom"); @@ -83,7 +100,7 @@ public void testCollectFirstAndLastOnFailure() { @Test public void testAsList() { UniAssertSubscriber> subscriber = Multi.createFrom().items(1, 2, 3) - .collectItems().asList() + .collect().asList() .subscribe().withSubscriber(UniAssertSubscriber.create()) .await(); @@ -93,7 +110,7 @@ public void testAsList() { @Test public void testCollectIn() { UniAssertSubscriber> subscriber = Multi.createFrom().range(1, 10) - .collectItems().in(LinkedList::new, LinkedList::add) + .collect().in(LinkedList::new, LinkedList::add) .subscribe().withSubscriber(UniAssertSubscriber.create()) .await(); @@ -103,7 +120,7 @@ public void testCollectIn() { @Test public void testCollectInWithSupplierThrowingException() { Multi.createFrom().range(1, 10) - .collectItems().in(() -> { + .collect().in(() -> { throw new IllegalArgumentException("boom"); }, (x, y) -> { }) @@ -114,7 +131,7 @@ public void testCollectInWithSupplierThrowingException() { @Test public void testCollectInWithAccumulatorThrowingException() { Multi.createFrom().range(1, 10) - .collectItems().in(LinkedList::new, (list, res) -> { + .collect().in(LinkedList::new, (list, res) -> { list.add(res); if (res == 5) { throw new IllegalArgumentException("boom"); @@ -127,7 +144,7 @@ public void testCollectInWithAccumulatorThrowingException() { @Test public void testCollectInWithSupplierReturningNull() { Multi.createFrom().range(1, 10) - .collectItems().in(() -> null, (x, y) -> { + .collect().in(() -> null, (x, y) -> { }) .subscribe().withSubscriber(UniAssertSubscriber.create()) .assertFailedWith(NullPointerException.class, "supplier"); @@ -136,7 +153,7 @@ public void testCollectInWithSupplierReturningNull() { @Test public void testCollectInWithAccumulatorSupplierReturningNull() { Multi.createFrom().range(1, 10) - .collectItems().with(new Collector() { + .collect().with(new Collector() { @Override public Supplier supplier() { return () -> 0; @@ -169,7 +186,7 @@ public Set characteristics() { @Test public void testCollectIntoMap() { UniAssertSubscriber> subscriber = persons - .collectItems().asMap(p -> p.firstName) + .collect().asMap(p -> p.firstName) .subscribe().withSubscriber(UniAssertSubscriber.create()) .assertCompleted(); @@ -185,7 +202,7 @@ public void testCollectIntoMap() { @Test public void testCollectAsMapWithEmpty() { UniAssertSubscriber> subscriber = Multi.createFrom(). empty() - .collectItems().asMap(p -> p.firstName) + .collect().asMap(p -> p.firstName) .subscribe().withSubscriber(UniAssertSubscriber.create()) .assertCompleted(); @@ -195,7 +212,7 @@ public void testCollectAsMapWithEmpty() { @Test public void testCollectAsMultiMap() { UniAssertSubscriber>> subscriber = personsWithDuplicates - .collectItems().asMultiMap(p -> p.firstName) + .collect().asMultiMap(p -> p.firstName) .subscribe().withSubscriber(new UniAssertSubscriber<>()) .assertCompleted(); @@ -209,7 +226,7 @@ public void testCollectAsMultiMap() { @Test public void testCollectAsMultiMapWithValueMapper() { UniAssertSubscriber>> subscriber = personsWithDuplicates - .collectItems().asMultiMap(p -> p.firstName, p -> p.id) + .collect().asMultiMap(p -> p.firstName, p -> p.id) .subscribe().withSubscriber(new UniAssertSubscriber<>()) .assertCompleted(); @@ -222,7 +239,7 @@ public void testCollectAsMultiMapWithValueMapper() { @Test public void testCollectAsMultiMapOnEmpty() { UniAssertSubscriber>> subscriber = Multi.createFrom(). empty() - .collectItems().asMultiMap(p -> p.firstName) + .collect().asMultiMap(p -> p.firstName) .subscribe().withSubscriber(new UniAssertSubscriber<>()) .assertCompleted(); assertThat(subscriber.getItem()).hasSize(0); @@ -231,7 +248,7 @@ public void testCollectAsMultiMapOnEmpty() { @Test public void testSumCollector() { - Multi.createFrom().range(1, 5).collectItems().with(Collectors.summingInt(value -> value)) + Multi.createFrom().range(1, 5).collect().with(Collectors.summingInt(value -> value)) .subscribe().withSubscriber(new UniAssertSubscriber<>()).assertCompleted().assertItem(10); } @@ -240,7 +257,7 @@ public void testWithFinisherReturningNull() { List list = new ArrayList<>(); Multi.createFrom().items("a", "b", "c") .map(String::toUpperCase) - .collectItems().with(Collector.of(() -> null, (n, t) -> list.add(t), (X, y) -> null, x -> null)) + .collect().with(Collector.of(() -> null, (n, t) -> list.add(t), (X, y) -> null, x -> null)) .await().indefinitely(); assertThat(list).containsExactly("A", "B", "C"); } diff --git a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiCombineTest.java b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiCombineTest.java index 120aa76f1..7bf847d05 100644 --- a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiCombineTest.java +++ b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiCombineTest.java @@ -97,7 +97,7 @@ public void combineIterableOfStreamsFollowedByAFlatMap() { public void testCombinationOfTwoStreamsAsTuple() { List> list = Multi.createBy() .combining().streams(Multi.createFrom().range(1, 4), Multi.createFrom().range(2, 5)).asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).hasSize(3).containsExactly(Tuple2.of(1, 2), Tuple2.of(2, 3), Tuple2.of(3, 4)); } @@ -107,7 +107,7 @@ public void testCombinationOfAStreamWithItself() { List> list = Multi.createBy() .combining().streams(stream, stream).asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).hasSize(4).containsExactly(Tuple2.of(1, 1), Tuple2.of(2, 2), Tuple2.of(3, 3), Tuple2.of(4, 4)); } @@ -119,7 +119,7 @@ public void testCombinationOfThreeStreamsAsTuple() { Multi s3 = Multi.createFrom().range(3, 6); List> list = Multi.createBy() .combining().streams(s1, s2, s3).asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).hasSize(3).containsExactly(Tuple3.of(1, 2, 3), Tuple3.of(2, 3, 4), Tuple3.of(3, 4, 5)); } @@ -131,7 +131,7 @@ public void testCombinationOfFourStreamsAsTuple() { Multi s4 = Multi.createFrom().range(4, 7); List> list = Multi.createBy() .combining().streams(s1, s2, s3, s4).asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).hasSize(3) .containsExactly(Tuple4.of(1, 2, 3, 4), Tuple4.of(2, 3, 4, 5), Tuple4.of(3, 4, 5, 6)); @@ -146,7 +146,7 @@ public void testCombinationOfFiveStreamsAsTuple() { Multi s5 = Multi.createFrom().range(5, 8); List> list = Multi.createBy() .combining().streams(s1, s2, s3, s4, s5).asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).hasSize(3) .containsExactly(Tuple5.of(1, 2, 3, 4, 5), Tuple5.of(2, 3, 4, 5, 6), @@ -163,7 +163,7 @@ public void testCombinationOfSixStreamsAsTuple() { Multi s6 = Multi.createFrom().range(6, 9); List> list = Multi.createBy() .combining().streams(s1, s2, s3, s4, s5, s6).asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).hasSize(3) .containsExactly( Tuple6.of(1, 2, 3, 4, 5, 6), @@ -182,7 +182,7 @@ public void testCombinationOfSevenStreamsAsTuple() { Multi s7 = Multi.createFrom().range(7, 10); List> list = Multi.createBy() .combining().streams(s1, s2, s3, s4, s5, s6, s7).asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).hasSize(3) .containsExactly( Tuple7.of(1, 2, 3, 4, 5, 6, 7), @@ -202,7 +202,7 @@ public void testCombinationOfEightStreamsAsTuple() { Multi s8 = Multi.createFrom().range(8, 11); List> list = Multi.createBy() .combining().streams(s1, s2, s3, s4, s5, s6, s7, s8).asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).hasSize(3) .containsExactly( Tuple8.of(1, 2, 3, 4, 5, 6, 7, 8), @@ -224,7 +224,7 @@ public void testCombinationOfNineStreamsAsTuple() { List> list = Multi .createBy() .combining().streams(s1, s2, s3, s4, s5, s6, s7, s8, s9).asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).hasSize(3) .containsExactly( Tuple9.of(1, 2, 3, 4, 5, 6, 7, 8, 9), @@ -256,13 +256,13 @@ public void testCombinationOfAStreamsOfDifferentSize() { List> list = Multi.createBy() .combining().streams(stream1, stream2).asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).hasSize(4).containsExactly(Tuple2.of(1, 1), Tuple2.of(2, 2), Tuple2.of(3, 3), Tuple2.of(4, 4)); list = Multi.createBy() .combining().streams(stream2, stream1).asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).hasSize(4).containsExactly(Tuple2.of(1, 1), Tuple2.of(2, 2), Tuple2.of(3, 3), Tuple2.of(4, 4)); } @@ -274,13 +274,13 @@ public void testCombinationOfAStreamsOfDifferentSizeUsingLatest() { List> list = Multi.createBy() .combining().streams(stream1, stream2).latestItems().asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).hasSize(7).containsExactly(Tuple2.of(4, 1), Tuple2.of(4, 2), Tuple2.of(4, 3), Tuple2.of(4, 4), Tuple2.of(4, 5), Tuple2.of(4, 6), Tuple2.of(4, 7)); list = Multi.createBy() .combining().streams(stream2, stream1).latestItems().asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).hasSize(4).containsExactly(Tuple2.of(7, 1), Tuple2.of(7, 2), Tuple2.of(7, 3), Tuple2.of(7, 4)); } @@ -444,7 +444,7 @@ public void testCombinationOfAFailingStream() { Multi.createBy() .combining().streams(stream, fail).asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); }); } @@ -605,15 +605,15 @@ public void testCombineLatest() { List> list = Multi.createBy().combining().streams(stream, stream).latestItems() .asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(Tuple2.of(3, 1), Tuple2.of(3, 2), Tuple2.of(3, 3)); List list2 = Multi.createBy().combining().streams(stream, stream).latestItems().using((a, b) -> a) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list2).containsExactly(3, 3, 3); list2 = Multi.createBy().combining().streams(stream, stream).latestItems().using((a, b) -> b) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list2).containsExactly(1, 2, 3); } @@ -622,7 +622,7 @@ public void testCombineLatestWithSinglePublisher() { Multi stream = Multi.createFrom().items(1, 2, 3); List list = Multi.createBy().combining().streams(Collections.singletonList(stream)) .using(l -> (Integer) l.get(0)) - .collectItems().asList() + .collect().asList() .await().indefinitely(); assertThat(list).containsExactly(1, 2, 3); } @@ -634,7 +634,7 @@ public void testCombineLatestWithEmpty() { List> list = Multi.createBy().combining().streams(stream, empty).latestItems() .asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).isEmpty(); } @@ -646,7 +646,7 @@ public void testCombineLatestWith3Streams() { List> list = Multi.createBy().combining().streams(one, two, three) .latestItems().asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(Tuple3.of(1, 2, 3), Tuple3.of(1, 2, 4)); } @@ -660,12 +660,12 @@ public void testCombineLatestWithFourStreams() { List> list = Multi.createBy().combining() .streams(one, two, three, four).latestItems().asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(Tuple4.of(1, 2, 4, 5)); list = Multi.createBy().combining().streams(one, two, four, three).latestItems().asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(Tuple4.of(1, 2, 5, 3), Tuple4.of(1, 2, 5, 4)); } @@ -680,18 +680,18 @@ public void testCombineLatestWithFiveStreams() { List> list = Multi.createBy().combining() .streams(one, two, three, four, five).latestItems().asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(Tuple5.of(1, 2, 4, 5, 6)); list = Multi.createBy().combining().streams(one, two, four, five, three).latestItems().asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(Tuple5.of(1, 2, 5, 6, 3), Tuple5.of(1, 2, 5, 6, 4)); list = Multi.createBy().combining().streams(one, two, four, Multi.createFrom(). empty(), three) .latestItems().asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).isEmpty(); } @@ -706,18 +706,18 @@ public void testCombineLatestWithSixStreams() { List> list = Multi.createBy().combining() .streams(one, two, three, four, five, six).latestItems().asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(Tuple6.of(1, 2, 4, 5, 6, 7)); list = Multi.createBy().combining().streams(one, two, four, five, six, three).latestItems().asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(Tuple6.of(1, 2, 5, 6, 7, 3), Tuple6.of(1, 2, 5, 6, 7, 4)); list = Multi.createBy().combining().streams(one, two, four, Multi.createFrom(). empty(), six, three) .latestItems().asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).isEmpty(); } @@ -733,12 +733,12 @@ public void testCombineLatestWithSevenStreams() { List> list = Multi.createBy().combining() .streams(one, two, three, four, five, six, seven).latestItems().asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(Tuple7.of(1, 2, 4, 5, 6, 7, 8)); list = Multi.createBy().combining().streams(one, two, four, five, six, seven, three).latestItems().asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(Tuple7.of(1, 2, 5, 6, 7, 8, 3), Tuple7.of(1, 2, 5, 6, 7, 8, 4)); @@ -746,7 +746,7 @@ public void testCombineLatestWithSevenStreams() { list = Multi.createBy().combining() .streams(one, two, four, Multi.createFrom(). empty(), six, three, seven) .latestItems().asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).isEmpty(); } @@ -764,13 +764,13 @@ public void testCombineLatestWithEightStreams() { List> list = Multi.createBy() .combining() .streams(one, two, three, four, five, six, seven, eight).latestItems().asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(Tuple8.of(1, 2, 4, 5, 6, 7, 8, 9)); list = Multi.createBy().combining().streams(one, two, four, five, six, seven, eight, three).latestItems() .asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(Tuple8.of(1, 2, 5, 6, 7, 8, 9, 3), Tuple8.of(1, 2, 5, 6, 7, 8, 9, 4)); @@ -778,7 +778,7 @@ public void testCombineLatestWithEightStreams() { list = Multi.createBy().combining() .streams(one, two, four, Multi.createFrom(). empty(), six, three, seven, eight) .latestItems().asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).isEmpty(); } @@ -798,13 +798,13 @@ public void testCombineLatestWithNineStreams() { .createBy() .combining() .streams(one, two, three, four, five, six, seven, eight, nine).latestItems().asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(Tuple9.of(1, 2, 4, 5, 6, 7, 8, 9, 10)); list = Multi.createBy().combining().streams(one, two, four, five, six, seven, eight, nine, three).latestItems() .asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(Tuple9.of(1, 2, 5, 6, 7, 8, 9, 10, 3), Tuple9.of(1, 2, 5, 6, 7, 8, 9, 10, 4)); @@ -812,7 +812,7 @@ public void testCombineLatestWithNineStreams() { list = Multi.createBy().combining() .streams(one, two, four, Multi.createFrom(). empty(), six, three, seven, eight, nine) .latestItems().asTuple() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).isEmpty(); } diff --git a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiCreateFromItemsTest.java b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiCreateFromItemsTest.java index 708f440ea..805da55bf 100644 --- a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiCreateFromItemsTest.java +++ b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiCreateFromItemsTest.java @@ -139,13 +139,13 @@ public void testCreateFromStreamOfOne() { public void testThatStreamCannotBeReused() { Stream stream = Stream.of(1, 2, 3, 4); List list = Multi.createFrom().items(stream) - .collectItems().asList() + .collect().asList() .await().indefinitely(); assertThat(list).containsExactly(1, 2, 3, 4); assertThatThrownBy(() -> Multi.createFrom().items(stream) - .collectItems().asList() + .collect().asList() .await().indefinitely()).isInstanceOf(IllegalStateException.class); } @@ -154,13 +154,13 @@ public void testThatMultiBasedOnStreamCannotBeReused() { Stream stream = Stream.of(1, 2, 3, 4); Multi multi = Multi.createFrom().items(stream); List list = multi - .collectItems().asList() + .collect().asList() .await().indefinitely(); assertThat(list).containsExactly(1, 2, 3, 4); assertThatThrownBy(() -> multi - .collectItems().asList() + .collect().asList() .await().indefinitely()).isInstanceOf(IllegalStateException.class); } diff --git a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiFilterTest.java b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiFilterTest.java index 602038cbe..f77e780de 100644 --- a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiFilterTest.java +++ b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiFilterTest.java @@ -58,7 +58,7 @@ public void testFilteringWithPredicate() { Predicate test = x -> x % 2 != 0; assertThat(Multi.createFrom().range(1, 4) .transform().byFilteringItemsWith(test) - .collectItems().asList() + .collect().asList() .await().indefinitely()).containsExactly(1, 3); } @@ -68,7 +68,7 @@ public void testFilteringWithUni() { .transform() .byTestingItemsWith( x -> Uni.createFrom().completionStage(() -> CompletableFuture.supplyAsync(() -> x % 2 != 0))) - .collectItems().asList() + .collect().asList() .await().indefinitely()).containsExactly(1, 3); } @@ -77,7 +77,7 @@ public void testFilterShortcut() { Predicate test = x -> x % 2 != 0; assertThat(Multi.createFrom().range(1, 4) .filter(test) - .collectItems().asList() + .collect().asList() .await().indefinitely()).containsExactly(1, 3); } diff --git a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiGroupTest.java b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiGroupTest.java index 2dec91d9f..e94bdb6a6 100644 --- a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiGroupTest.java +++ b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiGroupTest.java @@ -41,24 +41,36 @@ public void cleanup() { @Test public void testGroupIntoListsWithSize0() { assertThrows(IllegalArgumentException.class, - () -> Multi.createFrom().range(1, 5).groupItems().intoLists().of(0)); + () -> Multi.createFrom().range(1, 5).group().intoLists().of(0)); } @Test public void testGroupIntoListsWithSize0AndSkip() { assertThrows(IllegalArgumentException.class, - () -> Multi.createFrom().range(1, 5).groupItems().intoLists().of(0, 1)); + () -> Multi.createFrom().range(1, 5).group().intoLists().of(0, 1)); } @Test public void testGroupIntoListsWithSkip0() { assertThrows(IllegalArgumentException.class, - () -> Multi.createFrom().range(1, 5).groupItems().intoLists().of(1, 0)); + () -> Multi.createFrom().range(1, 5).group().intoLists().of(1, 0)); } @Test public void testGroupIntoListsOfTwoElements() { - AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).groupItems().intoLists().of(2) + AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).group().intoLists().of(2) + .subscribe().withSubscriber(AssertSubscriber.create(100)); + subscriber.assertCompleted(); + assertThat(subscriber.getItems()).containsExactly( + Arrays.asList(1, 2), Arrays.asList(3, 4), Arrays.asList(5, 6), Arrays.asList(7, 8), + Collections.singletonList(9)); + } + + @SuppressWarnings("deprecation") + @Test + public void testGroupIntoListsOfTwoElementsDeprecated() { + AssertSubscriber> subscriber = Multi.createFrom().range(1, 10) + .groupItems().intoLists().of(2) .subscribe().withSubscriber(AssertSubscriber.create(100)); subscriber.assertCompleted(); assertThat(subscriber.getItems()).containsExactly( @@ -68,7 +80,7 @@ public void testGroupIntoListsOfTwoElements() { @Test public void testGroupIntoListsOfTwoElementsWithRequests() { - AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).groupItems().intoLists().of(2) + AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).group().intoLists().of(2) .subscribe().withSubscriber(AssertSubscriber.create()); subscriber .assertSubscribed().assertHasNotReceivedAnyItem() @@ -87,7 +99,7 @@ public void testGroupIntoListsOfTwoElementsWithRequests() { @Test public void testGroupIntoListsOfTwoElementsWithSkip() { - AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).groupItems().intoLists() + AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).group().intoLists() .of(2, 3) .subscribe().withSubscriber(AssertSubscriber.create(100)); subscriber.assertCompleted(); @@ -97,7 +109,7 @@ public void testGroupIntoListsOfTwoElementsWithSkip() { @Test public void testGroupIntoListsOfTwoElementsWithSkipAndFailure() { - AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).groupItems().intoLists() + AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).group().intoLists() .of(2, 3).onCompletion().fail() .subscribe().withSubscriber(AssertSubscriber.create(100)); subscriber.assertFailedWith(NoSuchElementException.class, null); @@ -107,7 +119,7 @@ public void testGroupIntoListsOfTwoElementsWithSkipAndFailure() { @Test public void testGroupIntoListsOfTwoElementsWithSkipSmallerThanSize() { - AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).groupItems().intoLists() + AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).group().intoLists() .of(2, 1) .subscribe().withSubscriber(AssertSubscriber.create(100)); subscriber.assertCompleted(); @@ -119,7 +131,7 @@ public void testGroupIntoListsOfTwoElementsWithSkipSmallerThanSize() { @Test public void testGroupIntoListsOfTwoElementsWithSkipSmallerThanSizeAndFailure() { - AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).groupItems().intoLists() + AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).group().intoLists() .of(2, 1) .onCompletion().fail() .subscribe().withSubscriber(AssertSubscriber.create(100)); @@ -132,7 +144,7 @@ public void testGroupIntoListsOfTwoElementsWithSkipSmallerThanSizeAndFailure() { @Test public void testGroupIntoListsOfTwoElementsWithRequestsAndSkip() { - AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).groupItems().intoLists() + AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).group().intoLists() .of(2, 3) .subscribe().withSubscriber(AssertSubscriber.create()); subscriber @@ -151,12 +163,12 @@ public void testGroupIntoListsOfTwoElementsWithRequestsAndSkip() { @Test public void testCombinationOfToListsAndAwait() { - Multi> multi = Multi.createFrom().range(1, 10).groupItems().intoLists().of(2); + Multi> multi = Multi.createFrom().range(1, 10).group().intoLists().of(2); - assertThat(multi.collectItems().first().await().indefinitely()).containsExactly(1, 2); - assertThat(multi.collectItems().last().await().indefinitely()).containsExactly(9); + assertThat(multi.collect().first().await().indefinitely()).containsExactly(1, 2); + assertThat(multi.collect().last().await().indefinitely()).containsExactly(9); - assertThat(multi.collectItems().asList().await().indefinitely()).hasSize(5) + assertThat(multi.collect().asList().await().indefinitely()).hasSize(5) .containsExactly(Arrays.asList(1, 2), Arrays.asList(3, 4), Arrays.asList(5, 6), Arrays.asList(7, 8), Collections.singletonList(9)); } @@ -164,20 +176,20 @@ public void testCombinationOfToListsAndAwait() { @Test public void testAsListsOnEmptyStream() { assertThat( - Multi.createFrom().empty().groupItems().intoLists().of(2).collectItems().last().await().indefinitely()) + Multi.createFrom().empty().group().intoLists().of(2).collect().last().await().indefinitely()) .isNull(); } @Test public void testAsListsWithNegativeDuration() { assertThrows(IllegalArgumentException.class, - () -> Multi.createFrom().range(1, 10).groupItems().intoLists().every(Duration.ofMillis(-2))); + () -> Multi.createFrom().range(1, 10).group().intoLists().every(Duration.ofMillis(-2))); } @Test public void testAsListsWithDuration() { Multi publisher = Multi.createFrom().publisher(Multi.createFrom().ticks().every(Duration.ofMillis(2))); - AssertSubscriber> subscriber = publisher.groupItems().intoLists().every(Duration.ofMillis(100)) + AssertSubscriber> subscriber = publisher.group().intoLists().every(Duration.ofMillis(100)) .subscribe() .withSubscriber(AssertSubscriber.create(100)); @@ -189,7 +201,7 @@ public void testAsListsWithDuration() { public void testAsListsWithDurationWithCompletion() { Multi publisher = Multi.createFrom().publisher(Multi.createFrom().ticks().every(Duration.ofMillis(2))) .transform().byTakingFirstItems(10); - AssertSubscriber> subscriber = publisher.groupItems().intoLists().every(Duration.ofMillis(100)) + AssertSubscriber> subscriber = publisher.group().intoLists().every(Duration.ofMillis(100)) .subscribe() .withSubscriber(AssertSubscriber.create(100)); subscriber.await(); @@ -201,7 +213,7 @@ public void testAsListsWithDurationWithFailure() { Multi publisher = Multi.createFrom().publisher(Multi.createFrom().ticks().every(Duration.ofMillis(2))) .transform().byTakingFirstItems(10) .onCompletion().failWith(new IOException("boom")); - AssertSubscriber> subscriber = publisher.groupItems().intoLists().every(Duration.ofMillis(100)) + AssertSubscriber> subscriber = publisher.group().intoLists().every(Duration.ofMillis(100)) .subscribe() .withSubscriber(AssertSubscriber.create(100)); subscriber.await(); @@ -214,7 +226,7 @@ public void testAsListsWithDurationAndLackOfRequests() { AtomicBoolean cancelled = new AtomicBoolean(); Multi publisher = Multi.createFrom().publisher(Multi.createFrom().ticks().every(Duration.ofMillis(2))) .onCancellation().invoke(() -> cancelled.set(true)); - AssertSubscriber> subscriber = publisher.groupItems().intoLists().every(Duration.ofMillis(100)) + AssertSubscriber> subscriber = publisher.group().intoLists().every(Duration.ofMillis(100)) .subscribe() .withSubscriber(AssertSubscriber.create(2)); @@ -226,24 +238,24 @@ public void testAsListsWithDurationAndLackOfRequests() { @Test public void testGroupIntoMultisWithSize0() { assertThrows(IllegalArgumentException.class, - () -> Multi.createFrom().range(1, 5).groupItems().intoMultis().of(0)); + () -> Multi.createFrom().range(1, 5).group().intoMultis().of(0)); } @Test public void testGroupIntoMultisWithSize0AndSkip() { assertThrows(IllegalArgumentException.class, - () -> Multi.createFrom().range(1, 5).groupItems().intoMultis().of(0, 1)); + () -> Multi.createFrom().range(1, 5).group().intoMultis().of(0, 1)); } @Test public void testGroupIntoMultisWithSkip0() { assertThrows(IllegalArgumentException.class, - () -> Multi.createFrom().range(1, 5).groupItems().intoMultis().of(1, 0)); + () -> Multi.createFrom().range(1, 5).group().intoMultis().of(1, 0)); } @Test public void testGroupIntoMultisOfTwoElements() { - AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).groupItems().intoMultis() + AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).group().intoMultis() .of(2) .subscribe().withSubscriber(AssertSubscriber.create(100)); subscriber.assertCompleted(); @@ -255,7 +267,7 @@ public void testGroupIntoMultisOfTwoElements() { @Test public void testGroupIntoMultisOfTwoElementsWithFailure() { - AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).groupItems().intoMultis() + AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).group().intoMultis() .of(2) .onCompletion().fail() .subscribe().withSubscriber(AssertSubscriber.create(100)); @@ -269,14 +281,14 @@ public void testGroupIntoMultisOfTwoElementsWithFailure() { private List> flatten(List> items) { List> list = new ArrayList<>(); for (Multi multi : items) { - list.add(multi.collectItems().asList().await().indefinitely()); + list.add(multi.collect().asList().await().indefinitely()); } return list; } @Test public void testGroupIntoMultisOfTwoElementsWithRequests() { - AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).groupItems().intoMultis() + AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).group().intoMultis() .of(2) .subscribe().withSubscriber(AssertSubscriber.create()); subscriber @@ -295,7 +307,7 @@ public void testGroupIntoMultisOfTwoElementsWithRequests() { @Test public void testGroupIntoMultisOfTwoElementsWithSkip() { - AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).groupItems().intoMultis() + AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).group().intoMultis() .of(2, 3) .subscribe().withSubscriber(AssertSubscriber.create(100)); subscriber.assertCompleted(); @@ -305,7 +317,7 @@ public void testGroupIntoMultisOfTwoElementsWithSkip() { @Test public void testGroupIntoMultisOfTwoElementsWithSkipSmallerThanSize() { - AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).groupItems().intoMultis() + AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).group().intoMultis() .of(2, 1) .subscribe().withSubscriber(AssertSubscriber.create(100)); subscriber.assertCompleted(); @@ -317,7 +329,7 @@ public void testGroupIntoMultisOfTwoElementsWithSkipSmallerThanSize() { @Test public void testGroupIntoMultisOfTwoElementsWithRequestsAndSkip() { - AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).groupItems().intoMultis() + AssertSubscriber> subscriber = Multi.createFrom().range(1, 10).group().intoMultis() .of(2, 3) .subscribe().withSubscriber(AssertSubscriber.create()); subscriber @@ -335,14 +347,14 @@ public void testGroupIntoMultisOfTwoElementsWithRequestsAndSkip() { @Test public void testCombinationOfToMultisAndAwait() { - Multi> multi = Multi.createFrom().range(1, 10).groupItems().intoMultis().of(2); + Multi> multi = Multi.createFrom().range(1, 10).group().intoMultis().of(2); - assertThat(multi.collectItems().first().await().indefinitely().collectItems().asList().await().indefinitely()) + assertThat(multi.collect().first().await().indefinitely().collect().asList().await().indefinitely()) .containsExactly(1, 2); - assertThat(multi.collectItems().last().await().indefinitely().collectItems().asList().await().indefinitely()) + assertThat(multi.collect().last().await().indefinitely().collect().asList().await().indefinitely()) .containsExactly(9); - assertThat(flatten(multi.collectItems().asList().await().indefinitely())).hasSize(5) + assertThat(flatten(multi.collect().asList().await().indefinitely())).hasSize(5) .containsExactly(Arrays.asList(1, 2), Arrays.asList(3, 4), Arrays.asList(5, 6), Arrays.asList(7, 8), Collections.singletonList(9)); } @@ -350,20 +362,20 @@ public void testCombinationOfToMultisAndAwait() { @Test public void testAsMultisOnEmptyStream() { assertThat( - Multi.createFrom().empty().groupItems().intoMultis().of(2).collectItems().last().await().indefinitely()) + Multi.createFrom().empty().group().intoMultis().of(2).collect().last().await().indefinitely()) .isNull(); } @Test public void testAsMultisWithNegativeDuration() { assertThrows(IllegalArgumentException.class, - () -> Multi.createFrom().range(1, 10).groupItems().intoMultis().every(Duration.ofMillis(-2))); + () -> Multi.createFrom().range(1, 10).group().intoMultis().every(Duration.ofMillis(-2))); } @Test public void testAsMultisWithDuration() { Multi publisher = Multi.createFrom().publisher(Multi.createFrom().ticks().every(Duration.ofMillis(2))); - AssertSubscriber> subscriber = publisher.groupItems().intoMultis() + AssertSubscriber> subscriber = publisher.group().intoMultis() .every(Duration.ofMillis(100)) .subscribe() .withSubscriber(AssertSubscriber.create(100)); @@ -375,10 +387,10 @@ public void testAsMultisWithDuration() { @Test public void testBasicTimeWindow() { Multi> multi = Multi.createFrom().range(1, 7) - .groupItems().intoMultis().every(Duration.ofMillis(1)); + .group().intoMultis().every(Duration.ofMillis(1)); Uni> uni = multi .onItem().transformToMultiAndConcatenate(m -> m) - .collectItems().asList(); + .collect().asList(); List list = uni.await().atMost(Duration.ofSeconds(4)); assertThat(list).contains(1, 2, 3, 4, 5, 6); @@ -389,7 +401,7 @@ public void testBasicTimeWindowWithFailure() { Multi multi = Multi.createBy().concatenating().streams( Multi.createFrom().range(1, 7), Multi.createFrom().failure(() -> new IOException("boom"))) - .groupItems().intoMultis().every(Duration.ofMillis(1)) + .group().intoMultis().every(Duration.ofMillis(1)) .onItem().transformToMultiAndConcatenate(m -> m); multi.subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE)) @@ -402,8 +414,8 @@ public void testBasicTimeWindowWithFailure() { public void testThatWindowWithDurationEmitsEmptyLists() { AssertSubscriber> subscriber = AssertSubscriber.create(3); Multi.createFrom().nothing() - .groupItems().intoMultis().every(Duration.ofMillis(10)) - .onItem().transformToUniAndMerge(m -> m.collectItems().asList()) + .group().intoMultis().every(Duration.ofMillis(10)) + .onItem().transformToUniAndMerge(m -> m.collect().asList()) .subscribe().withSubscriber(subscriber); await().until(() -> subscriber.getItems().size() == 3); @@ -415,14 +427,14 @@ public void testThatWindowWithDurationEmitsEmptyLists() { @Test public void testGroupByWithKeyMapperOnly() { AssertSubscriber> subscriber = Multi.createFrom().range(1, 10) - .groupItems().by(i -> i % 2) + .group().by(i -> i % 2) .subscribe().withSubscriber(AssertSubscriber.create(100)); subscriber.assertCompleted(); assertThat(subscriber.getItems()).hasSize(2); - List odd = subscriber.getItems().get(0).collectItems().asList().await().indefinitely(); - List even = subscriber.getItems().get(1).collectItems().asList().await().indefinitely(); + List odd = subscriber.getItems().get(0).collect().asList().await().indefinitely(); + List even = subscriber.getItems().get(1).collect().asList().await().indefinitely(); assertThat(subscriber.getItems().get(0).key()).isEqualTo(1); assertThat(subscriber.getItems().get(1).key()).isEqualTo(0); @@ -434,14 +446,14 @@ public void testGroupByWithKeyMapperOnly() { @Test public void testGroupByWithKeyMapperAndValueMapper() { AssertSubscriber> subscriber = Multi.createFrom().range(1, 10) - .groupItems().by(i -> i % 2, t -> Integer.toString(t)) + .group().by(i -> i % 2, t -> Integer.toString(t)) .subscribe().withSubscriber(AssertSubscriber.create(100)); subscriber.assertCompleted(); assertThat(subscriber.getItems()).hasSize(2); - List odd = subscriber.getItems().get(0).collectItems().asList().await().indefinitely(); - List even = subscriber.getItems().get(1).collectItems().asList().await().indefinitely(); + List odd = subscriber.getItems().get(0).collect().asList().await().indefinitely(); + List even = subscriber.getItems().get(1).collect().asList().await().indefinitely(); assertThat(subscriber.getItems().get(0).key()).isEqualTo(1); assertThat(subscriber.getItems().get(1).key()).isEqualTo(0); @@ -453,32 +465,32 @@ public void testGroupByWithKeyMapperAndValueMapper() { @Test public void testGroupByProducingASingleGroup() { AssertSubscriber> subscriber = Multi.createFrom().range(1, 10) - .groupItems().by(i -> 0) + .group().by(i -> 0) .subscribe().withSubscriber(AssertSubscriber.create(100)); subscriber.assertCompleted(); assertThat(subscriber.getItems()).hasSize(1); - List numbers = subscriber.getItems().get(0).collectItems().asList().await().indefinitely(); + List numbers = subscriber.getItems().get(0).collect().asList().await().indefinitely(); assertThat(subscriber.getItems().get(0).key()).isEqualTo(0); assertThat(numbers).hasSize(9); } @Test public void testGroupByWithNullKeyMapper() { - assertThrows(IllegalArgumentException.class, () -> Multi.createFrom().range(1, 10).groupItems().by(null)); + assertThrows(IllegalArgumentException.class, () -> Multi.createFrom().range(1, 10).group().by(null)); } @Test public void testGroupByWithNullValueMapper() { assertThrows(IllegalArgumentException.class, - () -> Multi.createFrom().range(1, 10).groupItems().by(i -> i % 2, null)); + () -> Multi.createFrom().range(1, 10).group().by(i -> i % 2, null)); } @Test public void testGroupByOnFailingMulti() { AssertSubscriber> subscriber = Multi.createFrom() . failure(new IOException("boom")) - .groupItems().by(i -> i % 2) + .group().by(i -> i % 2) .subscribe().withSubscriber(AssertSubscriber.create(100)); subscriber.assertFailedWith(IOException.class, "boom"); @@ -488,7 +500,7 @@ public void testGroupByOnFailingMulti() { @Test public void testGroupByOnEmptyMulti() { AssertSubscriber> subscriber = Multi.createFrom(). empty() - .groupItems().by(i -> i % 2) + .group().by(i -> i % 2) .subscribe().withSubscriber(AssertSubscriber.create(100)); subscriber.assertCompleted().assertHasNotReceivedAnyItem(); @@ -497,7 +509,7 @@ public void testGroupByOnEmptyMulti() { @Test public void testGroupByFollowedWithAFlatMap() { AssertSubscriber subscriber = Multi.createFrom().range(1, 10) - .groupItems().by(i -> 1) + .group().by(i -> 1) .flatMap(gm -> gm) .subscribe().withSubscriber(AssertSubscriber.create(100)); @@ -512,7 +524,7 @@ public void requestingIsResumedAfterCancellationOfAGroupedMulti() { final AtomicBoolean done = new AtomicBoolean(); Multi.createFrom().range(0, 1001) .onItem().invoke(x -> counter.getAndIncrement()) - .groupItems().intoMultis().of(1) + .group().intoMultis().of(1) .subscribe().with(multi -> { AssertSubscriber subscriber = AssertSubscriber.create(0L); subscribers.add(subscriber); @@ -530,7 +542,7 @@ public void requestingIsResumedAfterCancellationOfAGroupedMulti() { @Test public void testSkipGroupWithFailures() { AssertSubscriber> subscriber = Multi.createFrom().failure(new IOException("boom")) - .groupItems().intoLists().of(2, 4) + .group().intoLists().of(2, 4) .subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE)); subscriber.assertFailedWith(IOException.class, "boom"); @@ -539,7 +551,7 @@ public void testSkipGroupWithFailures() { @Test public void testSkipGroupAsMultisWithFailures() { AssertSubscriber> subscriber = Multi.createFrom().failure(new IOException("boom")) - .groupItems().intoMultis().of(2, 4) + .group().intoMultis().of(2, 4) .subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE)); subscriber.assertFailedWith(IOException.class, "boom"); @@ -548,7 +560,7 @@ public void testSkipGroupAsMultisWithFailures() { @Test public void testOverlapGroupWithFailures() { AssertSubscriber> subscriber = Multi.createFrom().failure(new IOException("boom")) - .groupItems().intoLists().of(4, 2) + .group().intoLists().of(4, 2) .subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE)); subscriber.assertFailedWith(IOException.class, "boom"); @@ -557,7 +569,7 @@ public void testOverlapGroupWithFailures() { @Test public void testOverlapGroupAsMultisWithFailures() { AssertSubscriber> subscriber = Multi.createFrom().failure(new IOException("boom")) - .groupItems().intoMultis().of(4, 2) + .group().intoMultis().of(4, 2) .subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE)); subscriber.assertFailedWith(IOException.class, "boom"); @@ -566,7 +578,7 @@ public void testOverlapGroupAsMultisWithFailures() { @Test public void testExactGroupAsMultisWithFailures() { AssertSubscriber> subscriber = Multi.createFrom().failure(new IOException("boom")) - .groupItems().intoMultis().of(2) + .group().intoMultis().of(2) .subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE)); subscriber.assertFailedWith(IOException.class, "boom"); @@ -594,7 +606,7 @@ public void subscribe(MultiSubscriber subscriber) { }; AssertSubscriber> subscriber = rogue - .groupItems().intoLists().of(2, 4) + .group().intoLists().of(2, 4) .subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE)); subscriber.assertFailedWith(IOException.class, "boom-1"); @@ -623,7 +635,7 @@ public void subscribe(MultiSubscriber subscriber) { }; AssertSubscriber subscriber = rogue - .groupItems().intoMultis().of(2, 4) + .group().intoMultis().of(2, 4) .onItem().transformToMultiAndConcatenate(m -> m) .subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE)); @@ -653,7 +665,7 @@ public void subscribe(MultiSubscriber subscriber) { }; AssertSubscriber> subscriber = rogue - .groupItems().intoLists().of(4, 2) + .group().intoLists().of(4, 2) .subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE)); subscriber.assertFailedWith(IOException.class, "boom-1"); @@ -682,7 +694,7 @@ public void subscribe(MultiSubscriber subscriber) { }; AssertSubscriber subscriber = rogue - .groupItems().intoMultis().of(4, 2) + .group().intoMultis().of(4, 2) .onItem().transformToMultiAndConcatenate(m -> m) .subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE)); @@ -712,7 +724,7 @@ public void subscribe(MultiSubscriber subscriber) { }; AssertSubscriber subscriber = rogue - .groupItems().intoMultis().of(2) + .group().intoMultis().of(2) .onItem().transformToMultiAndConcatenate(m -> m) .subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE)); @@ -724,19 +736,19 @@ public void subscribe(MultiSubscriber subscriber) { public void testInvalidRequestsWhenGroupingIntoLists() { Subscriber> listExact = Mocks.subscriber(-1); Multi.createFrom().items(1, 2, 3, 4) - .groupItems().intoLists().of(2) + .group().intoLists().of(2) .subscribe().withSubscriber(listExact); verify(listExact).onError(any(IllegalArgumentException.class)); Subscriber> listSkip = Mocks.subscriber(-1); Multi.createFrom().items(1, 2, 3, 4) - .groupItems().intoLists().of(2, 4) + .group().intoLists().of(2, 4) .subscribe().withSubscriber(listSkip); verify(listSkip).onError(any(IllegalArgumentException.class)); Subscriber> listOverlap = Mocks.subscriber(-1); Multi.createFrom().items(1, 2, 3, 4) - .groupItems().intoLists().of(4, 2) + .group().intoLists().of(4, 2) .subscribe().withSubscriber(listOverlap); verify(listOverlap).onError(any(IllegalArgumentException.class)); } @@ -745,19 +757,19 @@ public void testInvalidRequestsWhenGroupingIntoLists() { public void testInvalidRequestsWhenGroupingIntoMultis() { Subscriber> listExact = Mocks.subscriber(-1); Multi.createFrom().items(1, 2, 3, 4) - .groupItems().intoMultis().of(2) + .group().intoMultis().of(2) .subscribe().withSubscriber(listExact); verify(listExact).onError(any(IllegalArgumentException.class)); Subscriber> listSkip = Mocks.subscriber(-1); Multi.createFrom().items(1, 2, 3, 4) - .groupItems().intoMultis().of(2, 4) + .group().intoMultis().of(2, 4) .subscribe().withSubscriber(listSkip); verify(listSkip).onError(any(IllegalArgumentException.class)); Subscriber> listOverlap = Mocks.subscriber(-1); Multi.createFrom().items(1, 2, 3, 4) - .groupItems().intoMultis().of(4, 2) + .group().intoMultis().of(4, 2) .subscribe().withSubscriber(listOverlap); verify(listOverlap).onError(any(IllegalArgumentException.class)); @@ -766,7 +778,7 @@ public void testInvalidRequestsWhenGroupingIntoMultis() { @Test public void testGroupByWithKeyMapperThrowingException() { AssertSubscriber> subscriber = Multi.createFrom().range(1, 10) - .groupItems(). by(i -> { + .group(). by(i -> { throw new ArithmeticException("boom"); }) .subscribe().withSubscriber(AssertSubscriber.create(100)); @@ -777,7 +789,7 @@ public void testGroupByWithKeyMapperThrowingException() { @Test public void testGroupByWithValueMapperThrowingException() { AssertSubscriber> subscriber = Multi.createFrom().range(1, 10) - .groupItems(). by(i -> i % 2, i -> { + .group(). by(i -> i % 2, i -> { throw new TestException("boom"); }) .subscribe().withSubscriber(AssertSubscriber.create(100)); @@ -788,7 +800,7 @@ public void testGroupByWithValueMapperThrowingException() { @Test public void testGroupByWithValueMapperReturningNull() { AssertSubscriber> subscriber = Multi.createFrom().range(1, 10) - .groupItems(). by(i -> i % 2, i -> null) + .group(). by(i -> i % 2, i -> null) .subscribe().withSubscriber(AssertSubscriber.create(100)); subscriber.assertFailedWith(NullPointerException.class, ""); @@ -797,7 +809,7 @@ public void testGroupByWithValueMapperReturningNull() { @Test public void testCancellationOnUpstream() { AssertSubscriber> subscriber = Multi.createFrom().ticks().every(Duration.ofMillis(2)) - .groupItems().by(l -> l % 2) + .group().by(l -> l % 2) .subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE)); subscriber.assertSubscribed(); @@ -823,7 +835,7 @@ public void testCancellationOnUpstream() { @Test public void testCancellationOnGroup() { AssertSubscriber> subscriber = Multi.createFrom().ticks().every(Duration.ofMillis(2)) - .groupItems().by(l -> l % 2) + .group().by(l -> l % 2) .subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE)); subscriber.assertSubscribed(); @@ -848,7 +860,7 @@ public void testCancellationOnGroup() { @Test public void testImmediateCancellationOnUpstream() { AssertSubscriber> subscriber = Multi.createFrom().ticks().every(Duration.ofMillis(2)) - .groupItems().by(l -> l % 2) + .group().by(l -> l % 2) .subscribe().withSubscriber(new AssertSubscriber<>(Long.MAX_VALUE, true)); subscriber.assertSubscribed(); @@ -864,7 +876,7 @@ public void testGroupByWithUpstreamFailure() { Multi.createFrom().emitter((Consumer>) emitter::set)); AssertSubscriber> subscriber = multi - .groupItems().by(l -> l % 2) + .group().by(l -> l % 2) .subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE)); subscriber.assertSubscribed(); @@ -890,7 +902,7 @@ public void testGroupByWithUpstreamFailure() { public void testGroupIntoListsWithMaximumDelay() { Multi publisher = Multi.createFrom().ticks().every(Duration.ofMillis(10)); - AssertSubscriber> subscriber = publisher.groupItems().intoLists().of(3, Duration.ofMillis(100)) + AssertSubscriber> subscriber = publisher.group().intoLists().of(3, Duration.ofMillis(100)) .subscribe() .withSubscriber(AssertSubscriber.create(10)); diff --git a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiOnEventTest.java b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiOnEventTest.java index c4fe2688d..0fd3a743b 100644 --- a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiOnEventTest.java +++ b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiOnEventTest.java @@ -639,7 +639,7 @@ public void testCallOnItem() { res.set(i); return sub.onItem().invoke(c -> twoGotCalled.incrementAndGet()); }) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(r).containsExactly(1, 2); assertThat(twoGotCalled).hasValue(2); @@ -655,7 +655,7 @@ public void testCallOnItemWithShortcut() { res.set(i); return sub.invoke(c -> twoGotCalled.incrementAndGet()); }) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(r).containsExactly(1, 2); assertThat(twoGotCalled).hasValue(2); @@ -672,7 +672,7 @@ public void testCallOnFailure() { res.set(i); return sub.onItem().invoke(c -> twoGotCalled.incrementAndGet()); }) - .collectItems().asList().await().indefinitely()) + .collect().asList().await().indefinitely()) .isInstanceOf(CompletionException.class) .hasCauseInstanceOf(IOException.class) .hasMessageContaining("boom"); @@ -692,7 +692,7 @@ public void testFailureInAsyncCallback() { } return Uni.createFrom().nullItem(); }) - .collectItems().asList() + .collect().asList() .await().indefinitely()).isInstanceOf(RuntimeException.class).hasMessageContaining("boom"); assertThat(res).hasValue(2); @@ -709,7 +709,7 @@ public void testNullReturnedByAsyncCallback() { } return Uni.createFrom().nullItem(); }) - .collectItems().asList() + .collect().asList() .await().indefinitely()).isInstanceOf(NullPointerException.class).hasMessageContaining("null"); assertThat(res).hasValue(2); } @@ -729,7 +729,7 @@ public void testCallWithSubFailure() { } return Uni.createFrom().nullItem(); }) - .collectItems().asList() + .collect().asList() .await().indefinitely()).isInstanceOf(IllegalStateException.class).hasMessageContaining("boom-2"); assertThat(twoGotCalled).hasValue(23); @@ -756,7 +756,7 @@ public void testInvokeOnItemWithShortcut() { AtomicInteger res = new AtomicInteger(); List r = numbers.invoke(res::set) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(r).containsExactly(1, 2); assertThat(res).hasValue(2); diff --git a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiSkipTest.java b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiSkipTest.java index b226e043d..1836aafcf 100644 --- a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiSkipTest.java +++ b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiSkipTest.java @@ -30,7 +30,7 @@ public void cleanup() { @Test public void testSimpleSkip() { List list = Multi.createFrom().range(1, 5).transform().bySkippingFirstItems(1) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(2, 3, 4); } @@ -38,7 +38,7 @@ public void testSimpleSkip() { @Test public void testSkipZero() { List list = Multi.createFrom().range(1, 5).transform().bySkippingFirstItems(0) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(1, 2, 3, 4); } @@ -46,7 +46,7 @@ public void testSkipZero() { @Test public void testSimpleSkipLast() { List list = Multi.createFrom().range(1, 5).transform().bySkippingLastItems(1) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(1, 2, 3); } @@ -54,7 +54,7 @@ public void testSimpleSkipLast() { @Test public void testSimpleSkipZeroLast() { List list = Multi.createFrom().range(1, 5).transform().bySkippingLastItems(0) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(1, 2, 3, 4); } diff --git a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiTakeTest.java b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiTakeTest.java index 84aa00e65..d6cf8a4ec 100644 --- a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiTakeTest.java +++ b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiTakeTest.java @@ -23,7 +23,7 @@ public class MultiTakeTest { @Test public void testSimpleTake() { List list = Multi.createFrom().range(1, 5).transform().byTakingFirstItems(1) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(1); } @@ -31,7 +31,7 @@ public void testSimpleTake() { @Test public void testTakeZero() { List list = Multi.createFrom().range(1, 5).transform().byTakingFirstItems(0) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).isEmpty(); } @@ -39,7 +39,7 @@ public void testTakeZero() { @Test public void testSimpleTakeLast() { List list = Multi.createFrom().range(1, 5).transform().byTakingLastItems(1) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(4); } @@ -47,7 +47,7 @@ public void testSimpleTakeLast() { @Test public void testSimpleTakeZeroLast() { List list = Multi.createFrom().range(1, 5).transform().byTakingLastItems(0) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).isEmpty(); } diff --git a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiTransformByMergingTest.java b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiTransformByMergingTest.java index 050af8876..1c227aa8d 100644 --- a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiTransformByMergingTest.java +++ b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiTransformByMergingTest.java @@ -23,7 +23,7 @@ public void testMerging() { Multi m1 = Multi.createFrom().range(1, 10); Multi m2 = Multi.createFrom().range(10, 12); - List list = m1.transform().byMergingWith(m2).collectItems().asList().await().indefinitely(); + List list = m1.transform().byMergingWith(m2).collect().asList().await().indefinitely(); assertThat(list).hasSize(11); } @@ -33,7 +33,7 @@ public void testMergingIterable() { Multi m2 = Multi.createFrom().range(10, 12); Multi m3 = Multi.createFrom().range(12, 14); - List list = m1.transform().byMergingWith(Arrays.asList(m2, m3)).collectItems().asList().await() + List list = m1.transform().byMergingWith(Arrays.asList(m2, m3)).collect().asList().await() .indefinitely(); assertThat(list).hasSize(13); } diff --git a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiTransformToMultiTest.java b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiTransformToMultiTest.java index ba7fc19d1..aaf397fae 100644 --- a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiTransformToMultiTest.java +++ b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiTransformToMultiTest.java @@ -479,7 +479,7 @@ public void testProduceCompletionStageDeprecated() { List list = Multi.createFrom().range(1, 4) .onItem().produceCompletionStage(i -> CompletableFuture.supplyAsync(() -> i + 1)) .merge() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).hasSize(3).contains(2, 3, 4); } @@ -491,7 +491,7 @@ public void testProduceCompletionStageRedeemingNullDeprecated() { Multi.createFrom().range(1, 4) .onItem().produceCompletionStage(i -> CompletableFuture.supplyAsync(() -> null)) .merge() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); }).isInstanceOf(NullPointerException.class); } @@ -506,7 +506,7 @@ public void testProduceCompletionStageRedeemingFailureDeprecated() { return cs; }) .merge() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); }).isInstanceOf(IllegalStateException.class) .hasMessage("boom"); } @@ -520,7 +520,7 @@ public void testProduceCompletionStageWithMapperThrowingExceptionDeprecated() { throw new IllegalStateException("boom"); }) .merge() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); }).isInstanceOf(IllegalStateException.class) .hasMessage("boom"); } @@ -534,7 +534,7 @@ public void testProduceCompletionStageWithMapperReturningNullDeprecated() { return null; }) .merge() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); }).isInstanceOf(NullPointerException.class); } @@ -544,7 +544,7 @@ public void testProduceCompletionStageAlternative() { .onItem() .transformToUni(i -> Uni.createFrom().completionStage(CompletableFuture.supplyAsync(() -> i + 1))) .merge() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).hasSize(3).contains(2, 3, 4); } @@ -555,7 +555,7 @@ public void testProduceIterableDeprecated() { List list = Multi.createFrom().range(1, 4) .onItem().produceIterable(i -> Arrays.asList(i, i + 1)) .merge() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).hasSize(6).containsExactlyInAnyOrder(1, 2, 2, 3, 3, 4); } @@ -564,7 +564,7 @@ public void testProduceIterableDeprecated() { public void testTransformToIterable() { List list = Multi.createFrom().range(1, 4) .onItem().transformToIterable(i -> Arrays.asList(i, i + 1)) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).hasSize(6).containsExactlyInAnyOrder(1, 2, 2, 3, 3, 4); } @@ -575,7 +575,7 @@ public void testTransformToIterableWithMapperThrowingException() { .onItem(). transformToIterable(i -> { throw new IllegalStateException("boom"); }) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); }) .isInstanceOf(IllegalStateException.class) .hasMessage("boom"); @@ -586,7 +586,7 @@ public void testTransformToIterableWithMapperReturningNull() { assertThatThrownBy(() -> { Multi.createFrom().range(1, 4) .onItem(). transformToIterable(i -> null) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); }) .isInstanceOf(NullPointerException.class); } @@ -596,7 +596,7 @@ public void testProduceIterableWithMapperReturningNullDeprecated() { assertThatThrownBy(() -> { Multi.createFrom().range(1, 4) .onItem(). produceIterable(i -> null).concatenate() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); }) .isInstanceOf(NullPointerException.class); } @@ -932,7 +932,7 @@ public void testMaxConcurrencyNormal() { @RepeatedTest(10) public void testThatConcurrencyDontMissItems() { int max = 10000; - List expected = Multi.createFrom().range(0, max).collectItems().asList().await().indefinitely(); + List expected = Multi.createFrom().range(0, max).collect().asList().await().indefinitely(); AssertSubscriber subscriber = Multi.createFrom().range(0, max) .onItem() .transformToMulti( @@ -949,7 +949,7 @@ public void testThatConcurrencyDontMissItems() { @RepeatedTest(10) public void testThatConcatenateDontMissItemsAndPreserveOrder() { int max = 10000; - List expected = Multi.createFrom().range(0, max).collectItems().asList().await().indefinitely(); + List expected = Multi.createFrom().range(0, max).collect().asList().await().indefinitely(); AssertSubscriber subscriber = Multi.createFrom().range(0, max) .onItem() .transformToMulti( diff --git a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiTransformToUniTest.java b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiTransformToUniTest.java index ac4ba065d..a1d5664cc 100644 --- a/implementation/src/test/java/io/smallrye/mutiny/operators/MultiTransformToUniTest.java +++ b/implementation/src/test/java/io/smallrye/mutiny/operators/MultiTransformToUniTest.java @@ -20,7 +20,7 @@ public void testTransformToUniAndConcatenate() { .onItem() .transformToUni(i -> Uni.createFrom().completionStage(CompletableFuture.supplyAsync(() -> i + 1))) .concatenate() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(2, 3, 4); } @@ -98,7 +98,7 @@ public void testTransformToUniAndConcatenateSingleCall() { List list = Multi.createFrom().range(1, 4) .onItem() .transformToUniAndConcatenate(i -> Uni.createFrom().completionStage(CompletableFuture.supplyAsync(() -> i + 1))) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(2, 3, 4); } @@ -109,7 +109,7 @@ public void testTransformToUniAndMerge() { .onItem() .transformToUni(i -> Uni.createFrom().completionStage(CompletableFuture.supplyAsync(() -> i + 1))) .merge() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactlyInAnyOrder(2, 3, 4); } @@ -178,7 +178,7 @@ public void testTransformToUniAndMergeSingleCall() { List list = Multi.createFrom().range(1, 4) .onItem() .transformToUniAndMerge(i -> Uni.createFrom().completionStage(CompletableFuture.supplyAsync(() -> i + 1))) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactlyInAnyOrder(2, 3, 4); } @@ -192,7 +192,7 @@ public void testTransformToUniAndMergeWithUniOfVoid() { return i; } }))) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactlyInAnyOrder(1, 3, 5); } @@ -208,7 +208,7 @@ public void testTransformToUniAndConcatenateWithUniOfVoid() { return i; } }))) - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(1, 3, 5); } @@ -219,7 +219,7 @@ public void testProduceUniDeprecated() { List list = Multi.createFrom().range(1, 4) .onItem().produceUni(i -> Uni.createFrom().completionStage(CompletableFuture.supplyAsync(() -> i + 1))) .concatenate() - .collectItems().asList().await().indefinitely(); + .collect().asList().await().indefinitely(); assertThat(list).containsExactly(2, 3, 4); } diff --git a/implementation/src/test/java/io/smallrye/mutiny/operators/UniOnItemDisjointTest.java b/implementation/src/test/java/io/smallrye/mutiny/operators/UniOnItemDisjointTest.java index c1e4a81f6..af962a50e 100644 --- a/implementation/src/test/java/io/smallrye/mutiny/operators/UniOnItemDisjointTest.java +++ b/implementation/src/test/java/io/smallrye/mutiny/operators/UniOnItemDisjointTest.java @@ -25,7 +25,7 @@ public class UniOnItemDisjointTest { public void testDisjointWithArray() { List r = array .onItem(). disjoint() - .collectItems().asList() + .collect().asList() .await().indefinitely(); assertThat(r).containsExactly("a", "b", "c"); } @@ -34,7 +34,7 @@ public void testDisjointWithArray() { public void testDisjointWithEmptyArray() { List r = Uni.createFrom().item(new String[0]) .onItem(). disjoint() - .collectItems().asList() + .collect().asList() .await().indefinitely(); assertThat(r).isEmpty(); } @@ -43,7 +43,7 @@ public void testDisjointWithEmptyArray() { public void testDisjointFromFailure() { assertThatThrownBy(() -> failed .onItem(). disjoint() - .collectItems().asList() + .collect().asList() .await().indefinitely()).hasCauseInstanceOf(IOException.class); } @@ -51,7 +51,7 @@ public void testDisjointFromFailure() { public void testDisjointFromInvalidItemType() { assertThatThrownBy(() -> Uni.createFrom().item("hello") .onItem(). disjoint() - .collectItems().asList() + .collect().asList() .await().indefinitely()).isInstanceOf(IllegalArgumentException.class); } @@ -59,7 +59,7 @@ public void testDisjointFromInvalidItemType() { public void testDisjointFromNull() { List list = Uni.createFrom().nullItem() .onItem(). disjoint() - .collectItems().asList() + .collect().asList() .await().indefinitely(); assertThat(list).isEmpty(); @@ -69,7 +69,7 @@ public void testDisjointFromNull() { public void testDisjointWithPublisher() { List r = Uni.createFrom().item(Flowable.just("a", "b", "c")) .onItem(). disjoint() - .collectItems().asList() + .collect().asList() .await().indefinitely(); assertThat(r).containsExactly("a", "b", "c"); } @@ -78,7 +78,7 @@ public void testDisjointWithPublisher() { public void testDisjointWithEmptyPublisher() { List r = Uni.createFrom().item(Flowable.empty()) .onItem(). disjoint() - .collectItems().asList() + .collect().asList() .await().indefinitely(); assertThat(r).isEmpty(); } @@ -87,7 +87,7 @@ public void testDisjointWithEmptyPublisher() { public void testDisjointWithMulti() { List r = Uni.createFrom().item(Multi.createFrom().items("a", "b", "c")) .onItem(). disjoint() - .collectItems().asList() + .collect().asList() .await().indefinitely(); assertThat(r).containsExactly("a", "b", "c"); } @@ -96,7 +96,7 @@ public void testDisjointWithMulti() { public void testDisjointWithEmptyMulti() { List r = Uni.createFrom().item(Multi.createFrom().empty()) .onItem(). disjoint() - .collectItems().asList() + .collect().asList() .await().indefinitely(); assertThat(r).isEmpty(); } @@ -105,7 +105,7 @@ public void testDisjointWithEmptyMulti() { public void testDisjointWithIterable() { List r = Uni.createFrom().item(Arrays.asList("a", "b", "c")) .onItem(). disjoint() - .collectItems().asList() + .collect().asList() .await().indefinitely(); assertThat(r).containsExactly("a", "b", "c"); } @@ -114,7 +114,7 @@ public void testDisjointWithIterable() { public void testDisjointWithEmptyIterable() { List r = Uni.createFrom().item(Collections.emptyList()) .onItem(). disjoint() - .collectItems().asList() + .collect().asList() .await().indefinitely(); assertThat(r).isEmpty(); } diff --git a/implementation/src/test/java/io/smallrye/mutiny/operators/UniOnNotNullItemTest.java b/implementation/src/test/java/io/smallrye/mutiny/operators/UniOnNotNullItemTest.java index be719a5cb..fc680f3eb 100644 --- a/implementation/src/test/java/io/smallrye/mutiny/operators/UniOnNotNullItemTest.java +++ b/implementation/src/test/java/io/smallrye/mutiny/operators/UniOnNotNullItemTest.java @@ -235,18 +235,18 @@ public void testProduceCompletionStageDeprecated() { public void testTransformToMulti() { assertThat(Uni.createFrom().item("hello") .onItem().ifNotNull().transformToMulti(x -> Multi.createFrom().item(x.toUpperCase())) - .collectItems().first() + .collect().first() .await().indefinitely()).isEqualTo("HELLO"); assertThat(Uni.createFrom().item(() -> (String) null) .onItem().ifNotNull().transformToMulti(x -> Multi.createFrom().item(x.toUpperCase())) - .collectItems().first() + .collect().first() .onItem().ifNull().continueWith("yolo") .await().indefinitely()).isEqualTo("yolo"); assertThatThrownBy(() -> Uni.createFrom(). failure(new Exception("boom")) .onItem().ifNotNull().transformToMulti(x -> Multi.createFrom().item(x.toUpperCase())) - .collectItems().first() + .collect().first() .onItem().ifNull().continueWith("yolo") .await().indefinitely()).hasMessageContaining("boom"); } @@ -256,18 +256,18 @@ public void testTransformToMulti() { public void testProduceMultiDeprecated() { assertThat(Uni.createFrom().item("hello") .onItem().ifNotNull().produceMulti(x -> Multi.createFrom().item(x.toUpperCase())) - .collectItems().first() + .collect().first() .await().indefinitely()).isEqualTo("HELLO"); assertThat(Uni.createFrom().item(() -> (String) null) .onItem().ifNotNull().produceMulti(x -> Multi.createFrom().item(x.toUpperCase())) - .collectItems().first() + .collect().first() .onItem().ifNull().continueWith("yolo") .await().indefinitely()).isEqualTo("yolo"); assertThatThrownBy(() -> Uni.createFrom(). failure(new Exception("boom")) .onItem().ifNotNull().produceMulti(x -> Multi.createFrom().item(x.toUpperCase())) - .collectItems().first() + .collect().first() .onItem().ifNull().continueWith("yolo") .await().indefinitely()).hasMessageContaining("boom"); } diff --git a/implementation/src/test/java/io/smallrye/mutiny/operators/UniRepeatTest.java b/implementation/src/test/java/io/smallrye/mutiny/operators/UniRepeatTest.java index 2b8d8e094..963ce1cfb 100644 --- a/implementation/src/test/java/io/smallrye/mutiny/operators/UniRepeatTest.java +++ b/implementation/src/test/java/io/smallrye/mutiny/operators/UniRepeatTest.java @@ -29,7 +29,7 @@ public class UniRepeatTest { public void testRepeatAtMost() { List list = Uni.createFrom().item(1) .repeat().atMost(3) - .collectItems().asList() + .collect().asList() .await().atMost(Duration.ofSeconds(5)); assertThat(list).hasSize(3).contains(1, 1, 1); } @@ -40,7 +40,7 @@ public void testRepeatUntil() { Iterator iterator = items.iterator(); List list = Uni.createFrom().item(iterator::next) .repeat().until(v -> v.equalsIgnoreCase("d")) - .collectItems().asList() + .collect().asList() .await().atMost(Duration.ofSeconds(5)); assertThat(list).hasSize(3).contains("a", "b", "c"); } @@ -67,7 +67,7 @@ public void testRepeatWhilst() { public void testRepeat0() { assertThrows(IllegalArgumentException.class, () -> Uni.createFrom().item(0) .repeat().atMost(0) - .collectItems().asList() + .collect().asList() .await().indefinitely()); } @@ -75,7 +75,7 @@ public void testRepeat0() { public void testRepeatUntilWithNullPredicate() { assertThrows(IllegalArgumentException.class, () -> Uni.createFrom().item(0) .repeat().until(null) - .collectItems().asList() + .collect().asList() .await().indefinitely()); } @@ -83,7 +83,7 @@ public void testRepeatUntilWithNullPredicate() { public void testRepeatWhilstWithNullPredicate() { assertThrows(IllegalArgumentException.class, () -> Uni.createFrom().item(0) .repeat().whilst(null) - .collectItems().asList() + .collect().asList() .await().indefinitely()); } @@ -92,7 +92,7 @@ public void testRepeat1() { AtomicInteger count = new AtomicInteger(); List list = Uni.createFrom().item(count::getAndIncrement) .repeat().atMost(1) - .collectItems().asList() + .collect().asList() .await().atMost(Duration.ofSeconds(5)); assertThat(list).containsExactly(0); @@ -105,7 +105,7 @@ public void testRepeatUntilOnlyOnce() { AtomicBoolean once = new AtomicBoolean(); List list = Uni.createFrom().item(count::getAndIncrement) .repeat().until(x -> once.getAndSet(true)) - .collectItems().asList() + .collect().asList() .await().atMost(Duration.ofSeconds(5)); assertThat(list).containsExactly(0); @@ -118,7 +118,7 @@ public void testRepeatWhilstOnlyOnce() { AtomicBoolean once = new AtomicBoolean(true); List list = Uni.createFrom().item(count::getAndIncrement) .repeat().whilst(x -> once.getAndSet(false)) - .collectItems().asList() + .collect().asList() .await().atMost(Duration.ofSeconds(5)); assertThat(list).containsExactly(0, 1); @@ -130,7 +130,7 @@ public void testNoRepeatUntil() { AtomicInteger count = new AtomicInteger(); List list = Uni.createFrom().item(count::getAndIncrement) .repeat().until(x -> true) - .collectItems().asList() + .collect().asList() .await().atMost(Duration.ofSeconds(5)); assertThat(list).isEmpty(); @@ -142,7 +142,7 @@ public void testNoRepeatWhilst() { AtomicInteger count = new AtomicInteger(); List list = Uni.createFrom().item(count::getAndIncrement) .repeat().whilst(x -> false) - .collectItems().asList() + .collect().asList() .await().atMost(Duration.ofSeconds(5)); assertThat(list).containsExactly(0); @@ -157,7 +157,7 @@ public void testRepeatCancelledWithTake() { .repeat().indefinitely() .runSubscriptionOn(Infrastructure.getDefaultWorkerPool()) .transform().byTakingFirstItems(num) - .collectItems().last() + .collect().last() .await().atMost(Duration.ofSeconds(5)); assertThat(num).isEqualTo(value); assertThat(count).hasValue(value); @@ -175,7 +175,7 @@ public void testRepeatUntilCancelledWithTake() { }) .runSubscriptionOn(Infrastructure.getDefaultWorkerPool()) .transform().byTakingFirstItems(num) - .collectItems().last() + .collect().last() .await().atMost(Duration.ofSeconds(5)); assertThat(num).isEqualTo(value); assertThat(count).hasValue(value); @@ -194,7 +194,7 @@ public void testRepeatWhilstCancelledWithTake() { }) .runSubscriptionOn(Infrastructure.getDefaultWorkerPool()) .transform().byTakingFirstItems(num) - .collectItems().last() + .collect().last() .await().atMost(Duration.ofSeconds(5)); assertThat(num).isEqualTo(value); assertThat(count).hasValue(value); @@ -206,7 +206,7 @@ public void testNoStackOverflow() { int value = Uni.createFrom().item(1).repeat().indefinitely() .runSubscriptionOn(Infrastructure.getDefaultWorkerPool()) .transform().byTakingFirstItems(100000L) - .collectItems().last() + .collect().last() .await().atMost(Duration.ofSeconds(5)); assertThat(value).isEqualTo(1); } @@ -217,7 +217,7 @@ public void testNoStackOverflowWithRepeatUntil() { int value = Uni.createFrom().item(1).repeat().until(x -> count.incrementAndGet() > 100000000L) .runSubscriptionOn(Infrastructure.getDefaultWorkerPool()) .transform().byTakingFirstItems(100000L) - .collectItems().last() + .collect().last() .await().atMost(Duration.ofSeconds(5)); assertThat(value).isEqualTo(1); } @@ -228,7 +228,7 @@ public void testNoStackOverflowWithRepeatWhilst() { int value = Uni.createFrom().item(1).repeat().whilst(x -> count.incrementAndGet() < 100000000L) .runSubscriptionOn(Infrastructure.getDefaultWorkerPool()) .transform().byTakingFirstItems(100000L) - .collectItems().last() + .collect().last() .await().atMost(Duration.ofSeconds(5)); assertThat(value).isEqualTo(1); } @@ -624,7 +624,7 @@ public void testRepetitionWithState() { () -> new AtomicInteger(0), (s, e) -> e.complete(s.getAndIncrement())) .repeat().atMost(3) - .collectItems().asList() + .collect().asList() .await().atMost(Duration.ofSeconds(5)); assertThat(list).containsExactly(0, 1, 2); } diff --git a/implementation/src/test/java/io/smallrye/mutiny/operators/UniToPublisherTest.java b/implementation/src/test/java/io/smallrye/mutiny/operators/UniToPublisherTest.java index c6cfd3972..fe511bbc2 100644 --- a/implementation/src/test/java/io/smallrye/mutiny/operators/UniToPublisherTest.java +++ b/implementation/src/test/java/io/smallrye/mutiny/operators/UniToPublisherTest.java @@ -218,6 +218,6 @@ public void testWithAsyncFailure() { public void testUniOfVoid() { Uni uni = Uni.createFrom().voidItem(); Multi publisher = uni.toMulti(); - assertThat(publisher.collectItems().asList().await().indefinitely()).isEmpty(); + assertThat(publisher.collect().asList().await().indefinitely()).isEmpty(); } } diff --git a/implementation/src/test/java/tck/MultiCollectTest.java b/implementation/src/test/java/tck/MultiCollectTest.java index a0402383a..ccc6b4bc3 100644 --- a/implementation/src/test/java/tck/MultiCollectTest.java +++ b/implementation/src/test/java/tck/MultiCollectTest.java @@ -22,21 +22,21 @@ public class MultiCollectTest extends AbstractTck { @Test public void toListStageShouldReturnAList() { List list = await( - Multi.createFrom().items(1, 2, 3).collectItems().asList().subscribeAsCompletionStage()); + Multi.createFrom().items(1, 2, 3).collect().asList().subscribeAsCompletionStage()); assertEquals(list, Arrays.asList(1, 2, 3)); } @Test public void toListStageShouldReturnEmpty() { assertEquals( - await(Multi.createFrom().items().collectItems().asList().subscribeAsCompletionStage()), + await(Multi.createFrom().items().collect().asList().subscribeAsCompletionStage()), Collections.emptyList()); } @Test public void collectShouldAccumulateResult() { CompletableFuture future = Multi.createFrom().items(1, 2, 3) - .collectItems().in( + .collect().in( () -> new AtomicInteger(0), AtomicInteger::addAndGet) .subscribeAsCompletionStage(); @@ -45,7 +45,7 @@ public void collectShouldAccumulateResult() { @Test public void collectShouldSupportEmptyStreams() { - CompletableFuture future = Multi.createFrom(). empty().collectItems().in( + CompletableFuture future = Multi.createFrom(). empty().collect().in( () -> new AtomicInteger(42), AtomicInteger::addAndGet) .subscribeAsCompletionStage(); @@ -56,7 +56,7 @@ public void collectShouldSupportEmptyStreams() { public void collectShouldPropagateUpstreamErrors() { assertThrows(QuietRuntimeException.class, () -> await(Multi.createFrom() . failure(new QuietRuntimeException("failed")) - .collectItems().in( + .collect().in( () -> new AtomicInteger(0), AtomicInteger::addAndGet) .subscribeAsCompletionStage())); @@ -65,14 +65,14 @@ public void collectShouldPropagateUpstreamErrors() { @Test public void finisherFunctionShouldBeInvoked() { assertEquals(await(Multi.createFrom().items("1", "2", "3") - .collectItems().with(Collectors.joining(", ")).subscribeAsCompletionStage()), "1, 2, 3"); + .collect().with(Collectors.joining(", ")).subscribeAsCompletionStage()), "1, 2, 3"); } @Test public void toListStageShouldPropagateUpstreamErrors() { assertThrows(QuietRuntimeException.class, () -> await(Multi.createFrom() .failure(new QuietRuntimeException("failed")) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage())); } @@ -88,7 +88,7 @@ public void collectStageShouldPropagateErrorsFromSupplierThroughCompletionStage( cancelled.complete(null); } }) - .collectItems().with(Collector. of(() -> { + .collect().with(Collector. of(() -> { throw new QuietRuntimeException("failed"); }, (a, b) -> { }, Integer::sum, Function.identity())) @@ -109,7 +109,7 @@ public void collectStageShouldPropagateErrorsFromAccumulator() { CompletionStage result = infiniteStream() .onTermination().invoke(() -> cancelled.complete(null)) - .collectItems().with(Collector.of(() -> "", (a, b) -> { + .collect().with(Collector.of(() -> "", (a, b) -> { throw new QuietRuntimeException("failed"); }, (a, b) -> a + b, Function.identity())) .subscribeAsCompletionStage(); @@ -122,7 +122,7 @@ public void collectStageShouldPropagateErrorsFromAccumulator() { public void collectStageShouldPropagateErrorsFromFinisher() { assertThrows(QuietRuntimeException.class, () -> { CompletionStage result = Multi.createFrom().items(1, 2, 3) - .collectItems().with(Collector. of(() -> 0, (a, b) -> { + .collect().with(Collector. of(() -> 0, (a, b) -> { }, Integer::sum, r -> { diff --git a/implementation/src/test/java/tck/MultiConcatTckTest.java b/implementation/src/test/java/tck/MultiConcatTckTest.java index af3498432..ed8171040 100644 --- a/implementation/src/test/java/tck/MultiConcatTckTest.java +++ b/implementation/src/test/java/tck/MultiConcatTckTest.java @@ -20,7 +20,7 @@ public void concatStageShouldConcatTwoGraphs() { Multi.createBy().concatenating().streams( Multi.createFrom().items(1, 2, 3), Multi.createFrom().items(4, 5, 6)) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Arrays.asList(1, 2, 3, 4, 5, 6)); } @@ -30,7 +30,7 @@ public void concatStageShouldPropagateExceptionsFromSecondStage() { assertThrows(QuietRuntimeException.class, () -> await( Multi.createBy().concatenating().streams( Multi.createFrom().items(1, 2, 3), - Multi.createFrom().failure(new QuietRuntimeException("failed"))).collectItems().asList() + Multi.createFrom().failure(new QuietRuntimeException("failed"))).collect().asList() .subscribeAsCompletionStage())); } @@ -40,7 +40,7 @@ public void concatStageShouldWorkWithEmptyFirstGraph() { Multi.createBy().concatenating().streams( Multi.createFrom().empty(), Multi.createFrom().items(1, 2, 3)) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Arrays.asList(1, 2, 3)); } @@ -51,7 +51,7 @@ public void concatStageShouldWorkWithEmptySecondGraph() { Multi.createBy().concatenating().streams( Multi.createFrom().items(1, 2, 3), Multi.createFrom().empty()) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Arrays.asList(1, 2, 3)); } @@ -62,7 +62,7 @@ public void concatStageShouldWorkWithBothGraphsEmpty() { Multi.createBy().concatenating().streams( Multi.createFrom().empty(), Multi.createFrom().empty()) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Collections.emptyList()); } @@ -77,7 +77,7 @@ public void concatStageShouldSupportNestedConcats() { Multi.createBy().concatenating().streams( Multi.createFrom().items(7, 8, 9), Multi.createFrom().items(10, 11, 12))) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)); } diff --git a/implementation/src/test/java/tck/MultiDistinctTckTest.java b/implementation/src/test/java/tck/MultiDistinctTckTest.java index 76b05f074..c73c8c164 100644 --- a/implementation/src/test/java/tck/MultiDistinctTckTest.java +++ b/implementation/src/test/java/tck/MultiDistinctTckTest.java @@ -22,7 +22,7 @@ public void distinctStageShouldReturnDistinctElements() { assertEquals(await( Multi.createFrom().items(1, 2, 2, 3, 2, 1, 3) .transform().byDroppingDuplicates() - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Arrays.asList(1, 2, 3)); } @@ -31,7 +31,7 @@ public void distinctStageShouldReturnDistinctElements() { public void distinctStageShouldReturnAnEmptyStreamWhenCalledOnEmptyStreams() { assertEquals(await(Multi.createFrom().empty() .transform().byDroppingDuplicates() - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Collections.emptyList()); } @@ -40,7 +40,7 @@ public void distinctStageShouldPropagateUpstreamExceptions() { assertThrows(QuietRuntimeException.class, () -> await(Multi.createFrom().failure(new QuietRuntimeException("failed")) .transform().byDroppingDuplicates() - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage())); } @@ -62,7 +62,7 @@ public boolean equals(Object obj) { CompletionStage> result = Multi.createFrom().items( new ObjectThatThrowsFromEquals(), new ObjectThatThrowsFromEquals()) .onTermination().invoke(() -> cancelled.complete(null)) - .transform().byDroppingDuplicates().collectItems().asList().subscribeAsCompletionStage(); + .transform().byDroppingDuplicates().collect().asList().subscribeAsCompletionStage(); await(cancelled); await(result); }); diff --git a/implementation/src/test/java/tck/MultiFirstTckTest.java b/implementation/src/test/java/tck/MultiFirstTckTest.java index c746028af..686cd27d4 100644 --- a/implementation/src/test/java/tck/MultiFirstTckTest.java +++ b/implementation/src/test/java/tck/MultiFirstTckTest.java @@ -14,7 +14,7 @@ public class MultiFirstTckTest extends AbstractTck { public void findFirstStageShouldFindTheFirstElement() { int res = await( Multi.createFrom().items(1, 2, 3) - .collectItems().first() + .collect().first() .subscribeAsCompletionStage()); assertEquals(res, 1); } @@ -22,14 +22,14 @@ public void findFirstStageShouldFindTheFirstElement() { @Test public void findFirstStageShouldFindTheFirstElementInSingleElementStream() { int result = await(Multi.createFrom().item(1) - .collectItems().first().subscribeAsCompletionStage()); + .collect().first().subscribeAsCompletionStage()); assertEquals(result, 1); } @Test public void findFirstStageShouldReturnEmptyForEmptyStream() { assertNull(await(Multi.createFrom().items() - .collectItems().first().subscribeAsCompletionStage())); + .collect().first().subscribeAsCompletionStage())); } @Test @@ -37,7 +37,7 @@ public void findFirstStageShouldCancelUpstream() { CompletableFuture cancelled = new CompletableFuture<>(); int result = await(infiniteStream() .onTermination().invoke(() -> cancelled.complete(null)) - .collectItems().first().subscribeAsCompletionStage()); + .collect().first().subscribeAsCompletionStage()); assertEquals(result, 1); await(cancelled); } @@ -46,13 +46,13 @@ public void findFirstStageShouldCancelUpstream() { public void findFirstStageShouldPropagateErrors() { assertThrows(QuietRuntimeException.class, () -> await(Multi.createFrom().failure(new QuietRuntimeException("failed")) - .collectItems().first().subscribeAsCompletionStage())); + .collect().first().subscribeAsCompletionStage())); } @Test public void findFirstStageShouldBeReusable() { int result = await(Multi.createFrom().items(1, 2, 3) - .collectItems().first().subscribeAsCompletionStage()); + .collect().first().subscribeAsCompletionStage()); assertEquals(result, 1); } } diff --git a/implementation/src/test/java/tck/MultiFlatMapCompletionStageTckTest.java b/implementation/src/test/java/tck/MultiFlatMapCompletionStageTckTest.java index 9f20c6f4e..f62874624 100644 --- a/implementation/src/test/java/tck/MultiFlatMapCompletionStageTckTest.java +++ b/implementation/src/test/java/tck/MultiFlatMapCompletionStageTckTest.java @@ -25,7 +25,7 @@ public void flatMapCsStageShouldMapFutures() { CompletableFuture three = new CompletableFuture<>(); CompletionStage> result = Multi.createFrom().> items(one, two, three) .onItem().transformToUni(i -> Uni.createFrom().completionStage(i)).merge() - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage(); one.complete(1); two.complete(2); @@ -56,7 +56,7 @@ public void flatMapCsStageShouldMaintainOrderOfFuturesIfConcurrencyIs1() throws CompletableFuture three = new CompletableFuture<>(); CompletionStage> result = Multi.createFrom().> items(one, two, three) .onItem().transformToUni(i -> Uni.createFrom().completionStage(i)).merge(1) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage(); three.complete(3); Thread.sleep(100L); //NOSONAR @@ -77,7 +77,7 @@ public void flatMapCsStageShouldOnlyMapOneElementAtATimeWithConcurrencyIs1() thr assertEquals(1, concurrentMaps.incrementAndGet()); return Uni.createFrom().completionStage(cs); }).merge(1) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage(); Thread.sleep(100L); // NOSONAR concurrentMaps.decrementAndGet(); @@ -98,7 +98,7 @@ public void flatMapCsStageShouldPropagateUpstreamErrors() { .onItem().transformToUni( i -> Uni.createFrom().completionStage(CompletableFuture.completedFuture(i))) .merge() - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage())); } @@ -111,7 +111,7 @@ public void flatMapCsStageShouldHandleErrorsThrownByCallback() { .onItem().transformToUni(i -> { throw new QuietRuntimeException("failed"); }).merge() - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage(); await(cancelled); await(result); @@ -129,7 +129,7 @@ public void flatMapCsStageShouldHandleFailedCompletionStages() { failed.completeExceptionally(new QuietRuntimeException("failed")); return Uni.createFrom().completionStage(failed); }).merge() - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage(); await(cancelled); await(result); @@ -146,7 +146,7 @@ public void flatMapCsStageShouldFailIfNullIsReturned() { .transformToUni(i -> Uni.createFrom().completionStage(CompletableFuture.completedFuture(null)) .onItem().ifNull().failWith(new NullPointerException())) .merge() - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage(); await(cancelled); await(result); diff --git a/implementation/src/test/java/tck/MultiFlatMapTckTest.java b/implementation/src/test/java/tck/MultiFlatMapTckTest.java index 9a28376e4..9a52b315d 100644 --- a/implementation/src/test/java/tck/MultiFlatMapTckTest.java +++ b/implementation/src/test/java/tck/MultiFlatMapTckTest.java @@ -41,7 +41,7 @@ public void flatMapStageShouldMapElements() { assertEquals(await(Multi.createFrom().items(1, 2, 3) .emitOn(executor) .flatMap(n -> Multi.createFrom().items(n, n, n)) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Arrays.asList(1, 1, 1, 2, 2, 2, 3, 3, 3)); } @@ -49,7 +49,7 @@ public void flatMapStageShouldMapElements() { public void flatMapStageShouldAllowEmptySubStreams() { assertEquals(await(Multi.createFrom().items(Multi.createFrom().empty(), Multi.createFrom().items(1, 2)) .flatMap(Function.identity()) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Arrays.asList(1, 2)); } @@ -66,7 +66,7 @@ public void flatMapStageShouldHandleExceptions() { .flatMap(foo -> { throw new QuietRuntimeException("failed"); }) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage(); await(cancelled); await(result); @@ -78,7 +78,7 @@ public void flatMapStageShouldPropagateUpstreamExceptions() { assertThrows(QuietRuntimeException.class, () -> await(Multi.createFrom().failure(new QuietRuntimeException("failed")) .flatMap(x -> Multi.createFrom().item(x)) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage())); } @@ -89,7 +89,7 @@ public void flatMapStageShouldPropagateSubstreamExceptions() { CompletionStage> result = infiniteStream() .onTermination().invoke(() -> cancelled.complete(null)) .flatMap(f -> Multi.createFrom().failure(new QuietRuntimeException("failed"))) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage(); await(cancelled); await(result); @@ -103,7 +103,7 @@ public void concatMapStageShouldOnlySubscribeToOnePublisherAtATime() throws Exce CompletionStage> result = Multi.createFrom().items(1, 2, 3, 4, 5) .concatMap(id -> Multi.createFrom() .publisher(new ScheduledPublisher(id, activePublishers, this::getExecutor))) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage(); assertEquals(result.toCompletableFuture().get(2, TimeUnit.SECONDS), @@ -118,7 +118,7 @@ public void flatMapStageShouldPropagateCancelToSubstreams() { .onTermination().invoke(() -> outerCancelled.complete(null)) .flatMap(i -> infiniteStream().onTermination().invoke(() -> innerCancelled.complete(null))) .transform().byTakingFirstItems(5) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()); await(outerCancelled); diff --git a/implementation/src/test/java/tck/MultiOnFailureResumeTest.java b/implementation/src/test/java/tck/MultiOnFailureResumeTest.java index 76d3f0e3c..aec57c044 100644 --- a/implementation/src/test/java/tck/MultiOnFailureResumeTest.java +++ b/implementation/src/test/java/tck/MultiOnFailureResumeTest.java @@ -25,7 +25,7 @@ public void onErrorResumeShouldCatchErrorFromSource() { exception.set(err); return "foo"; }) - .collectItems().asList(); + .collect().asList(); assertEquals(await(uni.subscribeAsCompletionStage()), Collections.singletonList("foo")); assertEquals(exception.get().getMessage(), "failed"); } @@ -38,7 +38,7 @@ public void onErrorResumeWithShouldCatchErrorFromSource() { exception.set(err); return Multi.createFrom().items("foo", "bar"); }) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Arrays.asList("foo", "bar")); assertEquals(exception.get().getMessage(), "failed"); } @@ -57,7 +57,7 @@ public void onErrorResumeShouldCatchErrorFromStage() { exception.set(err); return "foo"; }) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Arrays.asList("A", "foo")); assertEquals(exception.get().getMessage(), "failed"); } @@ -76,7 +76,7 @@ public void onErrorResumeWithShouldCatchErrorFromStage() { exception.set(err); return Multi.createFrom().items("foo", "bar"); }) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Arrays.asList("A", "foo", "bar")); assertEquals(exception.get().getMessage(), "failed"); } @@ -88,7 +88,7 @@ public void onErrorResumeStageShouldPropagateRuntimeExceptions() { .onFailure().recoverWithMulti(t -> { throw new QuietRuntimeException("failed"); }) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage())); } @@ -99,7 +99,7 @@ public void onErrorResumeWithStageShouldPropagateRuntimeExceptions() { .onFailure().recoverWithItem(t -> { throw new QuietRuntimeException("failed"); }) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage())); } @@ -109,7 +109,7 @@ public void onErrorResumeWithShouldBeAbleToInjectAFailure() { () -> await(Multi.createFrom(). failure(new QuietRuntimeException("failed")) .onFailure() .recoverWithMulti(err -> Multi.createFrom().failure(new QuietRuntimeException("boom"))) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage())); } } diff --git a/implementation/src/test/java/tck/MultiOnITemTransformToMultiAndConcatenateTckTest.java b/implementation/src/test/java/tck/MultiOnITemTransformToMultiAndConcatenateTckTest.java index a76ed65cb..aac4ac765 100644 --- a/implementation/src/test/java/tck/MultiOnITemTransformToMultiAndConcatenateTckTest.java +++ b/implementation/src/test/java/tck/MultiOnITemTransformToMultiAndConcatenateTckTest.java @@ -42,7 +42,7 @@ public void flatMapStageShouldMapElements() { assertEquals(await(Multi.createFrom().items(1, 2, 3) .emitOn(executor) .onItem().transformToMultiAndConcatenate(n -> Multi.createFrom().items(n, n, n)) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Arrays.asList(1, 1, 1, 2, 2, 2, 3, 3, 3)); } @@ -50,7 +50,7 @@ public void flatMapStageShouldMapElements() { public void flatMapStageShouldAllowEmptySubStreams() { assertEquals(await(Multi.createFrom().items(Multi.createFrom().empty(), Multi.createFrom().items(1, 2)) .onItem().transformToMultiAndConcatenate(Function.identity()) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Arrays.asList(1, 2)); } @@ -67,7 +67,7 @@ public void flatMapStageShouldHandleExceptions() { .onItem().transformToMultiAndConcatenate(foo -> { throw new QuietRuntimeException("failed"); }) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage(); await(cancelled); await(result); @@ -79,7 +79,7 @@ public void flatMapStageShouldPropagateUpstreamExceptions() { assertThrows(QuietRuntimeException.class, () -> await(Multi.createFrom().failure(new QuietRuntimeException("failed")) .onItem().transformToMultiAndConcatenate(x -> Multi.createFrom().item(x)) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage())); } @@ -92,7 +92,7 @@ public void flatMapStageShouldPropagateSubstreamExceptions() { .onItem() .transformToMultiAndConcatenate( f -> Multi.createFrom().failure(new QuietRuntimeException("failed"))) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage(); await(cancelled); await(result); @@ -109,7 +109,7 @@ public void flatMapStageShouldPropagateCancelToSubstreams() { .transformToMultiAndConcatenate( i -> infiniteStream().onTermination().invoke(() -> innerCancelled.complete(null))) .transform().byTakingFirstItems(5) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()); await(outerCancelled); diff --git a/implementation/src/test/java/tck/MultiOnITemTransformToMultiAndMergeTckTest.java b/implementation/src/test/java/tck/MultiOnITemTransformToMultiAndMergeTckTest.java index 15380ee2a..5060a9298 100644 --- a/implementation/src/test/java/tck/MultiOnITemTransformToMultiAndMergeTckTest.java +++ b/implementation/src/test/java/tck/MultiOnITemTransformToMultiAndMergeTckTest.java @@ -42,7 +42,7 @@ public void flatMapStageShouldMapElements() { assertEquals(await(Multi.createFrom().items(1, 2, 3) .emitOn(executor) .onItem().transformToMultiAndMerge(n -> Multi.createFrom().items(n, n, n)) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Arrays.asList(1, 1, 1, 2, 2, 2, 3, 3, 3)); } @@ -50,7 +50,7 @@ public void flatMapStageShouldMapElements() { public void flatMapStageShouldAllowEmptySubStreams() { assertEquals(await(Multi.createFrom().items(Multi.createFrom().empty(), Multi.createFrom().items(1, 2)) .onItem().transformToMultiAndMerge(Function.identity()) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Arrays.asList(1, 2)); } @@ -67,7 +67,7 @@ public void flatMapStageShouldHandleExceptions() { .onItem().transformToMultiAndMerge(foo -> { throw new QuietRuntimeException("failed"); }) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage(); await(cancelled); await(result); @@ -79,7 +79,7 @@ public void flatMapStageShouldPropagateUpstreamExceptions() { assertThrows(QuietRuntimeException.class, () -> await(Multi.createFrom().failure(new QuietRuntimeException("failed")) .onItem().transformToMultiAndMerge(x -> Multi.createFrom().item(x)) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage())); } @@ -91,7 +91,7 @@ public void flatMapStageShouldPropagateSubstreamExceptions() { .onTermination().invoke(() -> cancelled.complete(null)) .onItem() .transformToMultiAndMerge(f -> Multi.createFrom().failure(new QuietRuntimeException("failed"))) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage(); await(cancelled); await(result); @@ -107,7 +107,7 @@ public void flatMapStageShouldPropagateCancelToSubstreams() { .onItem().transformToMultiAndMerge(i -> infiniteStream().onTermination() .invoke(() -> innerCancelled.complete(null))) .transform().byTakingFirstItems(5) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()); await(outerCancelled); diff --git a/implementation/src/test/java/tck/MultiOnItemTransformTckTest.java b/implementation/src/test/java/tck/MultiOnItemTransformTckTest.java index 8ca26fbb5..e40a7c6d2 100644 --- a/implementation/src/test/java/tck/MultiOnItemTransformTckTest.java +++ b/implementation/src/test/java/tck/MultiOnItemTransformTckTest.java @@ -21,7 +21,7 @@ public class MultiOnItemTransformTckTest extends AbstractPublisherTck { public void mapStageShouldMapElements() { assertEquals(await(Multi.createFrom().items(1, 2, 3) .map(Object::toString) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Arrays.asList("1", "2", "3")); } @@ -34,7 +34,7 @@ public void mapStageShouldHandleExceptions() { .map(foo -> { throw new QuietRuntimeException("failed"); }) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage(); await(cancelled); await(result); @@ -46,7 +46,7 @@ public void mapStageShouldPropagateUpstreamExceptions() { assertThrows(QuietRuntimeException.class, () -> await(Multi.createFrom().failure(new QuietRuntimeException("failed")) .map(Function.identity()) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage())); } @@ -57,7 +57,7 @@ public void mapStageShouldFailIfNullReturned() { CompletionStage> result = infiniteStream() .onTermination().invoke(() -> cancelled.complete(null)) .map(t -> null) - .collectItems().asList().subscribeAsCompletionStage(); + .collect().asList().subscribeAsCompletionStage(); await(cancelled); await(result); }); diff --git a/implementation/src/test/java/tck/MultiSkipItemsWhileTckTest.java b/implementation/src/test/java/tck/MultiSkipItemsWhileTckTest.java index 0a6ca7c89..39ecaf77d 100644 --- a/implementation/src/test/java/tck/MultiSkipItemsWhileTckTest.java +++ b/implementation/src/test/java/tck/MultiSkipItemsWhileTckTest.java @@ -22,7 +22,7 @@ public class MultiSkipItemsWhileTckTest extends AbstractPublisherTck { public void dropWhileStageShouldSupportDroppingElements() { assertEquals(await(Multi.createFrom().items(1, 2, 3, 4, 0) .transform().bySkippingItemsWhile(i -> i < 3) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Arrays.asList(3, 4, 0)); } @@ -35,7 +35,7 @@ public void dropWhileStageShouldHandleErrors() { .transform().bySkippingItemsWhile(i -> { throw new QuietRuntimeException("failed"); }) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage(); await(cancelled); await(result); @@ -47,7 +47,7 @@ public void dropWhileStageShouldPropagateUpstreamErrorsWhileDropping() { assertThrows(QuietRuntimeException.class, () -> await(Multi.createFrom(). failure(new QuietRuntimeException("failed")) .transform().bySkippingItemsWhile(i -> i < 3) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage())); } @@ -60,7 +60,7 @@ public void dropWhileStageShouldPropagateUpstreamErrorsAfterFinishedDropping() { } }) .transform().bySkippingItemsWhile(i -> i < 3) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage())); } @@ -76,7 +76,7 @@ public void dropWhileStageShouldNotRunPredicateOnceItsFinishedDropping() { return false; } }) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Arrays.asList(3, 4)); } @@ -84,7 +84,7 @@ public void dropWhileStageShouldNotRunPredicateOnceItsFinishedDropping() { public void dropWhileStageShouldAllowCompletionWhileDropping() { assertEquals(await(Multi.createFrom().items(1, 1, 1, 1) .transform().bySkippingItemsWhile(i -> i < 3) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Collections.emptyList()); } diff --git a/implementation/src/test/java/tck/MultiTakeFirstItemsTckTest.java b/implementation/src/test/java/tck/MultiTakeFirstItemsTckTest.java index 947f69f77..7a0bfcb35 100644 --- a/implementation/src/test/java/tck/MultiTakeFirstItemsTckTest.java +++ b/implementation/src/test/java/tck/MultiTakeFirstItemsTckTest.java @@ -19,7 +19,7 @@ public class MultiTakeFirstItemsTckTest extends AbstractPublisherTck { public void limitStageShouldLimitTheOutputElements() { assertEquals(await(infiniteStream() .transform().byTakingFirstItems(3) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Arrays.asList(1, 2, 3)); } @@ -27,7 +27,7 @@ public void limitStageShouldLimitTheOutputElements() { public void limitStageShouldAllowLimitingToZero() { assertEquals(await(infiniteStream() .transform().byTakingFirstItems(0) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Collections.emptyList()); } @@ -42,7 +42,7 @@ public void request(long n) { public void cancel() { } })).transform().byTakingFirstItems(0) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Collections.emptyList()); } @@ -52,7 +52,7 @@ public void limitStageShouldCancelUpStreamWhenDone() { infiniteStream() .onTermination().invoke(() -> cancelled.complete(null)) .transform().byTakingFirstItems(1) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage(); await(cancelled); } @@ -69,7 +69,7 @@ public void limitStageShouldIgnoreSubsequentErrorsWhenDone() { } }) .transform().byTakingFirstItems(3) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Arrays.asList(1, 2, 3)); } @@ -87,7 +87,7 @@ public void limitStageShouldPropagateCancellation() { }) .transform().byTakingFirstItems(100) .transform().byTakingFirstItems(3) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()); await(cancelled); } diff --git a/implementation/src/test/java/tck/MultiTakeItemsWhileTckTest.java b/implementation/src/test/java/tck/MultiTakeItemsWhileTckTest.java index 9d396040c..16f0b4c34 100644 --- a/implementation/src/test/java/tck/MultiTakeItemsWhileTckTest.java +++ b/implementation/src/test/java/tck/MultiTakeItemsWhileTckTest.java @@ -21,7 +21,7 @@ public class MultiTakeItemsWhileTckTest extends AbstractPublisherTck { public void takeWhileStageShouldTakeWhileConditionIsTrue() { assertEquals(await(Multi.createFrom().items(1, 2, 3, 4, 5, 6, 1, 2) .transform().byTakingItemsWhile(i -> i < 5) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Arrays.asList(1, 2, 3, 4)); } @@ -29,7 +29,7 @@ public void takeWhileStageShouldTakeWhileConditionIsTrue() { public void takeWhileStageShouldEmitEmpty() { assertEquals(await(Multi.createFrom().items(1, 2, 3, 4, 5, 6) .transform().byTakingItemsWhile(i -> false) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Collections.emptyList()); } @@ -39,7 +39,7 @@ public void takeWhileShouldCancelUpStreamWhenDone() { infiniteStream() .onTermination().invoke(() -> cancelled.complete(null)) .transform().byTakingItemsWhile(t -> false) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage(); await(cancelled); } @@ -56,7 +56,7 @@ public void takeWhileShouldIgnoreSubsequentErrorsWhenDone() { } }) .transform().byTakingItemsWhile(t -> t < 3) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage()), Arrays.asList(1, 2)); } @@ -70,7 +70,7 @@ public void takeWhileStageShouldHandleErrors() { .transform().byTakingItemsWhile(i -> { throw new QuietRuntimeException("failed"); }) - .collectItems().asList() + .collect().asList() .subscribeAsCompletionStage(); await(cancelled); await(result); diff --git a/reactive-streams-operators/src/main/java/io/smallrye/mutiny/streams/stages/CollectStageFactory.java b/reactive-streams-operators/src/main/java/io/smallrye/mutiny/streams/stages/CollectStageFactory.java index 3b6a8de0c..025d8bd6f 100644 --- a/reactive-streams-operators/src/main/java/io/smallrye/mutiny/streams/stages/CollectStageFactory.java +++ b/reactive-streams-operators/src/main/java/io/smallrye/mutiny/streams/stages/CollectStageFactory.java @@ -37,7 +37,7 @@ private static class CollectStage implements TerminalStage { @Override public CompletionStage apply(Multi source) { - return source.collectItems().with(collector).subscribeAsCompletionStage(); + return source.collect().with(collector).subscribeAsCompletionStage(); } } diff --git a/reactive-streams-operators/src/main/java/io/smallrye/mutiny/streams/stages/FindFirstStageFactory.java b/reactive-streams-operators/src/main/java/io/smallrye/mutiny/streams/stages/FindFirstStageFactory.java index c30a908c7..d98ca5996 100644 --- a/reactive-streams-operators/src/main/java/io/smallrye/mutiny/streams/stages/FindFirstStageFactory.java +++ b/reactive-streams-operators/src/main/java/io/smallrye/mutiny/streams/stages/FindFirstStageFactory.java @@ -20,7 +20,7 @@ public class FindFirstStageFactory implements TerminalStageFactory> INSTANCE = source -> { CompletableFuture> future = new CompletableFuture<>(); source - .collectItems().first() + .collect().first() .subscribe().with( item -> future.complete(Optional.ofNullable(item)), future::completeExceptionally); diff --git a/rxjava/src/main/java/io/smallrye/mutiny/converters/multi/ToSingle.java b/rxjava/src/main/java/io/smallrye/mutiny/converters/multi/ToSingle.java index 8df8b131d..26ed77967 100644 --- a/rxjava/src/main/java/io/smallrye/mutiny/converters/multi/ToSingle.java +++ b/rxjava/src/main/java/io/smallrye/mutiny/converters/multi/ToSingle.java @@ -9,6 +9,7 @@ import io.smallrye.mutiny.converters.uni.UniRxConverters; public class ToSingle implements Function, Single>> { + @SuppressWarnings("rawtypes") public static final ToSingle INSTANCE = new ToSingle(); private ToSingle() { @@ -21,7 +22,7 @@ public ToSingleFailOnNull onEmptyThrow(Supplier supp @Override public Single> apply(Multi multi) { - return multi.collectItems().first().convert().with(UniRxConverters.toSingle()); + return multi.collect().first().convert().with(UniRxConverters.toSingle()); } } diff --git a/rxjava/src/main/java/io/smallrye/mutiny/converters/multi/ToSingleFailOnNull.java b/rxjava/src/main/java/io/smallrye/mutiny/converters/multi/ToSingleFailOnNull.java index c619e7699..66555604e 100644 --- a/rxjava/src/main/java/io/smallrye/mutiny/converters/multi/ToSingleFailOnNull.java +++ b/rxjava/src/main/java/io/smallrye/mutiny/converters/multi/ToSingleFailOnNull.java @@ -18,7 +18,7 @@ public class ToSingleFailOnNull implements Function, Single> { @Override public Single apply(Multi multi) { - return multi.collectItems().first() + return multi.collect().first() .onItem().ifNull().failWith(supplier) .convert().with(UniRxConverters.toSingle()) .map(Optional::get);