Example usage for org.apache.hadoop.yarn.api.records ApplicationId newInstance

List of usage examples for org.apache.hadoop.yarn.api.records ApplicationId newInstance

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.api.records ApplicationId newInstance.

Prototype

@Public
    @Unstable
    public static ApplicationId newInstance(long clusterTimestamp, int id) 

Source Link

Usage

From source file:org.apache.tez.client.TestTezClient.java

License:Apache License

public void testTezClient(boolean isSession) throws Exception {
    Map<String, LocalResource> lrs = Maps.newHashMap();
    String lrName1 = "LR1";
    lrs.put(lrName1, LocalResource.newInstance(URL.newInstance("file", "localhost", 0, "/test"),
            LocalResourceType.FILE, LocalResourceVisibility.PUBLIC, 1, 1));

    TezClientForTest client = configure(lrs, isSession);

    ArgumentCaptor<ApplicationSubmissionContext> captor = ArgumentCaptor
            .forClass(ApplicationSubmissionContext.class);
    when(client.mockYarnClient.getApplicationReport(client.mockAppId).getYarnApplicationState())
            .thenReturn(YarnApplicationState.RUNNING);
    client.start();//w  w  w. j a v a 2 s. c  o m
    verify(client.mockYarnClient, times(1)).init((Configuration) any());
    verify(client.mockYarnClient, times(1)).start();
    if (isSession) {
        verify(client.mockYarnClient, times(1)).submitApplication(captor.capture());
        ApplicationSubmissionContext context = captor.getValue();
        Assert.assertEquals(3, context.getAMContainerSpec().getLocalResources().size());
        Assert.assertTrue(context.getAMContainerSpec().getLocalResources()
                .containsKey(TezConstants.TEZ_AM_LOCAL_RESOURCES_PB_FILE_NAME));
        Assert.assertTrue(context.getAMContainerSpec().getLocalResources()
                .containsKey(TezConstants.TEZ_PB_BINARY_CONF_NAME));
        Assert.assertTrue(context.getAMContainerSpec().getLocalResources().containsKey(lrName1));
    } else {
        verify(client.mockYarnClient, times(0)).submitApplication(captor.capture());
    }

    String mockLR1Name = "LR1";
    Map<String, LocalResource> lrDAG = Collections.singletonMap(mockLR1Name,
            LocalResource.newInstance(URL.newInstance("file", "localhost", 0, "/test1"), LocalResourceType.FILE,
                    LocalResourceVisibility.PUBLIC, 1, 1));
    Vertex vertex = Vertex.create("Vertex", ProcessorDescriptor.create("P"), 1, Resource.newInstance(1, 1));
    DAG dag = DAG.create("DAG").addVertex(vertex).addTaskLocalFiles(lrDAG);
    DAGClient dagClient = client.submitDAG(dag);

    Assert.assertTrue(dagClient.getExecutionContext().contains(client.mockAppId.toString()));

    if (isSession) {
        verify(client.mockYarnClient, times(1)).submitApplication(captor.capture());
        verify(client.sessionAmProxy, times(1)).submitDAG((RpcController) any(), (SubmitDAGRequestProto) any());
    } else {
        verify(client.mockYarnClient, times(1)).submitApplication(captor.capture());
        ApplicationSubmissionContext context = captor.getValue();
        Assert.assertEquals(4, context.getAMContainerSpec().getLocalResources().size());
        Assert.assertTrue(context.getAMContainerSpec().getLocalResources()
                .containsKey(TezConstants.TEZ_AM_LOCAL_RESOURCES_PB_FILE_NAME));
        Assert.assertTrue(context.getAMContainerSpec().getLocalResources()
                .containsKey(TezConstants.TEZ_PB_BINARY_CONF_NAME));
        Assert.assertTrue(context.getAMContainerSpec().getLocalResources()
                .containsKey(TezConstants.TEZ_PB_PLAN_BINARY_NAME));
        Assert.assertTrue(context.getAMContainerSpec().getLocalResources().containsKey(lrName1));
    }

    // add resources
    String lrName2 = "LR2";
    lrs.clear();
    lrs.put(lrName2, LocalResource.newInstance(URL.newInstance("file", "localhost", 0, "/test2"),
            LocalResourceType.FILE, LocalResourceVisibility.PUBLIC, 1, 1));
    client.addAppMasterLocalFiles(lrs);

    ApplicationId appId2 = ApplicationId.newInstance(0, 2);
    when(client.mockYarnClient.createApplication().getNewApplicationResponse().getApplicationId())
            .thenReturn(appId2);

    when(client.mockYarnClient.getApplicationReport(appId2).getYarnApplicationState())
            .thenReturn(YarnApplicationState.RUNNING);
    dag = DAG.create("DAG")
            .addVertex(Vertex.create("Vertex", ProcessorDescriptor.create("P"), 1, Resource.newInstance(1, 1)));
    dagClient = client.submitDAG(dag);

    if (isSession) {
        // same app master
        verify(client.mockYarnClient, times(1)).submitApplication(captor.capture());
        Assert.assertTrue(dagClient.getExecutionContext().contains(client.mockAppId.toString()));
        // additional resource is sent
        ArgumentCaptor<SubmitDAGRequestProto> captor1 = ArgumentCaptor.forClass(SubmitDAGRequestProto.class);
        verify(client.sessionAmProxy, times(2)).submitDAG((RpcController) any(), captor1.capture());
        SubmitDAGRequestProto proto = captor1.getValue();
        Assert.assertEquals(1, proto.getAdditionalAmResources().getLocalResourcesCount());
        Assert.assertEquals(lrName2, proto.getAdditionalAmResources().getLocalResources(0).getName());
    } else {
        // new app master
        Assert.assertTrue(dagClient.getExecutionContext().contains(appId2.toString()));
        verify(client.mockYarnClient, times(2)).submitApplication(captor.capture());
        // additional resource is added
        ApplicationSubmissionContext context = captor.getValue();
        Assert.assertEquals(5, context.getAMContainerSpec().getLocalResources().size());
        Assert.assertTrue(context.getAMContainerSpec().getLocalResources()
                .containsKey(TezConstants.TEZ_AM_LOCAL_RESOURCES_PB_FILE_NAME));
        Assert.assertTrue(context.getAMContainerSpec().getLocalResources()
                .containsKey(TezConstants.TEZ_PB_BINARY_CONF_NAME));
        Assert.assertTrue(context.getAMContainerSpec().getLocalResources()
                .containsKey(TezConstants.TEZ_PB_PLAN_BINARY_NAME));
        Assert.assertTrue(context.getAMContainerSpec().getLocalResources().containsKey(lrName1));
        Assert.assertTrue(context.getAMContainerSpec().getLocalResources().containsKey(lrName2));
    }

    client.stop();
    if (isSession) {
        verify(client.sessionAmProxy, times(1)).shutdownSession((RpcController) any(),
                (ShutdownSessionRequestProto) any());
    }
    verify(client.mockYarnClient, times(1)).stop();
}

