use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class ObservableWithLatestFromTest method otherThrows.
@Test
public void otherThrows() {
PublishSubject<Integer> source = PublishSubject.create();
PublishSubject<Integer> other = PublishSubject.create();
Observable<Integer> result = source.withLatestFrom(other, COMBINER);
TestObserverEx<Integer> to = new TestObserverEx<>();
result.subscribe(to);
assertTrue(source.hasObservers());
assertTrue(other.hasObservers());
other.onNext(1);
source.onNext(1);
other.onError(new TestException());
to.assertTerminated();
to.assertValue((1 << 8) + 1);
to.assertNotComplete();
to.assertError(TestException.class);
assertFalse(source.hasObservers());
assertFalse(other.hasObservers());
}
use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class ObservableRetryTest method noCancelPreviousRetryWhile.
@Test
public void noCancelPreviousRetryWhile() {
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.retry(5, Functions.alwaysTrue()).test().assertResult(1);
assertEquals(0, counter.get());
}
use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class ObservableRetryTest method noCancelPreviousRetryWhile2.
@Test
public void noCancelPreviousRetryWhile2() {
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.retry(new BiPredicate<Integer, Throwable>() {
@Override
public boolean test(Integer a, Throwable b) throws Exception {
return a < 5;
}
}).test().assertResult(1);
assertEquals(0, counter.get());
}
use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class ObservableRetryTest method repeatFloodNoSubscriptionError.
@Test
public void repeatFloodNoSubscriptionError() {
List<Throwable> errors = TestHelper.trackPluginErrors();
final TestException error = new TestException();
try {
final PublishSubject<Integer> source = PublishSubject.create();
final PublishSubject<Integer> signaller = PublishSubject.create();
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
TestObserver<Integer> to = source.take(1).map(new Function<Integer, Integer>() {
@Override
public Integer apply(Integer v) throws Exception {
throw error;
}
}).retryWhen(new Function<Observable<Throwable>, ObservableSource<Integer>>() {
@Override
public ObservableSource<Integer> apply(Observable<Throwable> v) throws Exception {
return signaller;
}
}).test();
Runnable r1 = new Runnable() {
@Override
public void run() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
source.onNext(1);
}
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
signaller.onNext(1);
}
}
};
TestHelper.race(r1, r2);
to.dispose();
}
if (!errors.isEmpty()) {
for (Throwable e : errors) {
e.printStackTrace();
}
fail(errors + "");
}
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class ObservableTimeoutWithSelectorTest method timeoutSelectorWithFirstTimeoutFirstAndNoOtherObservable.
@Test
public void timeoutSelectorWithFirstTimeoutFirstAndNoOtherObservable() {
PublishSubject<Integer> source = PublishSubject.create();
final PublishSubject<Integer> timeout = PublishSubject.create();
Function<Integer, Observable<Integer>> timeoutFunc = new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer t1) {
return PublishSubject.create();
}
};
Observer<Object> o = TestHelper.mockObserver();
source.timeout(timeout, timeoutFunc).subscribe(o);
timeout.onNext(1);
InOrder inOrder = inOrder(o);
inOrder.verify(o).onError(isA(TimeoutException.class));
inOrder.verifyNoMoreInteractions();
}
Aggregations