|
15 | 15 | */
|
16 | 16 | package rx.internal.operators;
|
17 | 17 |
|
| 18 | +import static org.junit.Assert.assertEquals; |
18 | 19 | import static org.mockito.Matchers.isA;
|
19 |
| -import static org.mockito.Mockito.inOrder; |
20 |
| -import static org.mockito.Mockito.mock; |
21 |
| -import static org.mockito.Mockito.times; |
| 20 | +import static org.mockito.Mockito.*; |
22 | 21 |
|
23 | 22 | import java.util.NoSuchElementException;
|
24 | 23 |
|
|
27 | 26 |
|
28 | 27 | import rx.Observable;
|
29 | 28 | import rx.Observer;
|
| 29 | +import rx.Subscriber; |
30 | 30 | import rx.functions.Func1;
|
| 31 | +import rx.functions.Func2; |
31 | 32 |
|
32 | 33 | public class OperatorSingleTest {
|
33 | 34 |
|
@@ -241,4 +242,52 @@ public Boolean call(Integer t1) {
|
241 | 242 | inOrder.verify(observer, times(1)).onCompleted();
|
242 | 243 | inOrder.verifyNoMoreInteractions();
|
243 | 244 | }
|
| 245 | + |
| 246 | + @Test |
| 247 | + public void testSingleWithBackpressure() { |
| 248 | + Observable<Integer> observable = Observable.from(1, 2).single(); |
| 249 | + |
| 250 | + Subscriber<Integer> subscriber = spy(new Subscriber<Integer>() { |
| 251 | + |
| 252 | + @Override |
| 253 | + public void onStart() { |
| 254 | + request(1); |
| 255 | + } |
| 256 | + |
| 257 | + @Override |
| 258 | + public void onCompleted() { |
| 259 | + |
| 260 | + } |
| 261 | + |
| 262 | + @Override |
| 263 | + public void onError(Throwable e) { |
| 264 | + |
| 265 | + } |
| 266 | + |
| 267 | + @Override |
| 268 | + public void onNext(Integer integer) { |
| 269 | + request(1); |
| 270 | + } |
| 271 | + }); |
| 272 | + observable.subscribe(subscriber); |
| 273 | + |
| 274 | + InOrder inOrder = inOrder(subscriber); |
| 275 | + inOrder.verify(subscriber, times(1)).onError(isA(IllegalArgumentException.class)); |
| 276 | + inOrder.verifyNoMoreInteractions(); |
| 277 | + } |
| 278 | + |
| 279 | + @Test(timeout = 30000) |
| 280 | + public void testIssue1527() throws InterruptedException { |
| 281 | + //https://github.com/Netflix/RxJava/pull/1527 |
| 282 | + Observable<Integer> source = Observable.from(1, 2, 3, 4, 5, 6); |
| 283 | + Observable<Integer> reduced = source.reduce(new Func2<Integer, Integer, Integer>() { |
| 284 | + @Override |
| 285 | + public Integer call(Integer i1, Integer i2) { |
| 286 | + return i1 + i2; |
| 287 | + } |
| 288 | + }); |
| 289 | + |
| 290 | + Integer r = reduced.toBlocking().first(); |
| 291 | + assertEquals(21, r.intValue()); |
| 292 | + } |
244 | 293 | }
|
0 commit comments