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

1.x: fix sample(Observable) not requesting Long.MAX_VALUE #3653

Merged
merged 1 commit into from
Jan 31, 2016
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 @@ -69,7 +69,7 @@ public void onCompleted() {

};

Subscriber<T> result = new Subscriber<T>(child) {
Subscriber<T> result = new Subscriber<T>() {
@Override
public void onNext(T t) {
value.set(t);
Expand All @@ -88,6 +88,8 @@ public void onCompleted() {
}
};

child.add(result);

sampler.unsafeSubscribe(samplerSub);

return result;
Expand Down
45 changes: 37 additions & 8 deletions src/test/java/rx/internal/operators/OperatorSampleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,16 @@
package rx.internal.operators;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.inOrder;
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.mockito.Mockito.*;

import java.util.concurrent.TimeUnit;

import org.junit.Before;
import org.junit.Test;
import org.junit.*;
import org.mockito.InOrder;

import rx.*;
import rx.Observable.OnSubscribe;
import rx.functions.Action0;
import rx.functions.*;
import rx.schedulers.TestScheduler;
import rx.subjects.PublishSubject;

Expand Down Expand Up @@ -283,4 +278,38 @@ public void call(Subscriber<? super Integer> subscriber) {
o.throttleLast(1, TimeUnit.MILLISECONDS).subscribe().unsubscribe();
verify(s).unsubscribe();
}

@Test
public void testSampleOtherUnboundedIn() {

final long[] requested = { -1 };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe change to AtomicLong? Took me awhile to get it 💭


PublishSubject.create()
.doOnRequest(new Action1<Long>() {
@Override
public void call(Long t) {
requested[0] = t;
}
})
.sample(PublishSubject.create()).subscribe();

Assert.assertEquals(Long.MAX_VALUE, requested[0]);
}

@Test
public void testSampleTimedUnboundedIn() {

final long[] requested = { -1 };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AtomicLong?


PublishSubject.create()
.doOnRequest(new Action1<Long>() {
@Override
public void call(Long t) {
requested[0] = t;
}
})
.sample(1, TimeUnit.SECONDS).subscribe().unsubscribe();

Assert.assertEquals(Long.MAX_VALUE, requested[0]);
}
}