Skip to content
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

On error return backpressure #1771

Merged
merged 2 commits 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
11 changes: 11 additions & 0 deletions src/main/java/rx/internal/operators/OperatorOnErrorReturn.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Arrays;

import rx.Observable.Operator;
import rx.Producer;
import rx.Subscriber;
import rx.exceptions.CompositeException;
import rx.exceptions.Exceptions;
Expand Down Expand Up @@ -92,6 +93,16 @@ public void onCompleted() {
child.onCompleted();
}

@Override
public void setProducer(final Producer producer) {
child.setProducer(new Producer() {
@Override
public void request(long n) {
producer.request(n);
}
});
}

};
child.add(parent);
return parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package rx.internal.operators;

import rx.Observable;
import rx.Producer;
import rx.Observable.Operator;
import rx.Subscriber;
import rx.exceptions.Exceptions;
Expand Down Expand Up @@ -92,6 +93,16 @@ public void onCompleted() {
child.onCompleted();
}

@Override
public void setProducer(final Producer producer) {
child.setProducer(new Producer() {
@Override
public void request(long n) {
producer.request(n);
}
});
}

};
child.add(s);

Expand Down
39 changes: 39 additions & 0 deletions src/test/java/rx/internal/operators/OperatorOnErrorReturnTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import rx.Subscriber;
import rx.functions.Func1;
import rx.observers.TestSubscriber;
import rx.schedulers.Schedulers;

public class OperatorOnErrorReturnTest {

Expand Down Expand Up @@ -145,6 +146,41 @@ public String call(Throwable t1) {
verify(observer, Mockito.never()).onNext("three");
verify(observer, times(1)).onNext("resume");
}

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

@Override
public Integer call(Throwable t1) {
return 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();
}

private static class TestObservable implements Observable.OnSubscribe<String> {

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



}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import rx.Observer;
import rx.Subscriber;
import rx.functions.Func1;
import rx.observers.TestSubscriber;
import rx.schedulers.Schedulers;

public class OperatorOnExceptionResumeNextViaObservableTest {

Expand Down Expand Up @@ -188,6 +190,36 @@ public String call(String s) {
verify(observer, Mockito.never()).onError(any(Throwable.class));
verify(observer, times(1)).onCompleted();
}


@Test
public void testBackpressure() {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
Observable.range(0, 100000)
.onExceptionResumeNext(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();
}


private static class TestObservable implements Observable.OnSubscribe<String> {

Expand Down