use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class ObservableFlatMapStreamTest method eventsIgnoredAfterDispose.
@Test
public void eventsIgnoredAfterDispose() {
AtomicInteger calls = new AtomicInteger();
new Observable<Integer>() {
@Override
protected void subscribeActual(@NonNull Observer<? super Integer> observer) {
observer.onSubscribe(Disposable.empty());
observer.onNext(1);
observer.onNext(2);
observer.onComplete();
}
}.flatMapStream(v -> {
calls.getAndIncrement();
return Stream.of(1);
}).take(1).test().assertResult(1);
assertEquals(1, calls.get());
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class DeferredScalarObserverTest method disposedAfterOnNext.
@Test
public void disposedAfterOnNext() {
final TestObserver<Integer> to = new TestObserver<>();
TakeLast source = new TakeLast(new Observer<Integer>() {
Disposable upstream;
@Override
public void onSubscribe(Disposable d) {
this.upstream = d;
to.onSubscribe(d);
}
@Override
public void onNext(Integer value) {
to.onNext(value);
upstream.dispose();
}
@Override
public void onError(Throwable e) {
to.onError(e);
}
@Override
public void onComplete() {
to.onComplete();
}
});
source.onSubscribe(Disposable.empty());
source.onNext(1);
source.onComplete();
to.assertValue(1).assertNoErrors().assertNotComplete();
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class MaybeDoOnEventTest method onSubscribeCrash.
@Test
public void onSubscribeCrash() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final Disposable bs = Disposable.empty();
new Maybe<Integer>() {
@Override
protected void subscribeActual(MaybeObserver<? super Integer> observer) {
observer.onSubscribe(bs);
observer.onError(new TestException("Second"));
observer.onComplete();
observer.onSuccess(1);
}
}.doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(Disposable d) throws Exception {
throw new TestException("First");
}
}).to(TestHelper.<Integer>testConsumer()).assertFailureAndMessage(TestException.class, "First");
assertTrue(bs.isDisposed());
TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class MaybeConcatArrayTest method errorAfterTermination.
@Test
public void errorAfterTermination() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final MaybeObserver<?>[] o = { null };
Maybe.concatArrayDelayError(Maybe.just(1), Maybe.error(new IOException()), new Maybe<Integer>() {
@Override
protected void subscribeActual(MaybeObserver<? super Integer> observer) {
observer.onSubscribe(Disposable.empty());
observer.onSuccess(2);
o[0] = observer;
}
}).test().assertFailure(IOException.class, 1, 2);
o[0].onError(new TestException());
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.
the class MaybeDelayTest method delayedErrorOnError.
@Test
public void delayedErrorOnError() {
final TestScheduler scheduler = new TestScheduler();
final TestObserver<?> observer = Maybe.error(new TestException()).delay(5, TimeUnit.SECONDS, scheduler, true).test();
scheduler.advanceTimeTo(2, TimeUnit.SECONDS);
observer.assertNoErrors();
scheduler.advanceTimeTo(5, TimeUnit.SECONDS);
observer.assertError(TestException.class);
}
Aggregations