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

Don't lazyset maindisposable in scope completions #149

Merged
merged 2 commits into from
Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -52,7 +52,6 @@ final class AutoDisposingCompletableObserverImpl implements AutoDisposingComplet
}

@Override public void onComplete() {
mainDisposable.lazySet(AutoDisposableHelper.DISPOSED);
lifecycleDisposable.lazySet(AutoDisposableHelper.DISPOSED);
// Noop - we're unbound now
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ final class AutoDisposingMaybeObserverImpl<T> implements AutoDisposingMaybeObser
}

@Override public void onComplete() {
mainDisposable.lazySet(AutoDisposableHelper.DISPOSED);
lifecycleDisposable.lazySet(AutoDisposableHelper.DISPOSED);
// Noop - we're unbound now
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ final class AutoDisposingObserverImpl<T> extends AtomicInteger implements AutoDi
}

@Override public void onComplete() {
mainDisposable.lazySet(AutoDisposableHelper.DISPOSED);
lifecycleDisposable.lazySet(AutoDisposableHelper.DISPOSED);
// Noop - we're unbound now
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ final class AutoDisposingSingleObserverImpl<T> implements AutoDisposingSingleObs
}

@Override public void onComplete() {
mainDisposable.lazySet(AutoDisposableHelper.DISPOSED);
lifecycleDisposable.lazySet(AutoDisposableHelper.DISPOSED);
// Noop - we're unbound now
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ final class AutoDisposingSubscriberImpl<T> extends AtomicInteger
}

