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));
}
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()));
}
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());
}
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());
}
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();
}
Aggregations