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

Any/All should not unsubscribe downstream. #1938

Merged
merged 2 commits into from
Dec 13, 2014
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
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());
}
}