Search in sources :

Example 96 with BooleanSubscription

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

the class FlowableSwitchTest method testSwitchWithComplete.

@Test
public void testSwitchWithComplete() {
    Flowable<Flowable<String>> source = Flowable.unsafeCreate(new Publisher<Flowable<String>>() {

        @Override
        public void subscribe(Subscriber<? super Flowable<String>> observer) {
            observer.onSubscribe(new BooleanSubscription());
            publishNext(observer, 50, Flowable.unsafeCreate(new Publisher<String>() {

                @Override
                public void subscribe(final Subscriber<? super String> observer) {
                    observer.onSubscribe(new BooleanSubscription());
                    publishNext(observer, 60, "one");
                    publishNext(observer, 100, "two");
                }
            }));
            publishNext(observer, 200, Flowable.unsafeCreate(new Publisher<String>() {

                @Override
                public void subscribe(final Subscriber<? super String> observer) {
                    observer.onSubscribe(new BooleanSubscription());
                    publishNext(observer, 0, "three");
                    publishNext(observer, 100, "four");
                }
            }));
            publishCompleted(observer, 250);
        }
    });
    Flowable<String> sampled = Flowable.switchOnNext(source);
    sampled.subscribe(observer);
    InOrder inOrder = inOrder(observer);
    scheduler.advanceTimeTo(90, TimeUnit.MILLISECONDS);
    inOrder.verify(observer, never()).onNext(anyString());
    verify(observer, never()).onComplete();
    verify(observer, never()).onError(any(Throwable.class));
    scheduler.advanceTimeTo(125, TimeUnit.MILLISECONDS);
    inOrder.verify(observer, times(1)).onNext("one");
    verify(observer, never()).onComplete();
    verify(observer, never()).onError(any(Throwable.class));
    scheduler.advanceTimeTo(175, TimeUnit.MILLISECONDS);
    inOrder.verify(observer, times(1)).onNext("two");
    verify(observer, never()).onComplete();
    verify(observer, never()).onError(any(Throwable.class));
    scheduler.advanceTimeTo(225, TimeUnit.MILLISECONDS);
    inOrder.verify(observer, times(1)).onNext("three");
    verify(observer, never()).onComplete();
    verify(observer, never()).onError(any(Throwable.class));
    scheduler.advanceTimeTo(350, TimeUnit.MILLISECONDS);
    inOrder.verify(observer, times(1)).onNext("four");
    verify(observer, never()).onComplete();
    verify(observer, never()).onError(any(Throwable.class));
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) InOrder(org.mockito.InOrder)

Example 97 with BooleanSubscription

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

the class FlowableTimeoutWithSelectorTest method badSourceTimeout.

@Test
public void badSourceTimeout() {
    new Flowable<Integer>() {

        @Override
        protected void subscribeActual(Subscriber<? super Integer> observer) {
            observer.onSubscribe(new BooleanSubscription());
            observer.onNext(1);
            observer.onNext(2);
            observer.onError(new TestException("First"));
            observer.onNext(3);
            observer.onComplete();
            observer.onError(new TestException("Second"));
        }
    }.timeout(Functions.justFunction(Flowable.never()), Flowable.<Integer>never()).take(1).test().assertResult(1);
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.exceptions.TestException) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Test(org.junit.Test)

Example 98 with BooleanSubscription

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

the class FlowableStrictTest method noCancelOnError.

@Test
public void noCancelOnError() {
    final BooleanSubscription bs = new BooleanSubscription();
    Flowable.fromPublisher(new Publisher<Object>() {

        @Override
        public void subscribe(Subscriber<? super Object> p) {
            p.onSubscribe(bs);
            p.onError(new TestException());
        }
    }).strict().subscribe(new Subscriber<Object>() {

        Subscription s;

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

        @Override
        public void onNext(Object t) {
        // not called
        }

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

        @Override
        public void onComplete() {
        // not called
        }
    });
    assertFalse(bs.isCancelled());
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.exceptions.TestException) BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 99 with BooleanSubscription

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

the class FlowableStrictTest method badRequestOnNextRace.

@Test
public void badRequestOnNextRace() {
    for (int i = 0; i < 500; i++) {
        TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
        final PublishProcessor<Integer> pp = PublishProcessor.create();
        final StrictSubscriber<Integer> s = new StrictSubscriber<Integer>(ts);
        s.onSubscribe(new BooleanSubscription());
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                pp.onNext(1);
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                s.request(0);
            }
        };
        TestHelper.race(r1, r2);
        if (ts.valueCount() == 0) {
            ts.assertFailure(IllegalArgumentException.class);
        } else {
            ts.assertValue(1).assertNoErrors().assertNotComplete();
        }
    }
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.subscribers.TestSubscriber) StrictSubscriber(io.reactivex.internal.subscribers.StrictSubscriber) Test(org.junit.Test)

Example 100 with BooleanSubscription

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

the class FlowableStrictTest method doubleOnSubscribe.

@Test
public void doubleOnSubscribe() {
    final BooleanSubscription bs1 = new BooleanSubscription();
    final BooleanSubscription bs2 = new BooleanSubscription();
    final TestSubscriber<Object> ts = TestSubscriber.create();
    Flowable.fromPublisher(new Publisher<Object>() {

        @Override
        public void subscribe(Subscriber<? super Object> p) {
            p.onSubscribe(bs1);
            p.onSubscribe(bs2);
        }
    }).strict().subscribe(new Subscriber<Object>() {

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

        @Override
        public void onNext(Object t) {
            ts.onNext(t);
        }

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

        @Override
        public void onComplete() {
            ts.onComplete();
        }
    });
    ts.assertFailure(IllegalStateException.class);
    assertTrue(bs1.isCancelled());
    assertTrue(bs2.isCancelled());
    String es = ts.errors().get(0).toString();
    assertTrue(es, es.contains("ยง2.12"));
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Aggregations

BooleanSubscription (io.reactivex.internal.subscriptions.BooleanSubscription)131 Test (org.junit.Test)70 TestSubscriber (io.reactivex.subscribers.TestSubscriber)31 TestException (io.reactivex.exceptions.TestException)24 InOrder (org.mockito.InOrder)21 IOException (java.io.IOException)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 BooleanSupplier (io.reactivex.functions.BooleanSupplier)5 ForEachWhileSubscriber (io.reactivex.internal.subscribers.ForEachWhileSubscriber)5 ArrayDeque (java.util.ArrayDeque)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 Disposable (io.reactivex.disposables.Disposable)4 GroupedFlowable (io.reactivex.flowables.GroupedFlowable)4 Subscriber (org.reactivestreams.Subscriber)4 BaseObserveOnSubscriber (io.reactivex.internal.operators.flowable.FlowableObserveOn.BaseObserveOnSubscriber)3 Worker (io.reactivex.Scheduler.Worker)2 Nullable (io.reactivex.annotations.Nullable)2 ConnectableFlowable (io.reactivex.flowables.ConnectableFlowable)2 SubscribeOnSubscriber (io.reactivex.internal.operators.flowable.FlowableSubscribeOn.SubscribeOnSubscriber)2 FutureSubscriber (io.reactivex.internal.subscribers.FutureSubscriber)2