use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableDelaySubscriptionOtherTest method noPrematureSubscriptionToError.
@Test
public void noPrematureSubscriptionToError() {
PublishSubject<Object> other = PublishSubject.create();
TestObserver<Integer> to = new TestObserver<>();
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(to);
to.assertNotComplete();
to.assertNoErrors();
to.assertNoValues();
Assert.assertEquals("Premature subscription", 0, subscribed.get());
other.onComplete();
Assert.assertEquals("No subscription", 1, subscribed.get());
to.assertNoValues();
to.assertNotComplete();
to.assertError(TestException.class);
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableConcatMapSchedulerTest method concatArray.
@SuppressWarnings("unchecked")
@Test
public void concatArray() throws Exception {
for (int i = 2; i < 10; i++) {
Observable<Integer>[] obs = new Observable[i];
Arrays.fill(obs, Observable.just(1));
Integer[] expected = new Integer[i];
Arrays.fill(expected, 1);
Method m = Observable.class.getMethod("concatArray", ObservableSource[].class);
TestObserver<Integer> to = TestObserver.create();
((Observable<Integer>) m.invoke(null, new Object[] { obs })).subscribe(to);
to.assertValues(expected);
to.assertNoErrors();
to.assertComplete();
}
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableFlatMapTest method flatMapSelectorMaxConcurrent.
@Test
public void flatMapSelectorMaxConcurrent() {
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> to = new TestObserver<>();
source.subscribe(to);
to.awaitDone(5, TimeUnit.SECONDS);
to.assertNoErrors();
Set<Integer> expected = new HashSet<>(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(), to.values().size());
System.out.println("--> testFlatMapSelectorMaxConcurrent: " + to.values());
Assert.assertTrue(expected.containsAll(to.values()));
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableDelayTest method delaySupplierErrors.
@Test
public void delaySupplierErrors() {
final PublishSubject<Integer> ps = PublishSubject.create();
Observable<Integer> source = Observable.range(1, 5);
TestObserver<Integer> to = new TestObserver<>();
source.delaySubscription(ps).subscribe(to);
to.assertNoValues();
to.assertNoErrors();
to.assertNotComplete();
ps.onError(new TestException());
to.assertNoValues();
to.assertNotComplete();
to.assertError(TestException.class);
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class ObservableFlatMapTest method flatMapMaxConcurrent.
@Test
public void flatMapMaxConcurrent() {
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());
}
}, m);
TestObserver<Integer> to = new TestObserver<>();
source.subscribe(to);
to.awaitDone(5, TimeUnit.SECONDS);
to.assertNoErrors();
Set<Integer> expected = new HashSet<>(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(), to.values().size());
Assert.assertTrue(expected.containsAll(to.values()));
}
Aggregations