Search in sources :

Example 51 with TestSubscriber

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

the class MaybeCacheTest method crossCancelOnError.

@Test
public void crossCancelOnError() {
    final TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
    PublishProcessor<Integer> pp = PublishProcessor.create();
    Maybe<Integer> source = pp.singleElement().cache();
    source.subscribe(Functions.emptyConsumer(), new Consumer<Object>() {

        @Override
        public void accept(Object v) throws Exception {
            ts.cancel();
        }
    });
    source.toFlowable().subscribe(ts);
    pp.onError(new TestException());
    ts.assertEmpty();
}
Also used : TestException(io.reactivex.exceptions.TestException) TestSubscriber(io.reactivex.subscribers.TestSubscriber) TestException(io.reactivex.exceptions.TestException) Test(org.junit.Test)

Example 52 with TestSubscriber

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

the class HalfSerializerSubscriberTest method onErrorOnCompleteRace.

@Test
public void onErrorOnCompleteRace() {
    for (int i = 0; i < 500; i++) {
        final AtomicInteger wip = new AtomicInteger();
        final AtomicThrowable error = new AtomicThrowable();
        final TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
        ts.onSubscribe(new BooleanSubscription());
        final TestException ex = new TestException();
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                HalfSerializer.onError(ts, ex, wip, error);
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                HalfSerializer.onComplete(ts, wip, error);
            }
        };
        TestHelper.race(r1, r2, Schedulers.single());
        if (ts.completions() != 0) {
            ts.assertResult();
        } else {
            ts.assertFailure(TestException.class);
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.exceptions.TestException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Test(org.junit.Test)

Example 53 with TestSubscriber

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

the class HalfSerializerSubscriberTest method reentrantErrorOnError.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void reentrantErrorOnError() {
    final AtomicInteger wip = new AtomicInteger();
    final AtomicThrowable error = new AtomicThrowable();
    final Subscriber[] a = { null };
    final TestSubscriber ts = new TestSubscriber();
    FlowableSubscriber s = new FlowableSubscriber() {

        @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);
            HalfSerializer.onError(a[0], new IOException(), wip, error);
        }

        @Override
        public void onComplete() {
            ts.onComplete();
        }
    };
    a[0] = s;
    s.onSubscribe(new BooleanSubscription());
    HalfSerializer.onError(s, new TestException(), wip, error);
    ts.assertFailure(TestException.class);
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.exceptions.TestException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestSubscriber(io.reactivex.subscribers.TestSubscriber) TestSubscriber(io.reactivex.subscribers.TestSubscriber) IOException(java.io.IOException) BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 54 with TestSubscriber

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

the class HalfSerializerSubscriberTest method onNextOnCompleteRace.

@Test
public void onNextOnCompleteRace() {
    for (int i = 0; i < 500; i++) {
        final AtomicInteger wip = new AtomicInteger();
        final AtomicThrowable error = new AtomicThrowable();
        final TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
        ts.onSubscribe(new BooleanSubscription());
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                HalfSerializer.onNext(ts, 1, wip, error);
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                HalfSerializer.onComplete(ts, wip, error);
            }
        };
        TestHelper.race(r1, r2, Schedulers.single());
        ts.assertComplete().assertNoErrors();
        assertTrue(ts.valueCount() <= 1);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Test(org.junit.Test)

Example 55 with TestSubscriber

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

the class HalfSerializerSubscriberTest method reentrantOnNextOnComplete.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void reentrantOnNextOnComplete() {
    final AtomicInteger wip = new AtomicInteger();
    final AtomicThrowable error = new AtomicThrowable();
    final Subscriber[] a = { null };
    final TestSubscriber ts = new TestSubscriber();
    FlowableSubscriber s = new FlowableSubscriber() {

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

        @Override
        public void onNext(Object t) {
            if (t.equals(1)) {
                HalfSerializer.onComplete(a[0], wip, error);
            }
            ts.onNext(t);
        }

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

        @Override
        public void onComplete() {
            ts.onComplete();
        }
    };
    a[0] = s;
    s.onSubscribe(new BooleanSubscription());
    HalfSerializer.onNext(s, 1, wip, error);
    ts.assertResult(1);
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestSubscriber(io.reactivex.subscribers.TestSubscriber) TestSubscriber(io.reactivex.subscribers.TestSubscriber) BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Aggregations

TestSubscriber (io.reactivex.subscribers.TestSubscriber)65 Test (org.junit.Test)43 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 Task (com.example.android.architecture.blueprints.todoapp.data.Task)2 Optional (com.google.common.base.Optional)2 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