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

2.x: Fix Observable.concatMapEager queueing of source items #5609

Merged
merged 1 commit into from
Sep 18, 2017
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 @@ -24,6 +24,7 @@
import io.reactivex.internal.functions.ObjectHelper;
import io.reactivex.internal.fuseable.*;
import io.reactivex.internal.observers.*;
import io.reactivex.internal.queue.SpscLinkedArrayQueue;
import io.reactivex.internal.util.*;
import io.reactivex.plugins.RxJavaPlugins;

Expand Down Expand Up @@ -129,7 +130,7 @@ public void onSubscribe(Disposable d) {
}
}

queue = QueueDrainHelper.createQueue(prefetch);
queue = new SpscLinkedArrayQueue<T>(prefetch);

actual.onSubscribe(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1193,4 +1193,39 @@ public Flowable<Integer> apply(Integer i) throws Exception {
.assertResult(1, 2, 3, 4, 5)
;
}

@Test
@SuppressWarnings("unchecked")
public void maxConcurrencyOf2() {
List<Integer>[] list = new ArrayList[100];
for (int i = 0; i < 100; i++) {
List<Integer> lst = new ArrayList<Integer>();
list[i] = lst;
for (int k = 1; k <= 10; k++) {
lst.add((i) * 10 + k);
}
}

Flowable.range(1, 1000)
.buffer(10)
.concatMapEager(new Function<List<Integer>, Flowable<List<Integer>>>() {
@Override
public Flowable<List<Integer>> apply(List<Integer> v)
throws Exception {
return Flowable.just(v)
.subscribeOn(Schedulers.io())
.doOnNext(new Consumer<List<Integer>>() {
@Override
public void accept(List<Integer> v)
throws Exception {
Thread.sleep(new Random().nextInt(20));
}
});
}
}
, 2, 3)
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertResult(list);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1001,4 +1001,39 @@ public ObservableSource<Integer> apply(Integer i) throws Exception {
.assertResult(1, 2, 3, 4, 5)
;
}

@Test
@SuppressWarnings("unchecked")
public void maxConcurrencyOf2() {
List<Integer>[] list = new ArrayList[100];
for (int i = 0; i < 100; i++) {
List<Integer> lst = new ArrayList<Integer>();
list[i] = lst;
for (int k = 1; k <= 10; k++) {
lst.add((i) * 10 + k);
}
}

Observable.range(1, 1000)
.buffer(10)
.concatMapEager(new Function<List<Integer>, ObservableSource<List<Integer>>>() {
@Override
public ObservableSource<List<Integer>> apply(List<Integer> v)
throws Exception {
return Observable.just(v)
.subscribeOn(Schedulers.io())
.doOnNext(new Consumer<List<Integer>>() {
@Override
public void accept(List<Integer> v)
throws Exception {
Thread.sleep(new Random().nextInt(20));
}
});
}
}
, 2, 3)
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertResult(list);
}
}