Search in sources :

Example 46 with BooleanSubscription

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

the class FlowableSwitchTest method testSwitchWithSubsequenceComplete.

@Test
public void testSwitchWithSubsequenceComplete() {
    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(Subscriber<? super String> observer) {
                    observer.onSubscribe(new BooleanSubscription());
                    publishNext(observer, 50, "one");
                    publishNext(observer, 100, "two");
                }
            }));
            publishNext(observer, 130, Flowable.unsafeCreate(new Publisher<String>() {

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

                @Override
                public void subscribe(Subscriber<? super String> observer) {
                    observer.onSubscribe(new BooleanSubscription());
                    publishNext(observer, 50, "three");
                }
            }));
        }
    });
    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(250, TimeUnit.MILLISECONDS);
    inOrder.verify(observer, times(1)).onNext("three");
    verify(observer, never()).onComplete();
    verify(observer, never()).onError(any(Throwable.class));
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) InOrder(org.mockito.InOrder)

Example 47 with BooleanSubscription

use of io.reactivex.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.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 48 with BooleanSubscription

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

the class MaybeDelaySubscriptionTest method withPublisherCallAfterTerminalEvent.

@Test
public void withPublisherCallAfterTerminalEvent() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Flowable<Integer> f = new Flowable<Integer>() {

            @Override
            protected void subscribeActual(Subscriber<? super Integer> observer) {
                observer.onSubscribe(new BooleanSubscription());
                observer.onNext(1);
                observer.onError(new TestException());
                observer.onComplete();
                observer.onNext(2);
            }
        };
        Maybe.just(1).delaySubscription(f).test().assertResult(1);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.exceptions.TestException) Subscriber(org.reactivestreams.Subscriber) Test(org.junit.Test)

Example 49 with BooleanSubscription

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

the class ObservableRetryTest method testSourceObservableCallsUnsubscribe.

@Test
public void testSourceObservableCallsUnsubscribe() throws InterruptedException {
    final AtomicInteger subsCount = new AtomicInteger(0);
    final TestObserver<String> ts = new TestObserver<String>();
    ObservableSource<String> onSubscribe = new ObservableSource<String>() {

        @Override
        public void subscribe(Observer<? super String> s) {
            BooleanSubscription bs = new BooleanSubscription();
            // https://github.com/ReactiveX/RxJava/issues/1024
            if (!bs.isCancelled()) {
                subsCount.incrementAndGet();
                s.onError(new RuntimeException("failed"));
                // it unsubscribes the child directly
                // this simulates various error/completion scenarios that could occur
                // or just a source that proactively triggers cleanup
                // FIXME can't unsubscribe child
                //                    s.unsubscribe();
                bs.cancel();
            } else {
                s.onError(new RuntimeException());
            }
        }
    };
    Observable.unsafeCreate(onSubscribe).retry(3).subscribe(ts);
    // 1 + 3 retries
    assertEquals(4, subsCount.get());
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) Observer(io.reactivex.Observer) Test(org.junit.Test)

Example 50 with BooleanSubscription

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

the class EmptyComponentTest method normal.

@Test
public void normal() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestHelper.checkEnum(EmptyComponent.class);
        EmptyComponent c = EmptyComponent.INSTANCE;
        assertTrue(c.isDisposed());
        c.request(10);
        c.request(-10);
        Disposable d = Disposables.empty();
        c.onSubscribe(d);
        assertTrue(d.isDisposed());
        BooleanSubscription s = new BooleanSubscription();
        c.onSubscribe(s);
        assertTrue(s.isCancelled());
        c.onNext(null);
        c.onNext(1);
        c.onComplete();
        c.onError(new TestException());
        c.onSuccess(2);
        c.cancel();
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : EmptyComponent(io.reactivex.internal.util.EmptyComponent) BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.exceptions.TestException) 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