Skip to content

Commit

Permalink
Fix the issue that Sample doesn't call 'unsubscribe'
Browse files Browse the repository at this point in the history
  • Loading branch information
zsxwing committed Dec 12, 2014
1 parent dd73c15 commit 6c958e3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ static final class SamplerSubscriber<T> extends Subscriber<T> implements Action0
static final AtomicReferenceFieldUpdater<SamplerSubscriber, Object> VALUE_UPDATER
= AtomicReferenceFieldUpdater.newUpdater(SamplerSubscriber.class, Object.class, "value");
public SamplerSubscriber(Subscriber<? super T> subscriber) {
super(subscriber);
this.subscriber = subscriber;
}

Expand Down
21 changes: 17 additions & 4 deletions src/test/java/rx/internal/operators/OperatorSampleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@
import org.junit.Test;
import org.mockito.InOrder;

import rx.Observable;
import rx.*;
import rx.Observable.OnSubscribe;
import rx.Observer;
import rx.Scheduler;
import rx.Subscriber;
import rx.functions.Action0;
import rx.schedulers.TestScheduler;
import rx.subjects.PublishSubject;
import rx.subscriptions.Subscriptions;

public class OperatorSampleTest {
private TestScheduler scheduler;
Expand Down Expand Up @@ -271,4 +269,19 @@ public void sampleWithSamplerThrows() {
inOrder.verify(observer2, times(1)).onError(any(RuntimeException.class));
verify(observer, never()).onCompleted();
}

@Test
public void testSampleUnsubscribe() {
final Subscription s = mock(Subscription.class);
Observable<Integer> o = Observable.create(
new OnSubscribe<Integer>() {
@Override
public void call(Subscriber<? super Integer> subscriber) {
subscriber.add(s);
}
}
);
o.throttleLast(1, TimeUnit.MILLISECONDS).subscribe().unsubscribe();
verify(s).unsubscribe();
}
}

0 comments on commit 6c958e3

Please sign in to comment.