Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class RequestRetryTestFactory {

static final int RETRY_TEST_SCENARIO_NON_REPLAYABLE_FLOWABLE = 9;

static final int RETRY_TEST_SCENARIO_WRAPPED_NETWORK_ERROR = 10;

static final int RETRY_TEST_SCENARIO_WRAPPED_TIMEOUT_ERROR = 11;

// Cancelable

static final String RETRY_TEST_PRIMARY_HOST = "PrimaryDC";
Expand Down Expand Up @@ -284,6 +288,30 @@ public Mono<HttpResponse> send(HttpRequest request) {
throw new IllegalArgumentException("Continued retrying after success.");
}

case RETRY_TEST_SCENARIO_WRAPPED_NETWORK_ERROR:
switch (this.factory.tryNumber) {
case 1:
// fall through
case 2:
return Mono.error(Exceptions.propagate(new IOException()));
case 3:
return retryTestOkResponse;
default:
throw new IllegalArgumentException("Continued retrying after success.");
}

case RETRY_TEST_SCENARIO_WRAPPED_TIMEOUT_ERROR:
switch (this.factory.tryNumber) {
case 1:
// fall through
case 2:
return Mono.error(Exceptions.propagate(new TimeoutException()));
case 3:
return retryTestOkResponse;
default:
throw new IllegalArgumentException("Continued retrying after success.");
}

case RETRY_TEST_SCENARIO_TRY_TIMEOUT:
switch (this.factory.tryNumber) {
case 1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import com.azure.storage.common.policy.RetryPolicyType
import reactor.core.publisher.Mono
import reactor.test.StepVerifier
import spock.lang.Retry
import spock.lang.Specification
import spock.lang.Unroll

// Tests for package-private functionality.
@Retry(count = 3, delay = 1000)
class RetryTest extends APISpec {
class RetryTest extends Specification {
static URL retryTestURL = new URL("https://" + RequestRetryTestFactory.RETRY_TEST_PRIMARY_HOST)
static RequestRetryOptions retryTestOptions = new RequestRetryOptions(RetryPolicyType.EXPONENTIAL, 6, 2,
1000L, 4000L, RequestRetryTestFactory.RETRY_TEST_SECONDARY_HOST)
Expand Down Expand Up @@ -93,6 +94,36 @@ class RetryTest extends APISpec {
}).verifyComplete()
}

def "Retries wrapped network error"() {
setup:
RequestRetryTestFactory retryTestFactory = new RequestRetryTestFactory(RequestRetryTestFactory.RETRY_TEST_SCENARIO_WRAPPED_NETWORK_ERROR, retryTestOptions)

when:
def responseMono = Mono.defer { retryTestFactory.send(retryTestURL) }

then:
StepVerifier.create(responseMono)
.assertNext({
assert it.getStatusCode() == 200
assert retryTestFactory.getTryNumber() == 3
}).verifyComplete()
}

def "Retries wrapped timeout error"() {
setup:
RequestRetryTestFactory retryTestFactory = new RequestRetryTestFactory(RequestRetryTestFactory.RETRY_TEST_SCENARIO_WRAPPED_TIMEOUT_ERROR, retryTestOptions)

when:
def responseMono = Mono.defer { retryTestFactory.send(retryTestURL) }

then:
StepVerifier.create(responseMono)
.assertNext({
assert it.getStatusCode() == 200
assert retryTestFactory.getTryNumber() == 3
}).verifyComplete()
}

def "Retries try timeout"() {
setup:
RequestRetryTestFactory retryTestFactory = new RequestRetryTestFactory(RequestRetryTestFactory.RETRY_TEST_SCENARIO_TRY_TIMEOUT, retryTestOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.azure.core.http.policy.HttpLoggingPolicy;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.util.UrlBuilder;
import reactor.core.Exceptions;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

Expand Down Expand Up @@ -181,9 +182,10 @@ we do not consider the secondary at all (considerSecondary==false)). This will
A Timeout Exception is a client-side timeout coming from Rx.
*/
String action;
if (throwable instanceof IOException) {
Throwable unwrappedThrowable = Exceptions.unwrap(throwable);
if (unwrappedThrowable instanceof IOException) {
action = "Retry: Network error";
} else if (throwable instanceof TimeoutException) {
} else if (unwrappedThrowable instanceof TimeoutException) {
action = "Retry: Client timeout";
} else {
action = "NoRetry: Unknown error";
Expand Down