From source file:org.apache.tez.client.TestTezClientUtils.java

License:Apache License

@Test(timeout = 5000)
public void testAMLoggingOptsSimple() throws IOException, YarnException {

    TezConfiguration tezConf = new TezConfiguration();
    tezConf.set(TezConfiguration.TEZ_AM_LOG_LEVEL, "WARN");

    ApplicationId appId = ApplicationId.newInstance(1000, 1);
    DAG dag = DAG.create("testdag");
    dag.addVertex(Vertex.create("testVertex", ProcessorDescriptor.create("processorClassname"), 1)
            .setTaskLaunchCmdOpts("initialLaunchOpts"));
    AMConfiguration amConf = new AMConfiguration(tezConf, new HashMap<String, LocalResource>(),
            new Credentials());
    ApplicationSubmissionContext appSubmissionContext = TezClientUtils.createApplicationSubmissionContext(appId,
            dag, "amName", amConf, new HashMap<String, LocalResource>(), new Credentials(), false,
            new TezApiVersionInfo(), mock(HistoryACLPolicyManager.class));

    List<String> expectedCommands = new LinkedList<String>();
    expectedCommands.add("-Dlog4j.configuratorClass=org.apache.tez.common.TezLog4jConfigurator");
    expectedCommands.add("-Dlog4j.configuration=" + TezConstants.TEZ_CONTAINER_LOG4J_PROPERTIES_FILE);
    expectedCommands.add("-D" + YarnConfiguration.YARN_APP_CONTAINER_LOG_DIR + "="
            + ApplicationConstants.LOG_DIR_EXPANSION_VAR);
    expectedCommands.add("-D" + TezConstants.TEZ_ROOT_LOGGER_NAME + "=" + "WARN" + ","
            + TezConstants.TEZ_CONTAINER_LOGGER_NAME);

    List<String> commands = appSubmissionContext.getAMContainerSpec().getCommands();
    assertEquals(1, commands.size());/*w ww  .jav a  2 s. c o m*/
    for (String expectedCmd : expectedCommands) {
        assertTrue(commands.get(0).contains(expectedCmd));
    }

    Map<String, String> environment = appSubmissionContext.getAMContainerSpec().getEnvironment();
    String logEnv = environment.get(TezConstants.TEZ_CONTAINER_LOG_PARAMS);
    assertNull(logEnv);
}

