Skip to content

Commit

Permalink
YARN-11262. Fix CheckStyle & Junit Test.
Browse files Browse the repository at this point in the history
  • Loading branch information
slfan1989 committed Mar 9, 2025
1 parent 7038f26 commit b3aaa47
Show file tree
Hide file tree
Showing 10 changed files with 413 additions and 334 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,13 @@ public void testSimple(boolean pAllocateLeft,

if(allocateLeft){
for (long i = 5 * step; i < 15 * step; i++) {
assertTrue(

Resources.equals(cs.getResourcesAtTime(i),
Resource.newInstance(2048 * 10, 2 * 10)), "Agent-based allocation unexpected");
assertTrue(Resources.equals(cs.getResourcesAtTime(i),
Resource.newInstance(2048 * 10, 2 * 10)), "Agent-based allocation unexpected");
}
} else {
for (long i = 10 * step; i < 20 * step; i++) {
assertTrue(

Resources.equals(cs.getResourcesAtTime(i),
Resource.newInstance(2048 * 10, 2 * 10)), "Agent-based allocation unexpected");
assertTrue(Resources.equals(cs.getResourcesAtTime(i),
Resource.newInstance(2048 * 10, 2 * 10)), "Agent-based allocation unexpected");
}
}
}
Expand Down Expand Up @@ -264,30 +260,22 @@ public void testSharingPolicyFeedback(boolean pAllocateLeft,

if (allocateLeft) {
for (long i = 5 * step; i < 15 * step; i++) {
assertTrue(

Resources.equals(cs.getResourcesAtTime(i),
Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected");
assertTrue(Resources.equals(cs.getResourcesAtTime(i),
Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected");
}
for (long i = 15 * step; i < 25 * step; i++) {
// RR2 is pushed out by the presence of RR
assertTrue(

Resources.equals(cs2.getResourcesAtTime(i),
Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected");
assertTrue(Resources.equals(cs2.getResourcesAtTime(i),
Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected");
}
} else {
for (long i = 90 * step; i < 100 * step; i++) {
assertTrue(

Resources.equals(cs.getResourcesAtTime(i),
Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected");
assertTrue(Resources.equals(cs.getResourcesAtTime(i),
Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected");
}
for (long i = 80 * step; i < 90 * step; i++) {
assertTrue(

Resources.equals(cs2.getResourcesAtTime(i),
Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected");
assertTrue(Resources.equals(cs2.getResourcesAtTime(i),
Resource.newInstance(2048 * 20, 2 * 20)), "Agent-based allocation unexpected");
}
}
}
Expand Down Expand Up @@ -376,13 +364,11 @@ public void testOrderNoGapImpossible(boolean pAllocateLeft,
ReservationDefinition rDef = ReservationSystemTestUtil
.createSimpleReservationDefinition(30, 30 * step + f.length * step,
f.length * step, 1, recurrenceExpression);
assertTrue(

plan.addReservation(new InMemoryReservationAllocation(
ReservationSystemTestUtil.getNewReservationId(), rDef, "u1",
"dedicated", 30 * step, 30 * step + f.length * step,
ReservationSystemTestUtil.generateAllocation(30 * step, step, f),
res, minAlloc), false), plan.toString());
assertTrue(plan.addReservation(new InMemoryReservationAllocation(
ReservationSystemTestUtil.getNewReservationId(), rDef, "u1",
"dedicated", 30 * step, 30 * step + f.length * step,
ReservationSystemTestUtil.generateAllocation(30 * step, step, f),
res, minAlloc), false), plan.toString());

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

// validate
assertFalse(result, "Agent-based allocation should have failed");
assertTrue(plan
.getAllReservations().size() == 3, "Agent-based allocation should have failed");
assertTrue(plan.getAllReservations().size() == 3,
"Agent-based allocation should have failed");

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

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

// validate results, we expect the second one to be accepted
assertFalse(result, "Agent-based allocation failed");
assertTrue(plan.getAllReservations()
.size() == 2, "Agent-based allocation failed");
assertTrue(plan.getAllReservations().size() == 2,
"Agent-based allocation failed");

System.out.println("--------AFTER ALL IMPOSSIBLE ALLOCATION (queue: "
+ reservationID + ")----------");
Expand All @@ -738,19 +724,17 @@ private void prepareBasicPlan() throws PlanningException {
ReservationDefinition rDef =
ReservationSystemTestUtil.createSimpleReservationDefinition(
0, 0 + f.length * step, f.length * step);
assertTrue(
plan.addReservation(new InMemoryReservationAllocation(
ReservationSystemTestUtil.getNewReservationId(), rDef, "u1",
"dedicated", 0L, 0L + f.length * step, ReservationSystemTestUtil
.generateAllocation(0, step, f), res, minAlloc), false), plan.toString());
assertTrue(plan.addReservation(new InMemoryReservationAllocation(
ReservationSystemTestUtil.getNewReservationId(), rDef, "u1",
"dedicated", 0L, 0L + f.length * step, ReservationSystemTestUtil
.generateAllocation(0, step, f), res, minAlloc), false), plan.toString());

int[] f2 = { 5, 5, 5, 5, 5, 5, 5 };
Map<ReservationInterval, Resource> alloc =
ReservationSystemTestUtil.generateAllocation(5000, step, f2);
assertTrue(
plan.addReservation(new InMemoryReservationAllocation(
ReservationSystemTestUtil.getNewReservationId(), rDef, "u1",
"dedicated", 5000, 5000 + f2.length * step, alloc, res, minAlloc),
assertTrue(plan.addReservation(new InMemoryReservationAllocation(
ReservationSystemTestUtil.getNewReservationId(), rDef, "u1",
"dedicated", 5000, 5000 + f2.length * step, alloc, res, minAlloc),
false), plan.toString());

System.out.println("--------BEFORE AGENT----------");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

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

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse;
import org.apache.hadoop.yarn.api.records.Resource;
Expand All @@ -36,10 +40,6 @@
import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

/**
* Common test class for resource profile related tests.
*/
Expand Down Expand Up @@ -87,10 +87,10 @@ public void testLoadProfiles() throws Exception {
for (Map.Entry<String, Resource> entry : expected.entrySet()) {
String profile = entry.getKey();
Resource res = entry.getValue();
assertTrue(
profiles.containsKey(profile), "Mandatory profile '" + profile + "' missing");
assertEquals(res
, manager.getProfile(profile), "Profile " + profile + "' resources don't match");
assertTrue(profiles.containsKey(profile),
"Mandatory profile '" + profile + "' missing");
assertEquals(res, manager.getProfile(profile),
"Profile " + profile + "' resources don't match");
}
}

Expand Down Expand Up @@ -132,8 +132,8 @@ public void testGetProfile() throws Exception {
for (Map.Entry<String, Resource> entry : expected.entrySet()) {
String profile = entry.getKey();
Resource res = entry.getValue();
assertEquals(res
, manager.getProfile(profile), "Profile " + profile + "' resources don't match");
assertEquals(res, manager.getProfile(profile),
"Profile " + profile + "' resources don't match");
}
}

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

assertEquals(
expected.get("minimum"), manager.getMinimumProfile(), "Profile 'minimum' resources don't match");
assertEquals(
expected.get("default"), manager.getDefaultProfile(), "Profile 'default' resources don't match");
assertEquals(
expected.get("maximum"), manager.getMaximumProfile(), "Profile 'maximum' resources don't match");
assertEquals(expected.get("minimum"), manager.getMinimumProfile(),
"Profile 'minimum' resources don't match");
assertEquals(expected.get("default"), manager.getDefaultProfile(),
"Profile 'default' resources don't match");
assertEquals(expected.get("maximum"), manager.getMaximumProfile(),
"Profile 'maximum' resources don't match");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void testRPCResponseId() throws IOException, YarnException {

nodeStatus.setResponseId(response.getResponseId());
response = resourceTrackerService.nodeHeartbeat(nodeHeartBeatRequest);
assertTrue(response.getResponseId() == 2);
assertTrue(response.getResponseId() == 2);

/* try calling with less response id */
response = resourceTrackerService.nodeHeartbeat(nodeHeartBeatRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ public void testApplicationLifetimeMonitor(Class schedulerParameter)
rm.sendAMLaunched(app1.getCurrentAppAttempt().getAppAttemptId());
am1.registerAppAttempt();
rm.waitForState(app1.getApplicationId(), RMAppState.KILLED);
assertTrue(
(System.currentTimeMillis() - app1.getSubmitTime()) > 10000, "Application killed before lifetime value");
assertTrue((System.currentTimeMillis() - app1.getSubmitTime()) > 10000,
"Application killed before lifetime value");

Map<ApplicationTimeoutType, String> updateTimeout =
new HashMap<ApplicationTimeoutType, String>();
Expand Down Expand Up @@ -197,8 +197,8 @@ public void testApplicationLifetimeMonitor(Class schedulerParameter)
long afterUpdate =
applicationTimeouts.get(ApplicationTimeoutType.LIFETIME);

assertTrue(
afterUpdate > beforeUpdate, "Application lifetime value not updated");
assertTrue(afterUpdate > beforeUpdate,
"Application lifetime value not updated");

// verify for application report.
RecordFactory recordFactory =
Expand All @@ -209,17 +209,16 @@ public void testApplicationLifetimeMonitor(Class schedulerParameter)
Map<ApplicationTimeoutType, ApplicationTimeout> appTimeouts = rm
.getRMContext().getClientRMService().getApplicationReport(appRequest)
.getApplicationReport().getApplicationTimeouts();
assertTrue(
!appTimeouts.isEmpty(), "Application Timeout are empty.");
assertTrue(!appTimeouts.isEmpty(), "Application Timeout are empty.");
ApplicationTimeout timeout =
appTimeouts.get(ApplicationTimeoutType.LIFETIME);
assertTrue(
timeout.getRemainingTime() > 0, "Application remaining time is incorrect");
assertTrue(timeout.getRemainingTime() > 0,
"Application remaining time is incorrect");

rm.waitForState(app2.getApplicationId(), RMAppState.KILLED);
// verify for app killed with updated lifetime
assertTrue(
app2.getFinishTime() > afterUpdate, "Application killed before lifetime value");
assertTrue(app2.getFinishTime() > afterUpdate,
"Application killed before lifetime value");

if (scheduler.equals(CapacityScheduler.class)) {
// Supported only on capacity scheduler
Expand All @@ -229,11 +228,10 @@ public void testApplicationLifetimeMonitor(Class schedulerParameter)
// so killed after queue max lifetime.
rm.waitForState(app4.getApplicationId(), RMAppState.KILLED);
long totalTimeRun = app4.getFinishTime() - app4.getSubmitTime();
assertTrue(
totalTimeRun > (maxLifetime * 1000), "Application killed before lifetime value");
assertTrue(

totalTimeRun < ((maxLifetime + 10L) * 1000), "Application killed before lifetime value " + totalTimeRun);
assertTrue(totalTimeRun > (maxLifetime * 1000),
"Application killed before lifetime value");
assertTrue(totalTimeRun < ((maxLifetime + 10L) * 1000),
"Application killed before lifetime value " + totalTimeRun);
}
} finally {
stopRM(rm);
Expand Down Expand Up @@ -314,9 +312,8 @@ public void testApplicationLifetimeOnRMRestart(Class schedulerParameter) throws

// wait for app life time and application to be in killed state.
rm2.waitForState(recoveredApp1.getApplicationId(), RMAppState.KILLED);
assertTrue(
recoveredApp1.getFinishTime() > (recoveredApp1.getSubmitTime()
+ appLifetime * 1000), "Application killed before lifetime value");
assertTrue(recoveredApp1.getFinishTime() > (recoveredApp1.getSubmitTime()
+ appLifetime * 1000), "Application killed before lifetime value");
}

@Timeout(value = 60)
Expand Down Expand Up @@ -382,21 +379,21 @@ public synchronized void updateApplicationStateInternal(
fail("Update application should fail.");
} catch (YarnException e) {
// expected
assertTrue(
e.getMessage().contains(app1.getApplicationId().toString()), "State-store exception does not containe appId");
assertTrue(e.getMessage().contains(app1.getApplicationId().toString()),
"State-store exception does not containe appId");
}

applicationTimeouts = app1.getApplicationTimeouts();
// has old timeout time
long afterUpdate =
applicationTimeouts.get(ApplicationTimeoutType.LIFETIME);

assertEquals(beforeUpdate
, afterUpdate, "Application timeout is updated");
assertEquals(beforeUpdate, afterUpdate,
"Application timeout is updated");
rm1.waitForState(app1.getApplicationId(), RMAppState.KILLED);
// verify for app killed with updated lifetime
assertTrue(
app1.getFinishTime() > afterUpdate, "Application killed before lifetime value");
assertTrue(app1.getFinishTime() > afterUpdate,
"Application killed before lifetime value");
} finally {
stopRM(rm1);
}
Expand Down Expand Up @@ -446,21 +443,20 @@ public void testInheritAppLifetimeFromParentQueue(Class schedulerParameter) thro
rm.waitForState(app1.getApplicationId(), RMAppState.KILLED);
long totalTimeRun = app1.getFinishTime() - app1.getSubmitTime();
// Child queue should have inherited parent max and default lifetimes.
assertEquals(
maxRootLifetime
, csched.getQueue(CQ1).getMaximumApplicationLifetime(), "Child queue max lifetime should have overridden"
assertEquals(maxRootLifetime,
csched.getQueue(CQ1).getMaximumApplicationLifetime(),
"Child queue max lifetime should have overridden"
+ " parent value");
assertEquals(
defaultRootLifetime
, csched.getQueue(CQ1).getDefaultApplicationLifetime(), "Child queue default lifetime should have"
assertEquals(defaultRootLifetime,
csched.getQueue(CQ1).getDefaultApplicationLifetime(),
"Child queue default lifetime should have"
+ " overridden parent value");
// app1 (run in the 'child1' queue) should have run longer than the
// default lifetime but less than the max lifetime.
assertTrue(
totalTimeRun > (defaultRootLifetime * 1000), "Application killed before default lifetime value");
assertTrue(

totalTimeRun < (maxRootLifetime * 1000), "Application killed after max lifetime value " + totalTimeRun);
assertTrue(totalTimeRun > (defaultRootLifetime * 1000),
"Application killed before default lifetime value");
assertTrue(totalTimeRun < (maxRootLifetime * 1000),
"Application killed after max lifetime value " + totalTimeRun);
}
} finally {
stopRM(rm);
Expand Down Expand Up @@ -514,14 +510,12 @@ public void testOverrideParentQueueMaxAppLifetime(Class schedulerParameter) thro
rm.waitForState(app1.getApplicationId(), RMAppState.KILLED);
long totalTimeRun = app1.getFinishTime() - app1.getSubmitTime();
// Child queue's max lifetime can override parent's and be larger.
assertTrue(
(maxRootLifetime < maxChildLifetime)
&& (totalTimeRun > (maxChildLifetime * 1000)), "Application killed before default lifetime value");
assertEquals(
maxRootLifetime
, csched.getRootQueue().getMaximumApplicationLifetime(), "Root queue max lifetime property set incorrectly");
assertEquals(maxChildLifetime
, csched.getQueue(CQ1).getMaximumApplicationLifetime(), "Child queue max lifetime should have overridden"
assertTrue((maxRootLifetime < maxChildLifetime) && (totalTimeRun > (maxChildLifetime * 1000)),
"Application killed before default lifetime value");
assertEquals(maxRootLifetime, csched.getRootQueue().getMaximumApplicationLifetime(),
"Root queue max lifetime property set incorrectly");
assertEquals(maxChildLifetime, csched.getQueue(CQ1).getMaximumApplicationLifetime(),
"Child queue max lifetime should have overridden"
+ " parent value");
}
} finally {
Expand Down Expand Up @@ -577,18 +571,16 @@ public void testOverrideParentQueueDefaultAppLifetime(
long totalTimeRun = app1.getFinishTime() - app1.getSubmitTime();
// app1 (run in 'child1' queue) should have overridden the parent's
// default lifetime.
assertTrue(
totalTimeRun > (defaultChildLifetime * 1000), "Application killed before default lifetime value");
assertTrue(totalTimeRun > (defaultChildLifetime * 1000),
"Application killed before default lifetime value");
// Root and child queue's max lifetime should be -1.
assertEquals(
maxRootLifetime
, csched.getRootQueue().getMaximumApplicationLifetime(), "Root queue max lifetime property set incorrectly");
assertEquals(
maxChildLifetime
, csched.getQueue(CQ1).getMaximumApplicationLifetime(), "Child queue max lifetime property set incorrectly");
assertEquals(maxRootLifetime, csched.getRootQueue().getMaximumApplicationLifetime(),
"Root queue max lifetime property set incorrectly");
assertEquals(maxChildLifetime, csched.getQueue(CQ1).getMaximumApplicationLifetime(),
"Child queue max lifetime property set incorrectly");
// 'child1' queue's default lifetime should have overridden parent's.
assertEquals(defaultChildLifetime
, csched.getQueue(CQ1).getDefaultApplicationLifetime(), "Child queue default lifetime should have"
assertEquals(defaultChildLifetime, csched.getQueue(CQ1).getDefaultApplicationLifetime(),
"Child queue default lifetime should have"
+ " overridden parent value");
}
} finally {
Expand Down
Loading

0 comments on commit b3aaa47

Please sign in to comment.