18
18
19
19
package org .apache .hadoop .tools ;
20
20
21
+ import static org .assertj .core .api .Assertions .assertThat ;
22
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
23
+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
21
24
import static org .junit .jupiter .api .Assertions .assertThrows ;
22
- import static org .mockito .Mockito .*;
25
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
26
+ import static org .junit .jupiter .api .Assertions .fail ;
27
+ import static org .mockito .Mockito .doThrow ;
28
+ import static org .mockito .Mockito .mock ;
23
29
24
30
import org .apache .hadoop .hdfs .protocol .SnapshotDiffReport ;
25
31
import org .mockito .Mockito ;
34
40
import org .apache .hadoop .io .SequenceFile ;
35
41
import org .apache .hadoop .io .IOUtils ;
36
42
import org .apache .hadoop .io .Text ;
37
- import org .junit .runner .RunWith ;
38
- import org .junit .runners .Parameterized ;
39
- import org .junit .runners .Parameterized .Parameters ;
40
- import org .junit .jupiter .api .Test ;
41
43
import org .junit .jupiter .api .Timeout ;
42
- import org .junit .jupiter .api .Assertions ;
43
44
import org .junit .jupiter .api .BeforeAll ;
44
45
import org .junit .jupiter .api .AfterAll ;
45
- import static org .assertj .core .api .Assertions .assertThat ;
46
+ import org .junit .jupiter .params .ParameterizedTest ;
47
+ import org .junit .jupiter .params .provider .MethodSource ;
46
48
47
49
import java .io .File ;
48
50
import java .io .IOException ;
54
56
import java .util .List ;
55
57
import java .util .Random ;
56
58
57
- @ RunWith (value = Parameterized .class )
58
59
public class TestCopyListing extends SimpleCopyListing {
59
60
private static final Logger LOG = LoggerFactory .getLogger (TestCopyListing .class );
60
61
@@ -76,18 +77,18 @@ public static void destroy() {
76
77
}
77
78
}
78
79
79
- @ Parameters
80
80
public static Collection <Object []> data () {
81
- Object [][] data = new Object [][] { { 1 }, { 2 }, { 10 }, { 20 } };
81
+ Object [][] data = new Object [][]{{ 1 }, {2 }, {10 }, {20 }};
82
82
return Arrays .asList (data );
83
83
}
84
84
85
- public TestCopyListing (int numListstatusThreads ) {
86
- super (config , CREDENTIALS , numListstatusThreads , 0 , false );
85
+ public TestCopyListing () {
86
+ super (config , CREDENTIALS , 1 , 0 , false );
87
87
}
88
88
89
- protected TestCopyListing (Configuration configuration ) {
90
- super (configuration , CREDENTIALS );
89
+ public void initTestCopyListing (int numListstatusThreads ) {
90
+ initSimpleCopyListing (config , CREDENTIALS ,
91
+ numListstatusThreads , 0 , false );
91
92
}
92
93
93
94
@ Override
@@ -100,9 +101,12 @@ protected long getNumberOfPaths() {
100
101
return 0 ;
101
102
}
102
103
103
- @ Test
104
+
104
105
@ Timeout (value = 10 )
105
- public void testMultipleSrcToFile () {
106
+ @ ParameterizedTest
107
+ @ MethodSource ("data" )
108
+ public void testMultipleSrcToFile (int pNumListstatusThreads ) {
109
+ initTestCopyListing (pNumListstatusThreads );
106
110
FileSystem fs = null ;
107
111
try {
108
112
fs = FileSystem .get (getConf ());
@@ -122,7 +126,7 @@ public void testMultipleSrcToFile() {
122
126
fs .create (target ).close ();
123
127
try {
124
128
validatePaths (new DistCpContext (options ));
125
- Assertions . fail ("Invalid inputs accepted" );
129
+ fail ("Invalid inputs accepted" );
126
130
} catch (InvalidInputException ignore ) { }
127
131
TestDistCpUtils .delete (fs , "/tmp" );
128
132
@@ -132,20 +136,22 @@ public void testMultipleSrcToFile() {
132
136
fs .create (target ).close ();
133
137
try {
134
138
validatePaths (new DistCpContext (options ));
135
- Assertions . fail ("Invalid inputs accepted" );
139
+ fail ("Invalid inputs accepted" );
136
140
} catch (InvalidInputException ignore ) { }
137
141
TestDistCpUtils .delete (fs , "/tmp" );
138
142
} catch (IOException e ) {
139
143
LOG .error ("Exception encountered " , e );
140
- Assertions . fail ("Test input validation failed" );
144
+ fail ("Test input validation failed" );
141
145
} finally {
142
146
TestDistCpUtils .delete (fs , "/tmp" );
143
147
}
144
148
}
145
149
146
- @ Test
150
+ @ ParameterizedTest
147
151
@ Timeout (value = 10 )
148
- public void testDuplicates () {
152
+ @ MethodSource ("data" )
153
+ public void testDuplicates (int pNumListstatusThreads ) {
154
+ initTestCopyListing (pNumListstatusThreads );
149
155
FileSystem fs = null ;
150
156
try {
151
157
fs = FileSystem .get (getConf ());
@@ -162,20 +168,23 @@ public void testDuplicates() {
162
168
context );
163
169
try {
164
170
listing .buildListing (listingFile , context );
165
- Assertions . fail ("Duplicates not detected" );
171
+ fail ("Duplicates not detected" );
166
172
} catch (DuplicateFileException ignore ) {
167
173
}
168
174
} catch (IOException e ) {
169
175
LOG .error ("Exception encountered in test" , e );
170
- Assertions . fail ("Test failed " + e .getMessage ());
176
+ fail ("Test failed " + e .getMessage ());
171
177
} finally {
172
178
TestDistCpUtils .delete (fs , "/tmp" );
173
179
}
174
180
}
175
181
176
- @ Test
182
+ @ ParameterizedTest
177
183
@ Timeout (value = 10 )
178
- public void testDiffBasedSimpleCopyListing () throws IOException {
184
+ @ MethodSource ("data" )
185
+ public void testDiffBasedSimpleCopyListing (int pNumListstatusThreads )
186
+ throws IOException {
187
+ initTestCopyListing (pNumListstatusThreads );
179
188
assertThrows (DuplicateFileException .class , () -> {
180
189
FileSystem fs = null ;
181
190
Configuration configuration = getConf ();
@@ -194,10 +203,12 @@ public void testDiffBasedSimpleCopyListing() throws IOException {
194
203
});
195
204
}
196
205
197
- @ Test
206
+ @ ParameterizedTest
198
207
@ Timeout (value = 10 )
199
- public void testDiffBasedSimpleCopyListingWithoutTraverseDirectory ()
200
- throws IOException {
208
+ @ MethodSource ("data" )
209
+ public void testDiffBasedSimpleCopyListingWithoutTraverseDirectory (
210
+ int pNumListstatusThreads ) throws IOException {
211
+ initTestCopyListing (pNumListstatusThreads );
201
212
FileSystem fs = null ;
202
213
Configuration configuration = getConf ();
203
214
DistCpSync distCpSync = Mockito .mock (DistCpSync .class );
@@ -243,8 +254,10 @@ private void buildListingUsingSnapshotDiff(FileSystem fs,
243
254
listing .buildListing (listingFile , context );
244
255
}
245
256
246
- @ Test
247
- public void testDuplicateSourcePaths () throws Exception {
257
+ @ ParameterizedTest
258
+ @ MethodSource ("data" )
259
+ public void testDuplicateSourcePaths (int pNumListstatusThreads ) throws Exception {
260
+ initTestCopyListing (pNumListstatusThreads );
248
261
FileSystem fs = FileSystem .get (getConf ());
249
262
List <Path > srcPaths = new ArrayList <Path >();
250
263
try {
@@ -260,15 +273,17 @@ public void testDuplicateSourcePaths() throws Exception {
260
273
CopyListing listing =
261
274
CopyListing .getCopyListing (getConf (), CREDENTIALS , context );
262
275
listing .buildListing (listingFile , context );
263
- Assertions . assertTrue (fs .exists (listingFile ));
276
+ assertTrue (fs .exists (listingFile ));
264
277
} finally {
265
278
TestDistCpUtils .delete (fs , "/tmp" );
266
279
}
267
280
}
268
281
269
- @ Test
282
+ @ ParameterizedTest
270
283
@ Timeout (value = 10 )
271
- public void testBuildListing () {
284
+ @ MethodSource ("data" )
285
+ public void testBuildListing (int pNumListstatusThreads ) {
286
+ initTestCopyListing (pNumListstatusThreads );
272
287
FileSystem fs = null ;
273
288
try {
274
289
fs = FileSystem .get (getConf ());
@@ -303,7 +318,7 @@ public void testBuildListing() {
303
318
CopyListing listing = new SimpleCopyListing (getConf (), CREDENTIALS );
304
319
try {
305
320
listing .buildListing (listingFile , new DistCpContext (options ));
306
- Assertions . fail ("Duplicates not detected" );
321
+ fail ("Duplicates not detected" );
307
322
} catch (DuplicateFileException ignore ) {
308
323
}
309
324
assertThat (listing .getBytesToCopy ()).isEqualTo (10 );
@@ -312,21 +327,24 @@ public void testBuildListing() {
312
327
313
328
try {
314
329
listing .buildListing (listingFile , new DistCpContext (options ));
315
- Assertions . fail ("Invalid input not detected" );
330
+ fail ("Invalid input not detected" );
316
331
} catch (InvalidInputException ignore ) {
317
332
}
318
333
TestDistCpUtils .delete (fs , "/tmp" );
319
334
} catch (IOException e ) {
320
335
LOG .error ("Exception encountered " , e );
321
- Assertions . fail ("Test build listing failed" );
336
+ fail ("Test build listing failed" );
322
337
} finally {
323
338
TestDistCpUtils .delete (fs , "/tmp" );
324
339
}
325
340
}
326
341
327
- @ Test
342
+ @ ParameterizedTest
328
343
@ Timeout (value = 60 )
329
- public void testWithRandomFileListing () throws IOException {
344
+ @ MethodSource ("data" )
345
+ public void testWithRandomFileListing (int pNumListstatusThreads )
346
+ throws IOException {
347
+ initTestCopyListing (pNumListstatusThreads );
330
348
FileSystem fs = null ;
331
349
try {
332
350
fs = FileSystem .get (getConf ());
@@ -356,7 +374,7 @@ public void testWithRandomFileListing() throws IOException {
356
374
SimpleCopyListing listing = new SimpleCopyListing (getConf (), CREDENTIALS );
357
375
listing .buildListing (listingFile , new DistCpContext (options ));
358
376
359
- Assertions . assertEquals (listing .getNumberOfPaths (), pathCount );
377
+ assertEquals (listing .getNumberOfPaths (), pathCount );
360
378
validateFinalListing (listingFile , srcFiles );
361
379
fs .delete (listingFile , true );
362
380
@@ -369,7 +387,7 @@ public void testWithRandomFileListing() throws IOException {
369
387
long seed = System .nanoTime ();
370
388
listing .setSeedForRandomListing (seed );
371
389
listing .buildListing (listingFile , new DistCpContext (options ));
372
- Assertions . assertEquals (listing .getNumberOfPaths (), pathCount );
390
+ assertEquals (listing .getNumberOfPaths (), pathCount );
373
391
374
392
// validate randomness
375
393
Collections .shuffle (srcFiles , new Random (seed ));
@@ -391,7 +409,7 @@ private void validateFinalListing(Path pathToListFile, List<Path> srcFiles)
391
409
int idx = 0 ;
392
410
while (reader .next (currentKey )) {
393
411
reader .getCurrentValue (currentVal );
394
- Assertions . assertEquals (fs .makeQualified (srcFiles .get (idx ))
412
+ assertEquals (fs .makeQualified (srcFiles .get (idx ))
395
413
, currentVal .getPath (), "srcFiles.size=" + srcFiles .size ()
396
414
+ ", idx=" + idx );
397
415
if (LOG .isDebugEnabled ()) {
@@ -403,9 +421,11 @@ private void validateFinalListing(Path pathToListFile, List<Path> srcFiles)
403
421
}
404
422
405
423
406
- @ Test
424
+ @ ParameterizedTest
407
425
@ Timeout (value = 10 )
408
- public void testBuildListingForSingleFile () {
426
+ @ MethodSource ("data" )
427
+ public void testBuildListingForSingleFile (int pNumListstatusThreads ) {
428
+ initTestCopyListing (pNumListstatusThreads );
409
429
FileSystem fs = null ;
410
430
String testRootString = "/singleFileListing" ;
411
431
Path testRoot = new Path (testRootString );
@@ -437,21 +457,23 @@ public void testBuildListingForSingleFile() {
437
457
438
458
CopyListingFileStatus fileStatus = new CopyListingFileStatus ();
439
459
Text relativePath = new Text ();
440
- Assertions . assertTrue (reader .next (relativePath , fileStatus ));
441
- Assertions . assertTrue (relativePath .toString ().equals ("" ));
460
+ assertTrue (reader .next (relativePath , fileStatus ));
461
+ assertTrue (relativePath .toString ().equals ("" ));
442
462
}
443
463
catch (Exception e ) {
444
- Assertions . fail ("Unexpected exception encountered." );
464
+ fail ("Unexpected exception encountered." );
445
465
LOG .error ("Unexpected exception: " , e );
446
466
}
447
467
finally {
448
468
TestDistCpUtils .delete (fs , testRootString );
449
469
IOUtils .closeStream (reader );
450
470
}
451
471
}
452
-
453
- @ Test
454
- public void testFailOnCloseError () throws IOException {
472
+
473
+ @ ParameterizedTest
474
+ @ MethodSource ("data" )
475
+ public void testFailOnCloseError (int pNumListstatusThreads ) throws IOException {
476
+ initTestCopyListing (pNumListstatusThreads );
455
477
File inFile = File .createTempFile ("TestCopyListingIn" , null );
456
478
inFile .deleteOnExit ();
457
479
File outFile = File .createTempFile ("TestCopyListingOut" , null );
@@ -472,7 +494,7 @@ public void testFailOnCloseError() throws IOException {
472
494
} catch (Exception e ) {
473
495
actualEx = e ;
474
496
}
475
- Assertions . assertNotNull (actualEx , "close writer didn't fail" );
476
- Assertions . assertEquals (expectedEx , actualEx );
497
+ assertNotNull (actualEx , "close writer didn't fail" );
498
+ assertEquals (expectedEx , actualEx );
477
499
}
478
500
}
0 commit comments