From source file:org.apache.tez.client.TestTezClientUtils.java

License:Apache License

@Test(timeout = 5000)
public void testAMLoggingOptsPerLogger() throws IOException, YarnException {

    TezConfiguration tezConf = new TezConfiguration();
    tezConf.set(TezConfiguration.TEZ_AM_LOG_LEVEL,
            "WARN;org.apache.hadoop.ipc=DEBUG;org.apache.hadoop.security=DEBUG");

    ApplicationId appId = ApplicationId.newInstance(1000, 1);
    DAG dag = DAG.create("testdag");
    dag.addVertex(Vertex.create("testVertex", ProcessorDescriptor.create("processorClassname"), 1)
            .setTaskLaunchCmdOpts("initialLaunchOpts"));
    AMConfiguration amConf = new AMConfiguration(tezConf, new HashMap<String, LocalResource>(),
            new Credentials());
    ApplicationSubmissionContext appSubmissionContext = TezClientUtils.createApplicationSubmissionContext(appId,
            dag, "amName", amConf, new HashMap<String, LocalResource>(), new Credentials(), false,
            new TezApiVersionInfo(), mock(HistoryACLPolicyManager.class));

    List<String> expectedCommands = new LinkedList<String>();
    expectedCommands.add("-Dlog4j.configuratorClass=org.apache.tez.common.TezLog4jConfigurator");
    expectedCommands.add("-Dlog4j.configuration=" + TezConstants.TEZ_CONTAINER_LOG4J_PROPERTIES_FILE);
    expectedCommands.add("-D" + YarnConfiguration.YARN_APP_CONTAINER_LOG_DIR + "="
            + ApplicationConstants.LOG_DIR_EXPANSION_VAR);
    expectedCommands.add("-D" + TezConstants.TEZ_ROOT_LOGGER_NAME + "=" + "WARN" + ","
            + TezConstants.TEZ_CONTAINER_LOGGER_NAME);

    List<String> commands = appSubmissionContext.getAMContainerSpec().getCommands();
    assertEquals(1, commands.size());//  w  ww .  j av a 2  s. com
    for (String expectedCmd : expectedCommands) {
        assertTrue(commands.get(0).contains(expectedCmd));
    }

    Map<String, String> environment = appSubmissionContext.getAMContainerSpec().getEnvironment();
    String logEnv = environment.get(TezConstants.TEZ_CONTAINER_LOG_PARAMS);
    assertEquals("org.apache.hadoop.ipc=DEBUG;org.apache.hadoop.security=DEBUG", logEnv);
}

