|
18 | 18 | import static org.junit.Assert.assertEquals;
|
19 | 19 | import static org.junit.Assert.fail;
|
20 | 20 | import static org.mockito.Matchers.any;
|
| 21 | +import static org.mockito.Mockito.doThrow; |
21 | 22 | import static org.mockito.Mockito.inOrder;
|
22 | 23 | import static org.mockito.Mockito.mock;
|
23 | 24 | import static org.mockito.Mockito.never;
|
|
30 | 31 |
|
31 | 32 | import org.junit.Test;
|
32 | 33 | import org.mockito.InOrder;
|
| 34 | +import org.mockito.Mockito; |
33 | 35 |
|
34 | 36 | import rx.Observable;
|
35 | 37 | import rx.Observable.OnSubscribe;
|
@@ -118,6 +120,50 @@ public void testInfiniteRetry() {
|
118 | 120 | inOrder.verify(observer, times(1)).onCompleted();
|
119 | 121 | inOrder.verifyNoMoreInteractions();
|
120 | 122 | }
|
| 123 | + |
| 124 | + /** |
| 125 | + * Checks in a simple and synchronous way that retry resubscribes |
| 126 | + * after error. This test fails against 0.16.1-0.17.4, hangs on 0.17.5 and |
| 127 | + * passes in 0.17.6 thanks to fix for issue #1027. |
| 128 | + */ |
| 129 | + @SuppressWarnings("unchecked") |
| 130 | + @Test |
| 131 | + public void testRetrySubscribesAgainAfterError() { |
| 132 | + |
| 133 | + // record emitted values with this action |
| 134 | + Action1<Integer> record = mock(Action1.class); |
| 135 | + InOrder inOrder = inOrder(record); |
| 136 | + |
| 137 | + // always throw an exception with this action |
| 138 | + Action1<Integer> throwException = mock(Action1.class); |
| 139 | + doThrow(new RuntimeException()).when(throwException).call(Mockito.anyInt()); |
| 140 | + |
| 141 | + // create a retrying observable based on a PublishSubject |
| 142 | + PublishSubject<Integer> subject = PublishSubject.create(); |
| 143 | + subject |
| 144 | + // record item |
| 145 | + .doOnNext(record) |
| 146 | + // throw a RuntimeException |
| 147 | + .doOnNext(throwException) |
| 148 | + // retry on error |
| 149 | + .retry() |
| 150 | + // subscribe and ignore |
| 151 | + .subscribe(); |
| 152 | + |
| 153 | + inOrder.verifyNoMoreInteractions(); |
| 154 | + |
| 155 | + subject.onNext(1); |
| 156 | + inOrder.verify(record).call(1); |
| 157 | + |
| 158 | + subject.onNext(2); |
| 159 | + inOrder.verify(record).call(2); |
| 160 | + |
| 161 | + subject.onNext(3); |
| 162 | + inOrder.verify(record).call(3); |
| 163 | + |
| 164 | + inOrder.verifyNoMoreInteractions(); |
| 165 | + } |
| 166 | + |
121 | 167 |
|
122 | 168 | public static class FuncWithErrors implements Observable.OnSubscribe<String> {
|
123 | 169 |
|
@@ -356,4 +402,5 @@ public void testTimeoutWithRetry() {
|
356 | 402 |
|
357 | 403 | assertEquals("Start 6 threads, retry 5 then fail on 6", 6, so.efforts.get());
|
358 | 404 | }
|
| 405 | + |
359 | 406 | }
|
0 commit comments