8181import static org .elasticsearch .repositories .blobstore .BlobStoreTestUtil .randomPurpose ;
8282import static org .elasticsearch .repositories .s3 .S3ClientSettings .DISABLE_CHUNKED_ENCODING ;
8383import static org .elasticsearch .repositories .s3 .S3ClientSettings .ENDPOINT_SETTING ;
84+ import static org .elasticsearch .repositories .s3 .S3ClientSettings .MAX_CONNECTIONS_SETTING ;
8485import static org .elasticsearch .repositories .s3 .S3ClientSettings .MAX_RETRIES_SETTING ;
8586import static org .elasticsearch .repositories .s3 .S3ClientSettings .READ_TIMEOUT_SETTING ;
8687import static org .hamcrest .Matchers .allOf ;
@@ -154,6 +155,7 @@ protected BlobContainer createBlobContainer(
154155 final @ Nullable Integer maxRetries ,
155156 final @ Nullable TimeValue readTimeout ,
156157 final @ Nullable Boolean disableChunkedEncoding ,
158+ final @ Nullable Integer maxConnections ,
157159 final @ Nullable ByteSizeValue bufferSize ,
158160 final @ Nullable Integer maxBulkDeletes ,
159161 final @ Nullable BlobPath blobContainerPath
@@ -174,6 +176,9 @@ protected BlobContainer createBlobContainer(
174176 if (disableChunkedEncoding != null ) {
175177 clientSettings .put (DISABLE_CHUNKED_ENCODING .getConcreteSettingForNamespace (clientName ).getKey (), disableChunkedEncoding );
176178 }
179+ if (maxConnections != null ) {
180+ clientSettings .put (MAX_CONNECTIONS_SETTING .getConcreteSettingForNamespace (clientName ).getKey (), maxConnections );
181+ }
177182
178183 final MockSecureSettings secureSettings = new MockSecureSettings ();
179184 secureSettings .setString (
@@ -253,7 +258,7 @@ public void testWriteBlobWithRetries() throws Exception {
253258 final int maxRetries = randomInt (5 );
254259 final CountDown countDown = new CountDown (maxRetries + 1 );
255260
256- final BlobContainer blobContainer = createBlobContainer ( maxRetries , null , true , null , null , null );
261+ final BlobContainer blobContainer = blobContainerBuilder (). maxRetries ( maxRetries ). disableChunkedEncoding ( true ). build ( );
257262
258263 final byte [] bytes = randomBlobContent ();
259264 httpServer .createContext (downloadStorageEndpoint (blobContainer , "write_blob_max_retries" ), exchange -> {
@@ -301,7 +306,10 @@ public void testWriteBlobWithRetries() throws Exception {
301306 public void testWriteBlobWithReadTimeouts () {
302307 final byte [] bytes = randomByteArrayOfLength (randomIntBetween (10 , 128 ));
303308 final TimeValue readTimeout = TimeValue .timeValueMillis (randomIntBetween (100 , 500 ));
304- final BlobContainer blobContainer = createBlobContainer (1 , readTimeout , true , null , null , null );
309+ final BlobContainer blobContainer = blobContainerBuilder ().maxRetries (1 )
310+ .readTimeout (readTimeout )
311+ .disableChunkedEncoding (true )
312+ .build ();
305313
306314 // HTTP server does not send a response
307315 httpServer .createContext (downloadStorageEndpoint (blobContainer , "write_blob_timeout" ), exchange -> {
@@ -335,7 +343,10 @@ public void testWriteLargeBlob() throws Exception {
335343 final boolean useTimeout = rarely ();
336344 final TimeValue readTimeout = useTimeout ? TimeValue .timeValueMillis (randomIntBetween (100 , 500 )) : null ;
337345 final ByteSizeValue bufferSize = new ByteSizeValue (5 , ByteSizeUnit .MB );
338- final BlobContainer blobContainer = createBlobContainer (null , readTimeout , true , bufferSize , null , null );
346+ final BlobContainer blobContainer = blobContainerBuilder ().readTimeout (readTimeout )
347+ .disableChunkedEncoding (true )
348+ .bufferSize (bufferSize )
349+ .build ();
339350
340351 final int parts = randomIntBetween (1 , 5 );
341352 final long lastPartSize = randomLongBetween (10 , 512 );
@@ -431,7 +442,10 @@ public void testWriteLargeBlobStreaming() throws Exception {
431442 final boolean useTimeout = rarely ();
432443 final TimeValue readTimeout = useTimeout ? TimeValue .timeValueMillis (randomIntBetween (100 , 500 )) : null ;
433444 final ByteSizeValue bufferSize = new ByteSizeValue (5 , ByteSizeUnit .MB );
434- final BlobContainer blobContainer = createBlobContainer (null , readTimeout , true , bufferSize , null , null );
445+ final BlobContainer blobContainer = blobContainerBuilder ().readTimeout (readTimeout )
446+ .disableChunkedEncoding (true )
447+ .bufferSize (bufferSize )
448+ .build ();
435449
436450 final int parts = randomIntBetween (1 , 5 );
437451 final long lastPartSize = randomLongBetween (10 , 512 );
@@ -540,7 +554,10 @@ public void testReadRetriesAfterMeaningfulProgress() throws Exception {
540554 0 ,
541555 randomFrom (1000 , Math .toIntExact (S3Repository .BUFFER_SIZE_SETTING .get (Settings .EMPTY ).getBytes ()))
542556 );
543- final BlobContainer blobContainer = createBlobContainer (maxRetries , null , true , ByteSizeValue .ofBytes (bufferSizeBytes ), null , null );
557+ final BlobContainer blobContainer = blobContainerBuilder ().maxRetries (maxRetries )
558+ .disableChunkedEncoding (true )
559+ .bufferSize (ByteSizeValue .ofBytes (bufferSizeBytes ))
560+ .build ();
544561 final int meaningfulProgressBytes = Math .max (1 , bufferSizeBytes / 100 );
545562
546563 final byte [] bytes = randomBlobContent ();
@@ -613,7 +630,10 @@ public void testReadDoesNotRetryForRepositoryAnalysis() {
613630 0 ,
614631 randomFrom (1000 , Math .toIntExact (S3Repository .BUFFER_SIZE_SETTING .get (Settings .EMPTY ).getBytes ()))
615632 );
616- final BlobContainer blobContainer = createBlobContainer (maxRetries , null , true , ByteSizeValue .ofBytes (bufferSizeBytes ), null , null );
633+ final BlobContainer blobContainer = blobContainerBuilder ().maxRetries (maxRetries )
634+ .disableChunkedEncoding (true )
635+ .bufferSize (ByteSizeValue .ofBytes (bufferSizeBytes ))
636+ .build ();
617637
618638 final byte [] bytes = randomBlobContent ();
619639
@@ -651,7 +671,10 @@ public void testReadWithIndicesPurposeRetriesForever() throws IOException {
651671 0 ,
652672 randomFrom (1000 , Math .toIntExact (S3Repository .BUFFER_SIZE_SETTING .get (Settings .EMPTY ).getBytes ()))
653673 );
654- final BlobContainer blobContainer = createBlobContainer (maxRetries , null , true , ByteSizeValue .ofBytes (bufferSizeBytes ), null , null );
674+ final BlobContainer blobContainer = blobContainerBuilder ().maxRetries (maxRetries )
675+ .disableChunkedEncoding (true )
676+ .bufferSize (ByteSizeValue .ofBytes (bufferSizeBytes ))
677+ .build ();
655678 final int meaningfulProgressBytes = Math .max (1 , bufferSizeBytes / 100 );
656679
657680 final byte [] bytes = randomBlobContent (512 );
@@ -744,7 +767,7 @@ public void handle(HttpExchange exchange) throws IOException {
744767
745768 public void testDoesNotRetryOnNotFound () {
746769 final int maxRetries = between (3 , 5 );
747- final BlobContainer blobContainer = createBlobContainer ( maxRetries , null , true , null , null , null );
770+ final BlobContainer blobContainer = blobContainerBuilder (). maxRetries ( maxRetries ). disableChunkedEncoding ( true ). build ( );
748771
749772 final AtomicInteger numberOfReads = new AtomicInteger (0 );
750773 @ SuppressForbidden (reason = "use a http server" )
@@ -777,7 +800,11 @@ public void handle(HttpExchange exchange) throws IOException {
777800 public void testSuppressedDeletionErrorsAreCapped () {
778801 final TimeValue readTimeout = TimeValue .timeValueMillis (randomIntBetween (100 , 500 ));
779802 int maxBulkDeleteSize = randomIntBetween (1 , 10 );
780- final BlobContainer blobContainer = createBlobContainer (1 , readTimeout , true , null , maxBulkDeleteSize , null );
803+ final BlobContainer blobContainer = blobContainerBuilder ().maxRetries (1 )
804+ .readTimeout (readTimeout )
805+ .disableChunkedEncoding (true )
806+ .maxBulkDeletes (maxBulkDeleteSize )
807+ .build ();
781808 httpServer .createContext ("/" , exchange -> {
782809 if (isMultiDeleteRequest (exchange )) {
783810 exchange .sendResponseHeaders (
@@ -809,7 +836,11 @@ public void testSuppressedDeletionErrorsAreCapped() {
809836 public void testTrimmedLogAndCappedSuppressedErrorOnMultiObjectDeletionException () {
810837 final TimeValue readTimeout = TimeValue .timeValueMillis (randomIntBetween (100 , 500 ));
811838 int maxBulkDeleteSize = randomIntBetween (10 , 30 );
812- final BlobContainer blobContainer = createBlobContainer (1 , readTimeout , true , null , maxBulkDeleteSize , null );
839+ final BlobContainer blobContainer = blobContainerBuilder ().maxRetries (1 )
840+ .readTimeout (readTimeout )
841+ .disableChunkedEncoding (true )
842+ .maxBulkDeletes (maxBulkDeleteSize )
843+ .build ();
813844
814845 final Pattern pattern = Pattern .compile ("<Key>(.+?)</Key>" );
815846 httpServer .createContext ("/" , exchange -> {
0 commit comments