Skip to content

OnErrorResume Backpressure Tests #1768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,39 @@ public void run() {
}

}

@Test
public void testBackpressure() {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
Observable.range(0, 100000)
.onErrorResumeNext(new Func1<Throwable, Observable<Integer>>() {

@Override
public Observable<Integer> call(Throwable t1) {
return Observable.just(1);
}

})
.observeOn(Schedulers.computation())
.map(new Func1<Integer, Integer>() {
int c = 0;

@Override
public Integer call(Integer t1) {
if (c++ <= 1) {
// slow
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return t1;
}

})
.subscribe(ts);
ts.awaitTerminalEvent();
ts.assertNoErrors();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.mockito.Mockito;

Expand All @@ -29,6 +31,8 @@
import rx.Subscriber;
import rx.Subscription;
import rx.functions.Func1;
import rx.observers.TestSubscriber;
import rx.schedulers.Schedulers;

public class OperatorOnErrorResumeNextViaObservableTest {

Expand Down Expand Up @@ -143,4 +147,32 @@ public void run() {
System.out.println("done starting TestObservable thread");
}
}

@Test
public void testBackpressure() {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
Observable.range(0, 100000)
.onErrorResumeNext(Observable.just(1))
.observeOn(Schedulers.computation())
.map(new Func1<Integer, Integer>() {
int c = 0;

@Override
public Integer call(Integer t1) {
if (c++ <= 1) {
// slow
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return t1;
}

})
.subscribe(ts);
ts.awaitTerminalEvent();
ts.assertNoErrors();
}
}