use of io.reactivex.functions.Function in project RxJava by ReactiveX.
the class FlowableTimeoutWithSelectorTest method testTimeoutSelectorNormal1.
@Test(timeout = 2000)
public void testTimeoutSelectorNormal1() {
PublishProcessor<Integer> source = PublishProcessor.create();
final PublishProcessor<Integer> timeout = PublishProcessor.create();
Function<Integer, Flowable<Integer>> timeoutFunc = new Function<Integer, Flowable<Integer>>() {
@Override
public Flowable<Integer> apply(Integer t1) {
return timeout;
}
};
Flowable<Integer> other = Flowable.fromIterable(Arrays.asList(100));
Subscriber<Object> o = TestHelper.mockSubscriber();
InOrder inOrder = inOrder(o);
source.timeout(timeout, timeoutFunc, other).subscribe(o);
source.onNext(1);
source.onNext(2);
source.onNext(3);
timeout.onNext(1);
inOrder.verify(o).onNext(1);
inOrder.verify(o).onNext(2);
inOrder.verify(o).onNext(3);
inOrder.verify(o).onNext(100);
inOrder.verify(o).onComplete();
verify(o, never()).onError(any(Throwable.class));
}
use of io.reactivex.functions.Function in project RxJava by ReactiveX.
the class FlowableTimeoutWithSelectorTest method testTimeoutSelectorFirstFlowableThrows.
@Test
public void testTimeoutSelectorFirstFlowableThrows() {
PublishProcessor<Integer> source = PublishProcessor.create();
final PublishProcessor<Integer> timeout = PublishProcessor.create();
Function<Integer, Flowable<Integer>> timeoutFunc = new Function<Integer, Flowable<Integer>>() {
@Override
public Flowable<Integer> apply(Integer t1) {
return timeout;
}
};
Flowable<Integer> other = Flowable.fromIterable(Arrays.asList(100));
Subscriber<Object> o = TestHelper.mockSubscriber();
source.timeout(Flowable.<Integer>error(new TestException()), timeoutFunc, other).subscribe(o);
verify(o).onError(any(TestException.class));
verify(o, never()).onNext(any());
verify(o, never()).onComplete();
}
use of io.reactivex.functions.Function in project RxJava by ReactiveX.
the class FlowableTimeoutWithSelectorTest method testTimeoutSelectorWithFirstTimeoutFirstAndNoOtherFlowable.
@Test
public void testTimeoutSelectorWithFirstTimeoutFirstAndNoOtherFlowable() {
PublishProcessor<Integer> source = PublishProcessor.create();
final PublishProcessor<Integer> timeout = PublishProcessor.create();
Function<Integer, Flowable<Integer>> timeoutFunc = new Function<Integer, Flowable<Integer>>() {
@Override
public Flowable<Integer> apply(Integer t1) {
return PublishProcessor.create();
}
};
Subscriber<Object> o = TestHelper.mockSubscriber();
source.timeout(timeout, timeoutFunc).subscribe(o);
timeout.onNext(1);
InOrder inOrder = inOrder(o);
inOrder.verify(o).onError(isA(TimeoutException.class));
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.functions.Function in project RxJava by ReactiveX.
the class ObservableDebounceTest method debounceSelectorNormal1.
@Test
public void debounceSelectorNormal1() {
PublishSubject<Integer> source = PublishSubject.create();
final PublishSubject<Integer> debouncer = PublishSubject.create();
Function<Integer, Observable<Integer>> debounceSel = new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer t1) {
return debouncer;
}
};
Observer<Object> o = TestHelper.mockObserver();
InOrder inOrder = inOrder(o);
source.debounce(debounceSel).subscribe(o);
source.onNext(1);
debouncer.onNext(1);
source.onNext(2);
source.onNext(3);
source.onNext(4);
debouncer.onNext(2);
source.onNext(5);
source.onComplete();
inOrder.verify(o).onNext(1);
inOrder.verify(o).onNext(4);
inOrder.verify(o).onNext(5);
inOrder.verify(o).onComplete();
verify(o, never()).onError(any(Throwable.class));
}
use of io.reactivex.functions.Function in project RxJava by ReactiveX.
the class ObservableOnErrorResumeNextViaFunctionTest method testResumeNextWithAsyncExecution.
@Test
public void testResumeNextWithAsyncExecution() {
final AtomicReference<Throwable> receivedException = new AtomicReference<Throwable>();
Subscription s = mock(Subscription.class);
TestObservable w = new TestObservable(s, "one");
Function<Throwable, Observable<String>> resume = new Function<Throwable, Observable<String>>() {
@Override
public Observable<String> apply(Throwable t1) {
receivedException.set(t1);
return Observable.just("twoResume", "threeResume");
}
};
Observable<String> o = Observable.unsafeCreate(w).onErrorResumeNext(resume);
Observer<String> observer = TestHelper.mockObserver();
o.subscribe(observer);
try {
w.t.join();
} catch (InterruptedException e) {
fail(e.getMessage());
}
verify(observer, Mockito.never()).onError(any(Throwable.class));
verify(observer, times(1)).onComplete();
verify(observer, times(1)).onNext("one");
verify(observer, Mockito.never()).onNext("two");
verify(observer, Mockito.never()).onNext("three");
verify(observer, times(1)).onNext("twoResume");
verify(observer, times(1)).onNext("threeResume");
assertNotNull(receivedException.get());
}
Aggregations