|
30 | 30 |
|
31 | 31 | import org.apache.lucene.store.IndexInput;
|
32 | 32 | import org.opensearch.cluster.metadata.RepositoryMetadata;
|
33 |
| -import org.opensearch.common.CheckedTriFunction; |
| 33 | +import org.opensearch.common.CheckedConsumer; |
34 | 34 | import org.opensearch.common.StreamContext;
|
35 | 35 | import org.opensearch.common.blobstore.BlobPath;
|
36 | 36 | import org.opensearch.common.blobstore.stream.write.StreamContextSupplier;
|
|
52 | 52 | import org.opensearch.test.OpenSearchTestCase;
|
53 | 53 | import org.opensearch.threadpool.Scheduler;
|
54 | 54 | import org.junit.After;
|
| 55 | +import org.junit.Assert; |
55 | 56 | import org.junit.Before;
|
56 | 57 |
|
57 | 58 | import java.io.IOException;
|
@@ -513,24 +514,30 @@ private void testWriteBlobByStreams(boolean expectException, boolean throwExcept
|
513 | 514 | exceptionRef.set(ex);
|
514 | 515 | countDownLatch.countDown();
|
515 | 516 | });
|
516 |
| - blobContainer.asyncBlobUpload(new WriteContext("write_blob_by_streams_max_retries", new StreamContextSupplier() { |
517 |
| - @Override |
518 |
| - public StreamContext supplyStreamContext(long partSize) { |
519 |
| - return new StreamContext(new CheckedTriFunction<Integer, Long, Long, InputStreamContainer, IOException>() { |
520 |
| - @Override |
521 |
| - public InputStreamContainer apply(Integer partNo, Long size, Long position) throws IOException { |
522 |
| - InputStream inputStream = new OffsetRangeIndexInputStream(new ByteArrayIndexInput("desc", bytes), size, position); |
523 |
| - openInputStreams.add(inputStream); |
524 |
| - return new InputStreamContainer(inputStream, size, position); |
525 |
| - } |
526 |
| - }, partSize, calculateLastPartSize(bytes.length, partSize), calculateNumberOfParts(bytes.length, partSize)); |
527 |
| - } |
528 |
| - }, bytes.length, false, WritePriority.NORMAL, uploadSuccess -> { |
| 517 | + |
| 518 | + StreamContextSupplier streamContextSupplier = partSize -> new StreamContext((partNo, size, position) -> { |
| 519 | + InputStream inputStream = new OffsetRangeIndexInputStream(new ByteArrayIndexInput("desc", bytes), size, position); |
| 520 | + openInputStreams.add(inputStream); |
| 521 | + return new InputStreamContainer(inputStream, size, position); |
| 522 | + }, partSize, calculateLastPartSize(bytes.length, partSize), calculateNumberOfParts(bytes.length, partSize)); |
| 523 | + |
| 524 | + CheckedConsumer<Boolean, IOException> uploadFinalizer = uploadSuccess -> { |
529 | 525 | assertTrue(uploadSuccess);
|
530 | 526 | if (throwExceptionOnFinalizeUpload) {
|
531 | 527 | throw new RuntimeException();
|
532 | 528 | }
|
533 |
| - }, false, null), completionListener); |
| 529 | + }; |
| 530 | + |
| 531 | + WriteContext writeContext = new WriteContext.Builder().fileName("write_blob_by_streams_max_retries") |
| 532 | + .streamContextSupplier(streamContextSupplier) |
| 533 | + .fileSize(bytes.length) |
| 534 | + .failIfAlreadyExists(false) |
| 535 | + .writePriority(WritePriority.NORMAL) |
| 536 | + .uploadFinalizer(uploadFinalizer) |
| 537 | + .doRemoteDataIntegrityCheck(false) |
| 538 | + .build(); |
| 539 | + |
| 540 | + blobContainer.asyncBlobUpload(writeContext, completionListener); |
534 | 541 |
|
535 | 542 | assertTrue(countDownLatch.await(5000, TimeUnit.SECONDS));
|
536 | 543 | // wait for completableFuture to finish
|
@@ -563,24 +570,30 @@ private void testWriteBlobByStreamsLargeBlob(boolean expectException, boolean th
|
563 | 570 | countDownLatch.countDown();
|
564 | 571 | });
|
565 | 572 | List<InputStream> openInputStreams = new ArrayList<>();
|
566 |
| - blobContainer.asyncBlobUpload(new WriteContext("write_large_blob", new StreamContextSupplier() { |
567 |
| - @Override |
568 |
| - public StreamContext supplyStreamContext(long partSize) { |
569 |
| - return new StreamContext(new CheckedTriFunction<Integer, Long, Long, InputStreamContainer, IOException>() { |
570 |
| - @Override |
571 |
| - public InputStreamContainer apply(Integer partNo, Long size, Long position) throws IOException { |
572 |
| - InputStream inputStream = new OffsetRangeIndexInputStream(new ZeroIndexInput("desc", blobSize), size, position); |
573 |
| - openInputStreams.add(inputStream); |
574 |
| - return new InputStreamContainer(inputStream, size, position); |
575 |
| - } |
576 |
| - }, partSize, calculateLastPartSize(blobSize, partSize), calculateNumberOfParts(blobSize, partSize)); |
577 |
| - } |
578 |
| - }, blobSize, false, WritePriority.NORMAL, uploadSuccess -> { |
| 573 | + |
| 574 | + StreamContextSupplier streamContextSupplier = partSize1 -> new StreamContext((partNo, size, position) -> { |
| 575 | + InputStream inputStream = new OffsetRangeIndexInputStream(new ZeroIndexInput("desc", blobSize), size, position); |
| 576 | + openInputStreams.add(inputStream); |
| 577 | + return new InputStreamContainer(inputStream, size, position); |
| 578 | + }, partSize1, calculateLastPartSize(blobSize, partSize1), calculateNumberOfParts(blobSize, partSize1)); |
| 579 | + |
| 580 | + CheckedConsumer<Boolean, IOException> uploadFinalizer = uploadSuccess -> { |
579 | 581 | assertTrue(uploadSuccess);
|
580 | 582 | if (throwExceptionOnFinalizeUpload) {
|
581 | 583 | throw new RuntimeException();
|
582 | 584 | }
|
583 |
| - }, false, null), completionListener); |
| 585 | + }; |
| 586 | + |
| 587 | + WriteContext writeContext = new WriteContext.Builder().fileName("write_large_blob") |
| 588 | + .streamContextSupplier(streamContextSupplier) |
| 589 | + .fileSize(blobSize) |
| 590 | + .failIfAlreadyExists(false) |
| 591 | + .writePriority(WritePriority.NORMAL) |
| 592 | + .uploadFinalizer(uploadFinalizer) |
| 593 | + .doRemoteDataIntegrityCheck(false) |
| 594 | + .build(); |
| 595 | + |
| 596 | + blobContainer.asyncBlobUpload(writeContext, completionListener); |
584 | 597 |
|
585 | 598 | assertTrue(countDownLatch.await(5000, TimeUnit.SECONDS));
|
586 | 599 | if (expectException || throwExceptionOnFinalizeUpload) {
|
@@ -695,20 +708,23 @@ private void testLargeFilesRedirectedToSlowSyncClient(boolean expectException, W
|
695 | 708 |
|
696 | 709 | List<InputStream> openInputStreams = new ArrayList<>();
|
697 | 710 | final S3BlobContainer s3BlobContainer = Mockito.spy(new S3BlobContainer(blobPath, blobStore));
|
698 |
| - s3BlobContainer.asyncBlobUpload(new WriteContext("write_large_blob", new StreamContextSupplier() { |
699 |
| - @Override |
700 |
| - public StreamContext supplyStreamContext(long partSize) { |
701 |
| - return new StreamContext(new CheckedTriFunction<Integer, Long, Long, InputStreamContainer, IOException>() { |
702 |
| - @Override |
703 |
| - public InputStreamContainer apply(Integer partNo, Long size, Long position) throws IOException { |
704 |
| - InputStream inputStream = new OffsetRangeIndexInputStream(new ZeroIndexInput("desc", blobSize), size, position); |
705 |
| - openInputStreams.add(inputStream); |
706 |
| - return new InputStreamContainer(inputStream, size, position); |
707 |
| - } |
708 |
| - }, partSize, calculateLastPartSize(blobSize, partSize), calculateNumberOfParts(blobSize, partSize)); |
709 |
| - } |
710 |
| - }, blobSize, false, writePriority, uploadSuccess -> { assertTrue(uploadSuccess); }, false, null), completionListener); |
711 | 711 |
|
| 712 | + StreamContextSupplier streamContextSupplier = partSize1 -> new StreamContext((partNo, size, position) -> { |
| 713 | + InputStream inputStream = new OffsetRangeIndexInputStream(new ZeroIndexInput("desc", blobSize), size, position); |
| 714 | + openInputStreams.add(inputStream); |
| 715 | + return new InputStreamContainer(inputStream, size, position); |
| 716 | + }, partSize1, calculateLastPartSize(blobSize, partSize1), calculateNumberOfParts(blobSize, partSize1)); |
| 717 | + |
| 718 | + WriteContext writeContext = new WriteContext.Builder().fileName("write_large_blob") |
| 719 | + .streamContextSupplier(streamContextSupplier) |
| 720 | + .fileSize(blobSize) |
| 721 | + .failIfAlreadyExists(false) |
| 722 | + .writePriority(writePriority) |
| 723 | + .uploadFinalizer(Assert::assertTrue) |
| 724 | + .doRemoteDataIntegrityCheck(false) |
| 725 | + .build(); |
| 726 | + |
| 727 | + s3BlobContainer.asyncBlobUpload(writeContext, completionListener); |
712 | 728 | assertTrue(countDownLatch.await(5000, TimeUnit.SECONDS));
|
713 | 729 | if (expectException) {
|
714 | 730 | assertNotNull(exceptionRef.get());
|
|
0 commit comments