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 @@ -97,7 +97,7 @@ protected Map<String, HttpHandler> createHttpHandlers() {

@Override
protected HttpHandler createErroneousHttpHandler(final HttpHandler delegate) {
return new AzureErroneousHttpHandler(delegate, randomIntBetween(2, 3));
return new AzureErroneousHttpHandler(delegate, randomDoubleBetween(0, 0.25, false));
}

@Override
Expand Down Expand Up @@ -165,8 +165,8 @@ private static class AzureBlobStoreHttpHandler extends AzureHttpHandler implemen
@SuppressForbidden(reason = "this test uses a HttpServer to emulate an Azure endpoint")
private static class AzureErroneousHttpHandler extends ErroneousHttpHandler {

AzureErroneousHttpHandler(final HttpHandler delegate, final int maxErrorsPerRequest) {
super(delegate, maxErrorsPerRequest);
AzureErroneousHttpHandler(final HttpHandler delegate, final double maxErrorsPercentage) {
super(delegate, maxErrorsPercentage);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected Map<String, HttpHandler> createHttpHandlers() {

@Override
protected HttpHandler createErroneousHttpHandler(final HttpHandler delegate) {
return new GoogleErroneousHttpHandler(delegate, randomIntBetween(2, 3));
return new GoogleErroneousHttpHandler(delegate, randomDoubleBetween(0, 0.25, false));
}

@Override
Expand Down Expand Up @@ -305,8 +305,8 @@ private static class GoogleCloudStorageBlobStoreHttpHandler extends GoogleCloudS
@SuppressForbidden(reason = "this test uses a HttpServer to emulate a Google Cloud Storage endpoint")
private static class GoogleErroneousHttpHandler extends ErroneousHttpHandler {

GoogleErroneousHttpHandler(final HttpHandler delegate, final int maxErrorsPerRequest) {
super(delegate, maxErrorsPerRequest);
GoogleErroneousHttpHandler(final HttpHandler delegate, final double maxErrorsPercentage) {
super(delegate, maxErrorsPercentage);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected Map<String, HttpHandler> createHttpHandlers() {

@Override
protected HttpHandler createErroneousHttpHandler(final HttpHandler delegate) {
return new S3StatsCollectorHttpHandler(new S3ErroneousHttpHandler(delegate, randomIntBetween(2, 3)));
return new S3StatsCollectorHttpHandler(new S3ErroneousHttpHandler(delegate, randomDoubleBetween(0, 0.25, false)));
}

@Override
Expand Down Expand Up @@ -332,8 +332,8 @@ private void validateAuthHeader(HttpExchange exchange) {
@SuppressForbidden(reason = "this test uses a HttpServer to emulate an S3 endpoint")
private static class S3ErroneousHttpHandler extends ErroneousHttpHandler {

S3ErroneousHttpHandler(final HttpHandler delegate, final int maxErrorsPerRequest) {
super(delegate, maxErrorsPerRequest);
S3ErroneousHttpHandler(final HttpHandler delegate, final double maxErrorsPercentage) {
super(delegate, maxErrorsPercentage);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,15 @@ protected abstract static class ErroneousHttpHandler implements DelegatingHttpHa
private final Map<String, AtomicInteger> requests;

private final HttpHandler delegate;
private final int maxErrorsPerRequest;
private final double maxErrorsPercentage;

@SuppressForbidden(reason = "this test uses a HttpServer to emulate a cloud-based storage service")
protected ErroneousHttpHandler(final HttpHandler delegate, final int maxErrorsPerRequest) {
protected ErroneousHttpHandler(final HttpHandler delegate, final double maxErrorsPercentage) {
this.requests = new ConcurrentHashMap<>();
this.delegate = delegate;
this.maxErrorsPerRequest = maxErrorsPerRequest;
assert maxErrorsPerRequest > 1;
this.maxErrorsPercentage = maxErrorsPercentage;
// We don't want to fail too often as it will cost too much time, which will lead to flaky tests
assert maxErrorsPercentage >= 0 && maxErrorsPercentage <= 0.25;
}

@Override
Expand All @@ -295,7 +296,9 @@ public void handle(final HttpExchange exchange) throws IOException {

final boolean canFailRequest = canFailRequest(exchange);
final int count = requests.computeIfAbsent(requestId, req -> new AtomicInteger(0)).incrementAndGet();
if (count >= maxErrorsPerRequest || canFailRequest == false) {
// We should not fail more than 3 times as the default max retry count is 3 (see SdkDefaultRetrySetting.maxAttempts), the
// request will fail when retry count > 3.
if (random().nextDouble() > maxErrorsPercentage || count >= 3 || canFailRequest == false) {
requests.remove(requestId);
delegate.handle(exchange);
} else {
Expand Down
Loading