From source file:org.apache.tez.common.IDUtils.java

License:Apache License

/** Construct a TaskID object from given string 
 * @return constructed TaskID object or null if the given String is null
 * @throws IllegalArgumentException if the given string is malformed
 *///from  w w w  .  ja v a 2 s  . c  o  m
public static TezTaskID toTaskId(String str) throws IllegalArgumentException {
    if (str == null)
        return null;
    String exceptionMsg = null;
    try {
        String[] parts = str.split("_");
        if (parts.length == 6) {
            if (parts[0].equals(TezTaskID.TASK)) {
                ApplicationId appId = ApplicationId.newInstance(Long.valueOf(parts[1]),
                        Integer.parseInt(parts[2]));
                TezDAGID dagId = new TezDAGID(appId, Integer.parseInt(parts[3]));
                TezVertexID vId = new TezVertexID(dagId, Integer.parseInt(parts[4]));
                return new TezTaskID(vId, Integer.parseInt(parts[5]));
            } else
                exceptionMsg = "Bad TaskType identifier. TaskId string : " + str + " is not properly formed.";
        }
    } catch (Exception ex) {//fall below
    }
    if (exceptionMsg == null) {
        exceptionMsg = "TaskId string : " + str + " is not properly formed";
    }
    throw new IllegalArgumentException(exceptionMsg);
}

From source file:org.apache.tez.common.IDUtils.java

License:Apache License

/** Construct a TaskAttemptID object from given string 
 * @return constructed TaskAttemptID object or null if the given String is null
 * @throws IllegalArgumentException if the given string is malformed
 *//*  w  ww . j  a va  2s .  co m*/
public static TezTaskAttemptID toTaskAttemptId(String str) throws IllegalArgumentException {
    if (str == null)
        return null;
    String exceptionMsg = null;
    try {
        String[] parts = str.split(Character.toString(TezID.SEPARATOR));
        if (parts.length == 7) {
            if (parts[0].equals(TezTaskAttemptID.ATTEMPT)) {
                ApplicationId appId = ApplicationId.newInstance(Long.valueOf(parts[1]),
                        Integer.parseInt(parts[2]));
                TezDAGID dagId = new TezDAGID(appId, Integer.parseInt(parts[3]));
                TezVertexID vId = new TezVertexID(dagId, Integer.parseInt(parts[4]));
                TezTaskID tId = new TezTaskID(vId, Integer.parseInt(parts[5]));
                return new TezTaskAttemptID(tId, Integer.parseInt(parts[6]));
            } else
                exceptionMsg = "Bad TaskType identifier. TaskAttemptId string : " + str
                        + " is not properly formed.";
        }
    } catch (Exception ex) {
        //fall below
    }
    if (exceptionMsg == null) {
        exceptionMsg = "TaskAttemptId string : " + str + " is not properly formed";
    }
    throw new IllegalArgumentException(exceptionMsg);
}

From source file:org.apache.tez.dag.app.dag.app.TestTezTaskCommunicatorManager.java

License:Apache License

@Test(timeout = 5000)
public void testContainerAliveOnGetTask() throws IOException {

    TaskCommunicatorContext context = mock(TaskCommunicatorContext.class);
    Configuration conf = new Configuration(false);
    UserPayload userPayload = TezUtils.createUserPayloadFromConf(conf);

    ApplicationId appId = ApplicationId.newInstance(1000, 1);
    ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1);
    ContainerId containerId = createContainerId(appId, 1);

    doReturn(appAttemptId).when(context).getApplicationAttemptId();
    doReturn(userPayload).when(context).getInitialUserPayload();
    doReturn(new Credentials()).when(context).getAMCredentials();

    TezTaskCommunicatorImpl taskComm = new TezTaskCommunicatorImpl(context);

    ContainerContext containerContext = new ContainerContext(containerId.toString());
    taskComm.registerRunningContainer(containerId, "fakehost", 0);
    ContainerTask containerTask = taskComm.getUmbilical().getTask(containerContext);
    assertNull(containerTask);/*w w  w.  ja v  a  2s.  co  m*/

    verify(context).containerAlive(containerId);
}

