private RunningAppContext getRunningAppContext() { RunningAppContext mActxt = mock(RunningAppContext.class); @SuppressWarnings("unchecked") EventHandler<Event> eventHandler = mock(EventHandler.class); when(mActxt.getEventHandler()).thenReturn(eventHandler); return mActxt; }
@Before @SuppressWarnings("rawtypes") // mocked generics public void setup() { ApplicationId appId = ApplicationId.newInstance(200, 1); ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1); jid = MRBuilderUtils.newJobId(appId, 1); mActxt = mock(RunningAppContext.class); @SuppressWarnings("unchecked") EventHandler<Event> ea = mock(EventHandler.class); when(mActxt.getEventHandler()).thenReturn(ea); for (int i = 0; i < 40; ++i) { ContainerId cId = ContainerId.newContainerId(appAttemptId, i); if (0 == i % 7) { preemptedContainers.add(cId); } TaskId tId = 0 == i % 2 ? MRBuilderUtils.newTaskId(jid, i / 2, TaskType.MAP) : MRBuilderUtils.newTaskId(jid, i / 2 + 1, TaskType.REDUCE); assignedContainers.put(cId, MRBuilderUtils.newTaskAttemptId(tId, 0)); contToResourceMap.put(cId, Resource.newInstance(2 * minAlloc, 2)); } for (Map.Entry<ContainerId,TaskAttemptId> ent : assignedContainers.entrySet()) { System.out.println("cont:" + ent.getKey().getContainerId() + " type:" + ent.getValue().getTaskId().getTaskType() + " res:" + contToResourceMap.get(ent.getKey()).getMemorySize() + "MB" ); } }
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)); 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)); 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)); 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));