YARN-11248. Add unit test for FINISHED_CONTAINERS_PULLED_BY_AM event on DECOMMISSIONING (#4721)

Co-authored-by: Ashutosh Gupta <ashugpt@amazon.com>
Signed-off-by: Akira Ajisaka <aajisaka@apache.org>
(cherry picked from commit f02ff1afe2)
This commit is contained in:
Ashutosh Gupta 2022-08-16 11:07:05 +01:00 committed by Akira Ajisaka
parent eff292bd5f
commit 3b3bd89084
1 changed files with 25 additions and 0 deletions

View File

@ -51,6 +51,7 @@ import org.apache.hadoop.yarn.api.records.ResourceUtilization;
import org.apache.hadoop.yarn.event.EventHandler;
import org.apache.hadoop.yarn.event.InlineDispatcher;
import org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatResponse;
import org.apache.hadoop.yarn.server.api.records.NodeAction;
import org.apache.hadoop.yarn.server.api.records.NodeHealthStatus;
import org.apache.hadoop.yarn.server.api.records.NodeStatus;
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp;
@ -76,6 +77,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEv
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEventType;
import org.apache.hadoop.yarn.server.resourcemanager.security.DelegationTokenRenewer;
import org.apache.hadoop.yarn.server.utils.BuilderUtils;
import org.apache.hadoop.yarn.server.utils.YarnServerBuilderUtils;
import org.apache.hadoop.yarn.util.Records;
import org.junit.After;
import org.junit.Assert;
@ -1286,4 +1288,27 @@ public class TestRMNodeTransitions {
calcIntervalTest(rmNode, nodeUtil, hbDefault, hbMin, hbMax,
speedup, slowdown, vcoreUnit * 1.0F, hbDefault); // 100%
}
@Test
public void testFinishedContainersPulledByAmOnDecommissioningNode() {
RMNodeImpl rMNodeImpl = getRunningNode();
rMNodeImpl.handle(
new RMNodeEvent(rMNodeImpl.getNodeID(), RMNodeEventType.GRACEFUL_DECOMMISSION));
Assert.assertEquals(NodeState.DECOMMISSIONING, rMNodeImpl.getState());
ContainerId containerId = BuilderUtils.newContainerId(
BuilderUtils.newApplicationAttemptId(BuilderUtils.newApplicationId(0, 0), 0), 0);
List<ContainerId> containerIds = Arrays.asList(containerId);
rMNodeImpl.handle(
new RMNodeFinishedContainersPulledByAMEvent(rMNodeImpl.getNodeID(), containerIds));
Assert.assertEquals(NodeState.DECOMMISSIONING, rMNodeImpl.getState());
// Verify expected containersToBeRemovedFromNM from NodeHeartbeatResponse.
NodeHeartbeatResponse response =
YarnServerBuilderUtils.newNodeHeartbeatResponse(1, NodeAction.NORMAL, null, null, null,
null, 1000);
rMNodeImpl.setAndUpdateNodeHeartbeatResponse(response);
Assert.assertEquals(1, response.getContainersToBeRemovedFromNM().size());
}
}