@Override public void onComplete() {
mainSubscription.lazySet(AutoSubscriptionHelper.CANCELLED);
lifecycleDisposable.lazySet(AutoDisposableHelper.DISPOSED);
// Noop - we're unbound now
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,11 @@ public CompletableObserver apply(Completable source, CompletableObserver observe
assertThat(atomicAutoDisposingObserver.get()).isNotNull();
assertThat(atomicAutoDisposingObserver.get()).isInstanceOf(
AutoDisposingCompletableObserver.class);
assertThat(((AutoDisposingCompletableObserver) atomicAutoDisposingObserver.get())
.delegateObserver())
.isNotNull();
assertThat(((AutoDisposingCompletableObserver) atomicAutoDisposingObserver.get())
.delegateObserver())
.isSameAs(atomicObserver.get());
assertThat(
((AutoDisposingCompletableObserver) atomicAutoDisposingObserver.get()).delegateObserver()).isNotNull();
assertThat(
((AutoDisposingCompletableObserver) atomicAutoDisposingObserver.get()).delegateObserver()).isSameAs(
atomicObserver.get());
} finally {
RxJavaPlugins.reset();
}
Expand Down Expand Up @@ -361,11 +360,23 @@ public CompletableObserver apply(Completable source, CompletableObserver observe
@Test public void autoDispose_withScopeProviderCompleted_shouldNotReportDoubleSubscriptions() {
TestObserver<Object> o = new TestObserver<>();
CompletableSubject.create()
.to(AutoDispose.with(ScopeProvider.UNBOUND).forCompletable())
.to(AutoDispose.with(ScopeProvider.UNBOUND)
.forCompletable())
.subscribe(o);
o.assertNoValues();
o.assertNoErrors();

rule.assertNoErrors();
}

@Test public void unbound_shouldStillPassValues() {
TestObserver<Object> o = new TestObserver<>();
CompletableSubject s = CompletableSubject.create();
s.to(AutoDispose.with(ScopeProvider.UNBOUND)
.forCompletable())
.subscribe(o);

s.onComplete();
o.assertComplete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,11 @@ public class AutoDisposeMaybeObserverTest {

assertThat(atomicAutoDisposingObserver.get()).isNotNull();
assertThat(atomicAutoDisposingObserver.get()).isInstanceOf(AutoDisposingMaybeObserver.class);
assertThat(((AutoDisposingMaybeObserver) atomicAutoDisposingObserver.get())
.delegateObserver())
.isNotNull();
assertThat(((AutoDisposingMaybeObserver) atomicAutoDisposingObserver.get())
.delegateObserver())
.isSameAs(atomicObserver.get());
assertThat(
((AutoDisposingMaybeObserver) atomicAutoDisposingObserver.get()).delegateObserver()).isNotNull();
assertThat(
((AutoDisposingMaybeObserver) atomicAutoDisposingObserver.get()).delegateObserver()).isSameAs(
atomicObserver.get());
} finally {
RxJavaPlugins.reset();
}
Expand Down Expand Up @@ -391,11 +390,22 @@ public class AutoDisposeMaybeObserverTest {
@Test public void autoDispose_withScopeProviderCompleted_shouldNotReportDoubleSubscriptions() {
TestObserver<Object> o = new TestObserver<>();
MaybeSubject.create()
.to(AutoDispose.with(ScopeProvider.UNBOUND).forMaybe())
.to(AutoDispose.with(ScopeProvider.UNBOUND)
.forMaybe())
.subscribe(o);
o.assertNoValues();
o.assertNoErrors();

rule.assertNoErrors();
}

@Test public void unbound_shouldStillPassValues() {
TestObserver<Integer> o = new TestObserver<>();
MaybeSubject<Integer> s = MaybeSubject.create();
s.to(AutoDispose.with(ScopeProvider.UNBOUND).<Integer>forMaybe())
.subscribe(o);

s.onSuccess(1);
o.assertValue(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,15 @@ public class AutoDisposeObserverTest {

rule.assertNoErrors();
}

@Test public void unbound_shouldStillPassValues() {
TestObserver<Integer> o = new TestObserver<>();
PublishSubject<Integer> s = PublishSubject.create();
s.to(AutoDispose.with(ScopeProvider.UNBOUND).<Integer>forObservable())
.subscribe(o);

s.onNext(1);
o.assertValue(1);
o.dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,11 @@ public class AutoDisposeSingleObserverTest {

assertThat(atomicAutoDisposingObserver.get()).isNotNull();
assertThat(atomicAutoDisposingObserver.get()).isInstanceOf(AutoDisposingSingleObserver.class);
assertThat(((AutoDisposingSingleObserver) atomicAutoDisposingObserver.get())
.delegateObserver())
.isNotNull();
assertThat(((AutoDisposingSingleObserver) atomicAutoDisposingObserver.get())
.delegateObserver())
.isSameAs(atomicObserver.get());
assertThat(
((AutoDisposingSingleObserver) atomicAutoDisposingObserver.get()).delegateObserver()).isNotNull();
assertThat(
((AutoDisposingSingleObserver) atomicAutoDisposingObserver.get()).delegateObserver()).isSameAs(
atomicObserver.get());
} finally {
RxJavaPlugins.reset();
}
Expand Down Expand Up @@ -361,11 +360,22 @@ public class AutoDisposeSingleObserverTest {
@Test public void autoDispose_withScopeProviderCompleted_shouldNotReportDoubleSubscriptions() {
TestObserver<Object> o = new TestObserver<>();
SingleSubject.create()
.to(AutoDispose.with(ScopeProvider.UNBOUND).forSingle())
.to(AutoDispose.with(ScopeProvider.UNBOUND)
.forSingle())
.subscribe(o);
o.assertNoValues();
o.assertNoErrors();

rule.assertNoErrors();
}

@Test public void unbound_shouldStillPassValues() {
TestObserver<Integer> o = new TestObserver<>();
SingleSubject<Integer> s = SingleSubject.create();
s.to(AutoDispose.with(ScopeProvider.UNBOUND).<Integer>forSingle())
.subscribe(o);

s.onSuccess(1);
o.assertValue(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,11 @@ public class AutoDisposeSubscriberTest {

assertThat(atomicAutoDisposingSubscriber.get()).isNotNull();
assertThat(atomicAutoDisposingSubscriber.get()).isInstanceOf(AutoDisposingSubscriber.class);
assertThat(((AutoDisposingSubscriber) atomicAutoDisposingSubscriber.get())
.delegateSubscriber())
.isNotNull();
assertThat(((AutoDisposingSubscriber) atomicAutoDisposingSubscriber.get())
.delegateSubscriber())
.isSameAs(atomicSubscriber.get());
assertThat(
((AutoDisposingSubscriber) atomicAutoDisposingSubscriber.get()).delegateSubscriber()).isNotNull();
assertThat(
((AutoDisposingSubscriber) atomicAutoDisposingSubscriber.get()).delegateSubscriber()).isSameAs(
atomicSubscriber.get());
} finally {
RxJavaPlugins.reset();
}
Expand Down Expand Up @@ -341,11 +340,23 @@ public class AutoDisposeSubscriberTest {
@Test public void autoDispose_withScopeProviderCompleted_shouldNotReportDoubleSubscriptions() {
TestSubscriber<Object> o = new TestSubscriber<>();
PublishProcessor.create()
.to(AutoDispose.with(ScopeProvider.UNBOUND).forFlowable())
.to(AutoDispose.with(ScopeProvider.UNBOUND)
.forFlowable())
.subscribe(o);
o.assertNoValues();
o.assertNoErrors();

rule.assertNoErrors();
}

@Test public void unbound_shouldStillPassValues() {
TestSubscriber<Integer> o = new TestSubscriber<>();
PublishProcessor<Integer> s = PublishProcessor.create();
s.to(AutoDispose.with(ScopeProvider.UNBOUND).<Integer>forFlowable())
.subscribe(o);

s.onNext(1);
o.assertValue(1);
o.dispose();
}
}