Skip to content
Merged
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
13 changes: 11 additions & 2 deletions rxjava-core/src/test/java/rx/operators/OperatorPivotTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package rx.operators;

import java.util.Random;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
Expand Down Expand Up @@ -239,12 +240,16 @@ public void testConcurrencyAndSerialization() throws InterruptedException {
@Override
public Observable<String> call(final GroupedObservable<Boolean, GroupedObservable<String, Integer>> outerGroup) {
return outerGroup.flatMap(new Func1<GroupedObservable<String, Integer>, Observable<String>>() {

@Override
public Observable<String> call(final GroupedObservable<String, Integer> innerGroup) {
final AtomicInteger threadsPerGroup = new AtomicInteger();
return innerGroup.take(100).map(new Func1<Integer, String>() {

final ThreadLocal<Random> tlr = new ThreadLocal<Random>() {
@Override
protected Random initialValue() {
return new Random();
}
};
@Override
public String call(Integer i) {
int outerThreadCount = outerThreads.incrementAndGet();
Expand All @@ -256,7 +261,11 @@ public String call(Integer i) {
throw new RuntimeException("more than 1 thread for this group [" + innerGroup.getKey() + "]: " + innerThreadCount + " (before)");
}
try {
// give the other threads a shot.
Thread.sleep(tlr.get().nextInt(10) + 1);
return (outerGroup.getKey() ? "Even" : "Odd ") + " => from source: " + innerGroup.getKey() + " Value: " + i;
} catch (InterruptedException ex) {
throw new RuntimeException("Interrupted [" + innerGroup.getKey() + "]: " + i);
} finally {
int outerThreadCountAfter = outerThreads.decrementAndGet();
setMaxConcurrency(maxOuterConcurrency, outerThreadCountAfter);
Expand Down