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

OnSubscribeRange request overflow check #2771

Merged
merged 1 commit into from
Feb 24, 2015
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
2 changes: 1 addition & 1 deletion src/main/java/rx/internal/operators/OnSubscribeRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void request(long n) {
}
} else if (n > 0) {
// backpressure is requested
long _c = REQUESTED_UPDATER.getAndAdd(this, n);
long _c = BackpressureUtils.getAndAddRequest(REQUESTED_UPDATER,this, n);
if (_c == 0) {
while (true) {
/*
Expand Down
30 changes: 30 additions & 0 deletions src/test/java/rx/internal/operators/OnSubscribeRangeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import rx.Observable;
import rx.Observer;
import rx.Subscriber;
import rx.functions.Action1;
import rx.internal.util.RxRingBuffer;
import rx.observers.TestSubscriber;
Expand Down Expand Up @@ -190,4 +191,33 @@ public void testWithBackpressureRequestWayMore() {
ts.assertReceivedOnNext(list);
ts.assertTerminalEvent();
}

@Test
public void testRequestOverflow() {
final AtomicInteger count = new AtomicInteger();
int n = 10;
Observable.range(1, n).subscribe(new Subscriber<Integer>() {

@Override
public void onStart() {
request(2);
}

@Override
public void onCompleted() {
//do nothing
}

@Override
public void onError(Throwable e) {
throw new RuntimeException(e);
}

@Override
public void onNext(Integer t) {
count.incrementAndGet();
request(Long.MAX_VALUE - 1);
}});
assertEquals(n, count.get());
}
}