Search in sources :

Example 6 with MultiSubscriber

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

the class HalfSerializerTest method testThatOnNextIsNotReentrant.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testThatOnNextIsNotReentrant() {
    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.onNext(subscriber.get(), 2, 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.assertItems(1).assertNotTerminated();
}
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) Subscription(org.reactivestreams.Subscription) MultiSubscriber(io.smallrye.mutiny.subscription.MultiSubscriber) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 7 with MultiSubscriber

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

the class HalfSerializerTest method testThatOnFailureAndOnFailureAreNotReentrant.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testThatOnFailureAndOnFailureAreNotReentrant() {
    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) {
            test.onNext(t);
        }

        @Override
        public void onFailure(Throwable t) {
            test.onError(t);
            HalfSerializer.onError(subscriber.get(), new IOException("boom"), wip, failure);
        }

        @Override
        public void onCompletion() {
            test.onComplete();
        }
    };
    subscriber.set(s);
    Subscription subscription = mock(Subscription.class);
    s.onSubscribe(subscription);
    HalfSerializer.onError(s, new IOException("test"), wip, failure);
    test.assertFailedWith(IOException.class, "test");
}
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)

Example 8 with MultiSubscriber

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

the class MultiTakeTest method testTakeByTimeWithRogueUpstreamSendingFailureAfterCompletion.

@Test
public void testTakeByTimeWithRogueUpstreamSendingFailureAfterCompletion() {
    Multi<Integer> rogue = new AbstractMulti<Integer>() {

        @Override
        public void subscribe(MultiSubscriber<? super Integer> subscriber) {
            subscriber.onItem(1);
            subscriber.onItem(2);
            subscriber.onComplete();
            subscriber.onItem(3);
            subscriber.onError(new IOException("boom"));
        }
    };
    AssertSubscriber<Integer> subscriber = rogue.select().first(Duration.ofMillis(1000)).subscribe().withSubscriber(AssertSubscriber.create(100)).awaitCompletion();
    assertThat(subscriber.getItems()).hasSize(2);
}
Also used : IOException(java.io.IOException) MultiSubscriber(io.smallrye.mutiny.subscription.MultiSubscriber) Test(org.junit.jupiter.api.Test)

Example 9 with MultiSubscriber

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

the class MultiTakeTest method testTakeByTimeWithRogueUpstreamSendingCompletionAfterFailure.

@Test
public void testTakeByTimeWithRogueUpstreamSendingCompletionAfterFailure() {
    Multi<Integer> rogue = new AbstractMulti<Integer>() {

        @Override
        public void subscribe(MultiSubscriber<? super Integer> subscriber) {
            subscriber.onItem(1);
            subscriber.onItem(2);
            subscriber.onError(new IOException("boom"));
            subscriber.onItem(3);
            subscriber.onComplete();
        }
    };
    AssertSubscriber<Integer> subscriber = rogue.select().first(Duration.ofMillis(1000)).subscribe().withSubscriber(AssertSubscriber.create(100)).awaitFailure().assertFailedWith(IOException.class, "boom");
    assertThat(subscriber.getItems()).hasSize(2);
}
Also used : IOException(java.io.IOException) MultiSubscriber(io.smallrye.mutiny.subscription.MultiSubscriber) Test(org.junit.jupiter.api.Test)

Example 10 with MultiSubscriber

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

the class MultiGroupTest method testOverlapGroupWithRogueFailures.

@Test
public void testOverlapGroupWithRogueFailures() {
    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<List<Integer>> subscriber = rogue.group().intoLists().of(4, 2).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)

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