Search in sources :

Example 21 with TestSubscriber

use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.

the class QueueDrainHelperTest method postCompleteEmpty.

@Test
public void postCompleteEmpty() {
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
    ArrayDeque<Integer> queue = new ArrayDeque<Integer>();
    AtomicLong state = new AtomicLong();
    BooleanSupplier isCancelled = new BooleanSupplier() {

        @Override
        public boolean getAsBoolean() throws Exception {
            return false;
        }
    };
    ts.onSubscribe(new BooleanSubscription());
    QueueDrainHelper.postComplete(ts, queue, state, isCancelled);
    ts.assertResult();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.subscribers.TestSubscriber) BooleanSupplier(io.reactivex.functions.BooleanSupplier) ArrayDeque(java.util.ArrayDeque) Test(org.junit.Test)

Example 22 with TestSubscriber

use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.

the class ParallelJoinTest method overflowSlowpath.

@Test
public void overflowSlowpath() {
    @SuppressWarnings("unchecked") final Subscriber<? super Integer>[] subs = new Subscriber[1];
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>(1) {

        @Override
        public void onNext(Integer t) {
            super.onNext(t);
            subs[0].onNext(2);
            subs[0].onNext(3);
        }
    };
    new ParallelFlowable<Integer>() {

        @Override
        public void subscribe(Subscriber<? super Integer>[] subscribers) {
            subs[0] = subscribers[0];
            subscribers[0].onSubscribe(new BooleanSubscription());
            subscribers[0].onNext(1);
        }

        @Override
        public int parallelism() {
            return 1;
        }
    }.sequential(1).subscribe(ts);
    ts.assertFailure(MissingBackpressureException.class, 1);
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Subscriber(org.reactivestreams.Subscriber) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Test(org.junit.Test)

Example 23 with TestSubscriber

use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.

the class ParallelJoinTest method overflowSlowpathDelayError.

@Test
public void overflowSlowpathDelayError() {
    @SuppressWarnings("unchecked") final Subscriber<? super Integer>[] subs = new Subscriber[1];
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>(1) {

        @Override
        public void onNext(Integer t) {
            super.onNext(t);
            if (t == 1) {
                subs[0].onNext(2);
                subs[0].onNext(3);
            }
        }
    };
    new ParallelFlowable<Integer>() {

        @Override
        public void subscribe(Subscriber<? super Integer>[] subscribers) {
            subs[0] = subscribers[0];
            subscribers[0].onSubscribe(new BooleanSubscription());
            subscribers[0].onNext(1);
        }

        @Override
        public int parallelism() {
            return 1;
        }
    }.sequentialDelayError(1).subscribe(ts);
    ts.request(1);
    ts.assertFailure(MissingBackpressureException.class, 1, 2);
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Subscriber(org.reactivestreams.Subscriber) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Test(org.junit.Test)

Example 24 with TestSubscriber

use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.

the class AsyncProcessorTest method onErrorCrossCancel.

@Test
public void onErrorCrossCancel() {
    AsyncProcessor<Object> p = AsyncProcessor.create();
    final TestSubscriber<Object> ts2 = new TestSubscriber<Object>();
    TestSubscriber<Object> ts1 = new TestSubscriber<Object>() {

        @Override
        public void onError(Throwable t) {
            ts2.cancel();
            super.onError(t);
        }
    };
    p.subscribe(ts1);
    p.subscribe(ts2);
    p.onError(new TestException());
    ts1.assertFailure(TestException.class);
    ts2.assertEmpty();
}
Also used : TestException(io.reactivex.exceptions.TestException) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Test(org.junit.Test)

Example 25 with TestSubscriber

use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.

the class TestObserverTest method testGetEvents.

@Test
public void testGetEvents() {
    TestSubscriber<Integer> to = new TestSubscriber<Integer>();
    to.onSubscribe(EmptySubscription.INSTANCE);
    to.onNext(1);
    to.onNext(2);
    assertEquals(Arrays.<Object>asList(Arrays.asList(1, 2), Collections.emptyList(), Collections.emptyList()), to.getEvents());
    to.onComplete();
    assertEquals(Arrays.<Object>asList(Arrays.asList(1, 2), Collections.emptyList(), Collections.singletonList(Notification.createOnComplete())), to.getEvents());
    TestException ex = new TestException();
    TestSubscriber<Integer> to2 = new TestSubscriber<Integer>();
    to2.onSubscribe(EmptySubscription.INSTANCE);
    to2.onNext(1);
    to2.onNext(2);
    assertEquals(Arrays.<Object>asList(Arrays.asList(1, 2), Collections.emptyList(), Collections.emptyList()), to2.getEvents());
    to2.onError(ex);
    assertEquals(Arrays.<Object>asList(Arrays.asList(1, 2), Collections.singletonList(ex), Collections.emptyList()), to2.getEvents());
}
Also used : TestException(io.reactivex.exceptions.TestException) TestSubscriber(io.reactivex.subscribers.TestSubscriber)

Aggregations

TestSubscriber (io.reactivex.subscribers.TestSubscriber)63 Test (org.junit.Test)41 BooleanSubscription (io.reactivex.internal.subscriptions.BooleanSubscription)20 TestException (io.reactivex.exceptions.TestException)18 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 InOrder (org.mockito.InOrder)11 Disposable (io.reactivex.disposables.Disposable)9 TestScheduler (io.reactivex.schedulers.TestScheduler)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)6 BooleanSupplier (io.reactivex.functions.BooleanSupplier)5 ArrayDeque (java.util.ArrayDeque)5 IOException (java.io.IOException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Subscriber (org.reactivestreams.Subscriber)2 Flowable (io.reactivex.Flowable)1 Worker (io.reactivex.Scheduler.Worker)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 Action (io.reactivex.functions.Action)1 Function (io.reactivex.functions.Function)1 LongConsumer (io.reactivex.functions.LongConsumer)1