19
19
import org .apache .lucene .store .SimpleFSLockFactory ;
20
20
import org .apache .lucene .util .Constants ;
21
21
import org .apache .lucene .util .Version ;
22
+ import org .opensearch .common .lucene .store .ByteArrayIndexInput ;
23
+ import org .opensearch .core .common .unit .ByteSizeUnit ;
22
24
import org .opensearch .core .common .unit .ByteSizeValue ;
23
25
import org .opensearch .index .snapshots .blobstore .BlobStoreIndexShardSnapshot ;
24
26
import org .opensearch .index .store .StoreFileMetadata ;
31
33
import java .io .IOException ;
32
34
import java .nio .file .Path ;
33
35
36
+ import static org .mockito .ArgumentMatchers .argThat ;
34
37
import static org .mockito .Mockito .any ;
35
38
import static org .mockito .Mockito .doAnswer ;
36
39
import static org .mockito .Mockito .mock ;
40
+ import static org .mockito .Mockito .verify ;
41
+ import static org .mockito .Mockito .when ;
37
42
38
43
@ ThreadLeakFilters (filters = CleanerDaemonThreadLeakFilter .class )
39
44
public class OnDemandBlockSnapshotIndexInputTests extends OpenSearchTestCase {
@@ -43,7 +48,6 @@ public class OnDemandBlockSnapshotIndexInputTests extends OpenSearchTestCase {
43
48
private static final String FILE_NAME = "File_Name" ;
44
49
private static final String BLOCK_FILE_PREFIX = FILE_NAME ;
45
50
private static final boolean IS_CLONE = false ;
46
- private static final ByteSizeValue BYTE_SIZE_VALUE = new ByteSizeValue (1L );
47
51
private static final int FILE_SIZE = 29360128 ;
48
52
private TransferManager transferManager ;
49
53
private LockFactory lockFactory ;
@@ -74,7 +78,38 @@ public void test4MBBlock() throws Exception {
74
78
runAllTestsFor (22 );
75
79
}
76
80
77
- public void runAllTestsFor (int blockSizeShift ) throws Exception {
81
+ public void testChunkedRepository () throws IOException {
82
+ final long blockSize = new ByteSizeValue (1 , ByteSizeUnit .KB ).getBytes ();
83
+ final long repositoryChunkSize = new ByteSizeValue (2 , ByteSizeUnit .KB ).getBytes ();
84
+ final long fileSize = new ByteSizeValue (3 , ByteSizeUnit .KB ).getBytes ();
85
+
86
+ when (transferManager .fetchBlob (any ())).thenReturn (new ByteArrayIndexInput ("test" , new byte [(int ) blockSize ]));
87
+ try (
88
+ FSDirectory directory = new MMapDirectory (path , lockFactory );
89
+ IndexInput indexInput = new OnDemandBlockSnapshotIndexInput (
90
+ OnDemandBlockIndexInput .builder ()
91
+ .resourceDescription (RESOURCE_DESCRIPTION )
92
+ .offset (BLOCK_SNAPSHOT_FILE_OFFSET )
93
+ .length (FILE_SIZE )
94
+ .blockSizeShift ((int ) (Math .log (blockSize ) / Math .log (2 )))
95
+ .isClone (IS_CLONE ),
96
+ new BlobStoreIndexShardSnapshot .FileInfo (
97
+ FILE_NAME ,
98
+ new StoreFileMetadata (FILE_NAME , fileSize , "" , Version .LATEST ),
99
+ new ByteSizeValue (repositoryChunkSize )
100
+ ),
101
+ directory ,
102
+ transferManager
103
+ )
104
+ ) {
105
+ // Seek to the position past the first repository chunk
106
+ indexInput .seek (repositoryChunkSize );
107
+ }
108
+ // Verify the second chunk is requested (i.e. ".part1")
109
+ verify (transferManager ).fetchBlob (argThat (request -> request .getBlobName ().equals ("File_Name.part1" )));
110
+ }
111
+
112
+ private void runAllTestsFor (int blockSizeShift ) throws Exception {
78
113
final OnDemandBlockSnapshotIndexInput blockedSnapshotFile = createOnDemandBlockSnapshotIndexInput (blockSizeShift );
79
114
final int blockSize = 1 << blockSizeShift ;
80
115
TestGroup .testGetBlock (blockedSnapshotFile , blockSize , FILE_SIZE );
@@ -106,7 +141,7 @@ private OnDemandBlockSnapshotIndexInput createOnDemandBlockSnapshotIndexInput(in
106
141
fileInfo = new BlobStoreIndexShardSnapshot .FileInfo (
107
142
FILE_NAME ,
108
143
new StoreFileMetadata (FILE_NAME , FILE_SIZE , "" , Version .LATEST ),
109
- BYTE_SIZE_VALUE
144
+ null
110
145
);
111
146
112
147
int blockSize = 1 << blockSizeShift ;
@@ -182,7 +217,7 @@ private void initBlockFiles(int blockSize, FSDirectory fsDirectory) {
182
217
183
218
}
184
219
185
- public static class TestGroup {
220
+ private static class TestGroup {
186
221
187
222
public static void testGetBlock (OnDemandBlockSnapshotIndexInput blockedSnapshotFile , int blockSize , int fileSize ) {
188
223
// block 0
0 commit comments