|
23 | 23 | import java.util.*; |
24 | 24 |
|
25 | 25 | import org.apache.hadoop.yarn.api.records.NodeId; |
| 26 | +import org.apache.hadoop.yarn.api.records.Priority; |
26 | 27 | import org.apache.hadoop.yarn.conf.YarnConfiguration; |
| 28 | +import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager; |
27 | 29 | import org.apache.hadoop.yarn.server.resourcemanager.MockRM; |
28 | 30 | import org.apache.hadoop.yarn.server.resourcemanager.MockRMAppSubmissionData; |
29 | 31 | import org.apache.hadoop.yarn.server.resourcemanager.MockRMAppSubmitter; |
@@ -346,4 +348,44 @@ public void testOrderingUsingAppDemand() { |
346 | 348 | assertEquals("Comparator Output", 0, |
347 | 349 | policy.getComparator().compare(r1, r2)); |
348 | 350 | } |
| 351 | + |
| 352 | + @Test |
| 353 | + public void testRemoveEntitiesWithSizeBasedWeightAsCompletedJobs() { |
| 354 | + FairOrderingPolicy<MockSchedulableEntity> policy = |
| 355 | + new FairOrderingPolicy<MockSchedulableEntity>(); |
| 356 | + policy.setSizeBasedWeight(true); |
| 357 | + |
| 358 | + // Add 10 different schedulable entities |
| 359 | + List<MockSchedulableEntity> entities = new ArrayList<>(10); |
| 360 | + for (int i = 1; i <= 10; i++) { |
| 361 | + MockSchedulableEntity r = new MockSchedulableEntity(); |
| 362 | + r.setApplicationPriority(Priority.newInstance(i)); |
| 363 | + r.setUsed(Resources.createResource(4 * i)); |
| 364 | + r.setPending(Resources.createResource(4 * i)); |
| 365 | + AbstractComparatorOrderingPolicy.updateSchedulingResourceUsage( |
| 366 | + r.getSchedulingResourceUsage()); |
| 367 | + policy.addSchedulableEntity(r); |
| 368 | + entities.add(r); |
| 369 | + } |
| 370 | + |
| 371 | + // Mark the first 5 entities as completed by setting |
| 372 | + // the resources to 0 |
| 373 | + for (int i = 0; i < 5; i++) { |
| 374 | + MockSchedulableEntity r = entities.get(i); |
| 375 | + r.getSchedulingResourceUsage().setCachedUsed( |
| 376 | + CommonNodeLabelsManager.ANY, Resources.createResource(0)); |
| 377 | + r.getSchedulingResourceUsage().setCachedPending( |
| 378 | + CommonNodeLabelsManager.ANY, Resources.createResource(0)); |
| 379 | + policy.entityRequiresReordering(r); |
| 380 | + } |
| 381 | + |
| 382 | + policy.reorderScheduleEntities(); |
| 383 | + |
| 384 | + // Remove the first 5 elements |
| 385 | + for (int i = 0; i < 5; i++) { |
| 386 | + policy.removeSchedulableEntity(entities.get(i)); |
| 387 | + } |
| 388 | + |
| 389 | + Assert.assertEquals(5, policy.getNumSchedulableEntities()); |
| 390 | + } |
349 | 391 | } |
0 commit comments