Search in sources :

Example 11 with BooleanSubscription

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

the class FlowableDebounceTest method testDebounceNeverEmits.

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

        @Override
        public void subscribe(Subscriber<? super String> observer) {
            observer.onSubscribe(new BooleanSubscription());
            // all should be skipped since they are happening faster than the 200ms timeout
            // Should be skipped
            publishNext(observer, 100, "a");
            // Should be skipped
            publishNext(observer, 200, "b");
            // Should be skipped
            publishNext(observer, 300, "c");
            // Should be skipped
            publishNext(observer, 400, "d");
            // Should be skipped
            publishNext(observer, 500, "e");
            // Should be skipped
            publishNext(observer, 600, "f");
            // Should be skipped
            publishNext(observer, 700, "g");
            // Should be skipped
            publishNext(observer, 800, "h");
            // Should be published as soon as the timeout expires.
            publishCompleted(observer, 900);
        }
    });
    Flowable<String> sampled = source.debounce(200, TimeUnit.MILLISECONDS, scheduler);
    sampled.subscribe(observer);
    scheduler.advanceTimeTo(0, TimeUnit.MILLISECONDS);
    InOrder inOrder = inOrder(observer);
    inOrder.verify(observer, times(0)).onNext(anyString());
    scheduler.advanceTimeTo(1000, TimeUnit.MILLISECONDS);
    inOrder.verify(observer, times(1)).onComplete();
    inOrder.verifyNoMoreInteractions();
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) InOrder(org.mockito.InOrder)

Example 12 with BooleanSubscription

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

the class FlowableDebounceTest method testDebounceWithError.

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

        @Override
        public void subscribe(Subscriber<? super String> observer) {
            observer.onSubscribe(new BooleanSubscription());
            Exception error = new TestException();
            // Should be published since "two" will arrive after the timeout expires.
            publishNext(observer, 100, "one");
            // Should be skipped since onError will arrive before the timeout expires.
            publishNext(observer, 600, "two");
            // Should be published as soon as the timeout expires.
            publishError(observer, 700, error);
        }
    });
    Flowable<String> sampled = source.debounce(400, TimeUnit.MILLISECONDS, scheduler);
    sampled.subscribe(observer);
    scheduler.advanceTimeTo(0, TimeUnit.MILLISECONDS);
    InOrder inOrder = inOrder(observer);
    // 100 + 400 means it triggers at 500
    scheduler.advanceTimeTo(500, TimeUnit.MILLISECONDS);
    inOrder.verify(observer).onNext("one");
    scheduler.advanceTimeTo(701, TimeUnit.MILLISECONDS);
    inOrder.verify(observer).onError(any(TestException.class));
    inOrder.verifyNoMoreInteractions();
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) InOrder(org.mockito.InOrder)

Example 13 with BooleanSubscription

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

the class CompletableConcatTest method overflowReported.

@Test
public void overflowReported() {
    Completable.concat(Flowable.fromPublisher(new Publisher<Completable>() {

        @Override
        public void subscribe(Subscriber<? super Completable> s) {
            s.onSubscribe(new BooleanSubscription());
            s.onNext(Completable.never());
            s.onNext(Completable.never());
            s.onNext(Completable.never());
            s.onNext(Completable.never());
            s.onComplete();
        }
    }), 1).test().assertFailure(MissingBackpressureException.class);
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 14 with BooleanSubscription

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

the class FlowableDoOnEachTest method ignoreCancel.

@Test
public void ignoreCancel() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Flowable.fromPublisher(new Publisher<Object>() {

            @Override
            public void subscribe(Subscriber<? super Object> s) {
                s.onSubscribe(new BooleanSubscription());
                s.onNext(1);
                s.onNext(2);
                s.onError(new IOException());
                s.onComplete();
            }
        }).doOnNext(new Consumer<Object>() {

            @Override
            public void accept(Object e) throws Exception {
                throw new TestException();
            }
        }).test().assertFailure(TestException.class);
        TestHelper.assertUndeliverable(errors, 0, IOException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) IOException(java.io.IOException) IOException(java.io.IOException)

Example 15 with BooleanSubscription

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

the class FlowableDematerializeTest method eventsAfterDematerializedTerminal.

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

            @Override
            protected void subscribeActual(Subscriber<? super Object> observer) {
                observer.onSubscribe(new BooleanSubscription());
                observer.onNext(Notification.createOnComplete());
                observer.onNext(Notification.createOnNext(1));
                observer.onNext(Notification.createOnError(new TestException("First")));
                observer.onError(new TestException("Second"));
            }
        }.dematerialize().test().assertResult();
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "First");
        TestHelper.assertUndeliverable(errors, 1, TestException.class, "Second");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : 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