18
18
19
19
package org .apache .hadoop .tools ;
20
20
21
+ import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
22
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
23
+ import static org .junit .jupiter .api .Assertions .assertFalse ;
24
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
25
+
21
26
import org .apache .commons .io .IOUtils ;
22
27
import org .apache .hadoop .conf .Configuration ;
23
28
import org .apache .hadoop .fs .FSDataOutputStream ;
37
42
import org .apache .hadoop .yarn .server .resourcemanager .RMContext ;
38
43
import org .apache .hadoop .yarn .server .resourcemanager .rmapp .RMApp ;
39
44
import org .apache .hadoop .yarn .server .resourcemanager .rmapp .RMAppImpl ;
40
- import org .junit .Assert ;
41
- import org .junit .Test ;
45
+ import org .junit .jupiter . api . Test ;
46
+ import org .junit .jupiter . api . Timeout ;
42
47
43
48
import java .io .File ;
44
49
import java .io .IOException ;
@@ -55,7 +60,8 @@ public class TestHadoopArchiveLogs {
55
60
new Random ().nextBytes (DUMMY_DATA );
56
61
}
57
62
58
- @ Test (timeout = 10000 )
63
+ @ Test
64
+ @ Timeout (value = 10 )
59
65
public void testCheckFilesAndSeedApps () throws Exception {
60
66
Configuration conf = new Configuration ();
61
67
HadoopArchiveLogs hal = new HadoopArchiveLogs (conf );
@@ -64,7 +70,7 @@ public void testCheckFilesAndSeedApps() throws Exception {
64
70
String suffix = "logs" ;
65
71
Path logDir = new Path (rootLogDir , new Path (USER , suffix ));
66
72
fs .delete (logDir , true );
67
- Assert . assertFalse (fs .exists (logDir ));
73
+ assertFalse (fs .exists (logDir ));
68
74
fs .mkdirs (logDir );
69
75
70
76
// no files found
@@ -96,15 +102,16 @@ public void testCheckFilesAndSeedApps() throws Exception {
96
102
createFile (fs , new Path (app5Path , "file1" ), 2 );
97
103
createFile (fs , new Path (app5Path , "file2" ), 3 );
98
104
99
- Assert . assertEquals (0 , hal .eligibleApplications .size ());
105
+ assertEquals (0 , hal .eligibleApplications .size ());
100
106
hal .checkFilesAndSeedApps (fs , rootLogDir , suffix , new Path (rootLogDir ,
101
107
"archive-logs-work" ));
102
- Assert . assertEquals (1 , hal .eligibleApplications .size ());
103
- Assert . assertEquals (appId5 .toString (),
108
+ assertEquals (1 , hal .eligibleApplications .size ());
109
+ assertEquals (appId5 .toString (),
104
110
hal .eligibleApplications .iterator ().next ().getAppId ());
105
111
}
106
112
107
- @ Test (timeout = 10000 )
113
+ @ Test
114
+ @ Timeout (value = 10 )
108
115
public void testCheckMaxEligible () throws Exception {
109
116
Configuration conf = new Configuration ();
110
117
HadoopArchiveLogs .AppInfo app1 = new HadoopArchiveLogs .AppInfo (
@@ -129,46 +136,47 @@ public void testCheckMaxEligible() throws Exception {
129
136
ApplicationId .newInstance (CLUSTER_TIMESTAMP , 7 ).toString (), USER );
130
137
app7 .setFinishTime (CLUSTER_TIMESTAMP );
131
138
HadoopArchiveLogs hal = new HadoopArchiveLogs (conf );
132
- Assert . assertEquals (0 , hal .eligibleApplications .size ());
139
+ assertEquals (0 , hal .eligibleApplications .size ());
133
140
hal .eligibleApplications .add (app1 );
134
141
hal .eligibleApplications .add (app2 );
135
142
hal .eligibleApplications .add (app3 );
136
143
hal .eligibleApplications .add (app4 );
137
144
hal .eligibleApplications .add (app5 );
138
145
hal .eligibleApplications .add (app6 );
139
146
hal .eligibleApplications .add (app7 );
140
- Assert . assertEquals (7 , hal .eligibleApplications .size ());
147
+ assertEquals (7 , hal .eligibleApplications .size ());
141
148
hal .maxEligible = -1 ;
142
149
hal .checkMaxEligible ();
143
- Assert . assertEquals (7 , hal .eligibleApplications .size ());
150
+ assertEquals (7 , hal .eligibleApplications .size ());
144
151
hal .maxEligible = 6 ;
145
152
hal .checkMaxEligible ();
146
- Assert . assertEquals (6 , hal .eligibleApplications .size ());
147
- Assert . assertFalse (hal .eligibleApplications .contains (app5 ));
153
+ assertEquals (6 , hal .eligibleApplications .size ());
154
+ assertFalse (hal .eligibleApplications .contains (app5 ));
148
155
hal .maxEligible = 5 ;
149
156
hal .checkMaxEligible ();
150
- Assert . assertEquals (5 , hal .eligibleApplications .size ());
151
- Assert . assertFalse (hal .eligibleApplications .contains (app4 ));
157
+ assertEquals (5 , hal .eligibleApplications .size ());
158
+ assertFalse (hal .eligibleApplications .contains (app4 ));
152
159
hal .maxEligible = 4 ;
153
160
hal .checkMaxEligible ();
154
- Assert . assertEquals (4 , hal .eligibleApplications .size ());
155
- Assert . assertFalse (hal .eligibleApplications .contains (app7 ));
161
+ assertEquals (4 , hal .eligibleApplications .size ());
162
+ assertFalse (hal .eligibleApplications .contains (app7 ));
156
163
hal .maxEligible = 3 ;
157
164
hal .checkMaxEligible ();
158
- Assert . assertEquals (3 , hal .eligibleApplications .size ());
159
- Assert . assertFalse (hal .eligibleApplications .contains (app1 ));
165
+ assertEquals (3 , hal .eligibleApplications .size ());
166
+ assertFalse (hal .eligibleApplications .contains (app1 ));
160
167
hal .maxEligible = 2 ;
161
168
hal .checkMaxEligible ();
162
- Assert . assertEquals (2 , hal .eligibleApplications .size ());
163
- Assert . assertFalse (hal .eligibleApplications .contains (app2 ));
169
+ assertEquals (2 , hal .eligibleApplications .size ());
170
+ assertFalse (hal .eligibleApplications .contains (app2 ));
164
171
hal .maxEligible = 1 ;
165
172
hal .checkMaxEligible ();
166
- Assert . assertEquals (1 , hal .eligibleApplications .size ());
167
- Assert . assertFalse (hal .eligibleApplications .contains (app6 ));
168
- Assert . assertTrue (hal .eligibleApplications .contains (app3 ));
173
+ assertEquals (1 , hal .eligibleApplications .size ());
174
+ assertFalse (hal .eligibleApplications .contains (app6 ));
175
+ assertTrue (hal .eligibleApplications .contains (app3 ));
169
176
}
170
177
171
- @ Test (timeout = 30000 )
178
+ @ Test
179
+ @ Timeout (value = 30 )
172
180
public void testFilterAppsByAggregatedStatus () throws Exception {
173
181
try (MiniYARNCluster yarnCluster =
174
182
new MiniYARNCluster (TestHadoopArchiveLogs .class .getSimpleName (),
@@ -206,7 +214,7 @@ public void testFilterAppsByAggregatedStatus() throws Exception {
206
214
// appImpl8 is not in the RM
207
215
208
216
HadoopArchiveLogs hal = new HadoopArchiveLogs (conf );
209
- Assert . assertEquals (0 , hal .eligibleApplications .size ());
217
+ assertEquals (0 , hal .eligibleApplications .size ());
210
218
hal .eligibleApplications .add (
211
219
new HadoopArchiveLogs .AppInfo (appImpl1 .getApplicationId ().toString (),
212
220
USER ));
@@ -234,16 +242,17 @@ public void testFilterAppsByAggregatedStatus() throws Exception {
234
242
new HadoopArchiveLogs .AppInfo (appImpl8 .getApplicationId ().toString (),
235
243
USER );
236
244
hal .eligibleApplications .add (app8 );
237
- Assert . assertEquals (8 , hal .eligibleApplications .size ());
245
+ assertEquals (8 , hal .eligibleApplications .size ());
238
246
hal .filterAppsByAggregatedStatus ();
239
- Assert . assertEquals (3 , hal .eligibleApplications .size ());
240
- Assert . assertTrue (hal .eligibleApplications .contains (app4 ));
241
- Assert . assertTrue (hal .eligibleApplications .contains (app7 ));
242
- Assert . assertTrue (hal .eligibleApplications .contains (app8 ));
247
+ assertEquals (3 , hal .eligibleApplications .size ());
248
+ assertTrue (hal .eligibleApplications .contains (app4 ));
249
+ assertTrue (hal .eligibleApplications .contains (app7 ));
250
+ assertTrue (hal .eligibleApplications .contains (app8 ));
243
251
}
244
252
}
245
253
246
- @ Test (timeout = 10000 )
254
+ @ Test
255
+ @ Timeout (value = 10 )
247
256
public void testGenerateScript () throws Exception {
248
257
_testGenerateScript (false );
249
258
_testGenerateScript (true );
@@ -276,59 +285,59 @@ private void _testGenerateScript(boolean proxy) throws Exception {
276
285
277
286
File localScript = new File ("target" , "script.sh" );
278
287
localScript .delete ();
279
- Assert . assertFalse (localScript .exists ());
288
+ assertFalse (localScript .exists ());
280
289
hal .generateScript (localScript );
281
- Assert . assertTrue (localScript .exists ());
290
+ assertTrue (localScript .exists ());
282
291
String script = IOUtils .toString (localScript .toURI (), StandardCharsets .UTF_8 );
283
292
String [] lines = script .split ("\n " );
284
- Assert . assertEquals (22 , lines .length );
285
- Assert . assertEquals ("#!/bin/bash" , lines [0 ]);
286
- Assert . assertEquals ("set -e" , lines [1 ]);
287
- Assert . assertEquals ("set -x" , lines [2 ]);
288
- Assert . assertEquals ("if [ \" $YARN_SHELL_ID\" == \" 1\" ]; then" , lines [3 ]);
293
+ assertEquals (22 , lines .length );
294
+ assertEquals ("#!/bin/bash" , lines [0 ]);
295
+ assertEquals ("set -e" , lines [1 ]);
296
+ assertEquals ("set -x" , lines [2 ]);
297
+ assertEquals ("if [ \" $YARN_SHELL_ID\" == \" 1\" ]; then" , lines [3 ]);
289
298
boolean oneBefore = true ;
290
299
if (lines [4 ].contains (app1 .toString ())) {
291
- Assert . assertEquals ("\t appId=\" " + app1 .toString () + "\" " , lines [4 ]);
292
- Assert . assertEquals ("\t appId=\" " + app2 .toString () + "\" " , lines [10 ]);
300
+ assertEquals ("\t appId=\" " + app1 .toString () + "\" " , lines [4 ]);
301
+ assertEquals ("\t appId=\" " + app2 .toString () + "\" " , lines [10 ]);
293
302
} else {
294
303
oneBefore = false ;
295
- Assert . assertEquals ("\t appId=\" " + app2 .toString () + "\" " , lines [4 ]);
296
- Assert . assertEquals ("\t appId=\" " + app1 .toString () + "\" " , lines [10 ]);
304
+ assertEquals ("\t appId=\" " + app2 .toString () + "\" " , lines [4 ]);
305
+ assertEquals ("\t appId=\" " + app1 .toString () + "\" " , lines [10 ]);
297
306
}
298
- Assert . assertEquals ("\t user=\" " + USER + "\" " , lines [5 ]);
299
- Assert . assertEquals ("\t workingDir=\" " + (oneBefore ? workingDir .toString ()
307
+ assertEquals ("\t user=\" " + USER + "\" " , lines [5 ]);
308
+ assertEquals ("\t workingDir=\" " + (oneBefore ? workingDir .toString ()
300
309
: workingDir2 .toString ()) + "\" " , lines [6 ]);
301
- Assert . assertEquals ("\t remoteRootLogDir=\" " + (oneBefore
310
+ assertEquals ("\t remoteRootLogDir=\" " + (oneBefore
302
311
? remoteRootLogDir .toString () : remoteRootLogDir2 .toString ())
303
312
+ "\" " , lines [7 ]);
304
- Assert . assertEquals ("\t suffix=\" " + (oneBefore ? suffix : suffix2 )
313
+ assertEquals ("\t suffix=\" " + (oneBefore ? suffix : suffix2 )
305
314
+ "\" " , lines [8 ]);
306
- Assert . assertEquals ("elif [ \" $YARN_SHELL_ID\" == \" 2\" ]; then" ,
315
+ assertEquals ("elif [ \" $YARN_SHELL_ID\" == \" 2\" ]; then" ,
307
316
lines [9 ]);
308
- Assert . assertEquals ("\t user=\" " + USER + "\" " , lines [11 ]);
309
- Assert . assertEquals ("\t workingDir=\" " + (oneBefore
317
+ assertEquals ("\t user=\" " + USER + "\" " , lines [11 ]);
318
+ assertEquals ("\t workingDir=\" " + (oneBefore
310
319
? workingDir2 .toString () : workingDir .toString ()) + "\" " ,
311
320
lines [12 ]);
312
- Assert . assertEquals ("\t remoteRootLogDir=\" " + (oneBefore
321
+ assertEquals ("\t remoteRootLogDir=\" " + (oneBefore
313
322
? remoteRootLogDir2 .toString () : remoteRootLogDir .toString ())
314
323
+ "\" " , lines [13 ]);
315
- Assert . assertEquals ("\t suffix=\" " + (oneBefore ? suffix2 : suffix )
324
+ assertEquals ("\t suffix=\" " + (oneBefore ? suffix2 : suffix )
316
325
+ "\" " , lines [14 ]);
317
- Assert . assertEquals ("else" , lines [15 ]);
318
- Assert . assertEquals ("\t echo \" Unknown Mapping!\" " , lines [16 ]);
319
- Assert . assertEquals ("\t exit 1" , lines [17 ]);
320
- Assert . assertEquals ("fi" , lines [18 ]);
321
- Assert . assertEquals ("export HADOOP_CLIENT_OPTS=\" -Xmx1024m\" " , lines [19 ]);
322
- Assert . assertTrue (lines [20 ].startsWith ("export HADOOP_CLASSPATH=" ));
326
+ assertEquals ("else" , lines [15 ]);
327
+ assertEquals ("\t echo \" Unknown Mapping!\" " , lines [16 ]);
328
+ assertEquals ("\t exit 1" , lines [17 ]);
329
+ assertEquals ("fi" , lines [18 ]);
330
+ assertEquals ("export HADOOP_CLIENT_OPTS=\" -Xmx1024m\" " , lines [19 ]);
331
+ assertTrue (lines [20 ].startsWith ("export HADOOP_CLASSPATH=" ));
323
332
if (proxy ) {
324
- Assert . assertEquals (
333
+ assertEquals (
325
334
"\" $HADOOP_HOME\" /bin/hadoop org.apache.hadoop.tools." +
326
335
"HadoopArchiveLogsRunner -appId \" $appId\" -user \" $user\" " +
327
336
"-workingDir \" $workingDir\" -remoteRootLogDir " +
328
337
"\" $remoteRootLogDir\" -suffix \" $suffix\" " ,
329
338
lines [21 ]);
330
339
} else {
331
- Assert . assertEquals (
340
+ assertEquals (
332
341
"\" $HADOOP_HOME\" /bin/hadoop org.apache.hadoop.tools." +
333
342
"HadoopArchiveLogsRunner -appId \" $appId\" -user \" $user\" " +
334
343
"-workingDir \" $workingDir\" -remoteRootLogDir " +
@@ -343,7 +352,8 @@ private void _testGenerateScript(boolean proxy) throws Exception {
343
352
* are updated as well, if necessary.
344
353
* @throws Exception
345
354
*/
346
- @ Test (timeout = 5000 )
355
+ @ Test
356
+ @ Timeout (value = 5 )
347
357
public void testStatuses () throws Exception {
348
358
LogAggregationStatus [] statuses = new LogAggregationStatus [7 ];
349
359
statuses [0 ] = LogAggregationStatus .DISABLED ;
@@ -353,51 +363,52 @@ public void testStatuses() throws Exception {
353
363
statuses [4 ] = LogAggregationStatus .SUCCEEDED ;
354
364
statuses [5 ] = LogAggregationStatus .FAILED ;
355
365
statuses [6 ] = LogAggregationStatus .TIME_OUT ;
356
- Assert . assertArrayEquals (statuses , LogAggregationStatus .values ());
366
+ assertArrayEquals (statuses , LogAggregationStatus .values ());
357
367
}
358
368
359
- @ Test (timeout = 5000 )
369
+ @ Test
370
+ @ Timeout (value = 5 )
360
371
public void testPrepareWorkingDir () throws Exception {
361
372
Configuration conf = new Configuration ();
362
373
HadoopArchiveLogs hal = new HadoopArchiveLogs (conf );
363
374
FileSystem fs = FileSystem .getLocal (conf );
364
375
Path workingDir = new Path ("target" , "testPrepareWorkingDir" );
365
376
fs .delete (workingDir , true );
366
- Assert . assertFalse (fs .exists (workingDir ));
377
+ assertFalse (fs .exists (workingDir ));
367
378
// -force is false and the dir doesn't exist so it will create one
368
379
hal .force = false ;
369
380
boolean dirPrepared = hal .prepareWorkingDir (fs , workingDir );
370
- Assert . assertTrue (dirPrepared );
371
- Assert . assertTrue (fs .exists (workingDir ));
372
- Assert . assertEquals (
381
+ assertTrue (dirPrepared );
382
+ assertTrue (fs .exists (workingDir ));
383
+ assertEquals (
373
384
new FsPermission (FsAction .ALL , FsAction .ALL , FsAction .ALL ,
374
385
!Shell .WINDOWS ),
375
386
fs .getFileStatus (workingDir ).getPermission ());
376
387
// Throw a file in the dir
377
388
Path dummyFile = new Path (workingDir , "dummy.txt" );
378
389
fs .createNewFile (dummyFile );
379
- Assert . assertTrue (fs .exists (dummyFile ));
390
+ assertTrue (fs .exists (dummyFile ));
380
391
// -force is false and the dir exists, so nothing will happen and the dummy
381
392
// still exists
382
393
dirPrepared = hal .prepareWorkingDir (fs , workingDir );
383
- Assert . assertFalse (dirPrepared );
384
- Assert . assertTrue (fs .exists (workingDir ));
385
- Assert . assertTrue (fs .exists (dummyFile ));
386
- Assert . assertEquals (
394
+ assertFalse (dirPrepared );
395
+ assertTrue (fs .exists (workingDir ));
396
+ assertTrue (fs .exists (dummyFile ));
397
+ assertEquals (
387
398
new FsPermission (FsAction .ALL , FsAction .ALL , FsAction .ALL ,
388
399
!Shell .WINDOWS ),
389
400
fs .getFileStatus (workingDir ).getPermission ());
390
401
// -force is true and the dir exists, so it will recreate it and the dummy
391
402
// won't exist anymore
392
403
hal .force = true ;
393
404
dirPrepared = hal .prepareWorkingDir (fs , workingDir );
394
- Assert . assertTrue (dirPrepared );
395
- Assert . assertTrue (fs .exists (workingDir ));
396
- Assert . assertEquals (
405
+ assertTrue (dirPrepared );
406
+ assertTrue (fs .exists (workingDir ));
407
+ assertEquals (
397
408
new FsPermission (FsAction .ALL , FsAction .ALL , FsAction .ALL ,
398
409
!Shell .WINDOWS ),
399
410
fs .getFileStatus (workingDir ).getPermission ());
400
- Assert . assertFalse (fs .exists (dummyFile ));
411
+ assertFalse (fs .exists (dummyFile ));
401
412
}
402
413
403
414
private static void createFile (FileSystem fs , Path p , long sizeMultiple )
@@ -413,7 +424,7 @@ private static void createFile(FileSystem fs, Path p, long sizeMultiple)
413
424
out .close ();
414
425
}
415
426
}
416
- Assert . assertTrue (fs .exists (p ));
427
+ assertTrue (fs .exists (p ));
417
428
}
418
429
419
430
private static RMApp createRMApp (int id , Configuration conf , RMContext rmContext ,
0 commit comments