Skip to content

Commit bca0ed5

Browse files
Test max connections
1 parent 12e5dc1 commit bca0ed5

File tree

5 files changed

+163
-32
lines changed

5 files changed

+163
-32
lines changed

modules/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobContainerRetriesTests.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ protected BlobContainer createBlobContainer(
126126
final @Nullable Integer maxRetries,
127127
final @Nullable TimeValue readTimeout,
128128
final @Nullable Boolean disableChunkedEncoding,
129+
final @Nullable Integer maxConnections,
129130
final @Nullable ByteSizeValue bufferSize,
130131
final @Nullable Integer maxBulkDeletes,
131132
BlobPath blobContainerPath
@@ -225,7 +226,7 @@ public void testShouldRetryOnUnresolvableHost() {
225226

226227
private void executeListBlobsAndAssertRetries() {
227228
final int maxRetries = randomIntBetween(3, 5);
228-
final BlobContainer blobContainer = createBlobContainer(maxRetries, null, null, null, null, null);
229+
final BlobContainer blobContainer = createBlobContainer(maxRetries, null, null, null, null, null, null);
229230
expectThrows(StorageException.class, () -> blobContainer.listBlobs(randomPurpose()));
230231
assertEquals(maxRetries + 1, requestCounters.get("/storage/v1/b/bucket/o").get());
231232
}
@@ -234,7 +235,7 @@ public void testReadLargeBlobWithRetries() throws Exception {
234235
final int maxRetries = randomIntBetween(2, 10);
235236
final AtomicInteger countDown = new AtomicInteger(maxRetries);
236237

237-
final BlobContainer blobContainer = createBlobContainer(maxRetries, null, null, null, null, null);
238+
final BlobContainer blobContainer = createBlobContainer(maxRetries, null, null, null, null, null, null);
238239

239240
// SDK reads in 2 MB chunks so we use twice that to simulate 2 chunks
240241
final byte[] bytes = randomBytes(1 << 22);
@@ -263,7 +264,7 @@ public void testWriteBlobWithRetries() throws Exception {
263264
final int maxRetries = randomIntBetween(2, 10);
264265
final CountDown countDown = new CountDown(maxRetries);
265266

266-
final BlobContainer blobContainer = createBlobContainer(maxRetries, null, null, null, null, null);
267+
final BlobContainer blobContainer = createBlobContainer(maxRetries, null, null, null, null, null, null);
267268
final byte[] bytes = randomBlobContent();
268269
httpServer.createContext("/upload/storage/v1/b/bucket/o", safeHandler(exchange -> {
269270
assertThat(exchange.getRequestURI().getQuery(), containsString("uploadType=multipart"));
@@ -305,7 +306,7 @@ public void testWriteBlobWithRetries() throws Exception {
305306
public void testWriteBlobWithReadTimeouts() {
306307
final byte[] bytes = randomByteArrayOfLength(randomIntBetween(10, 128));
307308
final TimeValue readTimeout = TimeValue.timeValueMillis(randomIntBetween(100, 500));
308-
final BlobContainer blobContainer = createBlobContainer(1, readTimeout, null, null, null, null);
309+
final BlobContainer blobContainer = createBlobContainer(1, readTimeout, null, null, null, null, null);
309310

310311
// HTTP server does not send a response
311312
httpServer.createContext("/upload/storage/v1/b/bucket/o", exchange -> {
@@ -357,7 +358,7 @@ public void testWriteLargeBlob() throws IOException {
357358
logger.debug("starting with resumable upload id [{}]", sessionUploadId.get());
358359

359360
final TimeValue readTimeout = allowReadTimeout.get() ? TimeValue.timeValueSeconds(3) : null;
360-
final BlobContainer blobContainer = createBlobContainer(nbErrors + 1, readTimeout, null, null, null, null);
361+
final BlobContainer blobContainer = createBlobContainer(nbErrors + 1, readTimeout, null, null, null, null, null);
361362

362363
httpServer.createContext("/upload/storage/v1/b/bucket/o", safeHandler(exchange -> {
363364
final BytesReference requestBody = Streams.readFully(exchange.getRequestBody());
@@ -504,7 +505,7 @@ public String next() {
504505
return Integer.toString(totalDeletesSent++);
505506
}
506507
};
507-
final BlobContainer blobContainer = createBlobContainer(1, null, null, null, null, null);
508+
final BlobContainer blobContainer = createBlobContainer(1, null, null, null, null, null, null);
508509
httpServer.createContext("/batch/storage/v1", safeHandler(exchange -> {
509510
assert pendingDeletes.get() <= MAX_DELETES_PER_BATCH;
510511

@@ -540,7 +541,7 @@ public void testCompareAndExchangeWhenThrottled() throws IOException {
540541
httpServer.createContext("/", new ResponseInjectingHttpHandler(requestHandlers, new GoogleCloudStorageHttpHandler("bucket")));
541542

542543
final int maxRetries = randomIntBetween(1, 3);
543-
final BlobContainer container = createBlobContainer(maxRetries, null, null, null, null, null);
544+
final BlobContainer container = createBlobContainer(maxRetries, null, null, null, null, null, null);
544545
final byte[] data = randomBytes(randomIntBetween(1, BlobContainerUtils.MAX_REGISTER_CONTENT_LENGTH));
545546
final String key = randomIdentifier();
546547

modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Service.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,25 @@ DnsResolver getCustomDnsResolver() {
292292
return null;
293293
}
294294

295-
static SdkHttpClient buildHttpClient(S3ClientSettings clientSettings, @Nullable /* to use default resolver */ DnsResolver dnsResolver) {
295+
/**
296+
* An override for testing purposes.
297+
*/
298+
Optional<Duration> getConnectionAcquisitionTimeout() {
299+
return Optional.empty();
300+
}
301+
302+
private SdkHttpClient buildHttpClient(
303+
S3ClientSettings clientSettings,
304+
@Nullable /* to use default resolver */ DnsResolver dnsResolver
305+
) {
296306
ApacheHttpClient.Builder httpClientBuilder = ApacheHttpClient.builder();
297307

298-
// TODO NOMERGE: an IT test for maxConnections?
308+
var optConnectionAcquisitionTimout = getConnectionAcquisitionTimeout();
309+
if (optConnectionAcquisitionTimout.isPresent()) {
310+
// Only tests set this.
311+
httpClientBuilder.connectionAcquisitionTimeout(optConnectionAcquisitionTimout.get());
312+
}
313+
299314
httpClientBuilder.maxConnections(clientSettings.maxConnections);
300315
httpClientBuilder.socketTimeout(Duration.ofMillis(clientSettings.readTimeoutMillis));
301316

0 commit comments

Comments
 (0)