Skip to content

Commit 23c06b1

Browse files
committed
add two unit tests for issue #3008
1 parent eadd43f commit 23c06b1

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/test/java/rx/internal/operators/OperatorRetryWithPredicateTest.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
import static org.mockito.Mockito.*;
2121

2222
import java.io.IOException;
23+
import java.util.Arrays;
2324
import java.util.Collections;
25+
import java.util.List;
26+
import java.util.concurrent.CopyOnWriteArrayList;
2427
import java.util.concurrent.TimeUnit;
2528
import java.util.concurrent.atomic.*;
2629

@@ -305,4 +308,56 @@ public Integer call(Integer t1) {
305308

306309
assertEquals(1, value);
307310
}
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+
}
308363
}

0 commit comments

Comments
 (0)