3434import java .util .function .IntFunction ;
3535
3636import org .assertj .core .api .Assertions ;
37+ import org .junit .jupiter .api .AfterEach ;
3738import 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 ;
3941import org .junit .jupiter .params .provider .MethodSource ;
4042import org .slf4j .Logger ;
4143import org .slf4j .LoggerFactory ;
6870 * Both the original readVectored(allocator) and the readVectored(allocator, release)
6971 * operations are tested.
7072 */
73+ @ ParameterizedClass (name ="buffer-{0}" )
74+ @ MethodSource ("params" )
7175public abstract class AbstractContractVectoredReadTest extends AbstractFSContractTestBase {
7276
7377 private static final Logger LOG =
@@ -80,15 +84,15 @@ public abstract class AbstractContractVectoredReadTest extends AbstractFSContrac
8084 /**
8185 * Buffer allocator for vector IO.
8286 */
83- protected IntFunction <ByteBuffer > allocate ;
87+ private final IntFunction <ByteBuffer > allocate ;
8488
8589 /**
8690 * Buffer pool for vector IO.
8791 */
88- protected final ElasticByteBufferPool pool =
92+ private final ElasticByteBufferPool pool =
8993 new WeakReferencedElasticByteBufferPool ();
9094
91- protected String bufferType ;
95+ private final String bufferType ;
9296
9397 /**
9498 * Path to the vector file.
@@ -106,8 +110,8 @@ public static List<String> params() {
106110 return Arrays .asList ("direct" , "array" );
107111 }
108112
109- public void initAbstractContractVectoredReadTest (String pBufferType ) {
110- this .bufferType = pBufferType ;
113+ protected AbstractContractVectoredReadTest (String bufferType ) {
114+ this .bufferType = bufferType ;
111115 final boolean isDirect = !"array" .equals (bufferType );
112116 this .allocate = size -> pool .getBuffer (isDirect , size );
113117 }
@@ -147,6 +151,7 @@ public void setup() throws Exception {
147151 createFile (fs , vectorPath , true , DATASET );
148152 }
149153
154+ @ AfterEach
150155 @ Override
151156 public void teardown () throws Exception {
152157 pool .release ();
@@ -177,10 +182,8 @@ protected FSDataInputStream openVectorFile(final FileSystem fs) throws IOExcepti
177182 .build ());
178183 }
179184
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 {
184187 List <FileRange > fileRanges = new ArrayList <>();
185188 for (int i = 0 ; i < 10 ; i ++) {
186189 FileRange fileRange = FileRange .createFileRange (i * 100 , 100 );
@@ -201,10 +204,8 @@ public void testVectoredReadMultipleRanges(String pBufferType) throws Exception
201204 }
202205 }
203206
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 {
208209 List <FileRange > fileRanges = new ArrayList <>();
209210 range (fileRanges , 100 , 100 );
210211 try (FSDataInputStream in = openVectorFile ()) {
@@ -219,10 +220,8 @@ public void testVectoredReadAndReadFully(String pBufferType) throws Exception {
219220 }
220221 }
221222
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 {
226225 describe ("Read the whole file in one single vectored read" );
227226 List <FileRange > fileRanges = new ArrayList <>();
228227 range (fileRanges , 0 , DATASET_LEN );
@@ -240,10 +239,8 @@ public void testVectoredReadWholeFile(String pBufferType) throws Exception {
240239 * As the minimum seek value is 4*1024,none of the below ranges
241240 * will get merged.
242241 */
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 {
247244 List <FileRange > fileRanges = new ArrayList <>();
248245 range (fileRanges , 0 , 100 );
249246 range (fileRanges , 4_000 + 101 , 100 );
@@ -259,10 +256,8 @@ public void testDisjointRanges(String pBufferType) throws Exception {
259256 * As the minimum seek value is 4*1024, all the below ranges
260257 * will get merged into one.
261258 */
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 {
266261 List <FileRange > fileRanges = new ArrayList <>();
267262 final int length = 100 ;
268263 range (fileRanges , 0 , length );
@@ -279,10 +274,8 @@ public void testAllRangesMergedIntoOne(String pBufferType) throws Exception {
279274 * As the minimum seek value is 4*1024, the first three ranges will be
280275 * merged into and other two will remain as it is.
281276 */
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 {
286279 FileSystem fs = getFileSystem ();
287280 List <FileRange > fileRanges = new ArrayList <>();
288281 range (fileRanges , 8 * 1024 , 100 );
@@ -306,10 +299,8 @@ public void testSomeRangesMergedSomeUnmerged(String pBufferType) throws Exceptio
306299 * Most file systems won't support overlapping ranges.
307300 * Currently, only Raw Local supports it.
308301 */
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 {
313304 if (!isSupported (VECTOR_IO_OVERLAPPING_RANGES )) {
314305 verifyExceptionalVectoredRead (
315306 getSampleOverlappingRanges (),
@@ -327,10 +318,8 @@ public void testOverlappingRanges(String pBufferType) throws Exception {
327318 /**
328319 * Same ranges are special case of overlapping.
329320 */
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 {
334323 if (!isSupported (VECTOR_IO_OVERLAPPING_RANGES )) {
335324 verifyExceptionalVectoredRead (
336325 getSampleSameRanges (),
@@ -348,10 +337,8 @@ public void testSameRanges(String pBufferType) throws Exception {
348337 /**
349338 * A null range is not permitted.
350339 */
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 {
355342 List <FileRange > fileRanges = new ArrayList <>();
356343 range (fileRanges , 500 , 100 );
357344 fileRanges .add (null );
@@ -362,19 +349,15 @@ public void testNullRange(String pBufferType) throws Exception {
362349 /**
363350 * A null range is not permitted.
364351 */
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 {
369354 verifyExceptionalVectoredRead (
370355 null ,
371356 NullPointerException .class );
372357 }
373358
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 {
378361 List <FileRange > fileRanges = new ArrayList <>();
379362 range (fileRanges , 500 , 100 );
380363 range (fileRanges , 1000 , 200 );
@@ -387,10 +370,8 @@ public void testSomeRandomNonOverlappingRanges(String pBufferType) throws Except
387370 }
388371 }
389372
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 {
394375 List <FileRange > fileRanges = new ArrayList <>();
395376 final int offset = 500 ;
396377 final int length = 2011 ;
@@ -403,10 +384,8 @@ public void testConsecutiveRanges(String pBufferType) throws Exception {
403384 }
404385 }
405386
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 {
410389 List <FileRange > fileRanges = new ArrayList <>();
411390 try (FSDataInputStream in = openVectorFile ()) {
412391 in .readVectored (fileRanges , allocate );
@@ -425,10 +404,8 @@ public void testEmptyRanges(String pBufferType) throws Exception {
425404 * The contract option {@link ContractOptions#VECTOR_IO_EARLY_EOF_CHECK} is used
426405 * to determine which check to perform.
427406 */
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 {
432409 describe ("Testing reading with an offset past the end of the file" );
433410 List <FileRange > fileRanges = range (DATASET_LEN + 1 , 100 );
434411
@@ -441,10 +418,8 @@ public void testEOFRanges(String pBufferType) throws Exception {
441418 }
442419
443420
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 {
448423 describe ("Try to read whole file plus 1 byte" );
449424 List <FileRange > fileRanges = range (0 , DATASET_LEN + 1 );
450425
@@ -471,35 +446,29 @@ private void expectEOFinRead(final List<FileRange> fileRanges) throws Exception
471446 }
472447 }
473448
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+
478452 verifyExceptionalVectoredRead (range (0 , -50 ), IllegalArgumentException .class );
479453 }
480454
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 {
485457 verifyExceptionalVectoredRead (range (-1 , 50 ), EOFException .class );
486458 }
487459
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+
492463 final List <FileRange > range = range (0 , 10 );
493464 try (FSDataInputStream in = openVectorFile ()) {
494- intercept (NullPointerException .class , () ->
495- in .readVectored (range , allocate , null ));
465+ intercept (NullPointerException .class , () ->
466+ in .readVectored (range , allocate , null ));
496467 }
497468 }
498469
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 {
503472 List <FileRange > fileRanges = createSampleNonOverlappingRanges ();
504473 try (FSDataInputStream in = openVectorFile ()) {
505474 in .readVectored (fileRanges , allocate );
@@ -514,10 +483,8 @@ public void testNormalReadAfterVectoredRead(String pBufferType) throws Exception
514483 }
515484 }
516485
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 {
521488 List <FileRange > fileRanges = createSampleNonOverlappingRanges ();
522489 try (FSDataInputStream in = openVectorFile ()) {
523490 // read starting 200 bytes
@@ -532,10 +499,8 @@ public void testVectoredReadAfterNormalRead(String pBufferType) throws Exception
532499 }
533500 }
534501
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 {
539504 List <FileRange > fileRanges1 = createSampleNonOverlappingRanges ();
540505 List <FileRange > fileRanges2 = createSampleNonOverlappingRanges ();
541506 try (FSDataInputStream in = openVectorFile ()) {
@@ -553,10 +518,8 @@ public void testMultipleVectoredReads(String pBufferType) throws Exception {
553518 * operation and then uses a separate thread pool to process the
554519 * results asynchronously.
555520 */
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 {
560523 List <FileRange > fileRanges = new ArrayList <>();
561524 range (fileRanges , 8 * 1024 , 100 );
562525 range (fileRanges , 14 * 1024 , 100 );
0 commit comments