Skip to content

Commit ed26962

Browse files
Merge pull request #1068 from davidmoten/retry-unit-test
add synchronous test of resubscribe after error
2 parents 5d75967 + 69a1dbd commit ed26962

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

rxjava-core/src/test/java/rx/operators/OperatorRetryTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static org.junit.Assert.assertEquals;
1919
import static org.junit.Assert.fail;
2020
import static org.mockito.Matchers.any;
21+
import static org.mockito.Mockito.doThrow;
2122
import static org.mockito.Mockito.inOrder;
2223
import static org.mockito.Mockito.mock;
2324
import static org.mockito.Mockito.never;
@@ -30,6 +31,7 @@
3031

3132
import org.junit.Test;
3233
import org.mockito.InOrder;
34+
import org.mockito.Mockito;
3335

3436
import rx.Observable;
3537
import rx.Observable.OnSubscribe;
@@ -118,6 +120,50 @@ public void testInfiniteRetry() {
118120
inOrder.verify(observer, times(1)).onCompleted();
119121
inOrder.verifyNoMoreInteractions();
120122
}
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+
121167

122168
public static class FuncWithErrors implements Observable.OnSubscribe<String> {
123169

@@ -356,4 +402,5 @@ public void testTimeoutWithRetry() {
356402

357403
assertEquals("Start 6 threads, retry 5 then fail on 6", 6, so.efforts.get());
358404
}
405+
359406
}

0 commit comments

Comments
 (0)