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

OperatorCombineLatest request overflow check #2769

Merged
merged 1 commit into from
Feb 23, 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
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public MultiSourceProducer(final Subscriber<? super R> child, final List<? exten

@Override
public void request(long n) {
requested.getAndAdd(n);
BackpressureUtils.getAndAddRequest(requested, n);
if (!started.get() && started.compareAndSet(false, true)) {
/*
* NOTE: this logic will ONLY work if we don't have more sources than the size of the buffer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -851,5 +851,40 @@ public Long call(Long t1, Integer t2) {

assertEquals(SIZE, count.get());
}

@Test(timeout=10000)
public void testCombineLatestRequestOverflow() throws InterruptedException {
List<Observable<Integer>> sources = Arrays.asList(Observable.from(Arrays.asList(1,2,3,4)), Observable.from(Arrays.asList(5,6,7,8)));
Observable<Integer> o = Observable.combineLatest(sources,new FuncN<Integer>() {
@Override
public Integer call(Object... args) {
return (Integer) args[0];
}});
//should get at least 4
final CountDownLatch latch = new CountDownLatch(4);
o.subscribeOn(Schedulers.computation()).subscribe(new Subscriber<Integer>() {

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

@Override
public void onCompleted() {
//ignore
}

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

@Override
public void onNext(Integer t) {
latch.countDown();
request(Long.MAX_VALUE-1);
}});
assertTrue(latch.await(10, TimeUnit.SECONDS));
}

}