Search in sources :

Example 56 with TestSubscriber

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

the class HalfSerializerSubscriberTest method reentrantOnNextOnNext.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void reentrantOnNextOnNext() {
    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.onNext(a[0], 2, 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.assertValue(1).assertNoErrors().assertNotComplete();
}
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)

Example 57 with TestSubscriber

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

the class SinglePostCompleteSubscriberTest method requestCompleteRace.

@Test
public void requestCompleteRace() {
    for (int i = 0; i < 500; i++) {
        final TestSubscriber<Integer> ts = new TestSubscriber<Integer>(0L);
        final SinglePostCompleteSubscriber<Integer, Integer> spc = new SinglePostCompleteSubscriber<Integer, Integer>(ts) {

            private static final long serialVersionUID = -2848918821531562637L;

            @Override
            public void onNext(Integer t) {
            }

            @Override
            public void onError(Throwable t) {
            }

            @Override
            public void onComplete() {
                complete(1);
            }
        };
        spc.onSubscribe(new BooleanSubscription());
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                spc.onComplete();
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                ts.request(1);
            }
        };
        TestHelper.race(r1, r2);
        ts.assertResult(1);
    }
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Test(org.junit.Test)

Example 58 with TestSubscriber

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

the class QueueDrainHelperTest method postCompleteWithRequest.

@Test
public void postCompleteWithRequest() {
    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());
    queue.offer(1);
    state.getAndIncrement();
    QueueDrainHelper.postComplete(ts, queue, state, isCancelled);
    ts.assertResult(1);
}
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 59 with TestSubscriber

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

the class QueueDrainHelperTest method completeRequestRace.

@Test
public void completeRequestRace() {
    for (int i = 0; i < 500; i++) {
        final TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
        final ArrayDeque<Integer> queue = new ArrayDeque<Integer>();
        final AtomicLong state = new AtomicLong();
        final BooleanSupplier isCancelled = new BooleanSupplier() {

            @Override
            public boolean getAsBoolean() throws Exception {
                return false;
            }
        };
        ts.onSubscribe(new BooleanSubscription());
        queue.offer(1);
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                QueueDrainHelper.postCompleteRequest(1, ts, queue, state, isCancelled);
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                QueueDrainHelper.postComplete(ts, queue, state, isCancelled);
            }
        };
        TestHelper.race(r1, r2);
        ts.assertResult(1);
    }
}
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 60 with TestSubscriber

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

the class QueueDrainHelperTest method postCompleteCancelled.

@Test
public void postCompleteCancelled() {
    final 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 ts.isCancelled();
        }
    };
    ts.onSubscribe(new BooleanSubscription());
    queue.offer(1);
    state.getAndIncrement();
    ts.cancel();
    QueueDrainHelper.postComplete(ts, queue, state, isCancelled);
    ts.assertEmpty();
}
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)

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