Skip to content

Commit

Permalink
Fix non-deterministic unit test
Browse files Browse the repository at this point in the history
- there is no guarantee for how many threads Interval will use so useless to assert anything on it
  • Loading branch information
benjchristensen committed Dec 17, 2013
1 parent aa50b15 commit 3239222
Showing 1 changed file with 7 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,8 @@ public void testParallelMerge() {

@Test
public void testNumberOfThreads() {
final ConcurrentHashMap<String, String> threads = new ConcurrentHashMap<String, String>();
Observable.merge(getStreams())
.toBlockingObservable().forEach(new Action1<String>() {

@Override
public void call(String o) {
System.out.println("o: " + o + " Thread: " + Thread.currentThread());
threads.put(Thread.currentThread().getName(), Thread.currentThread().getName());
}
});

// without injecting anything, the getStream() method uses Interval which runs on a default scheduler
assertEquals(Runtime.getRuntime().availableProcessors(), threads.keySet().size());

// clear
threads.clear();

// now we parallelMerge into 3 streams and observeOn for each
final ConcurrentHashMap<Long, Long> threads = new ConcurrentHashMap<Long, Long>();
// parallelMerge into 3 streams and observeOn for each
// we expect 3 threads in the output
OperationParallelMerge.parallelMerge(getStreams(), 3)
.flatMap(new Func1<Observable<String>, Observable<String>>() {
Expand All @@ -90,8 +74,8 @@ public Observable<String> call(Observable<String> o) {

@Override
public void call(String o) {
System.out.println("o: " + o + " Thread: " + Thread.currentThread());
threads.put(Thread.currentThread().getName(), Thread.currentThread().getName());
System.out.println("o: " + o + " Thread: " + Thread.currentThread().getId());
threads.put(Thread.currentThread().getId(), Thread.currentThread().getId());
}
});

Expand All @@ -100,7 +84,7 @@ public void call(String o) {

@Test
public void testNumberOfThreadsOnScheduledMerge() {
final ConcurrentHashMap<String, String> threads = new ConcurrentHashMap<String, String>();
final ConcurrentHashMap<Long, Long> threads = new ConcurrentHashMap<Long, Long>();

// now we parallelMerge into 3 streams and observeOn for each
// we expect 3 threads in the output
Expand All @@ -109,8 +93,8 @@ public void testNumberOfThreadsOnScheduledMerge() {

@Override
public void call(String o) {
System.out.println("o: " + o + " Thread: " + Thread.currentThread());
threads.put(Thread.currentThread().getName(), Thread.currentThread().getName());
System.out.println("o: " + o + " Thread: " + Thread.currentThread().getId());
threads.put(Thread.currentThread().getId(), Thread.currentThread().getId());
}
});

Expand Down

0 comments on commit 3239222

Please sign in to comment.