51
51
import org .apache .hadoop .yarn .service .conf .YarnServiceConf ;
52
52
import org .apache .hadoop .yarn .util .DockerClientConfigHandler ;
53
53
import org .apache .hadoop .yarn .util .resource .ResourceUtils ;
54
- import org .junit .After ;
55
- import org .junit .Assert ;
56
- import org .junit .Before ;
57
- import org .junit .Rule ;
58
- import org .junit .Test ;
54
+ import org .junit .jupiter . api . AfterEach ;
55
+ import org .junit .jupiter . api . BeforeEach ;
56
+ import org .junit .jupiter . api . Test ;
57
+ import org .junit .jupiter . api . Timeout ;
58
+ import org .junit .jupiter . api . extension . RegisterExtension ;
59
59
import org .mockito .Mockito ;
60
60
import org .slf4j .Logger ;
61
61
import org .slf4j .LoggerFactory ;
71
71
import java .util .concurrent .TimeoutException ;
72
72
73
73
import static org .apache .hadoop .registry .client .api .RegistryConstants .KEY_REGISTRY_ZK_QUORUM ;
74
- import static org .junit .Assert .assertEquals ;
74
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
75
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
76
+ import static org .junit .jupiter .api .Assertions .fail ;
75
77
import static org .mockito .Mockito .times ;
76
78
import static org .mockito .Mockito .verify ;
77
79
@@ -83,11 +85,11 @@ public class TestServiceAM extends ServiceTestUtils{
83
85
private File basedir ;
84
86
YarnConfiguration conf = new YarnConfiguration ();
85
87
TestingCluster zkCluster ;
86
- @ Rule
87
- public ServiceTestUtils .ServiceFSWatcher rule =
88
+ @ RegisterExtension
89
+ private ServiceTestUtils .ServiceFSWatcher rule =
88
90
new ServiceTestUtils .ServiceFSWatcher ();
89
91
90
- @ Before
92
+ @ BeforeEach
91
93
public void setup () throws Exception {
92
94
basedir = new File ("target" , "apps" );
93
95
if (basedir .exists ()) {
@@ -101,7 +103,7 @@ public void setup() throws Exception {
101
103
LOG .info ("ZK cluster: {}" , zkCluster .getConnectString ());
102
104
}
103
105
104
- @ After
106
+ @ AfterEach
105
107
public void tearDown () throws IOException {
106
108
if (basedir != null ) {
107
109
FileUtils .deleteDirectory (basedir );
@@ -147,15 +149,15 @@ public void testContainerCompleted() throws TimeoutException,
147
149
148
150
am .waitForCompInstanceState (compa0 , ComponentInstanceState .INIT );
149
151
// still 1 pending instance
150
- Assert .assertEquals (1 ,
151
- am .getComponent ("compa" ).getPendingInstances ().size ());
152
+ assertEquals (1 , am .getComponent ("compa" ).getPendingInstances ().size ());
152
153
am .stop ();
153
154
}
154
155
155
156
// Test to verify that the containers of previous attempt are not prematurely
156
157
// released. These containers are sent by the RM to the AM in the
157
158
// heartbeat response.
158
- @ Test (timeout = 200000 )
159
+ @ Test
160
+ @ Timeout (value = 200 )
159
161
public void testContainersFromPreviousAttemptsWithRMRestart ()
160
162
throws Exception {
161
163
ApplicationId applicationId = ApplicationId .newInstance (
@@ -182,23 +184,23 @@ public void testContainersFromPreviousAttemptsWithRMRestart()
182
184
am .waitForCompInstanceState (comp10 , ComponentInstanceState .STARTED );
183
185
184
186
// 0 pending instance
185
- Assert . assertEquals (0 ,
187
+ assertEquals (0 ,
186
188
am .getComponent (comp1Name ).getPendingInstances ().size ());
187
189
188
190
GenericTestUtils .waitFor (() -> am .getCompInstance (comp1Name , comp1InstName )
189
191
.getContainerStatus () != null , 2000 , 200000 );
190
192
191
- Assert .assertEquals ("container state" ,
192
- org .apache .hadoop .yarn .api .records .ContainerState .RUNNING ,
193
+ assertEquals (org .apache .hadoop .yarn .api .records .ContainerState .RUNNING ,
193
194
am .getCompInstance (comp1Name , comp1InstName ).getContainerStatus ()
194
- .getState ());
195
+ .getState (), "container state" );
195
196
am .stop ();
196
197
}
197
198
198
199
// Test to verify that the containers of previous attempt are released and the
199
200
// component instance is added to the pending queue when the recovery wait
200
201
// time interval elapses.
201
- @ Test (timeout = 200000 )
202
+ @ Test
203
+ @ Timeout (value = 200 )
202
204
public void testContainersReleasedWhenExpired ()
203
205
throws Exception {
204
206
ApplicationId applicationId = ApplicationId .newInstance (
@@ -225,22 +227,22 @@ public void testContainersReleasedWhenExpired()
225
227
.equals (ComponentState .FLEXING ), 100 , 2000 );
226
228
227
229
// 1 pending instance
228
- Assert . assertEquals (1 , am .getComponent (comp1Name ).getPendingInstances ()
230
+ assertEquals (1 , am .getComponent (comp1Name ).getPendingInstances ()
229
231
.size ());
230
232
231
233
am .feedContainerToComp (exampleApp , 2 , comp1Name );
232
234
233
235
GenericTestUtils .waitFor (() -> am .getCompInstance (comp1Name , comp1InstName )
234
236
.getContainerStatus () != null , 2000 , 200000 );
235
- Assert .assertEquals ("container state" ,
236
- org .apache .hadoop .yarn .api .records .ContainerState .RUNNING ,
237
+ assertEquals (org .apache .hadoop .yarn .api .records .ContainerState .RUNNING ,
237
238
am .getCompInstance (comp1Name , comp1InstName ).getContainerStatus ()
238
- .getState ());
239
+ .getState (), "container state" );
239
240
}
240
241
241
242
// Test to verify that the AM doesn't wait for containers of a different app
242
243
// even though it corresponds to the same service.
243
- @ Test (timeout = 200000 )
244
+ @ Test
245
+ @ Timeout (value = 200 )
244
246
public void testContainersFromDifferentApp ()
245
247
throws Exception {
246
248
ApplicationId applicationId = ApplicationId .newInstance (
@@ -268,17 +270,16 @@ public void testContainersFromDifferentApp()
268
270
am .start ();
269
271
// 1 pending instance since the container in registry belongs to a different
270
272
// app.
271
- Assert . assertEquals (1 ,
273
+ assertEquals (1 ,
272
274
am .getComponent (comp1Name ).getPendingInstances ().size ());
273
275
274
276
am .feedContainerToComp (exampleApp , 1 , comp1Name );
275
277
GenericTestUtils .waitFor (() -> am .getCompInstance (comp1Name , comp1InstName )
276
278
.getContainerStatus () != null , 2000 , 200000 );
277
279
278
- Assert .assertEquals ("container state" ,
279
- org .apache .hadoop .yarn .api .records .ContainerState .RUNNING ,
280
+ assertEquals (org .apache .hadoop .yarn .api .records .ContainerState .RUNNING ,
280
281
am .getCompInstance (comp1Name , comp1InstName ).getContainerStatus ()
281
- .getState ());
282
+ .getState (), "container state" );
282
283
am .stop ();
283
284
}
284
285
@@ -314,13 +315,12 @@ public void testScheduleWithMultipleResourceTypes()
314
315
315
316
Collection <AMRMClient .ContainerRequest > rr =
316
317
amrmClientAsync .getMatchingRequests (0 );
317
- Assert . assertEquals (1 , rr .size ());
318
+ assertEquals (1 , rr .size ());
318
319
319
320
org .apache .hadoop .yarn .api .records .Resource capability =
320
321
rr .iterator ().next ().getCapability ();
321
- Assert .assertEquals (3333L , capability .getResourceValue ("resource-1" ));
322
- Assert .assertEquals ("Gi" ,
323
- capability .getResourceInformation ("resource-1" ).getUnits ());
322
+ assertEquals (3333L , capability .getResourceValue ("resource-1" ));
323
+ assertEquals ("Gi" , capability .getResourceInformation ("resource-1" ).getUnits ());
324
324
325
325
am .stop ();
326
326
}
@@ -432,8 +432,7 @@ public void testRecordTokensForContainers() throws Exception {
432
432
433
433
assertEquals (2 , amCreds .numberOfTokens ());
434
434
for (Token <? extends TokenIdentifier > tk : amCreds .getAllTokens ()) {
435
- Assert .assertTrue (
436
- tk .getKind ().equals (DockerCredentialTokenIdentifier .KIND ));
435
+ assertTrue (tk .getKind ().equals (DockerCredentialTokenIdentifier .KIND ));
437
436
}
438
437
439
438
am .stop ();
@@ -463,7 +462,7 @@ public void testIPChange() throws TimeoutException,
463
462
GenericTestUtils .waitFor (() -> comp1inst0 .getContainerStatus () != null ,
464
463
2000 , 200000 );
465
464
// first host status will match the container nodeId
466
- Assert . assertEquals ("localhost" ,
465
+ assertEquals ("localhost" ,
467
466
comp1inst0 .getContainerStatus ().getHost ());
468
467
469
468
LOG .info ("Change the IP and host" );
@@ -491,7 +490,8 @@ public void testIPChange() throws TimeoutException,
491
490
In case the id is set to null or unset so it is effectively null,
492
491
Path.checkPathArg throws an IllegalArgumentException.
493
492
**/
494
- @ Test (timeout = 30000 )
493
+ @ Test
494
+ @ Timeout (value = 30 )
495
495
public void testContainersReleasedWhenPreLaunchFails ()
496
496
throws Exception {
497
497
ApplicationId applicationId = ApplicationId .newInstance (
@@ -522,12 +522,12 @@ public void testContainersReleasedWhenPreLaunchFails()
522
522
am .getComponent (compA .getName ()).getPendingInstances ()
523
523
.contains (compAinst0 ), 2000 , 30000 );
524
524
525
- Assert .assertEquals (1 ,
526
- am .getComponent ("compa" ).getPendingInstances ().size ());
525
+ assertEquals (1 , am .getComponent ("compa" ).getPendingInstances ().size ());
527
526
am .stop ();
528
527
}
529
528
530
- @ Test (timeout = 30000 )
529
+ @ Test
530
+ @ Timeout (value = 30 )
531
531
public void testSyncSysFS () {
532
532
ApplicationId applicationId = ApplicationId .newInstance (
533
533
System .currentTimeMillis (), 1 );
@@ -554,7 +554,7 @@ public void testSyncSysFS() {
554
554
am .close ();
555
555
} catch (Exception e ) {
556
556
LOG .error ("Fail to sync sysfs." , e );
557
- Assert . fail ("Fail to sync sysfs." );
557
+ fail ("Fail to sync sysfs." );
558
558
}
559
559
}
560
560
@@ -593,14 +593,14 @@ public void testScheduleWithResourceAttributes() throws Exception {
593
593
594
594
Collection <AMRMClient .ContainerRequest > rr =
595
595
amrmClientAsync .getMatchingRequests (0 );
596
- Assert . assertEquals (1 , rr .size ());
596
+ assertEquals (1 , rr .size ());
597
597
598
598
org .apache .hadoop .yarn .api .records .Resource capability =
599
599
rr .iterator ().next ().getCapability ();
600
- Assert . assertEquals (1234L , capability .getResourceValue ("test-resource" ));
601
- Assert . assertEquals ("Gi" ,
600
+ assertEquals (1234L , capability .getResourceValue ("test-resource" ));
601
+ assertEquals ("Gi" ,
602
602
capability .getResourceInformation ("test-resource" ).getUnits ());
603
- Assert . assertEquals (2 , capability .getResourceInformation ("test-resource" )
603
+ assertEquals (2 , capability .getResourceInformation ("test-resource" )
604
604
.getAttributes ().size ());
605
605
am .stop ();
606
606
}
0 commit comments