use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class ObservableCreateTest method onErrorRace.
@Test
public void onErrorRace() {
Observable<Object> source = Observable.create(new ObservableOnSubscribe<Object>() {
@Override
public void subscribe(ObservableEmitter<Object> e) throws Exception {
final ObservableEmitter<Object> f = e.serialize();
final TestException ex = new TestException();
Runnable r1 = new Runnable() {
@Override
public void run() {
f.onError(null);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
f.onError(ex);
}
};
TestHelper.race(r1, r2);
}
});
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
source.test().assertFailure(Throwable.class);
}
} finally {
RxJavaPlugins.reset();
}
assertFalse(errors.isEmpty());
}
use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class ObservableCreateTest method serializedDrainDoneButNotEmpty.
@Test
public void serializedDrainDoneButNotEmpty() throws Throwable {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
TestObserver<Integer> to = new TestObserver<>();
AtomicReference<ObservableEmitter<Integer>> ref = new AtomicReference<>();
CountDownLatch cdl = new CountDownLatch(1);
Observable.<Integer>create(emitter -> {
emitter = emitter.serialize();
ref.set(emitter);
emitter.onNext(1);
}).doOnNext(v -> {
if (v == 1) {
TestHelper.raceOther(() -> {
ref.get().onNext(2);
ref.get().onComplete();
}, cdl);
ref.get().onNext(3);
}
}).subscribe(to);
cdl.await();
}
}
use of io.reactivex.rxjava3.core.Observable 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.core.Observable in project RxJava by ReactiveX.
the class ObservableDematerializeTest method dematerialize3.
@Test
public void dematerialize3() {
Exception exception = new Exception("test");
Observable<Integer> o = Observable.error(exception);
Observable<Integer> dematerialize = o.materialize().dematerialize(Functions.<Notification<Integer>>identity());
Observer<Integer> observer = TestHelper.mockObserver();
dematerialize.subscribe(observer);
verify(observer, times(1)).onError(exception);
verify(observer, times(0)).onComplete();
verify(observer, times(0)).onNext(any(Integer.class));
}
use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class ObservableDematerializeTest method errorPassThru.
@Test
public void errorPassThru() {
Exception exception = new Exception("test");
Observable<Notification<Integer>> o = Observable.error(exception);
Observable<Integer> dematerialize = o.dematerialize(Functions.<Notification<Integer>>identity());
Observer<Integer> observer = TestHelper.mockObserver();
dematerialize.subscribe(observer);
verify(observer, times(1)).onError(exception);
verify(observer, times(0)).onComplete();
verify(observer, times(0)).onNext(any(Integer.class));
}
Aggregations