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 flatMapIterable appearing to be empty when fused #5256

Merged
merged 1 commit into from
Apr 1, 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 @@ -411,7 +411,10 @@ public void clear() {
@Override
public boolean isEmpty() {
Iterator<? extends R> it = current;
return (it != null && !it.hasNext()) || queue.isEmpty();
if (it == null) {
return queue.isEmpty();
}
return !it.hasNext();
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -863,4 +863,55 @@ public void remove() {

ts.assertResult(1);
}

@Test
public void doubleShare() {
Iterable<Integer> it = Flowable.range(1, 300).blockingIterable();
Flowable.just(it, it)
.flatMapIterable(Functions.<Iterable<Integer>>identity())
.share()
.share()
.count()
.test()
.assertResult(600L);
}

@Test
public void multiShare() {
Iterable<Integer> it = Flowable.range(1, 300).blockingIterable();
for (int i = 0; i < 5; i++) {
Flowable<Integer> f = Flowable.just(it, it)
.flatMapIterable(Functions.<Iterable<Integer>>identity());

for (int j = 0; j < i; j++) {
f = f.share();
}

f
.count()
.test()
.withTag("Share: " + i)
.assertResult(600L);
}
}

@Test
public void multiShareHidden() {
Iterable<Integer> it = Flowable.range(1, 300).blockingIterable();
for (int i = 0; i < 5; i++) {
Flowable<Integer> f = Flowable.just(it, it)
.flatMapIterable(Functions.<Iterable<Integer>>identity())
.hide();

for (int j = 0; j < i; j++) {
f = f.share();
}

f
.count()
.test()
.withTag("Share: " + i)
.assertResult(600L);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public void onNextCancelRace() {
for (int i = 0; i < 1000; i++) {
final PublishProcessor<Integer> pp = PublishProcessor.create();
final TestObserver<List<Integer>> ts = pp.toList().test();

Runnable r1 = new Runnable() {
@Override
public void run() {
Expand All @@ -408,18 +408,17 @@ public void run() {
ts.cancel();
}
};

TestHelper.race(r1, r2);
}

}

@Test
public void onNextCancelRaceFlowable() {
for (int i = 0; i < 1000; i++) {
final PublishProcessor<Integer> pp = PublishProcessor.create();
final TestSubscriber<List<Integer>> ts = pp.toList().toFlowable().test();

Runnable r1 = new Runnable() {
@Override
public void run() {
Expand All @@ -432,20 +431,20 @@ public void run() {
ts.cancel();
}
};

TestHelper.race(r1, r2);
}

}

@Test
public void onCompleteCancelRaceFlowable() {
for (int i = 0; i < 1000; i++) {
final PublishProcessor<Integer> pp = PublishProcessor.create();
final TestSubscriber<List<Integer>> ts = pp.toList().toFlowable().test();

pp.onNext(1);

Runnable r1 = new Runnable() {
@Override
public void run() {
Expand All @@ -458,14 +457,13 @@ public void run() {
ts.cancel();
}
};

TestHelper.race(r1, r2);

if (ts.valueCount() != 0) {
ts.assertValue(Arrays.asList(1))
.assertNoErrors();
}
}

}
}