use of io.reactivex.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableFlatMapTest method testFlatMapSelectorMaxConcurrent.
@Test
public void testFlatMapSelectorMaxConcurrent() {
final int m = 4;
final AtomicInteger subscriptionCount = new AtomicInteger();
Observable<Integer> source = Observable.range(1, 10).flatMap(new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer t1) {
return composer(Observable.range(t1 * 10, 2), subscriptionCount, m).subscribeOn(Schedulers.computation());
}
}, new BiFunction<Integer, Integer, Integer>() {
@Override
public Integer apply(Integer t1, Integer t2) {
return t1 * 1000 + t2;
}
}, m);
TestObserver<Integer> ts = new TestObserver<Integer>();
source.subscribe(ts);
ts.awaitTerminalEvent();
ts.assertNoErrors();
Set<Integer> expected = new HashSet<Integer>(Arrays.asList(1010, 1011, 2020, 2021, 3030, 3031, 4040, 4041, 5050, 5051, 6060, 6061, 7070, 7071, 8080, 8081, 9090, 9091, 10100, 10101));
Assert.assertEquals(expected.size(), ts.valueCount());
System.out.println("--> testFlatMapSelectorMaxConcurrent: " + ts.values());
Assert.assertTrue(expected.containsAll(ts.values()));
}
use of io.reactivex.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableFlatMapTest method testFlatMapTransformsMaxConcurrentNormal.
@Test
public void testFlatMapTransformsMaxConcurrentNormal() {
final int m = 2;
final AtomicInteger subscriptionCount = new AtomicInteger();
Observable<Integer> onNext = composer(Observable.fromIterable(Arrays.asList(1, 2, 3)).observeOn(Schedulers.computation()), subscriptionCount, m).subscribeOn(Schedulers.computation());
Observable<Integer> onComplete = composer(Observable.fromIterable(Arrays.asList(4)), subscriptionCount, m).subscribeOn(Schedulers.computation());
Observable<Integer> onError = Observable.fromIterable(Arrays.asList(5));
Observable<Integer> source = Observable.fromIterable(Arrays.asList(10, 20, 30));
Observer<Object> o = TestHelper.mockObserver();
TestObserver<Object> ts = new TestObserver<Object>(o);
Function<Throwable, Observable<Integer>> just = just(onError);
source.flatMap(just(onNext), just, just0(onComplete), 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.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableDelaySubscriptionOtherTest method testCompleteTriggersSubscription.
@Test
public void testCompleteTriggersSubscription() {
PublishSubject<Object> other = PublishSubject.create();
TestObserver<Integer> ts = new TestObserver<Integer>();
final AtomicInteger subscribed = new AtomicInteger();
Observable.just(1).doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(Disposable d) {
subscribed.getAndIncrement();
}
}).delaySubscription(other).subscribe(ts);
ts.assertNotComplete();
ts.assertNoErrors();
ts.assertNoValues();
Assert.assertEquals("Premature subscription", 0, subscribed.get());
other.onComplete();
Assert.assertEquals("No subscription", 1, subscribed.get());
ts.assertValue(1);
ts.assertNoErrors();
ts.assertComplete();
}
use of io.reactivex.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableDelaySubscriptionOtherTest method testNoPrematureSubscriptionToError.
@Test
public void testNoPrematureSubscriptionToError() {
PublishSubject<Object> other = PublishSubject.create();
TestObserver<Integer> ts = new TestObserver<Integer>();
final AtomicInteger subscribed = new AtomicInteger();
Observable.<Integer>error(new TestException()).doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(Disposable d) {
subscribed.getAndIncrement();
}
}).delaySubscription(other).subscribe(ts);
ts.assertNotComplete();
ts.assertNoErrors();
ts.assertNoValues();
Assert.assertEquals("Premature subscription", 0, subscribed.get());
other.onComplete();
Assert.assertEquals("No subscription", 1, subscribed.get());
ts.assertNoValues();
ts.assertNotComplete();
ts.assertError(TestException.class);
}
use of io.reactivex.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableDetachTest method error.
@Test
public void error() {
TestObserver<Object> ts = new TestObserver<Object>();
Observable.error(new TestException()).onTerminateDetach().subscribe(ts);
ts.assertNoValues();
ts.assertError(TestException.class);
ts.assertNotComplete();
}
Aggregations