|
20 | 20 | import static org.mockito.Mockito.*;
|
21 | 21 |
|
22 | 22 | import java.io.IOException;
|
| 23 | +import java.util.Arrays; |
23 | 24 | import java.util.Collections;
|
| 25 | +import java.util.List; |
| 26 | +import java.util.concurrent.CopyOnWriteArrayList; |
24 | 27 | import java.util.concurrent.TimeUnit;
|
25 | 28 | import java.util.concurrent.atomic.*;
|
26 | 29 |
|
@@ -305,4 +308,56 @@ public Integer call(Integer t1) {
|
305 | 308 |
|
306 | 309 | assertEquals(1, value);
|
307 | 310 | }
|
| 311 | + |
| 312 | + @Test |
| 313 | + public void testIssue3008RetryWithPredicate() { |
| 314 | + final List<Long> list = new CopyOnWriteArrayList<Long>(); |
| 315 | + final AtomicBoolean isFirst = new AtomicBoolean(true); |
| 316 | + Observable.<Long> just(1L, 2L, 3L).map(new Func1<Long, Long>(){ |
| 317 | + @Override |
| 318 | + public Long call(Long x) { |
| 319 | + System.out.println("map " + x); |
| 320 | + if (x == 2 && isFirst.getAndSet(false)) { |
| 321 | + throw new RuntimeException("retryable error"); |
| 322 | + } |
| 323 | + return x; |
| 324 | + }}) |
| 325 | + .retry(new Func2<Integer, Throwable, Boolean>() { |
| 326 | + @Override |
| 327 | + public Boolean call(Integer t1, Throwable t2) { |
| 328 | + return true; |
| 329 | + }}) |
| 330 | + .forEach(new Action1<Long>() { |
| 331 | + |
| 332 | + @Override |
| 333 | + public void call(Long t) { |
| 334 | + System.out.println(t); |
| 335 | + list.add(t); |
| 336 | + }}); |
| 337 | + assertEquals(Arrays.asList(1L,1L,2L,3L), list); |
| 338 | + } |
| 339 | + |
| 340 | + @Test |
| 341 | + public void testIssue3008RetryInfinite() { |
| 342 | + final List<Long> list = new CopyOnWriteArrayList<Long>(); |
| 343 | + final AtomicBoolean isFirst = new AtomicBoolean(true); |
| 344 | + Observable.<Long> just(1L, 2L, 3L).map(new Func1<Long, Long>(){ |
| 345 | + @Override |
| 346 | + public Long call(Long x) { |
| 347 | + System.out.println("map " + x); |
| 348 | + if (x == 2 && isFirst.getAndSet(false)) { |
| 349 | + throw new RuntimeException("retryable error"); |
| 350 | + } |
| 351 | + return x; |
| 352 | + }}) |
| 353 | + .retry() |
| 354 | + .forEach(new Action1<Long>() { |
| 355 | + |
| 356 | + @Override |
| 357 | + public void call(Long t) { |
| 358 | + System.out.println(t); |
| 359 | + list.add(t); |
| 360 | + }}); |
| 361 | + assertEquals(Arrays.asList(1L,1L,2L,3L), list); |
| 362 | + } |
308 | 363 | }
|
0 commit comments