Search in sources :

Example 1 with BooleanSubscription

use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.

the class MaybeFlattenStreamAsFlowableTest method requestOneByOne.

@Test
public void requestOneByOne() {
    TestSubscriber<Integer> ts = new TestSubscriber<>();
    Maybe.just(1).flattenStreamAsFlowable(v -> Stream.of(1, 2, 3, 4, 5)).subscribe(new FlowableSubscriber<Integer>() {

        Subscription upstream;

        @Override
        public void onSubscribe(@NonNull Subscription s) {
            ts.onSubscribe(new BooleanSubscription());
            upstream = s;
            s.request(1);
        }

        @Override
        public void onNext(Integer t) {
            ts.onNext(t);
            upstream.request(1);
        }

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

        @Override
        public void onComplete() {
            ts.onComplete();
        }
    });
    ts.assertResult(1, 2, 3, 4, 5);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Iterator(java.util.Iterator) TestException(io.reactivex.rxjava3.exceptions.TestException) java.util.stream(java.util.stream) Test(org.junit.Test) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) NonNull(io.reactivex.rxjava3.annotations.NonNull) AtomicReference(java.util.concurrent.atomic.AtomicReference) Mockito(org.mockito.Mockito) QueueFuseable(io.reactivex.rxjava3.operators.QueueFuseable) Function(io.reactivex.rxjava3.functions.Function) Subscription(org.reactivestreams.Subscription) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) Assert(org.junit.Assert) MaybeSubject(io.reactivex.rxjava3.subjects.MaybeSubject) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) QueueSubscription(io.reactivex.rxjava3.operators.QueueSubscription) io.reactivex.rxjava3.testsupport(io.reactivex.rxjava3.testsupport) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Subscription(org.reactivestreams.Subscription) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) QueueSubscription(io.reactivex.rxjava3.operators.QueueSubscription) Test(org.junit.Test)

Example 2 with BooleanSubscription

use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.

the class SingleFlattenStreamAsFlowableTest method requestOneByOne.

@Test
public void requestOneByOne() {
    TestSubscriber<Integer> ts = new TestSubscriber<>();
    Single.just(1).flattenStreamAsFlowable(v -> Stream.of(1, 2, 3, 4, 5)).subscribe(new FlowableSubscriber<Integer>() {

        Subscription upstream;

        @Override
        public void onSubscribe(@NonNull Subscription s) {
            ts.onSubscribe(new BooleanSubscription());
            upstream = s;
            s.request(1);
        }

        @Override
        public void onNext(Integer t) {
            ts.onNext(t);
            upstream.request(1);
        }

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

        @Override
        public void onComplete() {
            ts.onComplete();
        }
    });
    ts.assertResult(1, 2, 3, 4, 5);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Iterator(java.util.Iterator) TestException(io.reactivex.rxjava3.exceptions.TestException) java.util.stream(java.util.stream) Test(org.junit.Test) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) NonNull(io.reactivex.rxjava3.annotations.NonNull) AtomicReference(java.util.concurrent.atomic.AtomicReference) SingleSubject(io.reactivex.rxjava3.subjects.SingleSubject) Mockito(org.mockito.Mockito) QueueFuseable(io.reactivex.rxjava3.operators.QueueFuseable) Function(io.reactivex.rxjava3.functions.Function) Subscription(org.reactivestreams.Subscription) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) Assert(org.junit.Assert) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) QueueSubscription(io.reactivex.rxjava3.operators.QueueSubscription) io.reactivex.rxjava3.testsupport(io.reactivex.rxjava3.testsupport) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Subscription(org.reactivestreams.Subscription) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) QueueSubscription(io.reactivex.rxjava3.operators.QueueSubscription) Test(org.junit.Test)

Example 3 with BooleanSubscription

use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.

the class FlowableCollectWithCollectorTest method collectorAccumulatorDropSignals.

@Test
public void collectorAccumulatorDropSignals() 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();
            }
        }).test().assertFailure(TestException.class);
        TestHelper.assertUndeliverable(errors, 0, IOException.class);
    });
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) Subscriber(org.reactivestreams.Subscriber) Test(org.junit.Test)

Example 4 with BooleanSubscription

use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.

the class NotificationLiteTest method subscriptionNotification.

@Test
public void subscriptionNotification() {
    Object o = NotificationLite.subscription(new BooleanSubscription());
    assertEquals("NotificationLite.Subscription[BooleanSubscription(cancelled=false)]", o.toString());
    assertFalse(NotificationLite.isError(o));
    assertFalse(NotificationLite.isComplete(o));
    assertFalse(NotificationLite.isDisposable(o));
    assertTrue(NotificationLite.isSubscription(o));
    assertNotNull(NotificationLite.getSubscription(o));
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 5 with BooleanSubscription

use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.

the class FlowableWindowWithStartEndFlowableTest method windowOpenMainCompletes.

@Test
public void windowOpenMainCompletes() {
    AtomicReference<Subscriber<? super Integer>> ref1 = new AtomicReference<>();
    PublishProcessor<Object> pp = PublishProcessor.create();
    Flowable<Integer> f1 = Flowable.<Integer>unsafeCreate(ref1::set);
    AtomicInteger counter = new AtomicInteger();
    TestSubscriber<Flowable<Object>> ts = pp.window(f1, v -> Flowable.never()).doOnNext(w -> {
        if (counter.getAndIncrement() == 0) {
            ref1.get().onNext(2);
            pp.onNext(1);
            pp.onComplete();
        }
        w.test();
    }).test();
    ref1.get().onSubscribe(new BooleanSubscription());
    ref1.get().onNext(1);
    ts.assertComplete();
}
Also used : java.util(java.util) io.reactivex.rxjava3.functions(io.reactivex.rxjava3.functions) java.util.concurrent.atomic(java.util.concurrent.atomic) io.reactivex.rxjava3.subscribers(io.reactivex.rxjava3.subscribers) IOException(java.io.IOException) io.reactivex.rxjava3.exceptions(io.reactivex.rxjava3.exceptions) io.reactivex.rxjava3.processors(io.reactivex.rxjava3.processors) TimeUnit(java.util.concurrent.TimeUnit) Functions(io.reactivex.rxjava3.internal.functions.Functions) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) org.reactivestreams(org.reactivestreams) org.junit(org.junit) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) Assert(org.junit.Assert) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) io.reactivex.rxjava3.testsupport(io.reactivex.rxjava3.testsupport) RxJavaPlugins(io.reactivex.rxjava3.plugins.RxJavaPlugins) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)

Aggregations

BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)227 Test (org.junit.Test)152 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)81 TestException (io.reactivex.rxjava3.exceptions.TestException)40 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)32 IOException (java.io.IOException)26 InOrder (org.mockito.InOrder)19 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)12 Subscriber (org.reactivestreams.Subscriber)11 io.reactivex.rxjava3.testsupport (io.reactivex.rxjava3.testsupport)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 Assert (org.junit.Assert)10 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 io.reactivex.rxjava3.functions (io.reactivex.rxjava3.functions)8 Functions (io.reactivex.rxjava3.internal.functions.Functions)8 ConditionalSubscriber (io.reactivex.rxjava3.operators.ConditionalSubscriber)8 RxJavaPlugins (io.reactivex.rxjava3.plugins.RxJavaPlugins)8 io.reactivex.rxjava3.processors (io.reactivex.rxjava3.processors)8 java.util (java.util)8