Skip to content

Commit

Permalink
Merge pull request #1938 from akarnokd/OperatorAnyFix
Browse files Browse the repository at this point in the history
Any/All should not unsubscribe downstream.
  • Loading branch information
benjchristensen committed Dec 13, 2014
2 parents e4239b5 + a40a659 commit 162e042
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
4 changes: 3 additions & 1 deletion src/main/java/rx/internal/operators/OperatorAll.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public OperatorAll(Func1<? super T, Boolean> predicate) {

@Override
public Subscriber<? super T> call(final Subscriber<? super Boolean> child) {
return new Subscriber<T>(child) {
Subscriber<T> s = new Subscriber<T>() {
boolean done;

@Override
Expand Down Expand Up @@ -65,5 +65,7 @@ public void onCompleted() {
}
}
};
child.add(s);
return s;
}
}
4 changes: 3 additions & 1 deletion src/main/java/rx/internal/operators/OperatorAny.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public OperatorAny(Func1<? super T, Boolean> predicate, boolean returnOnEmpty) {

@Override
public Subscriber<? super T> call(final Subscriber<? super Boolean> child) {
return new Subscriber<T>(child) {
Subscriber<T> s = new Subscriber<T>() {
boolean hasElements;
boolean done;

Expand Down Expand Up @@ -74,5 +74,7 @@ public void onCompleted() {
}

};
child.add(s);
return s;
}
}
31 changes: 23 additions & 8 deletions src/test/java/rx/internal/operators/OperatorAllTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@
*/
package rx.internal.operators;

import static org.junit.Assert.assertFalse;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import org.junit.Test;

import rx.Observable;
import rx.Observer;
import rx.*;
import rx.functions.Func1;

import java.util.Arrays;

public class OperatorAllTest {

@Test
Expand Down Expand Up @@ -113,4 +111,21 @@ public Boolean call(Integer i) {
});
assertFalse(allOdd.toBlocking().first());
}
@Test(timeout = 5000)
public void testIssue1935NoUnsubscribeDownstream() {
Observable<Integer> source = Observable.just(1)
.all(new Func1<Object, Boolean>() {
@Override
public Boolean call(Object t1) {
return false;
}
})
.flatMap(new Func1<Boolean, Observable<Integer>>() {
@Override
public Observable<Integer> call(Boolean t1) {
return Observable.just(2).delay(500, TimeUnit.MILLISECONDS);
}
});
assertEquals((Object)2, source.toBlocking().first());
}
}
23 changes: 15 additions & 8 deletions src/test/java/rx/internal/operators/OperatorAnyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,16 @@
*/
package rx.internal.operators;

import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import org.junit.Test;

import rx.Observable;
import rx.Observer;
import rx.*;
import rx.functions.Func1;
import rx.functions.Functions;
import rx.internal.util.UtilityFunctions;

public class OperatorAnyTest {
Expand Down Expand Up @@ -213,4 +209,15 @@ public Boolean call(Integer i) {
});
assertTrue(anyEven.toBlocking().first());
}
@Test(timeout = 5000)
public void testIssue1935NoUnsubscribeDownstream() {
Observable<Integer> source = Observable.just(1).isEmpty()
.flatMap(new Func1<Boolean, Observable<Integer>>() {
@Override
public Observable<Integer> call(Boolean t1) {
return Observable.just(2).delay(500, TimeUnit.MILLISECONDS);
}
});
assertEquals((Object)2, source.toBlocking().first());
}
}

0 comments on commit 162e042

Please sign in to comment.