OperationRetry { public static <T> OnSubscribeFunc<T> retry(final Observable<T> observable, final int retryCount) { return new Retry<T>(observable, retryCount); }  static OnSubscribeFunc<T> retry(final Observable<T> observable, final int retryCount); static OnSubscribeFunc<T> retry(final Observable<T> observable);  }
@Test public void testRetryFail() { int NUM_RETRIES = 1; int NUM_FAILURES = 2; @SuppressWarnings("unchecked") Observer<String> observer = mock(Observer.class); Observable<String> origin = Observable.create(new FuncWithErrors(NUM_FAILURES)); Observable.create(retry(origin, NUM_RETRIES)).subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1 + NUM_RETRIES)).onNext("beginningEveryTime"); inOrder.verify(observer, times(1)).onError(any(RuntimeException.class)); inOrder.verify(observer, never()).onNext("onSuccessOnly"); inOrder.verify(observer, never()).onCompleted(); inOrder.verifyNoMoreInteractions(); }
@Test public void testRetrySuccess() { int NUM_RETRIES = 3; int NUM_FAILURES = 2; @SuppressWarnings("unchecked") Observer<String> observer = mock(Observer.class); Observable<String> origin = Observable.create(new FuncWithErrors(NUM_FAILURES)); Observable.create(retry(origin, NUM_RETRIES)).subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1 + NUM_FAILURES)).onNext("beginningEveryTime"); inOrder.verify(observer, never()).onError(any(Throwable.class)); inOrder.verify(observer, times(1)).onNext("onSuccessOnly"); inOrder.verify(observer, times(1)).onCompleted(); inOrder.verifyNoMoreInteractions(); }
@Test public void testInfiniteRetry() { int NUM_FAILURES = 20; @SuppressWarnings("unchecked") Observer<String> observer = mock(Observer.class); Observable<String> origin = Observable.create(new FuncWithErrors(NUM_FAILURES)); Observable.create(retry(origin)).subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1 + NUM_FAILURES)).onNext("beginningEveryTime"); inOrder.verify(observer, never()).onError(any(Throwable.class)); inOrder.verify(observer, times(1)).onNext("onSuccessOnly"); inOrder.verify(observer, times(1)).onCompleted(); inOrder.verifyNoMoreInteractions(); }