Skip to content

Commit c04cfb8

Browse files
RomanWuattierakarnokd
authored andcommitted
Update the Javadoc of the retry operator (#6458)
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
1 parent 3958d1b commit c04cfb8

File tree

7 files changed

+33
-12
lines changed

7 files changed

+33
-12
lines changed

src/main/java/io/reactivex/Completable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,7 +2090,7 @@ public final Completable retry(BiPredicate<? super Integer, ? super Throwable> p
20902090
* <dt><b>Scheduler:</b></dt>
20912091
* <dd>{@code retry} does not operate by default on a particular {@link Scheduler}.</dd>
20922092
* </dl>
2093-
* @param times the number of times the returned Completable should retry this Completable
2093+
* @param times the number of times to resubscribe if the current Completable fails
20942094
* @return the new Completable instance
20952095
* @throws IllegalArgumentException if times is negative
20962096
*/
@@ -2110,7 +2110,7 @@ public final Completable retry(long times) {
21102110
* <dd>{@code retry} does not operate by default on a particular {@link Scheduler}.</dd>
21112111
* </dl>
21122112
* <p>History: 2.1.8 - experimental
2113-
* @param times the number of times the returned Completable should retry this Completable
2113+
* @param times the number of times to resubscribe if the current Completable fails
21142114
* @param predicate the predicate that is called with the latest throwable and should return
21152115
* true to indicate the returned Completable should resubscribe to this Completable.
21162116
* @return the new Completable instance

src/main/java/io/reactivex/Flowable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13399,7 +13399,7 @@ public final Flowable<T> retry(BiPredicate<? super Integer, ? super Throwable> p
1339913399
* </dl>
1340013400
*
1340113401
* @param count
13402-
* number of retry attempts before failing
13402+
* the number of times to resubscribe if the current Flowable fails
1340313403
* @return the source Publisher modified with retry logic
1340413404
* @see <a href="http://reactivex.io/documentation/operators/retry.html">ReactiveX operators documentation: Retry</a>
1340513405
*/
@@ -13420,7 +13420,7 @@ public final Flowable<T> retry(long count) {
1342013420
* <dt><b>Scheduler:</b></dt>
1342113421
* <dd>{@code retry} does not operate by default on a particular {@link Scheduler}.</dd>
1342213422
* </dl>
13423-
* @param times the number of times to repeat
13423+
* @param times the number of times to resubscribe if the current Flowable fails
1342413424
* @param predicate the predicate called with the failure Throwable and should return true to trigger a retry.
1342513425
* @return the new Flowable instance
1342613426
*/

src/main/java/io/reactivex/Maybe.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4031,7 +4031,7 @@ public final Maybe<T> retry(BiPredicate<? super Integer, ? super Throwable> pred
40314031
* </dl>
40324032
*
40334033
* @param count
4034-
* number of retry attempts before failing
4034+
* the number of times to resubscribe if the current Maybe fails
40354035
* @return the new Maybe instance
40364036
* @see <a href="http://reactivex.io/documentation/operators/retry.html">ReactiveX operators documentation: Retry</a>
40374037
*/
@@ -4048,7 +4048,7 @@ public final Maybe<T> retry(long count) {
40484048
* <dt><b>Scheduler:</b></dt>
40494049
* <dd>{@code retry} does not operate by default on a particular {@link Scheduler}.</dd>
40504050
* </dl>
4051-
* @param times the number of times to repeat
4051+
* @param times the number of times to resubscribe if the current Maybe fails
40524052
* @param predicate the predicate called with the failure Throwable and should return true to trigger a retry.
40534053
* @return the new Maybe instance
40544054
*/

src/main/java/io/reactivex/Observable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11075,7 +11075,7 @@ public final Observable<T> retry(BiPredicate<? super Integer, ? super Throwable>
1107511075
* </dl>
1107611076
*
1107711077
* @param times
11078-
* number of retry attempts before failing
11078+
* the number of times to resubscribe if the current Observable fails
1107911079
* @return the source ObservableSource modified with retry logic
1108011080
* @see <a href="http://reactivex.io/documentation/operators/retry.html">ReactiveX operators documentation: Retry</a>
1108111081
*/
@@ -11093,7 +11093,7 @@ public final Observable<T> retry(long times) {
1109311093
* <dt><b>Scheduler:</b></dt>
1109411094
* <dd>{@code retry} does not operate by default on a particular {@link Scheduler}.</dd>
1109511095
* </dl>
11096-
* @param times the number of times to repeat
11096+
* @param times the number of times to resubscribe if the current Observable fails
1109711097
* @param predicate the predicate called with the failure Throwable and should return true to trigger a retry.
1109811098
* @return the new Observable instance
1109911099
*/

src/test/java/io/reactivex/completable/CompletableTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,18 +2398,20 @@ public void retryTimes5Error() {
23982398

23992399
@Test(timeout = 5000)
24002400
public void retryTimes5Normal() {
2401-
final AtomicInteger calls = new AtomicInteger(5);
2401+
final AtomicInteger calls = new AtomicInteger();
24022402

24032403
Completable c = Completable.fromAction(new Action() {
24042404
@Override
24052405
public void run() {
2406-
if (calls.decrementAndGet() != 0) {
2406+
if (calls.incrementAndGet() != 6) {
24072407
throw new TestException();
24082408
}
24092409
}
24102410
}).retry(5);
24112411

24122412
c.blockingAwait();
2413+
2414+
assertEquals(6, calls.get());
24132415
}
24142416

24152417
@Test(expected = IllegalArgumentException.class)

src/test/java/io/reactivex/internal/operators/single/SingleMiscTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import java.util.concurrent.TimeUnit;
2828
import java.util.concurrent.TimeoutException;
2929
import java.util.concurrent.atomic.AtomicBoolean;
30+
import java.util.concurrent.atomic.AtomicInteger;
3031

32+
import static org.junit.Assert.assertEquals;
3133
import static org.junit.Assert.assertNotSame;
3234
import static org.junit.Assert.assertSame;
3335

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

200202
@Test
201203
public void retryTimes() {
204+
final AtomicInteger calls = new AtomicInteger();
205+
202206
Single.fromCallable(new Callable<Object>() {
203-
int c;
207+
204208
@Override
205209
public Object call() throws Exception {
206-
if (++c != 5) {
210+
if (calls.incrementAndGet() != 6) {
207211
throw new TestException();
208212
}
209213
return 1;
@@ -212,6 +216,8 @@ public Object call() throws Exception {
212216
.retry(5)
213217
.test()
214218
.assertResult(1);
219+
220+
assertEquals(6, calls.get());
215221
}
216222

217223
@Test

src/test/java/io/reactivex/maybe/MaybeTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3185,6 +3185,19 @@ public Publisher<Object> apply(Flowable<? extends Throwable> v) throws Exception
31853185
return (Publisher)v;
31863186
}
31873187
}).test().assertResult(1);
3188+
3189+
final AtomicInteger calls = new AtomicInteger();
3190+
try {
3191+
Maybe.error(new Callable<Throwable>() {
3192+
@Override
3193+
public Throwable call() {
3194+
calls.incrementAndGet();
3195+
return new TestException();
3196+
}
3197+
}).retry(5).test();
3198+
} finally {
3199+
assertEquals(6, calls.get());
3200+
}
31883201
}
31893202

31903203
@Test

0 commit comments

Comments
 (0)