Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite AzureBlobContainerRetriesTests#testRetryUntilFails #66531

Merged
merged 1 commit into from
Dec 17, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -404,23 +403,22 @@ public void testWriteLargeBlob() throws Exception {
}

public void testRetryUntilFail() throws IOException {
final AtomicBoolean requestReceived = new AtomicBoolean(false);
final int maxRetries = randomIntBetween(2, 5);
final AtomicInteger requestsReceived = new AtomicInteger(0);
httpServer.createContext("/account/container/write_blob_max_retries", exchange -> {
try {
if (requestReceived.compareAndSet(false, true)) {
throw new AssertionError("Should not receive two requests");
} else {
// We have to try to read the body since the netty async http client sends the request
// lazily
Streams.readFully(exchange.getRequestBody());
exchange.sendResponseHeaders(RestStatus.CREATED.getStatus(), -1);
requestsReceived.incrementAndGet();
// We have to try to read the body since the netty async http client sends the request
// lazily
if (Streams.readFully(exchange.getRequestBody()).length() > 0) {
throw new AssertionError("Should not receive any data");
}
} finally {
exchange.close();
}
});

final BlobContainer blobContainer = createBlobContainer(randomIntBetween(2, 5));
final BlobContainer blobContainer = createBlobContainer(maxRetries);
try (InputStream stream = new InputStream() {
@Override
public int read() throws IOException {
Expand All @@ -439,6 +437,7 @@ public void reset() {
final IOException ioe = expectThrows(IOException.class, () ->
blobContainer.writeBlob("write_blob_max_retries", stream, randomIntBetween(1, 128), randomBoolean()));
assertThat(ioe.getMessage(), is("Unable to write blob write_blob_max_retries"));
assertThat(requestsReceived.get(), equalTo(maxRetries + 1));
}
}

Expand Down