Search in sources :

Example 11 with MultiSubscriber

use of io.smallrye.mutiny.subscription.MultiSubscriber in project smallrye-mutiny by smallrye.

the class MultiGroupTest method testSkipGroupAsMultisWithRogueFailures.

@Test
public void testSkipGroupAsMultisWithRogueFailures() {
    AtomicReference<Throwable> caught = new AtomicReference<>();
    Infrastructure.setDroppedExceptionHandler(caught::set);
    AbstractMulti<Integer> rogue = new AbstractMulti<Integer>() {

        @Override
        public void subscribe(MultiSubscriber<? super Integer> subscriber) {
            subscriber.onSubscribe(mock(Subscription.class));
            subscriber.onItem(1);
            subscriber.onItem(2);
            subscriber.onItem(3);
            subscriber.onItem(4);
            subscriber.onFailure(new IOException("boom-1"));
            subscriber.onItem(5);
            subscriber.onItem(6);
            subscriber.onFailure(new IOException("boom-2"));
            subscriber.onCompletion();
        }
    };
    AssertSubscriber<Integer> subscriber = rogue.group().intoMultis().of(2, 4).onItem().transformToMultiAndConcatenate(m -> m).subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE));
    subscriber.assertFailedWith(IOException.class, "boom-1");
    assertThat(caught.get()).hasMessageContaining("boom-2");
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) Subscription(org.reactivestreams.Subscription) MultiSubscriber(io.smallrye.mutiny.subscription.MultiSubscriber) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 12 with MultiSubscriber

use of io.smallrye.mutiny.subscription.MultiSubscriber in project smallrye-mutiny by smallrye.

the class MultiGroupTest method testExactGroupAsMultisWithRogueFailures.

@Test
public void testExactGroupAsMultisWithRogueFailures() {
    AtomicReference<Throwable> caught = new AtomicReference<>();
    Infrastructure.setDroppedExceptionHandler(caught::set);
    AbstractMulti<Integer> rogue = new AbstractMulti<Integer>() {

        @Override
        public void subscribe(MultiSubscriber<? super Integer> subscriber) {
            subscriber.onSubscribe(mock(Subscription.class));
            subscriber.onItem(1);
            subscriber.onItem(2);
            subscriber.onItem(3);
            subscriber.onItem(4);
            subscriber.onFailure(new IOException("boom-1"));
            subscriber.onItem(5);
            subscriber.onItem(6);
            subscriber.onFailure(new IOException("boom-2"));
            subscriber.onCompletion();
        }
    };
    AssertSubscriber<Integer> subscriber = rogue.group().intoMultis().of(2).onItem().transformToMultiAndConcatenate(m -> m).subscribe().withSubscriber(AssertSubscriber.create(Long.MAX_VALUE));
    subscriber.assertFailedWith(IOException.class, "boom-1");
    assertThat(caught.get()).hasMessageContaining("boom-2");
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) Subscription(org.reactivestreams.Subscription) MultiSubscriber(io.smallrye.mutiny.subscription.MultiSubscriber) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 13 with MultiSubscriber

use of io.smallrye.mutiny.subscription.MultiSubscriber in project smallrye-mutiny by smallrye.

the class HalfSerializerTest method testThatOnNextAndOnFailureAreNotReentrant.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testThatOnNextAndOnFailureAreNotReentrant() {
    AtomicInteger wip = new AtomicInteger();
    AtomicReference<Throwable> failure = new AtomicReference<>();
    AtomicReference<Subscriber<Object>> subscriber = new AtomicReference<>();
    AssertSubscriber<Object> test = AssertSubscriber.create(10);
    MultiSubscriber s = new MultiSubscriber() {

        @Override
        public void onSubscribe(Subscription s) {
            test.onSubscribe(s);
        }

        @Override
        public void onItem(Object t) {
            if (t.equals(1)) {
                HalfSerializer.onError(subscriber.get(), new IOException("boom"), wip, failure);
            }
            test.onNext(t);
        }

        @Override
        public void onFailure(Throwable t) {
            test.onError(t);
        }

        @Override
        public void onCompletion() {
            test.onComplete();
        }
    };
    subscriber.set(s);
    Subscription subscription = mock(Subscription.class);
    s.onSubscribe(subscription);
    HalfSerializer.onNext(s, 1, wip, failure);
    test.assertFailedWith(IOException.class, "boom");
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AssertSubscriber(io.smallrye.mutiny.helpers.test.AssertSubscriber) Subscriber(org.reactivestreams.Subscriber) MultiSubscriber(io.smallrye.mutiny.subscription.MultiSubscriber) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) Subscription(org.reactivestreams.Subscription) MultiSubscriber(io.smallrye.mutiny.subscription.MultiSubscriber) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Aggregations

MultiSubscriber (io.smallrye.mutiny.subscription.MultiSubscriber)13 Test (org.junit.jupiter.api.Test)12 IOException (java.io.IOException)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Subscription (org.reactivestreams.Subscription)9 RepeatedTest (org.junit.jupiter.api.RepeatedTest)8 AssertSubscriber (io.smallrye.mutiny.helpers.test.AssertSubscriber)3 Subscriber (org.reactivestreams.Subscriber)3 CompositeException (io.smallrye.mutiny.CompositeException)1 Context (io.smallrye.mutiny.Context)1 Uni (io.smallrye.mutiny.Uni)1 ParameterValidation (io.smallrye.mutiny.helpers.ParameterValidation)1 Subscriptions (io.smallrye.mutiny.helpers.Subscriptions)1 Infrastructure (io.smallrye.mutiny.infrastructure.Infrastructure)1 AbstractMulti (io.smallrye.mutiny.operators.AbstractMulti)1 ContextSupport (io.smallrye.mutiny.subscription.ContextSupport)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1