Skip to content

Commit

Permalink
Fix testRetryUntilFails
Browse files Browse the repository at this point in the history
  • Loading branch information
fcofdez committed Dec 17, 2020
1 parent 62d8251 commit 0365818
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,23 +404,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 +438,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

0 comments on commit 0365818

Please sign in to comment.