use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class ConverterTest method observableConverterThrows.
@Test
public void observableConverterThrows() {
try {
Observable.just(1).to(new ObservableConverter<Integer, Integer>() {
@Override
public Integer apply(Observable<Integer> v) {
throw new TestException("Forced failure");
}
});
fail("Should have thrown!");
} catch (TestException ex) {
assertEquals("Forced failure", ex.getMessage());
}
}
use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class FlowableSwitchIfEmptyTest method requestsNotLost.
@Test
public void requestsNotLost() throws InterruptedException {
final TestSubscriber<Long> ts = new TestSubscriber<>(0L);
Flowable.unsafeCreate(new Publisher<Long>() {
@Override
public void subscribe(final Subscriber<? super Long> subscriber) {
subscriber.onSubscribe(new Subscription() {
final AtomicBoolean completed = new AtomicBoolean(false);
@Override
public void request(long n) {
if (n > 0 && completed.compareAndSet(false, true)) {
Schedulers.io().createWorker().schedule(new Runnable() {
@Override
public void run() {
subscriber.onComplete();
}
}, 100, TimeUnit.MILLISECONDS);
}
}
@Override
public void cancel() {
}
});
}
}).switchIfEmpty(Flowable.fromIterable(Arrays.asList(1L, 2L, 3L))).subscribeOn(Schedulers.computation()).subscribe(ts);
Thread.sleep(50);
// request while first observable is still finishing (as empty)
ts.request(1);
ts.request(1);
Thread.sleep(500);
ts.assertNotComplete();
ts.assertNoErrors();
ts.assertValueCount(2);
ts.cancel();
}
use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class RxJavaPluginsTest method observableCreate.
@SuppressWarnings("rawtypes")
@Test
public void observableCreate() {
try {
RxJavaPlugins.setOnObservableAssembly(new Function<Observable, Observable>() {
@Override
public Observable apply(Observable t) {
return new ObservableRange(1, 2);
}
});
Observable.range(10, 3).test().assertValues(1, 2).assertNoErrors().assertComplete();
} finally {
RxJavaPlugins.reset();
}
// make sure the reset worked
Observable.range(10, 3).test().assertValues(10, 11, 12).assertNoErrors().assertComplete();
}
use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class ConnectableObservable method connect.
/**
* Instructs the {@code ConnectableObservable} to begin emitting the items from its underlying
* {@link Observable} to its {@link Observer}s.
* <p>
* To disconnect from a synchronous source, use the {@link #connect(Consumer)} method.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>The behavior is determined by the implementor of this abstract class.</dd>
* </dl>
*
* @return the {@link Disposable} representing the connection
* @see <a href="http://reactivex.io/documentation/operators/connect.html">ReactiveX documentation: Connect</a>
*/
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable connect() {
ConnectConsumer cc = new ConnectConsumer();
connect(cc);
return cc.disposable;
}
use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class ObservableAllTest method predicateThrows.
@Test
public void predicateThrows() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
new Observable<Integer>() {
@Override
protected void subscribeActual(Observer<? super Integer> observer) {
observer.onSubscribe(Disposable.empty());
observer.onNext(1);
observer.onNext(2);
observer.onError(new TestException());
observer.onComplete();
}
}.all(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
throw new TestException();
}
}).test().assertFailure(TestException.class);
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
Aggregations