use of io.reactivex.rxjava3.core.ObservableOnSubscribe 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.ObservableOnSubscribe 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.ObservableOnSubscribe 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.ObservableOnSubscribe 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() {
}
});
}
use of io.reactivex.rxjava3.core.ObservableOnSubscribe in project Mycat2 by MyCATApache.
the class ValuesCsvScanPlan method execute.
@Override
public Observable execute(RootContext rootContext) {
return (Observable) Observable.create((ObservableOnSubscribe<VectorSchemaRoot>) emitter -> {
int size = 0;
for (VectorSchemaRoot vectorSchemaRoot : observable) {
size += vectorSchemaRoot.getRowCount();
emitter.onNext(vectorSchemaRoot);
}
LOGGER.debug(" size:{}", size);
emitter.onComplete();
});
}
Aggregations