use of io.reactivex.rxjava3.core.ObservableEmitter in project RxJava by ReactiveX.
the class ObservableCreateTest method basicSerialized.
@Test
@SuppressUndeliverable
public void basicSerialized() {
final Disposable d = Disposable.empty();
Observable.<Integer>create(new ObservableOnSubscribe<Integer>() {
@Override
public void subscribe(ObservableEmitter<Integer> e) throws Exception {
e = e.serialize();
e.setDisposable(d);
e.onNext(1);
e.onNext(2);
e.onNext(3);
e.onComplete();
e.onError(new TestException());
e.onNext(4);
e.onError(new TestException());
e.onComplete();
}
}).test().assertResult(1, 2, 3);
assertTrue(d.isDisposed());
}
use of io.reactivex.rxjava3.core.ObservableEmitter in project RxJava by ReactiveX.
the class ObservableCreateTest method basicWithCancellable.
@Test
@SuppressUndeliverable
public void basicWithCancellable() {
final Disposable d1 = Disposable.empty();
final Disposable d2 = Disposable.empty();
Observable.<Integer>create(new ObservableOnSubscribe<Integer>() {
@Override
public void subscribe(ObservableEmitter<Integer> e) throws Exception {
e.setDisposable(d1);
e.setCancellable(new Cancellable() {
@Override
public void cancel() throws Exception {
d2.dispose();
}
});
e.onNext(1);
e.onNext(2);
e.onNext(3);
e.onComplete();
e.onError(new TestException());
e.onNext(4);
e.onError(new TestException());
e.onComplete();
}
}).test().assertResult(1, 2, 3);
assertTrue(d1.isDisposed());
assertTrue(d2.isDisposed());
}
use of io.reactivex.rxjava3.core.ObservableEmitter 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.ObservableEmitter 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.ObservableEmitter in project RxJava by ReactiveX.
the class ObservableCreateTest method onErrorCrash.
@Test
public void onErrorCrash() {
Observable.create(new ObservableOnSubscribe<Object>() {
@Override
public void subscribe(ObservableEmitter<Object> e) throws Exception {
Disposable d = Disposable.empty();
e.setDisposable(d);
try {
e.onError(new IOException());
fail("Should have thrown");
} catch (TestException ex) {
// expected
}
assertTrue(d.isDisposed());
}
}).subscribe(new Observer<Object>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(Object value) {
}
@Override
public void onError(Throwable e) {
throw new TestException();
}
@Override
public void onComplete() {
}
});
}
Aggregations