use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class ObservableConcatTest method concatConcurrentWithInfinity.
@Test
public void concatConcurrentWithInfinity() {
final TestObservable<String> w1 = new TestObservable<>("one", "two", "three");
// This Observable will send "hello" MAX_VALUE time.
final TestObservable<String> w2 = new TestObservable<>("hello", Integer.MAX_VALUE);
Observer<String> observer = TestHelper.mockObserver();
TestObservable<Observable<String>> observableOfObservables = new TestObservable<>(Observable.unsafeCreate(w1), Observable.unsafeCreate(w2));
Observable<String> concatF = Observable.concat(Observable.unsafeCreate(observableOfObservables));
concatF.take(50).subscribe(observer);
// Wait for the thread to start up.
try {
w1.waitForThreadDone();
w2.waitForThreadDone();
} catch (InterruptedException e) {
e.printStackTrace();
}
InOrder inOrder = inOrder(observer);
inOrder.verify(observer, times(1)).onNext("one");
inOrder.verify(observer, times(1)).onNext("two");
inOrder.verify(observer, times(1)).onNext("three");
inOrder.verify(observer, times(47)).onNext("hello");
verify(observer, times(1)).onComplete();
verify(observer, never()).onError(any(Throwable.class));
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class ObservableDebounceTest method badSource.
@Test
public void badSource() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
new Observable<Integer>() {
@Override
protected void subscribeActual(Observer<? super Integer> observer) {
observer.onSubscribe(Disposable.empty());
observer.onComplete();
observer.onNext(1);
observer.onError(new TestException());
observer.onComplete();
}
}.debounce(1, TimeUnit.SECONDS, new TestScheduler()).test().assertResult();
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class ObservableDebounceTest method debounceWithTimeBackpressure.
@Test
public void debounceWithTimeBackpressure() throws InterruptedException {
TestScheduler scheduler = new TestScheduler();
TestObserverEx<Integer> observer = new TestObserverEx<>();
Observable.merge(Observable.just(1), Observable.just(2).delay(10, TimeUnit.MILLISECONDS, scheduler)).debounce(20, TimeUnit.MILLISECONDS, scheduler).take(1).subscribe(observer);
scheduler.advanceTimeBy(30, TimeUnit.MILLISECONDS);
observer.assertValue(2);
observer.assertTerminated();
observer.assertNoErrors();
}
use of io.reactivex.rxjava3.core.Observer 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.Observer 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));
}
Aggregations