From source file:org.apache.tez.dag.app.dag.impl.TestCommit.java

License:Apache License

@SuppressWarnings({ "unchecked", "rawtypes" })
public void setupDAG(DAGPlan dagPlan) {
    conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_ENABLED, false);
    appAttemptId = ApplicationAttemptId.newInstance(ApplicationId.newInstance(100, 1), 1);
    dagId = TezDAGID.getInstance(appAttemptId.getApplicationId(), 1);
    Assert.assertNotNull(dagId);//from   ww w.ja  v a  2s  . c o  m
    dispatcher = new DrainDispatcher();
    fsTokens = new Credentials();
    appContext = mock(AppContext.class);
    when(appContext.getHadoopShim()).thenReturn(new DefaultHadoopShim());
    rawExecutor = Executors.newCachedThreadPool(
            new ThreadFactoryBuilder().setDaemon(true).setNameFormat("App Shared Pool - " + "#%d").build());
    execService = MoreExecutors.listeningDecorator(rawExecutor);

    doReturn(execService).when(appContext).getExecService();
    historyEventHandler = new MockHistoryEventHandler(appContext);
    aclManager = new ACLManager("amUser");
    doReturn(conf).when(appContext).getAMConf();
    doReturn(appAttemptId).when(appContext).getApplicationAttemptId();
    doReturn(appAttemptId.getApplicationId()).when(appContext).getApplicationID();
    doReturn(dagId).when(appContext).getCurrentDAGID();
    doReturn(historyEventHandler).when(appContext).getHistoryHandler();
    doReturn(aclManager).when(appContext).getAMACLManager();
    dag = new DAGImpl(dagId, conf, dagPlan, dispatcher.getEventHandler(), taskCommunicatorManagerInterface,
            fsTokens, clock, "user", thh, appContext);
    doReturn(dag).when(appContext).getCurrentDAG();
    doReturn(dispatcher.getEventHandler()).when(appContext).getEventHandler();
    ClusterInfo clusterInfo = new ClusterInfo(Resource.newInstance(8192, 10));
    doReturn(clusterInfo).when(appContext).getClusterInfo();
    dispatcher.register(CallableEventType.class, new CallableEventDispatcher());
    taskEventDispatcher = new TaskEventDispatcher();
    dispatcher.register(TaskEventType.class, taskEventDispatcher);
    taskAttemptEventDispatcher = new TaskAttemptEventDispatcher();
    dispatcher.register(TaskAttemptEventType.class, taskAttemptEventDispatcher);
    vertexEventDispatcher = new VertexEventDispatcher();
    dispatcher.register(VertexEventType.class, vertexEventDispatcher);
    dagEventDispatcher = new DagEventDispatcher();
    dispatcher.register(DAGEventType.class, dagEventDispatcher);
    dagFinishEventHandler = new DAGFinishEventHandler();
    dispatcher.register(DAGAppMasterEventType.class, dagFinishEventHandler);
    dispatcher.init(conf);
    dispatcher.start();
}

From source file:org.apache.tez.dag.app.dag.impl.TestDAGImpl.java

License:Apache License

