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: Single.subscribe(BiConsumer) consistent isDisposed #5277

Merged
merged 1 commit into from
Apr 10, 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 @@ -37,6 +37,7 @@ public BiConsumerSingleObserver(BiConsumer<? super T, ? super Throwable> onCallb
@Override
public void onError(Throwable e) {
try {
lazySet(DisposableHelper.DISPOSED);
onCallback.accept(null, e);
} catch (Throwable ex) {
Exceptions.throwIfFatal(ex);
Expand All @@ -52,6 +53,7 @@ public void onSubscribe(Disposable d) {
@Override
public void onSuccess(T value) {
try {
lazySet(DisposableHelper.DISPOSED);
onCallback.accept(value, null);
} catch (Throwable ex) {
Exceptions.throwIfFatal(ex);
Expand Down
37 changes: 37 additions & 0 deletions src/test/java/io/reactivex/single/SingleSubscribeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import static org.junit.Assert.*;

import java.io.IOException;
import java.util.List;

import org.junit.Test;
Expand Down Expand Up @@ -227,4 +228,40 @@ public void successIsDisposed() {
public void errorIsDisposed() {
assertTrue(Single.error(new TestException()).subscribe(Functions.emptyConsumer(), Functions.emptyConsumer()).isDisposed());
}

@Test
public void biConsumerIsDisposedOnSuccess() {
final Object[] result = { null, null };

Disposable d = Single.just(1)
.subscribe(new BiConsumer<Integer, Throwable>() {
@Override
public void accept(Integer t1, Throwable t2) throws Exception {
result[0] = t1;
result[1] = t2;
}
});

assertTrue("Not disposed?!", d.isDisposed());
assertEquals(1, result[0]);
assertNull(result[1]);
}

@Test
public void biConsumerIsDisposedOnError() {
final Object[] result = { null, null };

Disposable d = Single.<Integer>error(new IOException())
.subscribe(new BiConsumer<Integer, Throwable>() {
@Override
public void accept(Integer t1, Throwable t2) throws Exception {
result[0] = t1;
result[1] = t2;
}
});

assertTrue("Not disposed?!", d.isDisposed());
assertNull(result[0]);
assertTrue("" + result[1], result[1] instanceof IOException);
}
}