use of io.reactivex.rxjava3.core.ObservableSource in project RxJava by ReactiveX.
the class ObservableSwitchTest method switchIssue737.
@Test
public void switchIssue737() {
// https://github.com/ReactiveX/RxJava/issues/737
Observable<Observable<String>> source = Observable.unsafeCreate(new ObservableSource<Observable<String>>() {
@Override
public void subscribe(Observer<? super Observable<String>> outerObserver) {
outerObserver.onSubscribe(Disposable.empty());
publishNext(outerObserver, 0, Observable.unsafeCreate(new ObservableSource<String>() {
@Override
public void subscribe(Observer<? super String> innerObserver) {
innerObserver.onSubscribe(Disposable.empty());
publishNext(innerObserver, 10, "1-one");
publishNext(innerObserver, 20, "1-two");
// The following events will be ignored
publishNext(innerObserver, 30, "1-three");
publishCompleted(innerObserver, 40);
}
}));
publishNext(outerObserver, 25, Observable.unsafeCreate(new ObservableSource<String>() {
@Override
public void subscribe(Observer<? super String> innerObserver) {
innerObserver.onSubscribe(Disposable.empty());
publishNext(innerObserver, 10, "2-one");
publishNext(innerObserver, 20, "2-two");
publishNext(innerObserver, 30, "2-three");
publishCompleted(innerObserver, 40);
}
}));
publishCompleted(outerObserver, 30);
}
});
Observable<String> sampled = Observable.switchOnNext(source);
sampled.subscribe(observer);
scheduler.advanceTimeTo(1000, TimeUnit.MILLISECONDS);
InOrder inOrder = inOrder(observer);
inOrder.verify(observer, times(1)).onNext("1-one");
inOrder.verify(observer, times(1)).onNext("1-two");
inOrder.verify(observer, times(1)).onNext("2-one");
inOrder.verify(observer, times(1)).onNext("2-two");
inOrder.verify(observer, times(1)).onNext("2-three");
inOrder.verify(observer, times(1)).onComplete();
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.rxjava3.core.ObservableSource in project RxJava by ReactiveX.
the class ObservableSwitchTest method unsubscribe.
@Test
public void unsubscribe() {
final AtomicBoolean isUnsubscribed = new AtomicBoolean();
Observable.switchOnNext(Observable.unsafeCreate(new ObservableSource<Observable<Integer>>() {
@Override
public void subscribe(final Observer<? super Observable<Integer>> observer) {
Disposable bs = Disposable.empty();
observer.onSubscribe(bs);
observer.onNext(Observable.just(1));
isUnsubscribed.set(bs.isDisposed());
}
})).take(1).subscribe();
assertTrue("Switch doesn't propagate 'unsubscribe'", isUnsubscribed.get());
}
use of io.reactivex.rxjava3.core.ObservableSource in project RxJava by ReactiveX.
the class ObservableRetryTest method noCancelPreviousRetryUntil.
@Test
public void noCancelPreviousRetryUntil() {
final AtomicInteger counter = new AtomicInteger();
final AtomicInteger times = new AtomicInteger();
Observable<Integer> source = Observable.defer(new Supplier<ObservableSource<Integer>>() {
@Override
public ObservableSource<Integer> get() throws Exception {
if (times.getAndIncrement() < 4) {
return Observable.error(new TestException());
}
return Observable.just(1);
}
}).doOnDispose(new Action() {
@Override
public void run() throws Exception {
counter.getAndIncrement();
}
});
source.retryUntil(new BooleanSupplier() {
@Override
public boolean getAsBoolean() throws Exception {
return false;
}
}).test().assertResult(1);
assertEquals(0, counter.get());
}
use of io.reactivex.rxjava3.core.ObservableSource in project RxJava by ReactiveX.
the class ObservableRetryTest method sourceObservableCallsUnsubscribe.
@Test
public void sourceObservableCallsUnsubscribe() throws InterruptedException {
final AtomicInteger subsCount = new AtomicInteger(0);
final TestObserver<String> to = new TestObserver<>();
ObservableSource<String> onSubscribe = new ObservableSource<String>() {
@Override
public void subscribe(Observer<? super String> observer) {
BooleanSubscription bs = new BooleanSubscription();
// https://github.com/ReactiveX/RxJava/issues/1024
if (!bs.isCancelled()) {
subsCount.incrementAndGet();
observer.onError(new RuntimeException("failed"));
// it unsubscribes the child directly
// this simulates various error/completion scenarios that could occur
// or just a source that proactively triggers cleanup
// FIXME can't unsubscribe child
// s.unsubscribe();
bs.cancel();
} else {
observer.onError(new RuntimeException());
}
}
};
Observable.unsafeCreate(onSubscribe).retry(3).subscribe(to);
// 1 + 3 retries
assertEquals(4, subsCount.get());
}
use of io.reactivex.rxjava3.core.ObservableSource in project RxJava by ReactiveX.
the class ObservableWindowWithStartEndObservableTest method startError.
@Test
public void startError() {
PublishSubject<Integer> source = PublishSubject.create();
PublishSubject<Integer> start = PublishSubject.create();
final PublishSubject<Integer> end = PublishSubject.create();
TestObserver<Integer> to = source.window(start, new Function<Integer, ObservableSource<Integer>>() {
@Override
public ObservableSource<Integer> apply(Integer v) throws Exception {
return end;
}
}).flatMap(Functions.<Observable<Integer>>identity()).test();
start.onError(new TestException());
to.assertFailure(TestException.class);
assertFalse("Source has observers!", source.hasObservers());
assertFalse("Start has observers!", start.hasObservers());
assertFalse("End has observers!", end.hasObservers());
}
Aggregations