Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 25 additions & 39 deletions src/test/java/io/reactivex/rxjava4/single/SingleRetryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@

import static org.junit.Assert.assertEquals;

import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicInteger;

import org.junit.Test;

import io.reactivex.rxjava4.core.*;
import io.reactivex.rxjava4.exceptions.TestException;
import io.reactivex.rxjava4.functions.Predicate;
import io.reactivex.rxjava4.internal.functions.Functions;

public class SingleRetryTest extends RxJavaTest {
Expand All @@ -31,22 +29,16 @@ public void retryTimesPredicateWithMatchingPredicate() {
final AtomicInteger atomicInteger = new AtomicInteger(3);
final AtomicInteger numberOfSubscribeCalls = new AtomicInteger(0);

Single.fromCallable(new Callable<Boolean>() {
@Override public Boolean call() throws Exception {
numberOfSubscribeCalls.incrementAndGet();
Single.fromCallable(() -> {
numberOfSubscribeCalls.incrementAndGet();

if (atomicInteger.decrementAndGet() != 0) {
throw new RuntimeException();
}

throw new IllegalArgumentException();
if (atomicInteger.decrementAndGet() != 0) {
throw new RuntimeException();
}

throw new IllegalArgumentException();
})
.retry(Integer.MAX_VALUE, new Predicate<Throwable>() {
@Override public boolean test(final Throwable throwable) throws Exception {
return !(throwable instanceof IllegalArgumentException);
}
})
.retry(Integer.MAX_VALUE, throwable -> !(throwable instanceof IllegalArgumentException))
.test()
.assertFailure(IllegalArgumentException.class);

Expand All @@ -58,16 +50,14 @@ public void retryTimesPredicateWithMatchingRetryAmount() {
final AtomicInteger atomicInteger = new AtomicInteger(3);
final AtomicInteger numberOfSubscribeCalls = new AtomicInteger(0);

Single.fromCallable(new Callable<Boolean>() {
@Override public Boolean call() throws Exception {
numberOfSubscribeCalls.incrementAndGet();
Single.fromCallable(() -> {
numberOfSubscribeCalls.incrementAndGet();

if (atomicInteger.decrementAndGet() != 0) {
throw new RuntimeException();
}

return true;
if (atomicInteger.decrementAndGet() != 0) {
throw new RuntimeException();
}

return true;
})
.retry(2, Functions.alwaysTrue())
.test()
Expand All @@ -81,16 +71,14 @@ public void retryTimesPredicateWithNotMatchingRetryAmount() {
final AtomicInteger atomicInteger = new AtomicInteger(3);
final AtomicInteger numberOfSubscribeCalls = new AtomicInteger(0);

Single.fromCallable(new Callable<Boolean>() {
@Override public Boolean call() throws Exception {
numberOfSubscribeCalls.incrementAndGet();
Single.fromCallable(() -> {
numberOfSubscribeCalls.incrementAndGet();

if (atomicInteger.decrementAndGet() != 0) {
throw new RuntimeException();
}

return true;
if (atomicInteger.decrementAndGet() != 0) {
throw new RuntimeException();
}

return true;
})
.retry(1, Functions.alwaysTrue())
.test()
Expand All @@ -104,16 +92,14 @@ public void retryTimesPredicateWithZeroRetries() {
final AtomicInteger atomicInteger = new AtomicInteger(2);
final AtomicInteger numberOfSubscribeCalls = new AtomicInteger(0);

Single.fromCallable(new Callable<Boolean>() {
@Override public Boolean call() throws Exception {
numberOfSubscribeCalls.incrementAndGet();
Single.fromCallable(() -> {
numberOfSubscribeCalls.incrementAndGet();

if (atomicInteger.decrementAndGet() != 0) {
throw new RuntimeException();
}

return true;
if (atomicInteger.decrementAndGet() != 0) {
throw new RuntimeException();
}

return true;
})
.retry(0, Functions.alwaysTrue())
.test()
Expand Down