Search in sources :

Example 66 with Subscriber

use of org.reactivestreams.Subscriber in project resilience4j by resilience4j.

the class RateLimiterSubscriberTest method shouldHonorCancelledWhenCallingOnNext.

@Test
public void shouldHonorCancelledWhenCallingOnNext() throws Exception {
    // Given
    Subscription subscription = mock(Subscription.class);
    Subscriber childSubscriber = mock(Subscriber.class);
    Subscriber decoratedSubscriber = RateLimiterOperator.of(rateLimiter).apply(childSubscriber);
    decoratedSubscriber.onSubscribe(subscription);
    // When
    ((Subscription) decoratedSubscriber).cancel();
    decoratedSubscriber.onNext(1);
    // Then
    verify(childSubscriber, never()).onNext(any());
    assertSinglePermitUsed();
}
Also used : Subscriber(org.reactivestreams.Subscriber) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 67 with Subscriber

use of org.reactivestreams.Subscriber in project RxJava by ReactiveX.

the class FlowableCollectWithCollectorTest method collectorAccumulatorDropSignalsToFlowable.

@Test
public void collectorAccumulatorDropSignalsToFlowable() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        Flowable<Integer> source = new Flowable<Integer>() {

            @Override
            protected void subscribeActual(Subscriber<? super Integer> s) {
                s.onSubscribe(new BooleanSubscription());
                s.onNext(1);
                s.onNext(2);
                s.onError(new IOException());
                s.onComplete();
            }
        };
        source.collect(new Collector<Integer, Integer, Integer>() {

            @Override
            public Supplier<Integer> supplier() {
                return () -> 1;
            }

            @Override
            public BiConsumer<Integer, Integer> accumulator() {
                return (a, b) -> {
                    throw new TestException();
                };
            }

            @Override
            public BinaryOperator<Integer> combiner() {
                return (a, b) -> a + b;
            }

            @Override
            public Function<Integer, Integer> finisher() {
                return a -> a;
            }

            @Override
            public Set<Characteristics> characteristics() {
                return Collections.emptySet();
            }
        }).toFlowable().test().assertFailure(TestException.class);
        TestHelper.assertUndeliverable(errors, 0, IOException.class);
    });
}
Also used : java.util(java.util) TestHelper(io.reactivex.rxjava3.testsupport.TestHelper) TestException(io.reactivex.rxjava3.exceptions.TestException) Assert.assertFalse(org.junit.Assert.assertFalse) java.util.stream(java.util.stream) IOException(java.io.IOException) Test(org.junit.Test) java.util.function(java.util.function) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) Subscriber(org.reactivestreams.Subscriber) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) io.reactivex.rxjava3.processors(io.reactivex.rxjava3.processors) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) Subscriber(org.reactivestreams.Subscriber) IOException(java.io.IOException) Test(org.junit.Test)

Example 68 with Subscriber

use of org.reactivestreams.Subscriber in project RxJava by ReactiveX.

the class FlowableMapOptionalTest method crashDropsOnNexts.

@Test
public void crashDropsOnNexts() {
    Flowable<Integer> source = new Flowable<Integer>() {

        @Override
        protected void subscribeActual(Subscriber<? super Integer> s) {
            s.onSubscribe(new BooleanSubscription());
            s.onNext(1);
            s.onNext(2);
        }
    };
    source.mapOptional(v -> {
        throw new TestException();
    }).test().assertFailure(TestException.class);
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) Subscriber(org.reactivestreams.Subscriber) Test(org.junit.Test)

Example 69 with Subscriber

use of org.reactivestreams.Subscriber in project RxJava by ReactiveX.

the class FlowableMapOptionalTest method crashDropsOnNextsConditional.

@Test
public void crashDropsOnNextsConditional() {
    Flowable<Integer> source = new Flowable<Integer>() {

        @Override
        protected void subscribeActual(Subscriber<? super Integer> s) {
            s.onSubscribe(new BooleanSubscription());
            s.onNext(1);
            s.onNext(2);
        }
    };
    source.mapOptional(v -> {
        throw new TestException();
    }).filter(v -> true).test().assertFailure(TestException.class);
}
Also used : QueueFuseable(io.reactivex.rxjava3.operators.QueueFuseable) Function(io.reactivex.rxjava3.functions.Function) TestException(io.reactivex.rxjava3.exceptions.TestException) Assert.assertFalse(org.junit.Assert.assertFalse) ImmediateThinScheduler(io.reactivex.rxjava3.internal.schedulers.ImmediateThinScheduler) Optional(java.util.Optional) Test(org.junit.Test) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) Subscriber(org.reactivestreams.Subscriber) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) io.reactivex.rxjava3.testsupport(io.reactivex.rxjava3.testsupport) io.reactivex.rxjava3.processors(io.reactivex.rxjava3.processors) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) Subscriber(org.reactivestreams.Subscriber) Test(org.junit.Test)

Example 70 with Subscriber

use of org.reactivestreams.Subscriber in project RxJava by ReactiveX.

the class ParallelJoinTest method onNextMissingBackpressureRace.

@Test
public void onNextMissingBackpressureRace() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
            AtomicReference<Subscriber<? super Integer>> ref1 = new AtomicReference<>();
            AtomicReference<Subscriber<? super Integer>> ref2 = new AtomicReference<>();
            Flowable<Integer> f1 = new Flowable<Integer>() {

                @Override
                public void subscribeActual(Subscriber<? super Integer> s) {
                    s.onSubscribe(new BooleanSubscription());
                    ref1.set(s);
                }
            };
            Flowable<Integer> f2 = new Flowable<Integer>() {

                @Override
                public void subscribeActual(Subscriber<? super Integer> s) {
                    s.onSubscribe(new BooleanSubscription());
                    ref2.set(s);
                }
            };
            ParallelFlowable.fromArray(f1, f2).sequential(1).test(0);
            TestHelper.race(() -> {
                ref1.get().onNext(1);
                ref1.get().onNext(2);
            }, () -> {
                ref2.get().onNext(3);
                ref2.get().onNext(4);
            });
            errors.clear();
        }
    });
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Subscriber(org.reactivestreams.Subscriber) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Aggregations

Subscriber (org.reactivestreams.Subscriber)92 Subscription (org.reactivestreams.Subscription)56 Test (org.junit.Test)49 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)24 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)23 ProtonClient (io.vertx.proton.ProtonClient)22 ProtonConnection (io.vertx.proton.ProtonConnection)22 Message (org.apache.qpid.proton.message.Message)20 List (java.util.List)18 AmqpValue (org.apache.qpid.proton.amqp.messaging.AmqpValue)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)17 Handler (io.vertx.core.Handler)16 Logger (io.vertx.core.impl.logging.Logger)16 LoggerFactory (io.vertx.core.impl.logging.LoggerFactory)16 ProtonStreams (io.vertx.proton.streams.ProtonStreams)16 ExecutionException (java.util.concurrent.ExecutionException)16 Symbol (org.apache.qpid.proton.amqp.Symbol)16 Section (org.apache.qpid.proton.amqp.messaging.Section)16 ArrayList (java.util.ArrayList)14 Collections (java.util.Collections)13