34
34
import java .util .function .IntFunction ;
35
35
36
36
import org .assertj .core .api .Assertions ;
37
+ import org .junit .jupiter .api .AfterEach ;
37
38
import org .junit .jupiter .api .BeforeEach ;
38
- import org .junit .jupiter .params .ParameterizedTest ;
39
+ import org .junit .jupiter .api .Test ;
40
+ import org .junit .jupiter .params .ParameterizedClass ;
39
41
import org .junit .jupiter .params .provider .MethodSource ;
40
42
import org .slf4j .Logger ;
41
43
import org .slf4j .LoggerFactory ;
68
70
* Both the original readVectored(allocator) and the readVectored(allocator, release)
69
71
* operations are tested.
70
72
*/
73
+ @ ParameterizedClass (name ="buffer-{0}" )
74
+ @ MethodSource ("params" )
71
75
public abstract class AbstractContractVectoredReadTest extends AbstractFSContractTestBase {
72
76
73
77
private static final Logger LOG =
@@ -80,15 +84,15 @@ public abstract class AbstractContractVectoredReadTest extends AbstractFSContrac
80
84
/**
81
85
* Buffer allocator for vector IO.
82
86
*/
83
- protected IntFunction <ByteBuffer > allocate ;
87
+ private final IntFunction <ByteBuffer > allocate ;
84
88
85
89
/**
86
90
* Buffer pool for vector IO.
87
91
*/
88
- protected final ElasticByteBufferPool pool =
92
+ private final ElasticByteBufferPool pool =
89
93
new WeakReferencedElasticByteBufferPool ();
90
94
91
- protected String bufferType ;
95
+ private final String bufferType ;
92
96
93
97
/**
94
98
* Path to the vector file.
@@ -106,8 +110,8 @@ public static List<String> params() {
106
110
return Arrays .asList ("direct" , "array" );
107
111
}
108
112
109
- public void initAbstractContractVectoredReadTest (String pBufferType ) {
110
- this .bufferType = pBufferType ;
113
+ protected AbstractContractVectoredReadTest (String bufferType ) {
114
+ this .bufferType = bufferType ;
111
115
final boolean isDirect = !"array" .equals (bufferType );
112
116
this .allocate = size -> pool .getBuffer (isDirect , size );
113
117
}
@@ -147,6 +151,7 @@ public void setup() throws Exception {
147
151
createFile (fs , vectorPath , true , DATASET );
148
152
}
149
153
154
+ @ AfterEach
150
155
@ Override
151
156
public void teardown () throws Exception {
152
157
pool .release ();
@@ -177,10 +182,8 @@ protected FSDataInputStream openVectorFile(final FileSystem fs) throws IOExcepti
177
182
.build ());
178
183
}
179
184
180
- @ MethodSource ("params" )
181
- @ ParameterizedTest (name = "Buffer type : {0}" )
182
- public void testVectoredReadMultipleRanges (String pBufferType ) throws Exception {
183
- initAbstractContractVectoredReadTest (pBufferType );
185
+ @ Test
186
+ public void testVectoredReadMultipleRanges () throws Exception {
184
187
List <FileRange > fileRanges = new ArrayList <>();
185
188
for (int i = 0 ; i < 10 ; i ++) {
186
189
FileRange fileRange = FileRange .createFileRange (i * 100 , 100 );
@@ -201,10 +204,8 @@ public void testVectoredReadMultipleRanges(String pBufferType) throws Exception
201
204
}
202
205
}
203
206
204
- @ MethodSource ("params" )
205
- @ ParameterizedTest (name = "Buffer type : {0}" )
206
- public void testVectoredReadAndReadFully (String pBufferType ) throws Exception {
207
- initAbstractContractVectoredReadTest (pBufferType );
207
+ @ Test
208
+ public void testVectoredReadAndReadFully () throws Exception {
208
209
List <FileRange > fileRanges = new ArrayList <>();
209
210
range (fileRanges , 100 , 100 );
210
211
try (FSDataInputStream in = openVectorFile ()) {
@@ -219,10 +220,8 @@ public void testVectoredReadAndReadFully(String pBufferType) throws Exception {
219
220
}
220
221
}
221
222
222
- @ MethodSource ("params" )
223
- @ ParameterizedTest (name = "Buffer type : {0}" )
224
- public void testVectoredReadWholeFile (String pBufferType ) throws Exception {
225
- initAbstractContractVectoredReadTest (pBufferType );
223
+ @ Test
224
+ public void testVectoredReadWholeFile () throws Exception {
226
225
describe ("Read the whole file in one single vectored read" );
227
226
List <FileRange > fileRanges = new ArrayList <>();
228
227
range (fileRanges , 0 , DATASET_LEN );
@@ -240,10 +239,8 @@ public void testVectoredReadWholeFile(String pBufferType) throws Exception {
240
239
* As the minimum seek value is 4*1024,none of the below ranges
241
240
* will get merged.
242
241
*/
243
- @ MethodSource ("params" )
244
- @ ParameterizedTest (name = "Buffer type : {0}" )
245
- public void testDisjointRanges (String pBufferType ) throws Exception {
246
- initAbstractContractVectoredReadTest (pBufferType );
242
+ @ Test
243
+ public void testDisjointRanges () throws Exception {
247
244
List <FileRange > fileRanges = new ArrayList <>();
248
245
range (fileRanges , 0 , 100 );
249
246
range (fileRanges , 4_000 + 101 , 100 );
@@ -259,10 +256,8 @@ public void testDisjointRanges(String pBufferType) throws Exception {
259
256
* As the minimum seek value is 4*1024, all the below ranges
260
257
* will get merged into one.
261
258
*/
262
- @ MethodSource ("params" )
263
- @ ParameterizedTest (name = "Buffer type : {0}" )
264
- public void testAllRangesMergedIntoOne (String pBufferType ) throws Exception {
265
- initAbstractContractVectoredReadTest (pBufferType );
259
+ @ Test
260
+ public void testAllRangesMergedIntoOne () throws Exception {
266
261
List <FileRange > fileRanges = new ArrayList <>();
267
262
final int length = 100 ;
268
263
range (fileRanges , 0 , length );
@@ -279,10 +274,8 @@ public void testAllRangesMergedIntoOne(String pBufferType) throws Exception {
279
274
* As the minimum seek value is 4*1024, the first three ranges will be
280
275
* merged into and other two will remain as it is.
281
276
*/
282
- @ MethodSource ("params" )
283
- @ ParameterizedTest (name = "Buffer type : {0}" )
284
- public void testSomeRangesMergedSomeUnmerged (String pBufferType ) throws Exception {
285
- initAbstractContractVectoredReadTest (pBufferType );
277
+ @ Test
278
+ public void testSomeRangesMergedSomeUnmerged () throws Exception {
286
279
FileSystem fs = getFileSystem ();
287
280
List <FileRange > fileRanges = new ArrayList <>();
288
281
range (fileRanges , 8 * 1024 , 100 );
@@ -306,10 +299,8 @@ public void testSomeRangesMergedSomeUnmerged(String pBufferType) throws Exceptio
306
299
* Most file systems won't support overlapping ranges.
307
300
* Currently, only Raw Local supports it.
308
301
*/
309
- @ MethodSource ("params" )
310
- @ ParameterizedTest (name = "Buffer type : {0}" )
311
- public void testOverlappingRanges (String pBufferType ) throws Exception {
312
- initAbstractContractVectoredReadTest (pBufferType );
302
+ @ Test
303
+ public void testOverlappingRanges () throws Exception {
313
304
if (!isSupported (VECTOR_IO_OVERLAPPING_RANGES )) {
314
305
verifyExceptionalVectoredRead (
315
306
getSampleOverlappingRanges (),
@@ -327,10 +318,8 @@ public void testOverlappingRanges(String pBufferType) throws Exception {
327
318
/**
328
319
* Same ranges are special case of overlapping.
329
320
*/
330
- @ MethodSource ("params" )
331
- @ ParameterizedTest (name = "Buffer type : {0}" )
332
- public void testSameRanges (String pBufferType ) throws Exception {
333
- initAbstractContractVectoredReadTest (pBufferType );
321
+ @ Test
322
+ public void testSameRanges () throws Exception {
334
323
if (!isSupported (VECTOR_IO_OVERLAPPING_RANGES )) {
335
324
verifyExceptionalVectoredRead (
336
325
getSampleSameRanges (),
@@ -348,10 +337,8 @@ public void testSameRanges(String pBufferType) throws Exception {
348
337
/**
349
338
* A null range is not permitted.
350
339
*/
351
- @ MethodSource ("params" )
352
- @ ParameterizedTest (name = "Buffer type : {0}" )
353
- public void testNullRange (String pBufferType ) throws Exception {
354
- initAbstractContractVectoredReadTest (pBufferType );
340
+ @ Test
341
+ public void testNullRange () throws Exception {
355
342
List <FileRange > fileRanges = new ArrayList <>();
356
343
range (fileRanges , 500 , 100 );
357
344
fileRanges .add (null );
@@ -362,19 +349,15 @@ public void testNullRange(String pBufferType) throws Exception {
362
349
/**
363
350
* A null range is not permitted.
364
351
*/
365
- @ MethodSource ("params" )
366
- @ ParameterizedTest (name = "Buffer type : {0}" )
367
- public void testNullRangeList (String pBufferType ) throws Exception {
368
- initAbstractContractVectoredReadTest (pBufferType );
352
+ @ Test
353
+ public void testNullRangeList () throws Exception {
369
354
verifyExceptionalVectoredRead (
370
355
null ,
371
356
NullPointerException .class );
372
357
}
373
358
374
- @ MethodSource ("params" )
375
- @ ParameterizedTest (name = "Buffer type : {0}" )
376
- public void testSomeRandomNonOverlappingRanges (String pBufferType ) throws Exception {
377
- initAbstractContractVectoredReadTest (pBufferType );
359
+ @ Test
360
+ public void testSomeRandomNonOverlappingRanges () throws Exception {
378
361
List <FileRange > fileRanges = new ArrayList <>();
379
362
range (fileRanges , 500 , 100 );
380
363
range (fileRanges , 1000 , 200 );
@@ -387,10 +370,8 @@ public void testSomeRandomNonOverlappingRanges(String pBufferType) throws Except
387
370
}
388
371
}
389
372
390
- @ MethodSource ("params" )
391
- @ ParameterizedTest (name = "Buffer type : {0}" )
392
- public void testConsecutiveRanges (String pBufferType ) throws Exception {
393
- initAbstractContractVectoredReadTest (pBufferType );
373
+ @ Test
374
+ public void testConsecutiveRanges () throws Exception {
394
375
List <FileRange > fileRanges = new ArrayList <>();
395
376
final int offset = 500 ;
396
377
final int length = 2011 ;
@@ -403,10 +384,8 @@ public void testConsecutiveRanges(String pBufferType) throws Exception {
403
384
}
404
385
}
405
386
406
- @ MethodSource ("params" )
407
- @ ParameterizedTest (name = "Buffer type : {0}" )
408
- public void testEmptyRanges (String pBufferType ) throws Exception {
409
- initAbstractContractVectoredReadTest (pBufferType );
387
+ @ Test
388
+ public void testEmptyRanges () throws Exception {
410
389
List <FileRange > fileRanges = new ArrayList <>();
411
390
try (FSDataInputStream in = openVectorFile ()) {
412
391
in .readVectored (fileRanges , allocate );
@@ -425,10 +404,8 @@ public void testEmptyRanges(String pBufferType) throws Exception {
425
404
* The contract option {@link ContractOptions#VECTOR_IO_EARLY_EOF_CHECK} is used
426
405
* to determine which check to perform.
427
406
*/
428
- @ MethodSource ("params" )
429
- @ ParameterizedTest (name = "Buffer type : {0}" )
430
- public void testEOFRanges (String pBufferType ) throws Exception {
431
- initAbstractContractVectoredReadTest (pBufferType );
407
+ @ Test
408
+ public void testEOFRanges () throws Exception {
432
409
describe ("Testing reading with an offset past the end of the file" );
433
410
List <FileRange > fileRanges = range (DATASET_LEN + 1 , 100 );
434
411
@@ -441,10 +418,8 @@ public void testEOFRanges(String pBufferType) throws Exception {
441
418
}
442
419
443
420
444
- @ MethodSource ("params" )
445
- @ ParameterizedTest (name = "Buffer type : {0}" )
446
- public void testVectoredReadWholeFilePlusOne (String pBufferType ) throws Exception {
447
- initAbstractContractVectoredReadTest (pBufferType );
421
+ @ Test
422
+ public void testVectoredReadWholeFilePlusOne () throws Exception {
448
423
describe ("Try to read whole file plus 1 byte" );
449
424
List <FileRange > fileRanges = range (0 , DATASET_LEN + 1 );
450
425
@@ -471,35 +446,29 @@ private void expectEOFinRead(final List<FileRange> fileRanges) throws Exception
471
446
}
472
447
}
473
448
474
- @ MethodSource ("params" )
475
- @ ParameterizedTest (name = "Buffer type : {0}" )
476
- public void testNegativeLengthRange (String pBufferType ) throws Exception {
477
- initAbstractContractVectoredReadTest (pBufferType );
449
+ @ Test
450
+ public void testNegativeLengthRange () throws Exception {
451
+
478
452
verifyExceptionalVectoredRead (range (0 , -50 ), IllegalArgumentException .class );
479
453
}
480
454
481
- @ MethodSource ("params" )
482
- @ ParameterizedTest (name = "Buffer type : {0}" )
483
- public void testNegativeOffsetRange (String pBufferType ) throws Exception {
484
- initAbstractContractVectoredReadTest (pBufferType );
455
+ @ Test
456
+ public void testNegativeOffsetRange () throws Exception {
485
457
verifyExceptionalVectoredRead (range (-1 , 50 ), EOFException .class );
486
458
}
487
459
488
- @ MethodSource ("params" )
489
- @ ParameterizedTest (name = "Buffer type : {0}" )
490
- public void testNullReleaseOperation (String pBufferType ) throws Exception {
491
- initAbstractContractVectoredReadTest (pBufferType );
460
+ @ Test
461
+ public void testNullReleaseOperation () throws Exception {
462
+
492
463
final List <FileRange > range = range (0 , 10 );
493
464
try (FSDataInputStream in = openVectorFile ()) {
494
- intercept (NullPointerException .class , () ->
495
- in .readVectored (range , allocate , null ));
465
+ intercept (NullPointerException .class , () ->
466
+ in .readVectored (range , allocate , null ));
496
467
}
497
468
}
498
469
499
- @ MethodSource ("params" )
500
- @ ParameterizedTest (name = "Buffer type : {0}" )
501
- public void testNormalReadAfterVectoredRead (String pBufferType ) throws Exception {
502
- initAbstractContractVectoredReadTest (pBufferType );
470
+ @ Test
471
+ public void testNormalReadAfterVectoredRead () throws Exception {
503
472
List <FileRange > fileRanges = createSampleNonOverlappingRanges ();
504
473
try (FSDataInputStream in = openVectorFile ()) {
505
474
in .readVectored (fileRanges , allocate );
@@ -514,10 +483,8 @@ public void testNormalReadAfterVectoredRead(String pBufferType) throws Exception
514
483
}
515
484
}
516
485
517
- @ MethodSource ("params" )
518
- @ ParameterizedTest (name = "Buffer type : {0}" )
519
- public void testVectoredReadAfterNormalRead (String pBufferType ) throws Exception {
520
- initAbstractContractVectoredReadTest (pBufferType );
486
+ @ Test
487
+ public void testVectoredReadAfterNormalRead () throws Exception {
521
488
List <FileRange > fileRanges = createSampleNonOverlappingRanges ();
522
489
try (FSDataInputStream in = openVectorFile ()) {
523
490
// read starting 200 bytes
@@ -532,10 +499,8 @@ public void testVectoredReadAfterNormalRead(String pBufferType) throws Exception
532
499
}
533
500
}
534
501
535
- @ MethodSource ("params" )
536
- @ ParameterizedTest (name = "Buffer type : {0}" )
537
- public void testMultipleVectoredReads (String pBufferType ) throws Exception {
538
- initAbstractContractVectoredReadTest (pBufferType );
502
+ @ Test
503
+ public void testMultipleVectoredReads () throws Exception {
539
504
List <FileRange > fileRanges1 = createSampleNonOverlappingRanges ();
540
505
List <FileRange > fileRanges2 = createSampleNonOverlappingRanges ();
541
506
try (FSDataInputStream in = openVectorFile ()) {
@@ -553,10 +518,8 @@ public void testMultipleVectoredReads(String pBufferType) throws Exception {
553
518
* operation and then uses a separate thread pool to process the
554
519
* results asynchronously.
555
520
*/
556
- @ MethodSource ("params" )
557
- @ ParameterizedTest (name = "Buffer type : {0}" )
558
- public void testVectoredIOEndToEnd (String pBufferType ) throws Exception {
559
- initAbstractContractVectoredReadTest (pBufferType );
521
+ @ Test
522
+ public void testVectoredIOEndToEnd () throws Exception {
560
523
List <FileRange > fileRanges = new ArrayList <>();
561
524
range (fileRanges , 8 * 1024 , 100 );
562
525
range (fileRanges , 14 * 1024 , 100 );
0 commit comments