@SuppressWarnings({ "unchecked", "rawtypes" })
@Before/*  w  w w  .java 2  s .c  o m*/
public void setup() {
    conf = new Configuration();
    conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_ENABLED, false);
    appAttemptId = ApplicationAttemptId.newInstance(ApplicationId.newInstance(100, 1), 1);
    dagId = TezDAGID.getInstance(appAttemptId.getApplicationId(), 1);
    Assert.assertNotNull(dagId);
    dagPlan = createTestDAGPlan();
    dispatcher = new DrainDispatcher();
    fsTokens = new Credentials();
    appContext = mock(AppContext.class);
    execService = mock(ListeningExecutorService.class);
    final ListenableFuture<Void> mockFuture = mock(ListenableFuture.class);

    Mockito.doAnswer(new Answer() {
        public ListenableFuture<Void> answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            CallableEvent e = (CallableEvent) args[0];
            dispatcher.getEventHandler().handle(e);
            return mockFuture;
        }
    }).when(execService).submit((Callable<Void>) any());

    doReturn(execService).when(appContext).getExecService();
    historyEventHandler = mock(HistoryEventHandler.class);
    aclManager = new ACLManager("amUser");
    doReturn(conf).when(appContext).getAMConf();
    doReturn(appAttemptId).when(appContext).getApplicationAttemptId();
    doReturn(appAttemptId.getApplicationId()).when(appContext).getApplicationID();
    doReturn(dagId).when(appContext).getCurrentDAGID();
    doReturn(historyEventHandler).when(appContext).getHistoryHandler();
    doReturn(aclManager).when(appContext).getAMACLManager();
    dag = new DAGImpl(dagId, conf, dagPlan, dispatcher.getEventHandler(), taskAttemptListener, fsTokens, clock,
            "user", thh, appContext);
    doReturn(dag).when(appContext).getCurrentDAG();
    mrrAppContext = mock(AppContext.class);
    doReturn(aclManager).when(mrrAppContext).getAMACLManager();
    doReturn(execService).when(mrrAppContext).getExecService();
    mrrDagId = TezDAGID.getInstance(appAttemptId.getApplicationId(), 2);
    mrrDagPlan = createTestMRRDAGPlan();
    mrrDag = new DAGImpl(mrrDagId, conf, mrrDagPlan, dispatcher.getEventHandler(), taskAttemptListener,
            fsTokens, clock, "user", thh, mrrAppContext);
    doReturn(conf).when(mrrAppContext).getAMConf();
    doReturn(mrrDag).when(mrrAppContext).getCurrentDAG();
    doReturn(appAttemptId).when(mrrAppContext).getApplicationAttemptId();
    doReturn(appAttemptId.getApplicationId()).when(mrrAppContext).getApplicationID();
    doReturn(historyEventHandler).when(mrrAppContext).getHistoryHandler();
    groupAppContext = mock(AppContext.class);
    doReturn(aclManager).when(groupAppContext).getAMACLManager();
    doReturn(execService).when(groupAppContext).getExecService();
    groupDagId = TezDAGID.getInstance(appAttemptId.getApplicationId(), 3);
    groupDagPlan = createGroupDAGPlan();
    groupDag = new DAGImpl(groupDagId, conf, groupDagPlan, dispatcher.getEventHandler(), taskAttemptListener,
            fsTokens, clock, "user", thh, groupAppContext);
    doReturn(conf).when(groupAppContext).getAMConf();
    doReturn(groupDag).when(groupAppContext).getCurrentDAG();
    doReturn(appAttemptId).when(groupAppContext).getApplicationAttemptId();
    doReturn(appAttemptId.getApplicationId()).when(groupAppContext).getApplicationID();
    doReturn(historyEventHandler).when(groupAppContext).getHistoryHandler();

    // reset totalCommitCounter to 0
    TotalCountingOutputCommitter.totalCommitCounter = 0;
    dispatcher.register(CallableEventType.class, new CallableEventDispatcher());
    taskEventDispatcher = new TaskEventDispatcher();
    dispatcher.register(TaskEventType.class, taskEventDispatcher);
    taskAttemptEventDispatcher = new TaskAttemptEventDispatcher();
    dispatcher.register(TaskAttemptEventType.class, taskAttemptEventDispatcher);
    vertexEventDispatcher = new VertexEventDispatcher();
    dispatcher.register(VertexEventType.class, vertexEventDispatcher);
    dagEventDispatcher = new DagEventDispatcher();
    dispatcher.register(DAGEventType.class, dagEventDispatcher);
    dagFinishEventHandler = new DAGFinishEventHandler();
    dispatcher.register(DAGAppMasterEventType.class, dagFinishEventHandler);
    dispatcher.register(TaskEventType.class, new TaskEventHandler());
    dispatcher.init(conf);
    dispatcher.start();
}

