| 
22 | 22 | 
 
  | 
23 | 23 | import org.apache.http.HttpStatus;  | 
24 | 24 | import org.apache.logging.log4j.Level;  | 
25 |  | -import org.apache.lucene.index.CorruptIndexException;  | 
26 |  | -import org.apache.lucene.store.AlreadyClosedException;  | 
27 | 25 | import org.elasticsearch.ExceptionsHelper;  | 
28 | 26 | import org.elasticsearch.cluster.metadata.RepositoryMetadata;  | 
29 | 27 | import org.elasticsearch.common.BackoffPolicy;  | 
 | 
85 | 83 | import java.util.concurrent.atomic.AtomicBoolean;  | 
86 | 84 | import java.util.concurrent.atomic.AtomicInteger;  | 
87 | 85 | import java.util.concurrent.atomic.AtomicLong;  | 
88 |  | -import java.util.concurrent.atomic.AtomicReference;  | 
89 | 86 | import java.util.function.IntConsumer;  | 
90 | 87 | import java.util.regex.Pattern;  | 
91 | 88 | 
 
  | 
@@ -343,57 +340,6 @@ public void testWriteBlobWithReadTimeouts() {  | 
343 | 340 |         assertThat(exception.getCause().getCause().getMessage().toLowerCase(Locale.ROOT), containsString("read timed out"));  | 
344 | 341 |     }  | 
345 | 342 | 
 
  | 
346 |  | -    /**  | 
347 |  | -     * This test shows that the AWS SDKv1 defers the closing of the InputStream used to upload a blob after the HTTP request has been sent  | 
348 |  | -     * to S3, swallowing any exception thrown at closing time.  | 
349 |  | -     */  | 
350 |  | -    public void testWriteBlobWithExceptionThrownAtClosingTime() throws Exception {  | 
351 |  | -        var maxRetries = randomInt(3);  | 
352 |  | -        var blobLength = randomIntBetween(1, 4096 * 3);  | 
353 |  | -        var blobName = getTestName().toLowerCase(Locale.ROOT);  | 
354 |  | -        var blobContainer = createBlobContainer(maxRetries, null, true, null, null);  | 
355 |  | - | 
356 |  | -        var uploadedBytes = new AtomicReference<BytesReference>();  | 
357 |  | -        httpServer.createContext(downloadStorageEndpoint(blobContainer, blobName), exchange -> {  | 
358 |  | -            var requestComponents = parseRequest(exchange);  | 
359 |  | -            if (requestComponents.isPutObjectRequest()) {  | 
360 |  | -                var body = Streams.readFully(exchange.getRequestBody());  | 
361 |  | -                if (uploadedBytes.compareAndSet(null, body)) {  | 
362 |  | -                    exchange.sendResponseHeaders(HttpStatus.SC_OK, -1);  | 
363 |  | -                    exchange.close();  | 
364 |  | -                    return;  | 
365 |  | -                }  | 
366 |  | -            }  | 
367 |  | -            exchange.sendResponseHeaders(HttpStatus.SC_BAD_REQUEST, -1);  | 
368 |  | -            exchange.close();  | 
369 |  | -        });  | 
370 |  | - | 
371 |  | -        final byte[] bytes = randomByteArrayOfLength(blobLength);  | 
372 |  | - | 
373 |  | -        var exceptionThrown = new AtomicBoolean();  | 
374 |  | -        blobContainer.writeBlobAtomic(randomPurpose(), blobName, new FilterInputStream(new ByteArrayInputStream(bytes)) {  | 
375 |  | -            @Override  | 
376 |  | -            public void close() throws IOException {  | 
377 |  | -                if (exceptionThrown.compareAndSet(false, true)) {  | 
378 |  | -                    switch (randomInt(3)) {  | 
379 |  | -                        case 0:  | 
380 |  | -                            throw new CorruptIndexException("simulated", blobName);  | 
381 |  | -                        case 1:  | 
382 |  | -                            throw new AlreadyClosedException("simulated");  | 
383 |  | -                        case 2:  | 
384 |  | -                            throw new RuntimeException("simulated");  | 
385 |  | -                        case 3:  | 
386 |  | -                        default:  | 
387 |  | -                            throw new IOException("simulated");  | 
388 |  | -                    }  | 
389 |  | -                }  | 
390 |  | -            }  | 
391 |  | -        }, blobLength, true);  | 
392 |  | - | 
393 |  | -        assertThat(exceptionThrown.get(), is(true));  | 
394 |  | -        assertArrayEquals(bytes, BytesReference.toBytes(uploadedBytes.get()));  | 
395 |  | -    }  | 
396 |  | - | 
397 | 343 |     public void testWriteLargeBlob() throws Exception {  | 
398 | 344 |         final boolean useTimeout = rarely();  | 
399 | 345 |         final TimeValue readTimeout = useTimeout ? TimeValue.timeValueMillis(randomIntBetween(100, 500)) : null;  | 
 | 
0 commit comments