Search in sources :

Example 1 with GroupedMulti

use of io.smallrye.mutiny.GroupedMulti in project smallrye-mutiny by smallrye.

the class MultiGroupTest method testGroupByOnFailingMulti.

@Test
public void testGroupByOnFailingMulti() {
    AssertSubscriber<GroupedMulti<Integer, Integer>> subscriber = Multi.createFrom().<Integer>failure(new IOException("boom")).group().by(i -> i % 2).subscribe().withSubscriber(AssertSubscriber.create(100));
    subscriber.assertFailedWith(IOException.class, "boom");
    assertThat(subscriber.getItems()).hasSize(0);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GroupedMulti(io.smallrye.mutiny.GroupedMulti) IOException(java.io.IOException) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 2 with GroupedMulti

use of io.smallrye.mutiny.GroupedMulti in project smallrye-mutiny by smallrye.

the class MultiGroupTest method testGroupByWithUpstreamFailure.

@RepeatedTest(10)
public void testGroupByWithUpstreamFailure() {
    AtomicReference<MultiEmitter<? super Long>> emitter = new AtomicReference<>();
    Multi<Long> multi = Multi.createBy().merging().streams(Multi.createFrom().ticks().every(Duration.ofMillis(2)), Multi.createFrom().emitter((Consumer<MultiEmitter<? super Long>>) emitter::set));
    AssertSubscriber<GroupedMulti<Long, Long>> subscriber = multi.group().by(l -> l % 2).subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE));
    subscriber.assertSubscribed();
    await().until(() -> subscriber.getItems().size() == 2);
    AssertSubscriber<Long> s1 = subscriber.getItems().get(0).subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE));
    s1.assertSubscribed();
    AssertSubscriber<Long> s2 = subscriber.getItems().get(1).subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE));
    s2.assertSubscribed();
    await().until(() -> s1.getItems().size() >= 3);
    await().until(() -> s2.getItems().size() >= 3);
    emitter.get().fail(new TestException("boom"));
    s1.awaitFailure().assertFailedWith(TestException.class, "boom");
    s2.awaitFailure().assertFailedWith(TestException.class, "boom");
    subscriber.assertFailedWith(TestException.class, "boom");
}
Also used : Consumer(java.util.function.Consumer) TestException(io.smallrye.mutiny.TestException) GroupedMulti(io.smallrye.mutiny.GroupedMulti) AtomicReference(java.util.concurrent.atomic.AtomicReference) MultiEmitter(io.smallrye.mutiny.subscription.MultiEmitter) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Aggregations

GroupedMulti (io.smallrye.mutiny.GroupedMulti)2 RepeatedTest (org.junit.jupiter.api.RepeatedTest)2 TestException (io.smallrye.mutiny.TestException)1 MultiEmitter (io.smallrye.mutiny.subscription.MultiEmitter)1 IOException (java.io.IOException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Consumer (java.util.function.Consumer)1 Test (org.junit.jupiter.api.Test)1