Skip to content

Commit

Permalink
Update the Javadoc of the retry operator
Browse files Browse the repository at this point in the history
Specify that the `times` function parameter describes "the number of times
to resubscribe if the current *operator* fails".

Also, this commit updates some unit tests to illustrate the Javadoc wording.

Solves: #6402
  • Loading branch information
RomanWuattier committed Apr 11, 2019
1 parent 3958d1b commit fcb3f09
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/main/java/io/reactivex/Completable.java
Original file line number Diff line number Diff line change
Expand Up @@ -2090,7 +2090,7 @@ public final Completable retry(BiPredicate<? super Integer, ? super Throwable> p
* <dt><b>Scheduler:</b></dt>
* <dd>{@code retry} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
* @param times the number of times the returned Completable should retry this Completable
* @param times the number of times to resubscribe if the current Completable fails
* @return the new Completable instance
* @throws IllegalArgumentException if times is negative
*/
Expand All @@ -2110,7 +2110,7 @@ public final Completable retry(long times) {
* <dd>{@code retry} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
* <p>History: 2.1.8 - experimental
* @param times the number of times the returned Completable should retry this Completable
* @param times the number of times to resubscribe if the current Completable fails
* @param predicate the predicate that is called with the latest throwable and should return
* true to indicate the returned Completable should resubscribe to this Completable.
* @return the new Completable instance
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/reactivex/Flowable.java
Original file line number Diff line number Diff line change
Expand Up @@ -13399,7 +13399,7 @@ public final Flowable<T> retry(BiPredicate<? super Integer, ? super Throwable> p
* </dl>
*
* @param count
* number of retry attempts before failing
* the number of times to resubscribe if the current Flowable fails
* @return the source Publisher modified with retry logic
* @see <a href="http://reactivex.io/documentation/operators/retry.html">ReactiveX operators documentation: Retry</a>
*/
Expand All @@ -13420,7 +13420,7 @@ public final Flowable<T> retry(long count) {
* <dt><b>Scheduler:</b></dt>
* <dd>{@code retry} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
* @param times the number of times to repeat
* @param times the number of times to resubscribe if the current Flowable fails
* @param predicate the predicate called with the failure Throwable and should return true to trigger a retry.
* @return the new Flowable instance
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/reactivex/Maybe.java
Original file line number Diff line number Diff line change
Expand Up @@ -4031,7 +4031,7 @@ public final Maybe<T> retry(BiPredicate<? super Integer, ? super Throwable> pred
* </dl>
*
* @param count
* number of retry attempts before failing
* the number of times to resubscribe if the current Maybe fails
* @return the new Maybe instance
* @see <a href="http://reactivex.io/documentation/operators/retry.html">ReactiveX operators documentation: Retry</a>
*/
Expand All @@ -4048,7 +4048,7 @@ public final Maybe<T> retry(long count) {
* <dt><b>Scheduler:</b></dt>
* <dd>{@code retry} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
* @param times the number of times to repeat
* @param times the number of times to resubscribe if the current Maybe fails
* @param predicate the predicate called with the failure Throwable and should return true to trigger a retry.
* @return the new Maybe instance
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/reactivex/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -11075,7 +11075,7 @@ public final Observable<T> retry(BiPredicate<? super Integer, ? super Throwable>
* </dl>
*
* @param times
* number of retry attempts before failing
* the number of times to resubscribe if the current Observable fails
* @return the source ObservableSource modified with retry logic
* @see <a href="http://reactivex.io/documentation/operators/retry.html">ReactiveX operators documentation: Retry</a>
*/
Expand All @@ -11093,7 +11093,7 @@ public final Observable<T> retry(long times) {
* <dt><b>Scheduler:</b></dt>
* <dd>{@code retry} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
* @param times the number of times to repeat
* @param times the number of times to resubscribe if the current Observable fails
* @param predicate the predicate called with the failure Throwable and should return true to trigger a retry.
* @return the new Observable instance
*/
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/io/reactivex/completable/CompletableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2398,18 +2398,20 @@ public void retryTimes5Error() {

@Test(timeout = 5000)
public void retryTimes5Normal() {
final AtomicInteger calls = new AtomicInteger(5);
final AtomicInteger calls = new AtomicInteger();

Completable c = Completable.fromAction(new Action() {
@Override
public void run() {
if (calls.decrementAndGet() != 0) {
if (calls.incrementAndGet() != 6) {
throw new TestException();
}
}
}).retry(5);

c.blockingAwait();

assertEquals(6, calls.get());
}

@Test(expected = IllegalArgumentException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;

Expand Down Expand Up @@ -199,11 +201,13 @@ public boolean test(Integer i, Throwable e) throws Exception {

@Test
public void retryTimes() {
final AtomicInteger calls = new AtomicInteger();

Single.fromCallable(new Callable<Object>() {
int c;

@Override
public Object call() throws Exception {
if (++c != 5) {
if (calls.incrementAndGet() != 6) {
throw new TestException();
}
return 1;
Expand All @@ -212,6 +216,8 @@ public Object call() throws Exception {
.retry(5)
.test()
.assertResult(1);

assertEquals(6, calls.get());
}

@Test
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/io/reactivex/maybe/MaybeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3185,6 +3185,20 @@ public Publisher<Object> apply(Flowable<? extends Throwable> v) throws Exception
return (Publisher)v;
}
}).test().assertResult(1);


final AtomicInteger calls = new AtomicInteger();
try {
Maybe.error(new Callable<Throwable>() {
@Override
public Throwable call() {
calls.incrementAndGet();
return new TestException();
}
}).retry(5).test();
} finally {
assertEquals(6, calls.get());
}
}

@Test
Expand Down

0 comments on commit fcb3f09

Please sign in to comment.