use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class ObservableDelayTest method delayWithObservableDelayThrows.
@Test
public void delayWithObservableDelayThrows() {
PublishSubject<Integer> source = PublishSubject.create();
final PublishSubject<Integer> delay = PublishSubject.create();
Function<Integer, Observable<Integer>> delayFunc = new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer t1) {
return delay;
}
};
Observer<Object> o = TestHelper.mockObserver();
InOrder inOrder = inOrder(o);
source.delay(delayFunc).subscribe(o);
source.onNext(1);
delay.onError(new TestException());
inOrder.verify(o).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
verify(o, never()).onNext(any());
verify(o, never()).onComplete();
}
use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class ObservableDelayTest method delayWithObservableAsTimed.
@Test
public void delayWithObservableAsTimed() {
Observable<Long> source = Observable.interval(1L, TimeUnit.SECONDS, scheduler).take(3);
final Observable<Long> delayer = Observable.timer(500L, TimeUnit.MILLISECONDS, scheduler);
Function<Long, Observable<Long>> delayFunc = new Function<Long, Observable<Long>>() {
@Override
public Observable<Long> apply(Long t1) {
return delayer;
}
};
Observable<Long> delayed = source.delay(delayFunc);
delayed.subscribe(observer);
InOrder inOrder = inOrder(observer);
scheduler.advanceTimeTo(1499L, TimeUnit.MILLISECONDS);
verify(observer, never()).onNext(anyLong());
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(1500L, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext(0L);
inOrder.verify(observer, never()).onNext(anyLong());
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(2400L, TimeUnit.MILLISECONDS);
inOrder.verify(observer, never()).onNext(anyLong());
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(2500L, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext(1L);
inOrder.verify(observer, never()).onNext(anyLong());
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(3400L, TimeUnit.MILLISECONDS);
inOrder.verify(observer, never()).onNext(anyLong());
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(3500L, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext(2L);
verify(observer, times(1)).onComplete();
verify(observer, never()).onError(any(Throwable.class));
}
use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class ObservableDelayTest method delayWithObservableDelayFunctionThrows.
@Test
public void delayWithObservableDelayFunctionThrows() {
PublishSubject<Integer> source = PublishSubject.create();
Function<Integer, Observable<Integer>> delayFunc = new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer t1) {
throw new TestException();
}
};
Observer<Object> o = TestHelper.mockObserver();
InOrder inOrder = inOrder(o);
source.delay(delayFunc).subscribe(o);
source.onNext(1);
inOrder.verify(o).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
verify(o, never()).onNext(any());
verify(o, never()).onComplete();
}
use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class ObservableFlatMapTest method flatMapMaxConcurrent.
@Test
public void flatMapMaxConcurrent() {
final int m = 4;
final AtomicInteger subscriptionCount = new AtomicInteger();
Observable<Integer> source = Observable.range(1, 10).flatMap(new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer t1) {
return composer(Observable.range(t1 * 10, 2), subscriptionCount, m).subscribeOn(Schedulers.computation());
}
}, m);
TestObserver<Integer> to = new TestObserver<>();
source.subscribe(to);
to.awaitDone(5, TimeUnit.SECONDS);
to.assertNoErrors();
Set<Integer> expected = new HashSet<>(Arrays.asList(10, 11, 20, 21, 30, 31, 40, 41, 50, 51, 60, 61, 70, 71, 80, 81, 90, 91, 100, 101));
Assert.assertEquals(expected.size(), to.values().size());
Assert.assertTrue(expected.containsAll(to.values()));
}
use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.
the class ObservableFlatMapTest method failingFusedInnerCancelsSource.
@Test
public void failingFusedInnerCancelsSource() {
final AtomicInteger counter = new AtomicInteger();
Observable.range(1, 5).doOnNext(new Consumer<Integer>() {
@Override
public void accept(Integer v) throws Exception {
counter.getAndIncrement();
}
}).flatMap(new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer v) throws Exception {
return Observable.<Integer>fromIterable(new Iterable<Integer>() {
@Override
public Iterator<Integer> iterator() {
return new Iterator<Integer>() {
@Override
public boolean hasNext() {
return true;
}
@Override
public Integer next() {
throw new TestException();
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
});
}
}).test().assertFailure(TestException.class);
assertEquals(1, counter.get());
}
Aggregations