From source file:org.apache.tez.dag.app.dag.impl.TestDAGSchedulerNaturalOrderControlled.java

License:Apache License

private Vertex createMockVertex(String name, int vertexIdInt, int totalTasks, int distanceFromRoot) {
    ApplicationId appId = ApplicationId.newInstance(1000, 1);
    TezDAGID dagId = TezDAGID.getInstance(appId, 1);
    TezVertexID vertexId = TezVertexID.getInstance(dagId, vertexIdInt);

    Vertex vertex = mock(Vertex.class);
    doReturn(name).when(vertex).getName();
    doReturn(totalTasks).when(vertex).getTotalTasks();
    doReturn(vertexId).when(vertex).getVertexId();
    doReturn(distanceFromRoot).when(vertex).getDistanceFromRoot();
    doReturn(vertexId + " [" + name + "]").when(vertex).getLogIdentifier();
    return vertex;
}

From source file:org.apache.tez.dag.app.dag.impl.TestTaskAttempt.java

License:Apache License

@Test(timeout = 5000)
// Ensure the dag does not go into an error state if a attempt kill is
// received while STARTING
public void testLaunchFailedWhileKilling() throws Exception {
    ApplicationId appId = ApplicationId.newInstance(1, 2);
    ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 0);
    TezDAGID dagID = TezDAGID.getInstance(appId, 1);
    TezVertexID vertexID = TezVertexID.getInstance(dagID, 1);
    TezTaskID taskID = TezTaskID.getInstance(vertexID, 1);
    TezTaskAttemptID taskAttemptID = TezTaskAttemptID.getInstance(taskID, 0);

    MockEventHandler eventHandler = new MockEventHandler();
    TaskAttemptListener taListener = mock(TaskAttemptListener.class);
    when(taListener.getAddress()).thenReturn(new InetSocketAddress("localhost", 0));

    Configuration taskConf = new Configuration();
    taskConf.setClass("fs.file.impl", StubbedFS.class, FileSystem.class);
    taskConf.setBoolean("fs.file.impl.disable.cache", true);

    TaskLocationHint locationHint = TaskLocationHint
            .createTaskLocationHint(new HashSet<String>(Arrays.asList(new String[] { "127.0.0.1" })), null);
    Resource resource = Resource.newInstance(1024, 1);

    AppContext mockAppContext = mock(AppContext.class);
    doReturn(new ClusterInfo()).when(mockAppContext).getClusterInfo();

    TaskAttemptImpl taImpl = new MockTaskAttemptImpl(taskID, 1, eventHandler, taListener, taskConf,
            new SystemClock(), mock(TaskHeartbeatHandler.class), mockAppContext, locationHint, false, resource,
            createFakeContainerContext(), false);

    NodeId nid = NodeId.newInstance("127.0.0.1", 0);
    ContainerId contId = ContainerId.newInstance(appAttemptId, 3);
    Container container = mock(Container.class);
    when(container.getId()).thenReturn(contId);
    when(container.getNodeId()).thenReturn(nid);

    taImpl.handle(new TaskAttemptEventSchedule(taskAttemptID, 0, 0));
    // At state STARTING.
    taImpl.handle(new TaskAttemptEventKillRequest(taskAttemptID, null,
            TaskAttemptTerminationCause.TERMINATED_BY_CLIENT));
    // At some KILLING state.
    taImpl.handle(new TaskAttemptEventKillRequest(taskAttemptID, null,
            TaskAttemptTerminationCause.TERMINATED_BY_CLIENT));
    // taImpl.handle(new TaskAttemptEventContainerTerminating(taskAttemptID,
    // null));//from ww  w  .ja v a 2 s  . c  om
    assertFalse(eventHandler.internalError);
}