Search in sources :

Example 41 with TestSubscriber

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

the class FlowableFlatMapTest method testFlatMapTransformsMaxConcurrentNormal.

@Test
public void testFlatMapTransformsMaxConcurrentNormal() {
    final int m = 2;
    final AtomicInteger subscriptionCount = new AtomicInteger();
    Flowable<Integer> onNext = composer(Flowable.fromIterable(Arrays.asList(1, 2, 3)).observeOn(Schedulers.computation()), subscriptionCount, m).subscribeOn(Schedulers.computation());
    Flowable<Integer> onComplete = composer(Flowable.fromIterable(Arrays.asList(4)), subscriptionCount, m).subscribeOn(Schedulers.computation());
    Flowable<Integer> onError = Flowable.fromIterable(Arrays.asList(5));
    Flowable<Integer> source = Flowable.fromIterable(Arrays.asList(10, 20, 30));
    Subscriber<Object> o = TestHelper.mockSubscriber();
    TestSubscriber<Object> ts = new TestSubscriber<Object>(o);
    Function<Integer, Flowable<Integer>> just = just(onNext);
    Function<Throwable, Flowable<Integer>> just2 = just(onError);
    Callable<Flowable<Integer>> just0 = just0(onComplete);
    source.flatMap(just, just2, just0, m).subscribe(ts);
    ts.awaitTerminalEvent(1, TimeUnit.SECONDS);
    ts.assertNoErrors();
    ts.assertTerminated();
    verify(o, times(3)).onNext(1);
    verify(o, times(3)).onNext(2);
    verify(o, times(3)).onNext(3);
    verify(o).onNext(4);
    verify(o).onComplete();
    verify(o, never()).onNext(5);
    verify(o, never()).onError(any(Throwable.class));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestSubscriber(io.reactivex.subscribers.TestSubscriber)

Example 42 with TestSubscriber

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

the class FlowableFlatMapTest method testFlatMapMaxConcurrent.

@Test
public void testFlatMapMaxConcurrent() {
    final int m = 4;
    final AtomicInteger subscriptionCount = new AtomicInteger();
    Flowable<Integer> source = Flowable.range(1, 10).flatMap(new Function<Integer, Flowable<Integer>>() {

        @Override
        public Flowable<Integer> apply(Integer t1) {
            return composer(Flowable.range(t1 * 10, 2), subscriptionCount, m).subscribeOn(Schedulers.computation());
        }
    }, m);
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
    source.subscribe(ts);
    ts.awaitTerminalEvent();
    ts.assertNoErrors();
    Set<Integer> expected = new HashSet<Integer>(Arrays.asList(10, 11, 20, 21, 30, 31, 40, 41, 50, 51, 60, 61, 70, 71, 80, 81, 90, 91, 100, 101));
    Assert.assertEquals(expected.size(), ts.valueCount());
    Assert.assertTrue(expected.containsAll(ts.values()));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestSubscriber(io.reactivex.subscribers.TestSubscriber)

Example 43 with TestSubscriber

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

the class FlowableWithLatestFromTest method testOtherThrows.

@Test
public void testOtherThrows() {
    PublishProcessor<Integer> source = PublishProcessor.create();
    PublishProcessor<Integer> other = PublishProcessor.create();
    Flowable<Integer> result = source.withLatestFrom(other, COMBINER);
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
    result.subscribe(ts);
    assertTrue(source.hasSubscribers());
    assertTrue(other.hasSubscribers());
    other.onNext(1);
    source.onNext(1);
    other.onError(new TestException());
    ts.assertTerminated();
    ts.assertValue((1 << 8) + 1);
    ts.assertNotComplete();
    ts.assertError(TestException.class);
    assertFalse(source.hasSubscribers());
    assertFalse(other.hasSubscribers());
}
Also used : TestException(io.reactivex.exceptions.TestException) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Test(org.junit.Test)

Example 44 with TestSubscriber

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

the class FlowableWithLatestFromTest method testSourceThrows.

@Test
public void testSourceThrows() {
    PublishProcessor<Integer> source = PublishProcessor.create();
    PublishProcessor<Integer> other = PublishProcessor.create();
    Flowable<Integer> result = source.withLatestFrom(other, COMBINER);
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
    result.subscribe(ts);
    assertTrue(source.hasSubscribers());
    assertTrue(other.hasSubscribers());
    other.onNext(1);
    source.onNext(1);
    source.onError(new TestException());
    ts.assertTerminated();
    ts.assertValue((1 << 8) + 1);
    ts.assertError(TestException.class);
    ts.assertNotComplete();
    assertFalse(source.hasSubscribers());
    assertFalse(other.hasSubscribers());
}
Also used : TestException(io.reactivex.exceptions.TestException) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Test(org.junit.Test)

Example 45 with TestSubscriber

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

the class FlowableWithLatestFromTest method withError.

@Test
public void withError() {
    TestSubscriber<String> ts = new TestSubscriber<String>(0);
    Flowable.range(1, 3).withLatestFrom(new Flowable<?>[] { Flowable.just(1), Flowable.error(new TestException()) }, toArray).subscribe(ts);
    ts.assertNoValues();
    ts.assertError(TestException.class);
    ts.assertNotComplete();
}
Also used : TestException(io.reactivex.exceptions.TestException) TestSubscriber(io.reactivex.subscribers.TestSubscriber) 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