|
18 | 18 |
|
19 | 19 | package org.apache.hadoop.yarn.server.resourcemanager.nodelabels; |
20 | 20 |
|
| 21 | +import java.io.IOException; |
21 | 22 | import java.util.HashMap; |
22 | 23 | import java.util.Map; |
23 | 24 | import java.util.Set; |
24 | 25 |
|
25 | 26 | import org.apache.hadoop.conf.Configuration; |
26 | 27 | import org.apache.hadoop.yarn.api.records.NodeId; |
27 | 28 | import org.apache.hadoop.yarn.api.records.Resource; |
| 29 | +import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager; |
28 | 30 | import org.apache.hadoop.yarn.nodelabels.NodeLabelTestBase; |
29 | 31 | import org.apache.hadoop.yarn.util.resource.Resources; |
30 | 32 | import org.junit.After; |
@@ -364,4 +366,31 @@ public void testGetQueueResource() throws Exception { |
364 | 366 | Assert.assertEquals(clusterResource, |
365 | 367 | mgr.getQueueResource("Q5", q5Label, clusterResource)); |
366 | 368 | } |
| 369 | + |
| 370 | + @Test(timeout=5000) |
| 371 | + public void testGetLabelResourceWhenMultipleNMsExistingInSameHost() throws IOException { |
| 372 | + // active two NM to n1, one large and one small |
| 373 | + mgr.activateNode(NodeId.newInstance("n1", 1), SMALL_RESOURCE); |
| 374 | + mgr.activateNode(NodeId.newInstance("n1", 2), SMALL_RESOURCE); |
| 375 | + mgr.activateNode(NodeId.newInstance("n1", 3), SMALL_RESOURCE); |
| 376 | + mgr.activateNode(NodeId.newInstance("n1", 4), SMALL_RESOURCE); |
| 377 | + |
| 378 | + // check resource of no label, it should be small * 4 |
| 379 | + Assert.assertEquals( |
| 380 | + mgr.getResourceByLabel(CommonNodeLabelsManager.NO_LABEL, null), |
| 381 | + Resources.multiply(SMALL_RESOURCE, 4)); |
| 382 | + |
| 383 | + // change two of these nodes to p1, check resource of no_label and P1 |
| 384 | + mgr.addToCluserNodeLabels(toSet("p1")); |
| 385 | + mgr.addLabelsToNode(ImmutableMap.of(toNodeId("n1:1"), toSet("p1"), |
| 386 | + toNodeId("n1:2"), toSet("p1"))); |
| 387 | + |
| 388 | + // check resource |
| 389 | + Assert.assertEquals( |
| 390 | + mgr.getResourceByLabel(CommonNodeLabelsManager.NO_LABEL, null), |
| 391 | + Resources.multiply(SMALL_RESOURCE, 2)); |
| 392 | + Assert.assertEquals( |
| 393 | + mgr.getResourceByLabel("p1", null), |
| 394 | + Resources.multiply(SMALL_RESOURCE, 2)); |
| 395 | + } |
367 | 396 | } |
0 commit comments