|
15 | 15 | */
|
16 | 16 | package rx.internal.operators;
|
17 | 17 |
|
| 18 | +import static org.junit.Assert.assertEquals; |
18 | 19 | import static org.mockito.Matchers.any;
|
19 | 20 | import static org.mockito.Mockito.mock;
|
20 | 21 | import static org.mockito.Mockito.never;
|
21 | 22 | import static org.mockito.Mockito.times;
|
22 | 23 | import static org.mockito.Mockito.verify;
|
23 | 24 |
|
| 25 | +import java.util.Arrays; |
| 26 | +import java.util.concurrent.TimeUnit; |
| 27 | +import java.util.concurrent.atomic.AtomicLong; |
| 28 | + |
24 | 29 | import org.junit.Test;
|
25 | 30 |
|
26 | 31 | import rx.Observable;
|
27 | 32 | import rx.Observer;
|
28 |
| -import rx.internal.operators.OperatorSkip; |
| 33 | +import rx.functions.Action1; |
| 34 | +import rx.observers.TestSubscriber; |
29 | 35 |
|
30 | 36 | public class OperatorSkipTest {
|
31 | 37 |
|
@@ -144,4 +150,36 @@ public void testSkipError() {
|
144 | 150 | verify(observer, never()).onCompleted();
|
145 | 151 |
|
146 | 152 | }
|
| 153 | + |
| 154 | + @Test |
| 155 | + public void testBackpressureMultipleSmallAsyncRequests() throws InterruptedException { |
| 156 | + final AtomicLong requests = new AtomicLong(0); |
| 157 | + TestSubscriber<Long> ts = new TestSubscriber<Long>(0); |
| 158 | + Observable.interval(100, TimeUnit.MILLISECONDS) |
| 159 | + .doOnRequest(new Action1<Long>() { |
| 160 | + @Override |
| 161 | + public void call(Long n) { |
| 162 | + requests.addAndGet(n); |
| 163 | + } |
| 164 | + }).skip(4).subscribe(ts); |
| 165 | + Thread.sleep(100); |
| 166 | + ts.requestMore(1); |
| 167 | + ts.requestMore(1); |
| 168 | + Thread.sleep(100); |
| 169 | + ts.unsubscribe(); |
| 170 | + ts.assertUnsubscribed(); |
| 171 | + ts.assertNoErrors(); |
| 172 | + assertEquals(6, requests.get()); |
| 173 | + } |
| 174 | + |
| 175 | + @Test |
| 176 | + public void testRequestOverflowDoesNotOccur() { |
| 177 | + TestSubscriber<Integer> ts = new TestSubscriber<Integer>(Long.MAX_VALUE-1); |
| 178 | + Observable.range(1, 10).skip(5).subscribe(ts); |
| 179 | + ts.assertTerminalEvent(); |
| 180 | + ts.assertCompleted(); |
| 181 | + ts.assertNoErrors(); |
| 182 | + assertEquals(Arrays.asList(6,7,8,9,10), ts.getOnNextEvents()); |
| 183 | + } |
| 184 | + |
147 | 185 | }
|
0 commit comments