use of org.apache.hadoop.mapreduce.v2.app.rm.preemption.KillAMPreemptionPolicy in project hadoop by apache.
the class TestKillAMPreemptionPolicy method testKillAMPreemptPolicy.
@SuppressWarnings("unchecked")
@Test
public void testKillAMPreemptPolicy() {
ApplicationId appId = ApplicationId.newInstance(123456789, 1);
ContainerId container = ContainerId.newContainerId(ApplicationAttemptId.newInstance(appId, 1), 1);
AMPreemptionPolicy.Context mPctxt = mock(AMPreemptionPolicy.Context.class);
when(mPctxt.getTaskAttempt(any(ContainerId.class))).thenReturn(MRBuilderUtils.newTaskAttemptId(MRBuilderUtils.newTaskId(MRBuilderUtils.newJobId(appId, 1), 1, TaskType.MAP), 0));
List<Container> p = new ArrayList<Container>();
p.add(Container.newInstance(container, null, null, null, null, null));
when(mPctxt.getContainers(any(TaskType.class))).thenReturn(p);
KillAMPreemptionPolicy policy = new KillAMPreemptionPolicy();
// strictContract is null & contract is null
RunningAppContext mActxt = getRunningAppContext();
policy.init(mActxt);
PreemptionMessage pM = getPreemptionMessage(false, false, container);
policy.preempt(mPctxt, pM);
verify(mActxt.getEventHandler(), times(0)).handle(any(TaskAttemptEvent.class));
verify(mActxt.getEventHandler(), times(0)).handle(any(JobCounterUpdateEvent.class));
// strictContract is not null & contract is null
mActxt = getRunningAppContext();
policy.init(mActxt);
pM = getPreemptionMessage(true, false, container);
policy.preempt(mPctxt, pM);
verify(mActxt.getEventHandler(), times(2)).handle(any(TaskAttemptEvent.class));
verify(mActxt.getEventHandler(), times(2)).handle(any(JobCounterUpdateEvent.class));
// strictContract is null & contract is not null
mActxt = getRunningAppContext();
policy.init(mActxt);
pM = getPreemptionMessage(false, true, container);
policy.preempt(mPctxt, pM);
verify(mActxt.getEventHandler(), times(2)).handle(any(TaskAttemptEvent.class));
verify(mActxt.getEventHandler(), times(2)).handle(any(JobCounterUpdateEvent.class));
// strictContract is not null & contract is not null
mActxt = getRunningAppContext();
policy.init(mActxt);
pM = getPreemptionMessage(true, true, container);
policy.preempt(mPctxt, pM);
verify(mActxt.getEventHandler(), times(4)).handle(any(TaskAttemptEvent.class));
verify(mActxt.getEventHandler(), times(4)).handle(any(JobCounterUpdateEvent.class));
}
Aggregations