Fix CRLFs in TestKillAMPreemptionPolicy.java

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1596058 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew Wang 2014-05-19 21:18:55 +00:00
parent 161dcf1d12
commit 4a839f0cc1

View File

@ -1,144 +1,144 @@
/** /**
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the * to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at * with the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.hadoop.mapreduce.v2.app; package org.apache.hadoop.mapreduce.v2.app;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.apache.hadoop.mapreduce.v2.api.records.TaskType; import org.apache.hadoop.mapreduce.v2.api.records.TaskType;
import org.apache.hadoop.mapreduce.v2.app.MRAppMaster.RunningAppContext; import org.apache.hadoop.mapreduce.v2.app.MRAppMaster.RunningAppContext;
import org.apache.hadoop.mapreduce.v2.app.job.event.JobCounterUpdateEvent; import org.apache.hadoop.mapreduce.v2.app.job.event.JobCounterUpdateEvent;
import org.apache.hadoop.mapreduce.v2.app.job.event.TaskAttemptEvent; import org.apache.hadoop.mapreduce.v2.app.job.event.TaskAttemptEvent;
import org.apache.hadoop.mapreduce.v2.app.rm.preemption.AMPreemptionPolicy; import org.apache.hadoop.mapreduce.v2.app.rm.preemption.AMPreemptionPolicy;
import org.apache.hadoop.mapreduce.v2.app.rm.preemption.KillAMPreemptionPolicy; import org.apache.hadoop.mapreduce.v2.app.rm.preemption.KillAMPreemptionPolicy;
import org.apache.hadoop.mapreduce.v2.util.MRBuilderUtils; import org.apache.hadoop.mapreduce.v2.util.MRBuilderUtils;
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.ApplicationId;
import org.apache.hadoop.yarn.api.records.Container; import org.apache.hadoop.yarn.api.records.Container;
import org.apache.hadoop.yarn.api.records.ContainerId; import org.apache.hadoop.yarn.api.records.ContainerId;
import org.apache.hadoop.yarn.api.records.PreemptionContainer; import org.apache.hadoop.yarn.api.records.PreemptionContainer;
import org.apache.hadoop.yarn.api.records.PreemptionContract; import org.apache.hadoop.yarn.api.records.PreemptionContract;
import org.apache.hadoop.yarn.api.records.PreemptionMessage; import org.apache.hadoop.yarn.api.records.PreemptionMessage;
import org.apache.hadoop.yarn.api.records.StrictPreemptionContract; import org.apache.hadoop.yarn.api.records.StrictPreemptionContract;
import org.apache.hadoop.yarn.event.EventHandler; import org.apache.hadoop.yarn.event.EventHandler;
import org.apache.hadoop.yarn.factories.RecordFactory; import org.apache.hadoop.yarn.factories.RecordFactory;
import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider; import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
import org.junit.Test; import org.junit.Test;
public class TestKillAMPreemptionPolicy { public class TestKillAMPreemptionPolicy {
private final RecordFactory recordFactory = RecordFactoryProvider private final RecordFactory recordFactory = RecordFactoryProvider
.getRecordFactory(null); .getRecordFactory(null);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void testKillAMPreemptPolicy() { public void testKillAMPreemptPolicy() {
ApplicationId appId = ApplicationId.newInstance(123456789, 1); ApplicationId appId = ApplicationId.newInstance(123456789, 1);
ContainerId container = ContainerId.newInstance( ContainerId container = ContainerId.newInstance(
ApplicationAttemptId.newInstance(appId, 1), 1); ApplicationAttemptId.newInstance(appId, 1), 1);
AMPreemptionPolicy.Context mPctxt = mock(AMPreemptionPolicy.Context.class); AMPreemptionPolicy.Context mPctxt = mock(AMPreemptionPolicy.Context.class);
when(mPctxt.getTaskAttempt(any(ContainerId.class))).thenReturn( when(mPctxt.getTaskAttempt(any(ContainerId.class))).thenReturn(
MRBuilderUtils.newTaskAttemptId(MRBuilderUtils.newTaskId( MRBuilderUtils.newTaskAttemptId(MRBuilderUtils.newTaskId(
MRBuilderUtils.newJobId(appId, 1), 1, TaskType.MAP), 0)); MRBuilderUtils.newJobId(appId, 1), 1, TaskType.MAP), 0));
List<Container> p = new ArrayList<Container>(); List<Container> p = new ArrayList<Container>();
p.add(Container.newInstance(container, null, null, null, null, null)); p.add(Container.newInstance(container, null, null, null, null, null));
when(mPctxt.getContainers(any(TaskType.class))).thenReturn(p); when(mPctxt.getContainers(any(TaskType.class))).thenReturn(p);
KillAMPreemptionPolicy policy = new KillAMPreemptionPolicy(); KillAMPreemptionPolicy policy = new KillAMPreemptionPolicy();
// strictContract is null & contract is null // strictContract is null & contract is null
RunningAppContext mActxt = getRunningAppContext(); RunningAppContext mActxt = getRunningAppContext();
policy.init(mActxt); policy.init(mActxt);
PreemptionMessage pM = getPreemptionMessage(false, false, container); PreemptionMessage pM = getPreemptionMessage(false, false, container);
policy.preempt(mPctxt, pM); policy.preempt(mPctxt, pM);
verify(mActxt.getEventHandler(), times(0)).handle( verify(mActxt.getEventHandler(), times(0)).handle(
any(TaskAttemptEvent.class)); any(TaskAttemptEvent.class));
verify(mActxt.getEventHandler(), times(0)).handle( verify(mActxt.getEventHandler(), times(0)).handle(
any(JobCounterUpdateEvent.class)); any(JobCounterUpdateEvent.class));
// strictContract is not null & contract is null // strictContract is not null & contract is null
mActxt = getRunningAppContext(); mActxt = getRunningAppContext();
policy.init(mActxt); policy.init(mActxt);
pM = getPreemptionMessage(true, false, container); pM = getPreemptionMessage(true, false, container);
policy.preempt(mPctxt, pM); policy.preempt(mPctxt, pM);
verify(mActxt.getEventHandler(), times(2)).handle( verify(mActxt.getEventHandler(), times(2)).handle(
any(TaskAttemptEvent.class)); any(TaskAttemptEvent.class));
verify(mActxt.getEventHandler(), times(2)).handle( verify(mActxt.getEventHandler(), times(2)).handle(
any(JobCounterUpdateEvent.class)); any(JobCounterUpdateEvent.class));
// strictContract is null & contract is not null // strictContract is null & contract is not null
mActxt = getRunningAppContext(); mActxt = getRunningAppContext();
policy.init(mActxt); policy.init(mActxt);
pM = getPreemptionMessage(false, true, container); pM = getPreemptionMessage(false, true, container);
policy.preempt(mPctxt, pM); policy.preempt(mPctxt, pM);
verify(mActxt.getEventHandler(), times(2)).handle( verify(mActxt.getEventHandler(), times(2)).handle(
any(TaskAttemptEvent.class)); any(TaskAttemptEvent.class));
verify(mActxt.getEventHandler(), times(2)).handle( verify(mActxt.getEventHandler(), times(2)).handle(
any(JobCounterUpdateEvent.class)); any(JobCounterUpdateEvent.class));
// strictContract is not null & contract is not null // strictContract is not null & contract is not null
mActxt = getRunningAppContext(); mActxt = getRunningAppContext();
policy.init(mActxt); policy.init(mActxt);
pM = getPreemptionMessage(true, true, container); pM = getPreemptionMessage(true, true, container);
policy.preempt(mPctxt, pM); policy.preempt(mPctxt, pM);
verify(mActxt.getEventHandler(), times(4)).handle( verify(mActxt.getEventHandler(), times(4)).handle(
any(TaskAttemptEvent.class)); any(TaskAttemptEvent.class));
verify(mActxt.getEventHandler(), times(4)).handle( verify(mActxt.getEventHandler(), times(4)).handle(
any(JobCounterUpdateEvent.class)); any(JobCounterUpdateEvent.class));
} }
private RunningAppContext getRunningAppContext() { private RunningAppContext getRunningAppContext() {
RunningAppContext mActxt = mock(RunningAppContext.class); RunningAppContext mActxt = mock(RunningAppContext.class);
EventHandler<?> eventHandler = mock(EventHandler.class); EventHandler<?> eventHandler = mock(EventHandler.class);
when(mActxt.getEventHandler()).thenReturn(eventHandler); when(mActxt.getEventHandler()).thenReturn(eventHandler);
return mActxt; return mActxt;
} }
private PreemptionMessage getPreemptionMessage(boolean strictContract, private PreemptionMessage getPreemptionMessage(boolean strictContract,
boolean contract, final ContainerId container) { boolean contract, final ContainerId container) {
PreemptionMessage preemptionMessage = recordFactory PreemptionMessage preemptionMessage = recordFactory
.newRecordInstance(PreemptionMessage.class); .newRecordInstance(PreemptionMessage.class);
Set<PreemptionContainer> cntrs = new HashSet<PreemptionContainer>(); Set<PreemptionContainer> cntrs = new HashSet<PreemptionContainer>();
PreemptionContainer preemptContainer = recordFactory PreemptionContainer preemptContainer = recordFactory
.newRecordInstance(PreemptionContainer.class); .newRecordInstance(PreemptionContainer.class);
preemptContainer.setId(container); preemptContainer.setId(container);
cntrs.add(preemptContainer); cntrs.add(preemptContainer);
if (strictContract) { if (strictContract) {
StrictPreemptionContract set = recordFactory StrictPreemptionContract set = recordFactory
.newRecordInstance(StrictPreemptionContract.class); .newRecordInstance(StrictPreemptionContract.class);
set.setContainers(cntrs); set.setContainers(cntrs);
preemptionMessage.setStrictContract(set); preemptionMessage.setStrictContract(set);
} }
if (contract) { if (contract) {
PreemptionContract preemptContract = recordFactory PreemptionContract preemptContract = recordFactory
.newRecordInstance(PreemptionContract.class); .newRecordInstance(PreemptionContract.class);
preemptContract.setContainers(cntrs); preemptContract.setContainers(cntrs);
preemptionMessage.setContract(preemptContract); preemptionMessage.setContract(preemptContract);
} }
return preemptionMessage; return preemptionMessage;
} }
} }