|
1 | 1 | package rx.internal.operators;
|
2 | 2 |
|
3 |
| -import static org.junit.Assert.assertEquals; |
4 |
| -import static org.junit.Assert.assertTrue; |
| 3 | +import static org.junit.Assert.*; |
5 | 4 |
|
6 |
| -import java.util.ArrayList; |
7 |
| -import java.util.Arrays; |
8 |
| -import java.util.List; |
9 |
| -import java.util.concurrent.atomic.AtomicBoolean; |
| 5 | +import java.util.*; |
| 6 | +import java.util.concurrent.atomic.*; |
10 | 7 |
|
11 |
| -import org.junit.Test; |
| 8 | +import org.junit.*; |
12 | 9 |
|
| 10 | +import rx.*; |
13 | 11 | import rx.Observable;
|
14 |
| -import rx.Subscriber; |
15 |
| -import rx.functions.Action0; |
16 |
| -import rx.functions.Action1; |
| 12 | +import rx.Observable.OnSubscribe; |
| 13 | +import rx.functions.*; |
17 | 14 |
|
18 | 15 | public class OperatorDoOnRequestTest {
|
19 | 16 |
|
@@ -76,5 +73,51 @@ public void onNext(Integer t) {
|
76 | 73 | });
|
77 | 74 | assertEquals(Arrays.asList(3L,1L,2L,3L,4L,5L), requests);
|
78 | 75 | }
|
| 76 | + |
| 77 | + @Test |
| 78 | + public void dontRequestIfDownstreamRequestsLate() { |
| 79 | + final List<Long> requested = new ArrayList<Long>(); |
79 | 80 |
|
| 81 | + Action1<Long> empty = Actions.empty(); |
| 82 | + |
| 83 | + final AtomicReference<Producer> producer = new AtomicReference<Producer>(); |
| 84 | + |
| 85 | + Observable.create(new OnSubscribe<Integer>() { |
| 86 | + @Override |
| 87 | + public void call(Subscriber<? super Integer> t) { |
| 88 | + t.setProducer(new Producer() { |
| 89 | + @Override |
| 90 | + public void request(long n) { |
| 91 | + requested.add(n); |
| 92 | + } |
| 93 | + }); |
| 94 | + } |
| 95 | + }).doOnRequest(empty).subscribe(new Subscriber<Object>() { |
| 96 | + @Override |
| 97 | + public void onNext(Object t) { |
| 98 | + |
| 99 | + } |
| 100 | + |
| 101 | + @Override |
| 102 | + public void onError(Throwable e) { |
| 103 | + |
| 104 | + } |
| 105 | + |
| 106 | + @Override |
| 107 | + public void onCompleted() { |
| 108 | + |
| 109 | + } |
| 110 | + |
| 111 | + @Override |
| 112 | + public void setProducer(Producer p) { |
| 113 | + producer.set(p); |
| 114 | + } |
| 115 | + }); |
| 116 | + |
| 117 | + producer.get().request(1); |
| 118 | + |
| 119 | + System.out.println(requested); |
| 120 | + Assert.assertEquals(2, requested.size()); |
| 121 | + Assert.assertEquals(Arrays.asList(0L, 1L), requested); |
| 122 | + } |
80 | 123 | }
|
0 commit comments