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

3.x: Fix parallel() on grouped flowable not replenishing properly #6719

Merged
merged 6 commits into from
Nov 20, 2019
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 @@ -743,19 +743,27 @@ public T poll() {
produced++;
return v;
}
tryReplenish();
return null;
}

@Override
public boolean isEmpty() {
if (queue.isEmpty()) {
tryReplenish();
return true;
}
return false;
}

void tryReplenish() {
int p = produced;
if (p != 0) {
produced = 0;
if ((once.get() & ABANDONED) == 0) {
parent.upstream.request(p);
}
}
return null;
}

@Override
public boolean isEmpty() {
return queue.isEmpty();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2413,4 +2413,34 @@ public void run() {
}
}
}

@Test
public void fusedParallelGroupProcessing() {
Flowable.range(0, 500000)
.subscribeOn(Schedulers.single())
.groupBy(new Function<Integer, Integer>() {
@Override
public Integer apply(Integer i) throws Throwable {
return i % 2;
}
})
.flatMap(new Function<GroupedFlowable<Integer, Integer>, Publisher<Integer>>() {
@Override
public Publisher<Integer> apply(GroupedFlowable<Integer, Integer> g) {
return g.getKey() == 0
? g
.parallel()
.runOn(Schedulers.computation())
.map(Functions.<Integer>identity())
.sequential()
: g.map(Functions.<Integer>identity()) // no need to use hide
;
}
})
.test()
.awaitDone(20, TimeUnit.SECONDS)
.assertValueCount(500000)
.assertComplete()
.assertNoErrors();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1972,4 +1972,20 @@ public void fusedNoConcurrentCleanDueToCancel() {
}
}
}

@Test
public void fusedParallelProcessing() {
Flowable.range(0, 500000)
.subscribeOn(Schedulers.single())
.observeOn(Schedulers.computation())
.parallel()
.runOn(Schedulers.computation())
.map(Functions.<Integer>identity())
.sequential()
.test()
.awaitDone(20, TimeUnit.SECONDS)
.assertValueCount(500000)
.assertComplete()
.assertNoErrors();
}
}