use of org.apache.cassandra.cql3.functions.Function in project RxJava by ReactiveX.
the class FlowableOnErrorReturnTest method normalBackpressure.
@Test
public void normalBackpressure() {
TestSubscriber<Integer> ts = TestSubscriber.create(0);
PublishProcessor<Integer> pp = PublishProcessor.create();
pp.onErrorReturn(new Function<Throwable, Integer>() {
@Override
public Integer apply(Throwable e) {
return 3;
}
}).subscribe(ts);
ts.request(2);
pp.onNext(1);
pp.onNext(2);
pp.onError(new TestException("Forced failure"));
ts.assertValues(1, 2);
ts.assertNoErrors();
ts.assertNotComplete();
ts.request(2);
ts.assertValues(1, 2, 3);
ts.assertNoErrors();
ts.assertComplete();
}
use of org.apache.cassandra.cql3.functions.Function in project RxJava by ReactiveX.
the class FlowableOnErrorResumeNextViaFunctionTest method resumeNextWithAsyncExecution.
@Test
public void resumeNextWithAsyncExecution() {
final AtomicReference<Throwable> receivedException = new AtomicReference<>();
Subscription s = mock(Subscription.class);
TestFlowable w = new TestFlowable(s, "one");
Function<Throwable, Flowable<String>> resume = new Function<Throwable, Flowable<String>>() {
@Override
public Flowable<String> apply(Throwable t1) {
receivedException.set(t1);
return Flowable.just("twoResume", "threeResume");
}
};
Flowable<String> flowable = Flowable.unsafeCreate(w).onErrorResumeNext(resume);
Subscriber<String> subscriber = TestHelper.mockSubscriber();
flowable.subscribe(subscriber);
try {
w.t.join();
} catch (InterruptedException e) {
fail(e.getMessage());
}
verify(subscriber, Mockito.never()).onError(any(Throwable.class));
verify(subscriber, times(1)).onComplete();
verify(subscriber, times(1)).onNext("one");
verify(subscriber, Mockito.never()).onNext("two");
verify(subscriber, Mockito.never()).onNext("three");
verify(subscriber, times(1)).onNext("twoResume");
verify(subscriber, times(1)).onNext("threeResume");
assertNotNull(receivedException.get());
}
use of org.apache.cassandra.cql3.functions.Function in project RxJava by ReactiveX.
the class ObservableOnErrorResumeNextTest method functionThrowsError.
/**
* Test that when a function throws an exception this is propagated through onError.
*/
@Test
public void functionThrowsError() {
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) {
throw new RuntimeException("exception from function");
}
};
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());
}
// we should get the "one" value before the error
verify(observer, times(1)).onNext("one");
// we should have received an onError call on the Observer since the resume function threw an exception
verify(observer, times(1)).onError(any(Throwable.class));
verify(observer, times(0)).onComplete();
}
use of org.apache.cassandra.cql3.functions.Function in project RxJava by ReactiveX.
the class ObservableOnErrorResumeNextTest method resumeNextWithAsyncExecution.
@Test
public void resumeNextWithAsyncExecution() {
final AtomicReference<Throwable> receivedException = new AtomicReference<>();
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());
}
use of org.apache.cassandra.cql3.functions.Function in project RxJava by ReactiveX.
the class FlowableTimerTest method timerInterruptible.
@Test
public void timerInterruptible() throws Exception {
ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();
try {
for (Scheduler s : new Scheduler[] { Schedulers.single(), Schedulers.computation(), Schedulers.newThread(), Schedulers.io(), Schedulers.from(exec, true) }) {
final AtomicBoolean interrupted = new AtomicBoolean();
TestSubscriber<Long> ts = Flowable.timer(1, TimeUnit.MILLISECONDS, s).map(new Function<Long, Long>() {
@Override
public Long apply(Long v) throws Exception {
try {
Thread.sleep(3000);
} catch (InterruptedException ex) {
interrupted.set(true);
}
return v;
}
}).test();
Thread.sleep(500);
ts.cancel();
Thread.sleep(500);
assertTrue(s.getClass().getSimpleName(), interrupted.get());
}
} finally {
exec.shutdown();
}
}
Aggregations