Skip to content

Commit b3aaa47

Browse files
committed
YARN-11262. Fix CheckStyle & Junit Test.
1 parent 7038f26 commit b3aaa47

File tree

10 files changed

+413
-334
lines changed

10 files changed

+413
-334
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/reservation/planning/TestGreedyReservationAgent.java

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,13 @@ public void testSimple(boolean pAllocateLeft,
170170

171171
if(allocateLeft){
172172
for (long i = 5 * step; i < 15 * step; i++) {
173-
assertTrue(
174-
175-
Resources.equals(cs.getResourcesAtTime(i),
176-
Resource.newInstance(2048 * 10, 2 * 10)), "Agent-based allocation unexpected");
173+
assertTrue(Resources.equals(cs.getResourcesAtTime(i),
174+
Resource.newInstance(2048 * 10, 2 * 10)), "Agent-based allocation unexpected");
177175
}
178176
} else {
179177
for (long i = 10 * step; i < 20 * step; i++) {
180-
assertTrue(
181-
182-
Resources.equals(cs.getResourcesAtTime(i),
183-
Resource.newInstance(2048 * 10, 2 * 10)), "Agent-based allocation unexpected");
178+
assertTrue(Resources.equals(cs.getResourcesAtTime(i),
179+
Resource.newInstance(2048 * 10, 2 * 10)), "Agent-based allocation unexpected");
184180
}
185181
}
186182
}
@@ -264,30 +260,22 @@ public void testSharingPolicyFeedback(boolean pAllocateLeft,
264260

265261
if (allocateLeft) {
266262
for (long i = 5 * step; i < 15 * step; i++) {
267-
assertTrue(
268-
269-
Resources.equals(cs.getResourcesAtTime(i),
270-
Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected");
263+
assertTrue(Resources.equals(cs.getResourcesAtTime(i),
264+
Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected");
271265
}
272266
for (long i = 15 * step; i < 25 * step; i++) {
273267
// RR2 is pushed out by the presence of RR
274-
assertTrue(
275-
276-
Resources.equals(cs2.getResourcesAtTime(i),
277-
Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected");
268+
assertTrue(Resources.equals(cs2.getResourcesAtTime(i),
269+
Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected");
278270
}
279271
} else {
280272
for (long i = 90 * step; i < 100 * step; i++) {
281-
assertTrue(
282-
283-
Resources.equals(cs.getResourcesAtTime(i),
284-
Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected");
273+
assertTrue(Resources.equals(cs.getResourcesAtTime(i),
274+
Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected");
285275
}
286276
for (long i = 80 * step; i < 90 * step; i++) {
287-
assertTrue(
288-
289-
Resources.equals(cs2.getResourcesAtTime(i),
290-
Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected");
277+
assertTrue(Resources.equals(cs2.getResourcesAtTime(i),
278+
Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected");
291279
}
292280
}
293281
}
@@ -376,13 +364,11 @@ public void testOrderNoGapImpossible(boolean pAllocateLeft,
376364
ReservationDefinition rDef = ReservationSystemTestUtil
377365
.createSimpleReservationDefinition(30, 30 * step + f.length * step,
378366
f.length * step, 1, recurrenceExpression);
379-
assertTrue(
380-
381-
plan.addReservation(new InMemoryReservationAllocation(
382-
ReservationSystemTestUtil.getNewReservationId(), rDef, "u1",
383-
"dedicated", 30 * step, 30 * step + f.length * step,
384-
ReservationSystemTestUtil.generateAllocation(30 * step, step, f),
385-
res, minAlloc), false), plan.toString());
367+
assertTrue(plan.addReservation(new InMemoryReservationAllocation(
368+
ReservationSystemTestUtil.getNewReservationId(), rDef, "u1",
369+
"dedicated", 30 * step, 30 * step + f.length * step,
370+
ReservationSystemTestUtil.generateAllocation(30 * step, step, f),
371+
res, minAlloc), false), plan.toString());
386372

387373
// create a chain of 4 RR, mixing gang and non-gang
388374
ReservationDefinition rr = new ReservationDefinitionPBImpl();
@@ -416,8 +402,8 @@ public void testOrderNoGapImpossible(boolean pAllocateLeft,
416402

417403
// validate
418404
assertFalse(result, "Agent-based allocation should have failed");
419-
assertTrue(plan
420-
.getAllReservations().size() == 3, "Agent-based allocation should have failed");
405+
assertTrue(plan.getAllReservations().size() == 3,
406+
"Agent-based allocation should have failed");
421407

422408
System.out
423409
.println("--------AFTER ORDER_NO_GAP IMPOSSIBLE ALLOCATION (queue: "
@@ -618,8 +604,8 @@ public void testAnyImpossible(boolean pAllocateLeft,
618604
}
619605
// validate results, we expect the second one to be accepted
620606
assertFalse(result, "Agent-based allocation should have failed");
621-
assertTrue(plan
622-
.getAllReservations().size() == 2, "Agent-based allocation should have failed");
607+
assertTrue(plan.getAllReservations().size() == 2,
608+
"Agent-based allocation should have failed");
623609

624610
System.out.println("--------AFTER ANY IMPOSSIBLE ALLOCATION (queue: "
625611
+ reservationID + ")----------");
@@ -719,8 +705,8 @@ public void testAllImpossible(boolean pAllocateLeft,
719705

720706
// validate results, we expect the second one to be accepted
721707
assertFalse(result, "Agent-based allocation failed");
722-
assertTrue(plan.getAllReservations()
723-
.size() == 2, "Agent-based allocation failed");
708+
assertTrue(plan.getAllReservations().size() == 2,
709+
"Agent-based allocation failed");
724710

725711
System.out.println("--------AFTER ALL IMPOSSIBLE ALLOCATION (queue: "
726712
+ reservationID + ")----------");
@@ -738,19 +724,17 @@ private void prepareBasicPlan() throws PlanningException {
738724
ReservationDefinition rDef =
739725
ReservationSystemTestUtil.createSimpleReservationDefinition(
740726
0, 0 + f.length * step, f.length * step);
741-
assertTrue(
742-
plan.addReservation(new InMemoryReservationAllocation(
743-
ReservationSystemTestUtil.getNewReservationId(), rDef, "u1",
744-
"dedicated", 0L, 0L + f.length * step, ReservationSystemTestUtil
745-
.generateAllocation(0, step, f), res, minAlloc), false), plan.toString());
727+
assertTrue(plan.addReservation(new InMemoryReservationAllocation(
728+
ReservationSystemTestUtil.getNewReservationId(), rDef, "u1",
729+
"dedicated", 0L, 0L + f.length * step, ReservationSystemTestUtil
730+
.generateAllocation(0, step, f), res, minAlloc), false), plan.toString());
746731

747732
int[] f2 = { 5, 5, 5, 5, 5, 5, 5 };
748733
Map<ReservationInterval, Resource> alloc =
749734
ReservationSystemTestUtil.generateAllocation(5000, step, f2);
750-
assertTrue(
751-
plan.addReservation(new InMemoryReservationAllocation(
752-
ReservationSystemTestUtil.getNewReservationId(), rDef, "u1",
753-
"dedicated", 5000, 5000 + f2.length * step, alloc, res, minAlloc),
735+
assertTrue(plan.addReservation(new InMemoryReservationAllocation(
736+
ReservationSystemTestUtil.getNewReservationId(), rDef, "u1",
737+
"dedicated", 5000, 5000 + f2.length * step, alloc, res, minAlloc),
754738
false), plan.toString());
755739

756740
System.out.println("--------BEFORE AGENT----------");

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resource/TestResourceProfiles.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
package org.apache.hadoop.yarn.server.resourcemanager.resource;
2020

21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
23+
import static org.junit.jupiter.api.Assertions.fail;
24+
2125
import org.apache.hadoop.conf.Configuration;
2226
import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse;
2327
import org.apache.hadoop.yarn.api.records.Resource;
@@ -36,10 +40,6 @@
3640
import java.util.HashMap;
3741
import java.util.Map;
3842

39-
import static org.junit.jupiter.api.Assertions.assertEquals;
40-
import static org.junit.jupiter.api.Assertions.assertTrue;
41-
import static org.junit.jupiter.api.Assertions.fail;
42-
4343
/**
4444
* Common test class for resource profile related tests.
4545
*/
@@ -87,10 +87,10 @@ public void testLoadProfiles() throws Exception {
8787
for (Map.Entry<String, Resource> entry : expected.entrySet()) {
8888
String profile = entry.getKey();
8989
Resource res = entry.getValue();
90-
assertTrue(
91-
profiles.containsKey(profile), "Mandatory profile '" + profile + "' missing");
92-
assertEquals(res
93-
, manager.getProfile(profile), "Profile " + profile + "' resources don't match");
90+
assertTrue(profiles.containsKey(profile),
91+
"Mandatory profile '" + profile + "' missing");
92+
assertEquals(res, manager.getProfile(profile),
93+
"Profile " + profile + "' resources don't match");
9494
}
9595
}
9696

@@ -132,8 +132,8 @@ public void testGetProfile() throws Exception {
132132
for (Map.Entry<String, Resource> entry : expected.entrySet()) {
133133
String profile = entry.getKey();
134134
Resource res = entry.getValue();
135-
assertEquals(res
136-
, manager.getProfile(profile), "Profile " + profile + "' resources don't match");
135+
assertEquals(res, manager.getProfile(profile),
136+
"Profile " + profile + "' resources don't match");
137137
}
138138
}
139139

@@ -150,12 +150,12 @@ public void testGetMandatoryProfiles() throws Exception {
150150
expected.put("default", Resource.newInstance(2048, 2));
151151
expected.put("maximum", Resource.newInstance(8192, 4));
152152

153-
assertEquals(
154-
expected.get("minimum"), manager.getMinimumProfile(), "Profile 'minimum' resources don't match");
155-
assertEquals(
156-
expected.get("default"), manager.getDefaultProfile(), "Profile 'default' resources don't match");
157-
assertEquals(
158-
expected.get("maximum"), manager.getMaximumProfile(), "Profile 'maximum' resources don't match");
153+
assertEquals(expected.get("minimum"), manager.getMinimumProfile(),
154+
"Profile 'minimum' resources don't match");
155+
assertEquals(expected.get("default"), manager.getDefaultProfile(),
156+
"Profile 'default' resources don't match");
157+
assertEquals(expected.get("maximum"), manager.getMaximumProfile(),
158+
"Profile 'maximum' resources don't match");
159159

160160
}
161161

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/TestRMNMRPCResponseId.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void testRPCResponseId() throws IOException, YarnException {
127127

128128
nodeStatus.setResponseId(response.getResponseId());
129129
response = resourceTrackerService.nodeHeartbeat(nodeHeartBeatRequest);
130-
assertTrue(response.getResponseId() == 2);
130+
assertTrue(response.getResponseId() == 2);
131131

132132
/* try calling with less response id */
133133
response = resourceTrackerService.nodeHeartbeat(nodeHeartBeatRequest);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/TestApplicationLifetimeMonitor.java

Lines changed: 45 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ public void testApplicationLifetimeMonitor(Class schedulerParameter)
168168
rm.sendAMLaunched(app1.getCurrentAppAttempt().getAppAttemptId());
169169
am1.registerAppAttempt();
170170
rm.waitForState(app1.getApplicationId(), RMAppState.KILLED);
171-
assertTrue(
172-
(System.currentTimeMillis() - app1.getSubmitTime()) > 10000, "Application killed before lifetime value");
171+
assertTrue((System.currentTimeMillis() - app1.getSubmitTime()) > 10000,
172+
"Application killed before lifetime value");
173173

174174
Map<ApplicationTimeoutType, String> updateTimeout =
175175
new HashMap<ApplicationTimeoutType, String>();
@@ -197,8 +197,8 @@ public void testApplicationLifetimeMonitor(Class schedulerParameter)
197197
long afterUpdate =
198198
applicationTimeouts.get(ApplicationTimeoutType.LIFETIME);
199199

200-
assertTrue(
201-
afterUpdate > beforeUpdate, "Application lifetime value not updated");
200+
assertTrue(afterUpdate > beforeUpdate,
201+
"Application lifetime value not updated");
202202

203203
// verify for application report.
204204
RecordFactory recordFactory =
@@ -209,17 +209,16 @@ public void testApplicationLifetimeMonitor(Class schedulerParameter)
209209
Map<ApplicationTimeoutType, ApplicationTimeout> appTimeouts = rm
210210
.getRMContext().getClientRMService().getApplicationReport(appRequest)
211211
.getApplicationReport().getApplicationTimeouts();
212-
assertTrue(
213-
!appTimeouts.isEmpty(), "Application Timeout are empty.");
212+
assertTrue(!appTimeouts.isEmpty(), "Application Timeout are empty.");
214213
ApplicationTimeout timeout =
215214
appTimeouts.get(ApplicationTimeoutType.LIFETIME);
216-
assertTrue(
217-
timeout.getRemainingTime() > 0, "Application remaining time is incorrect");
215+
assertTrue(timeout.getRemainingTime() > 0,
216+
"Application remaining time is incorrect");
218217

219218
rm.waitForState(app2.getApplicationId(), RMAppState.KILLED);
220219
// verify for app killed with updated lifetime
221-
assertTrue(
222-
app2.getFinishTime() > afterUpdate, "Application killed before lifetime value");
220+
assertTrue(app2.getFinishTime() > afterUpdate,
221+
"Application killed before lifetime value");
223222

224223
if (scheduler.equals(CapacityScheduler.class)) {
225224
// Supported only on capacity scheduler
@@ -229,11 +228,10 @@ public void testApplicationLifetimeMonitor(Class schedulerParameter)
229228
// so killed after queue max lifetime.
230229
rm.waitForState(app4.getApplicationId(), RMAppState.KILLED);
231230
long totalTimeRun = app4.getFinishTime() - app4.getSubmitTime();
232-
assertTrue(
233-
totalTimeRun > (maxLifetime * 1000), "Application killed before lifetime value");
234-
assertTrue(
235-
236-
totalTimeRun < ((maxLifetime + 10L) * 1000), "Application killed before lifetime value " + totalTimeRun);
231+
assertTrue(totalTimeRun > (maxLifetime * 1000),
232+
"Application killed before lifetime value");
233+
assertTrue(totalTimeRun < ((maxLifetime + 10L) * 1000),
234+
"Application killed before lifetime value " + totalTimeRun);
237235
}
238236
} finally {
239237
stopRM(rm);
@@ -314,9 +312,8 @@ public void testApplicationLifetimeOnRMRestart(Class schedulerParameter) throws
314312

315313
// wait for app life time and application to be in killed state.
316314
rm2.waitForState(recoveredApp1.getApplicationId(), RMAppState.KILLED);
317-
assertTrue(
318-
recoveredApp1.getFinishTime() > (recoveredApp1.getSubmitTime()
319-
+ appLifetime * 1000), "Application killed before lifetime value");
315+
assertTrue(recoveredApp1.getFinishTime() > (recoveredApp1.getSubmitTime()
316+
+ appLifetime * 1000), "Application killed before lifetime value");
320317
}
321318

322319
@Timeout(value = 60)
@@ -382,21 +379,21 @@ public synchronized void updateApplicationStateInternal(
382379
fail("Update application should fail.");
383380
} catch (YarnException e) {
384381
// expected
385-
assertTrue(
386-
e.getMessage().contains(app1.getApplicationId().toString()), "State-store exception does not containe appId");
382+
assertTrue(e.getMessage().contains(app1.getApplicationId().toString()),
383+
"State-store exception does not containe appId");
387384
}
388385

389386
applicationTimeouts = app1.getApplicationTimeouts();
390387
// has old timeout time
391388
long afterUpdate =
392389
applicationTimeouts.get(ApplicationTimeoutType.LIFETIME);
393390

394-
assertEquals(beforeUpdate
395-
, afterUpdate, "Application timeout is updated");
391+
assertEquals(beforeUpdate, afterUpdate,
392+
"Application timeout is updated");
396393
rm1.waitForState(app1.getApplicationId(), RMAppState.KILLED);
397394
// verify for app killed with updated lifetime
398-
assertTrue(
399-
app1.getFinishTime() > afterUpdate, "Application killed before lifetime value");
395+
assertTrue(app1.getFinishTime() > afterUpdate,
396+
"Application killed before lifetime value");
400397
} finally {
401398
stopRM(rm1);
402399
}
@@ -446,21 +443,20 @@ public void testInheritAppLifetimeFromParentQueue(Class schedulerParameter) thro
446443
rm.waitForState(app1.getApplicationId(), RMAppState.KILLED);
447444
long totalTimeRun = app1.getFinishTime() - app1.getSubmitTime();
448445
// Child queue should have inherited parent max and default lifetimes.
449-
assertEquals(
450-
maxRootLifetime
451-
, csched.getQueue(CQ1).getMaximumApplicationLifetime(), "Child queue max lifetime should have overridden"
446+
assertEquals(maxRootLifetime,
447+
csched.getQueue(CQ1).getMaximumApplicationLifetime(),
448+
"Child queue max lifetime should have overridden"
452449
+ " parent value");
453-
assertEquals(
454-
defaultRootLifetime
455-
, csched.getQueue(CQ1).getDefaultApplicationLifetime(), "Child queue default lifetime should have"
450+
assertEquals(defaultRootLifetime,
451+
csched.getQueue(CQ1).getDefaultApplicationLifetime(),
452+
"Child queue default lifetime should have"
456453
+ " overridden parent value");
457454
// app1 (run in the 'child1' queue) should have run longer than the
458455
// default lifetime but less than the max lifetime.
459-
assertTrue(
460-
totalTimeRun > (defaultRootLifetime * 1000), "Application killed before default lifetime value");
461-
assertTrue(
462-
463-
totalTimeRun < (maxRootLifetime * 1000), "Application killed after max lifetime value " + totalTimeRun);
456+
assertTrue(totalTimeRun > (defaultRootLifetime * 1000),
457+
"Application killed before default lifetime value");
458+
assertTrue(totalTimeRun < (maxRootLifetime * 1000),
459+
"Application killed after max lifetime value " + totalTimeRun);
464460
}
465461
} finally {
466462
stopRM(rm);
@@ -514,14 +510,12 @@ public void testOverrideParentQueueMaxAppLifetime(Class schedulerParameter) thro
514510
rm.waitForState(app1.getApplicationId(), RMAppState.KILLED);
515511
long totalTimeRun = app1.getFinishTime() - app1.getSubmitTime();
516512
// Child queue's max lifetime can override parent's and be larger.
517-
assertTrue(
518-
(maxRootLifetime < maxChildLifetime)
519-
&& (totalTimeRun > (maxChildLifetime * 1000)), "Application killed before default lifetime value");
520-
assertEquals(
521-
maxRootLifetime
522-
, csched.getRootQueue().getMaximumApplicationLifetime(), "Root queue max lifetime property set incorrectly");
523-
assertEquals(maxChildLifetime
524-
, csched.getQueue(CQ1).getMaximumApplicationLifetime(), "Child queue max lifetime should have overridden"
513+
assertTrue((maxRootLifetime < maxChildLifetime) && (totalTimeRun > (maxChildLifetime * 1000)),
514+
"Application killed before default lifetime value");
515+
assertEquals(maxRootLifetime, csched.getRootQueue().getMaximumApplicationLifetime(),
516+
"Root queue max lifetime property set incorrectly");
517+
assertEquals(maxChildLifetime, csched.getQueue(CQ1).getMaximumApplicationLifetime(),
518+
"Child queue max lifetime should have overridden"
525519
+ " parent value");
526520
}
527521
} finally {
@@ -577,18 +571,16 @@ public void testOverrideParentQueueDefaultAppLifetime(
577571
long totalTimeRun = app1.getFinishTime() - app1.getSubmitTime();
578572
// app1 (run in 'child1' queue) should have overridden the parent's
579573
// default lifetime.
580-
assertTrue(
581-
totalTimeRun > (defaultChildLifetime * 1000), "Application killed before default lifetime value");
574+
assertTrue(totalTimeRun > (defaultChildLifetime * 1000),
575+
"Application killed before default lifetime value");
582576
// Root and child queue's max lifetime should be -1.
583-
assertEquals(
584-
maxRootLifetime
585-
, csched.getRootQueue().getMaximumApplicationLifetime(), "Root queue max lifetime property set incorrectly");
586-
assertEquals(
587-
maxChildLifetime
588-
, csched.getQueue(CQ1).getMaximumApplicationLifetime(), "Child queue max lifetime property set incorrectly");
577+
assertEquals(maxRootLifetime, csched.getRootQueue().getMaximumApplicationLifetime(),
578+
"Root queue max lifetime property set incorrectly");
579+
assertEquals(maxChildLifetime, csched.getQueue(CQ1).getMaximumApplicationLifetime(),
580+
"Child queue max lifetime property set incorrectly");
589581
// 'child1' queue's default lifetime should have overridden parent's.
590-
assertEquals(defaultChildLifetime
591-
, csched.getQueue(CQ1).getDefaultApplicationLifetime(), "Child queue default lifetime should have"
582+
assertEquals(defaultChildLifetime, csched.getQueue(CQ1).getDefaultApplicationLifetime(),
583+
"Child queue default lifetime should have"
592584
+ " overridden parent value");
593585
}
594586
} finally {

0 commit comments

Comments
 (0)