23
23
import java .nio .ByteBuffer ;
24
24
import java .nio .IntBuffer ;
25
25
import java .util .Collections ;
26
+ import java .util .Comparator ;
26
27
import java .util .List ;
27
28
import java .util .Optional ;
28
29
import java .util .concurrent .CompletableFuture ;
47
48
import static org .apache .hadoop .fs .VectoredReadUtils .mergeSortedRanges ;
48
49
import static org .apache .hadoop .fs .VectoredReadUtils .readRangeFrom ;
49
50
import static org .apache .hadoop .fs .VectoredReadUtils .readVectored ;
51
+ import static org .apache .hadoop .fs .VectoredReadUtils .sortRangeList ;
50
52
import static org .apache .hadoop .fs .VectoredReadUtils .sortRanges ;
51
53
import static org .apache .hadoop .fs .VectoredReadUtils .validateAndSortRanges ;
52
54
import static org .apache .hadoop .test .LambdaTestUtils .intercept ;
@@ -196,7 +198,7 @@ public void testSortAndMerge() {
196
198
);
197
199
assertIsNotOrderedDisjoint (input , 100 , 800 );
198
200
final List <CombinedFileRange > outputList = mergeSortedRanges (
199
- sortRanges (input ), 100 , 1001 , 2500 );
201
+ sortRangeList (input ), 100 , 1001 , 2500 );
200
202
201
203
assertRangeListSize (outputList , 1 );
202
204
CombinedFileRange output = outputList .get (0 );
@@ -208,7 +210,7 @@ public void testSortAndMerge() {
208
210
// the minSeek doesn't allow the first two to merge
209
211
assertIsNotOrderedDisjoint (input , 100 , 100 );
210
212
final List <CombinedFileRange > list2 = mergeSortedRanges (
211
- sortRanges (input ),
213
+ sortRangeList (input ),
212
214
100 , 1000 , 2100 );
213
215
assertRangeListSize (list2 , 2 );
214
216
assertRangeElement (list2 , 0 , 1000 , 100 );
@@ -219,7 +221,7 @@ public void testSortAndMerge() {
219
221
// the maxSize doesn't allow the third range to merge
220
222
assertIsNotOrderedDisjoint (input , 100 , 800 );
221
223
final List <CombinedFileRange > list3 = mergeSortedRanges (
222
- sortRanges (input ),
224
+ sortRangeList (input ),
223
225
100 , 1001 , 2099 );
224
226
assertRangeListSize (list3 , 2 );
225
227
CombinedFileRange range0 = list3 .get (0 );
@@ -240,7 +242,7 @@ public void testSortAndMerge() {
240
242
// test the round up and round down (the maxSize doesn't allow any merges)
241
243
assertIsNotOrderedDisjoint (input , 16 , 700 );
242
244
final List <CombinedFileRange > list4 = mergeSortedRanges (
243
- sortRanges (input ),
245
+ sortRangeList (input ),
244
246
16 , 1001 , 100 );
245
247
assertRangeListSize (list4 , 3 );
246
248
// range[992,1104)
@@ -273,6 +275,27 @@ private static <ELEMENT extends FileRange> void assertFileRange(
273
275
.isEqualTo (length );
274
276
}
275
277
278
+ /**
279
+ * Verify that {@link VectoredReadUtils#sortRanges(List)}
280
+ * returns an array matching the list sort ranges.
281
+ */
282
+ @ Test
283
+ public void testArraySortRange () throws Throwable {
284
+ List <FileRange > input = asList (
285
+ createFileRange (3000 , 100 , "1" ),
286
+ createFileRange (2100 , 100 , null ),
287
+ createFileRange (1000 , 100 , "3" )
288
+ );
289
+ final FileRange [] rangeArray = sortRanges (input );
290
+ final List <? extends FileRange > rangeList = sortRangeList (input );
291
+ Assertions .assertThat (rangeArray )
292
+ .describedAs ("range array from sortRanges()" )
293
+ .isSortedAccordingTo (Comparator .comparingLong (FileRange ::getOffset ));
294
+ Assertions .assertThat (rangeList .toArray (new FileRange [0 ]))
295
+ .describedAs ("range from sortRangeList()" )
296
+ .isEqualTo (rangeArray );
297
+ }
298
+
276
299
/**
277
300
* Assert that a file range satisfies the conditions.
278
301
* @param range range to validate
@@ -399,7 +422,7 @@ public void testSortAndMergeMoreCases() throws Exception {
399
422
);
400
423
assertIsNotOrderedDisjoint (input , 100 , 800 );
401
424
List <CombinedFileRange > outputList = mergeSortedRanges (
402
- sortRanges (input ), 1 , 1001 , 2500 );
425
+ sortRangeList (input ), 1 , 1001 , 2500 );
403
426
Assertions .assertThat (outputList )
404
427
.describedAs ("merged range size" )
405
428
.hasSize (1 );
@@ -411,7 +434,7 @@ public void testSortAndMergeMoreCases() throws Exception {
411
434
assertOrderedDisjoint (outputList , 1 , 800 );
412
435
413
436
outputList = mergeSortedRanges (
414
- sortRanges (input ), 100 , 1001 , 2500 );
437
+ sortRangeList (input ), 100 , 1001 , 2500 );
415
438
assertRangeListSize (outputList , 1 );
416
439
417
440
output = outputList .get (0 );
0 commit comments