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.runtime.task.TestTaskExecution.java

License:Apache License

@Test(timeout = 5000)
public void testGetTaskShouldDie() throws InterruptedException, ExecutionException {
    ListeningExecutorService executor = null;
    try {//  w ww.j  a  v a2  s  .  c  o  m
        ExecutorService rawExecutor = Executors.newFixedThreadPool(1);
        executor = MoreExecutors.listeningDecorator(rawExecutor);
        ApplicationId appId = ApplicationId.newInstance(10000, 1);
        ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1);
        ContainerId containerId = ContainerId.newInstance(appAttemptId, 1);

        TezTaskUmbilicalForTest umbilical = new TezTaskUmbilicalForTest();
        ContainerContext containerContext = new ContainerContext(containerId.toString());

        ContainerReporter containerReporter = new ContainerReporter(umbilical, containerContext, 100);
        ListenableFuture<ContainerTask> getTaskFuture = executor.submit(containerReporter);

        getTaskFuture.get();
        assertEquals(1, umbilical.getTaskInvocations);

    } finally {
        executor.shutdownNow();
    }
}

From source file:org.apache.tez.runtime.task.TestTaskExecution2.java

License:Apache License

@Test(timeout = 5000)
public void testSingleSuccessfulTask()
        throws IOException, InterruptedException, TezException, ExecutionException {
    ListeningExecutorService executor = null;
    try {/* www.  j ava  2 s.c  o  m*/
        ExecutorService rawExecutor = Executors.newFixedThreadPool(1);
        executor = MoreExecutors.listeningDecorator(rawExecutor);
        ApplicationId appId = ApplicationId.newInstance(10000, 1);
        TaskExecutionTestHelpers.TezTaskUmbilicalForTest umbilical = new TaskExecutionTestHelpers.TezTaskUmbilicalForTest();
        TaskReporter taskReporter = createTaskReporter(appId, umbilical);

        TezTaskRunner2 taskRunner = createTaskRunner(appId, umbilical, taskReporter, executor,
                TestProcessor.CONF_EMPTY);
        // Setup the executor
        Future<TaskRunner2Result> taskRunnerFuture = taskExecutor
                .submit(new TaskRunnerCallable2ForTest(taskRunner));
        // Signal the processor to go through
        TestProcessor.signal();
        TaskRunner2Result result = taskRunnerFuture.get();
        verifyTaskRunnerResult(result, EndReason.SUCCESS, null, false, null);
        assertNull(taskReporter.currentCallable);
        umbilical.verifyTaskSuccessEvent();
        assertFalse(TestProcessor.wasAborted());
    } finally {
        executor.shutdownNow();
    }
}

From source file:org.apache.tez.runtime.task.TestTaskExecution2.java

License:Apache License

@Test(timeout = 5000)
public void testMultipleSuccessfulTasks()
        throws IOException, InterruptedException, TezException, ExecutionException {

    ListeningExecutorService executor = null;
    try {//w ww  .  j a v a 2s. c om
        ExecutorService rawExecutor = Executors.newFixedThreadPool(1);
        executor = MoreExecutors.listeningDecorator(rawExecutor);
        ApplicationId appId = ApplicationId.newInstance(10000, 1);
        TaskExecutionTestHelpers.TezTaskUmbilicalForTest umbilical = new TaskExecutionTestHelpers.TezTaskUmbilicalForTest();
        TaskReporter taskReporter = createTaskReporter(appId, umbilical);

        TezTaskRunner2 taskRunner = createTaskRunner(appId, umbilical, taskReporter, executor,
                TestProcessor.CONF_EMPTY, true);
        LogicalIOProcessorRuntimeTask runtimeTask = taskRunner.task;
        // Setup the executor
        Future<TaskRunner2Result> taskRunnerFuture = taskExecutor
                .submit(new TaskRunnerCallable2ForTest(taskRunner));
        // Signal the processor to go through
        TestProcessor.signal();
        TaskRunner2Result result = taskRunnerFuture.get();
        verifyTaskRunnerResult(result, EndReason.SUCCESS, null, false, null);
        assertNull(taskReporter.currentCallable);
        umbilical.verifyTaskSuccessEvent();
        assertFalse(TestProcessor.wasAborted());
        umbilical.resetTrackedEvents();
        TezCounters tezCounters = runtimeTask.getCounters();
        verifySysCounters(tezCounters, 5, 5);

        taskRunner = createTaskRunner(appId, umbilical, taskReporter, executor, TestProcessor.CONF_EMPTY,
                false);
        runtimeTask = taskRunner.task;
        // Setup the executor
        taskRunnerFuture = taskExecutor.submit(new TaskRunnerCallable2ForTest(taskRunner));
        // Signal the processor to go through
        TestProcessor.signal();
        result = taskRunnerFuture.get();
        verifyTaskRunnerResult(result, EndReason.SUCCESS, null, false, null);
        assertNull(taskReporter.currentCallable);
        umbilical.verifyTaskSuccessEvent();
        assertFalse(TestProcessor.wasAborted());
        tezCounters = runtimeTask.getCounters();
        verifySysCounters(tezCounters, -1, -1);
    } finally {
        executor.shutdownNow();
    }
}

From source file:org.apache.tez.runtime.task.TestTaskExecution2.java

License:Apache License

@Test(timeout = 5000)
public void testFailedTaskTezException()
        throws IOException, InterruptedException, TezException, ExecutionException {

    ListeningExecutorService executor = null;
    try {//  w  w  w  .j a va2 s.c  om
        ExecutorService rawExecutor = Executors.newFixedThreadPool(1);
        executor = MoreExecutors.listeningDecorator(rawExecutor);
        ApplicationId appId = ApplicationId.newInstance(10000, 1);
        TaskExecutionTestHelpers.TezTaskUmbilicalForTest umbilical = new TaskExecutionTestHelpers.TezTaskUmbilicalForTest();
        TaskReporter taskReporter = createTaskReporter(appId, umbilical);

        TezTaskRunner2 taskRunner = createTaskRunner(appId, umbilical, taskReporter, executor,
                TestProcessor.CONF_THROW_TEZ_EXCEPTION);
        // Setup the executor
        Future<TaskRunner2Result> taskRunnerFuture = taskExecutor
                .submit(new TaskRunnerCallable2ForTest(taskRunner));
        // Signal the processor to go through
        TestProcessor.awaitStart();
        TestProcessor.signal();
        TaskRunner2Result result = taskRunnerFuture.get();
        verifyTaskRunnerResult(result, EndReason.TASK_ERROR, createProcessorTezException(), false,
                TaskFailureType.NON_FATAL);

        assertNull(taskReporter.currentCallable);
        umbilical.verifyTaskFailedEvent(FAILURE_START_STRING,
                TezException.class.getName() + ": " + TezException.class.getSimpleName());
        // Failure detected as a result of fall off from the run method. abort isn't required.
        assertFalse(TestProcessor.wasAborted());
        assertTrue(taskRunner.task.getCounters().countCounters() != 0);
    } finally {
        executor.shutdownNow();
    }
}

From source file:org.apache.tez.runtime.task.TestTaskExecution2.java

License:Apache License

@Test(timeout = 5000)
public void testFailedTask2() throws IOException, InterruptedException, TezException, ExecutionException {

    ListeningExecutorService executor = null;
    try {//w  w w. j a  v  a2 s .c  om
        ExecutorService rawExecutor = Executors.newFixedThreadPool(1);
        executor = MoreExecutors.listeningDecorator(rawExecutor);
        ApplicationId appId = ApplicationId.newInstance(10000, 1);
        TaskExecutionTestHelpers.TezTaskUmbilicalForTest umbilical = new TaskExecutionTestHelpers.TezTaskUmbilicalForTest();
        TaskReporter taskReporter = createTaskReporter(appId, umbilical);

        TezTaskRunner2 taskRunner = createTaskRunner(appId, umbilical, taskReporter, executor,
                "NotExitedProcessor", TestProcessor.CONF_EMPTY, false, true);
        // Setup the executor
        Future<TaskRunner2Result> taskRunnerFuture = taskExecutor
                .submit(new TaskRunnerCallable2ForTest(taskRunner));

        TaskRunner2Result result = taskRunnerFuture.get();
        verifyTaskRunnerResult(result, EndReason.TASK_ERROR,
                new TezReflectionException("TezReflectionException"), false, TaskFailureType.NON_FATAL);

        assertNull(taskReporter.currentCallable);
        umbilical.verifyTaskFailedEvent(FAILURE_START_STRING, ":org.apache.tez.dag.api.TezReflectionException: "
                + "Unable to load class: NotExitedProcessor");
        // Failure detected as a result of fall off from the run method. abort isn't required.
        assertFalse(TestProcessor.wasAborted());
        assertTrue(taskRunner.task.getCounters().countCounters() != 0);
    } finally {
        executor.shutdownNow();
    }
}

From source file:org.apache.tez.runtime.task.TestTaskExecution2.java

License:Apache License

@Test(timeout = 5000)
public void testFailedTaskIOException()
        throws IOException, InterruptedException, TezException, ExecutionException {

    ListeningExecutorService executor = null;
    try {/*from   ww  w  . j  a v a2 s  . c o m*/
        ExecutorService rawExecutor = Executors.newFixedThreadPool(1);
        executor = MoreExecutors.listeningDecorator(rawExecutor);
        ApplicationId appId = ApplicationId.newInstance(10000, 1);
        TaskExecutionTestHelpers.TezTaskUmbilicalForTest umbilical = new TaskExecutionTestHelpers.TezTaskUmbilicalForTest();
        TaskReporter taskReporter = createTaskReporter(appId, umbilical);

        TezTaskRunner2 taskRunner = createTaskRunner(appId, umbilical, taskReporter, executor,
                TestProcessor.CONF_THROW_IO_EXCEPTION);
        // Setup the executor
        Future<TaskRunner2Result> taskRunnerFuture = taskExecutor
                .submit(new TaskRunnerCallable2ForTest(taskRunner));
        // Signal the processor to go through
        TestProcessor.awaitStart();
        TestProcessor.signal();
        TaskRunner2Result result = taskRunnerFuture.get();
        verifyTaskRunnerResult(result, EndReason.TASK_ERROR, createProcessorIOException(), false,
                TaskFailureType.NON_FATAL);

        assertNull(taskReporter.currentCallable);
        umbilical.verifyTaskFailedEvent(FAILURE_START_STRING,
                IOException.class.getName() + ": " + IOException.class.getSimpleName());
        // Failure detected as a result of fall off from the run method. abort isn't required.
        assertFalse(TestProcessor.wasAborted());
        assertTrue(taskRunner.task.getCounters().countCounters() != 0);
    } finally {
        executor.shutdownNow();
    }
}

From source file:org.apache.tez.runtime.task.TestTaskExecution2.java

License:Apache License

@Test(timeout = 5000)
public void testHeartbeatException()
        throws IOException, InterruptedException, TezException, ExecutionException {

    ListeningExecutorService executor = null;
    try {/*from   w w w . j  a  va 2  s  .  co  m*/
        ExecutorService rawExecutor = Executors.newFixedThreadPool(1);
        executor = MoreExecutors.listeningDecorator(rawExecutor);
        ApplicationId appId = ApplicationId.newInstance(10000, 1);
        TaskExecutionTestHelpers.TezTaskUmbilicalForTest umbilical = new TaskExecutionTestHelpers.TezTaskUmbilicalForTest();
        TaskReporter taskReporter = createTaskReporter(appId, umbilical);

        TezTaskRunner2 taskRunner = createTaskRunner(appId, umbilical, taskReporter, executor,
                TestProcessor.CONF_EMPTY);
        // Setup the executor
        Future<TaskRunner2Result> taskRunnerFuture = taskExecutor
                .submit(new TaskRunnerCallable2ForTest(taskRunner));
        // Signal the processor to go through
        TestProcessor.awaitStart();
        umbilical.signalThrowException();
        umbilical.awaitRegisteredEvent();
        // Not signaling an actual start to verify task interruption

        TaskRunner2Result result = taskRunnerFuture.get();
        verifyTaskRunnerResult(result, EndReason.COMMUNICATION_FAILURE, new IOException("IOException"),
                TaskExecutionTestHelpers.HEARTBEAT_EXCEPTION_STRING, false, TaskFailureType.NON_FATAL);

        TestProcessor.awaitCompletion();
        assertTrue(TestProcessor.wasInterrupted());
        assertNull(taskReporter.currentCallable);
        // No completion events since umbilical communication already failed.
        umbilical.verifyNoCompletionEvents();
        assertTrue(TestProcessor.wasAborted());
    } finally {
        executor.shutdownNow();
    }
}

From source file:org.apache.tez.runtime.task.TestTaskExecution2.java

License:Apache License

@Test(timeout = 5000)
public void testHeartbeatShouldDie()
        throws IOException, InterruptedException, TezException, ExecutionException {

    ListeningExecutorService executor = null;
    try {//from w w  w .ja va2  s . c o  m
        ExecutorService rawExecutor = Executors.newFixedThreadPool(1);
        executor = MoreExecutors.listeningDecorator(rawExecutor);
        ApplicationId appId = ApplicationId.newInstance(10000, 1);
        TaskExecutionTestHelpers.TezTaskUmbilicalForTest umbilical = new TaskExecutionTestHelpers.TezTaskUmbilicalForTest();
        TaskReporter taskReporter = createTaskReporter(appId, umbilical);

        TezTaskRunner2 taskRunner = createTaskRunner(appId, umbilical, taskReporter, executor,
                TestProcessor.CONF_EMPTY);
        // Setup the executor
        Future<TaskRunner2Result> taskRunnerFuture = taskExecutor
                .submit(new TaskRunnerCallable2ForTest(taskRunner));
        // Signal the processor to go through
        TestProcessor.awaitStart();
        umbilical.signalSendShouldDie();
        umbilical.awaitRegisteredEvent();
        // Not signaling an actual start to verify task interruption

        TaskRunner2Result result = taskRunnerFuture.get();
        verifyTaskRunnerResult(result, EndReason.CONTAINER_STOP_REQUESTED, null, true, null);

        TestProcessor.awaitCompletion();
        assertTrue(TestProcessor.wasInterrupted());
        assertNull(taskReporter.currentCallable);
        // TODO Is this statement correct ?
        // No completion events since shouldDie was requested by the AM, which should have killed the
        // task.
        umbilical.verifyNoCompletionEvents();
        assertTrue(TestProcessor.wasAborted());
    } finally {
        executor.shutdownNow();
    }
}

From source file:org.apache.tez.runtime.task.TestTaskExecution2.java

License:Apache License

@Test(timeout = 5000)
public void testSignalDeprecatedFatalErrorAndLoop()
        throws IOException, InterruptedException, TezException, ExecutionException {

    ListeningExecutorService executor = null;
    try {/*from   w w w  .j  a va  2s . com*/
        ExecutorService rawExecutor = Executors.newFixedThreadPool(1);
        executor = MoreExecutors.listeningDecorator(rawExecutor);
        ApplicationId appId = ApplicationId.newInstance(10000, 1);
        TaskExecutionTestHelpers.TezTaskUmbilicalForTest umbilical = new TaskExecutionTestHelpers.TezTaskUmbilicalForTest();
        TaskReporter taskReporter = createTaskReporter(appId, umbilical);

        TezTaskRunner2 taskRunner = createTaskRunner(appId, umbilical, taskReporter, executor,
                TestProcessor.CONF_SIGNAL_DEPRECATEDFATAL_AND_LOOP);
        // Setup the executor
        Future<TaskRunner2Result> taskRunnerFuture = taskExecutor
                .submit(new TaskRunnerCallable2ForTest(taskRunner));
        // Signal the processor to go through
        TestProcessor.awaitStart();
        TestProcessor.signal();

        TestProcessor.awaitLoop();
        // The fatal error should have caused an interrupt.

        TaskRunner2Result result = taskRunnerFuture.get();
        verifyTaskRunnerResult(result, EndReason.TASK_ERROR, createProcessorIOException(), false,
                TaskFailureType.NON_FATAL);

        TestProcessor.awaitCompletion();
        assertTrue(TestProcessor.wasInterrupted());
        assertNull(taskReporter.currentCallable);
        umbilical.verifyTaskFailedEvent(FAILURE_START_STRING,
                IOException.class.getName() + ": " + IOException.class.getSimpleName());
        // Signal fatal error should cause the processor to fail.
        assertTrue(TestProcessor.wasAborted());
    } finally {
        executor.shutdownNow();
    }
}

From source file:org.apache.tez.runtime.task.TestTaskExecution2.java

License:Apache License

@Test(timeout = 5000)
public void testSignalFatalAndThrow()
        throws IOException, InterruptedException, TezException, ExecutionException {

    ListeningExecutorService executor = null;
    try {//from www.ja va  2 s.  com
        ExecutorService rawExecutor = Executors.newFixedThreadPool(1);
        executor = MoreExecutors.listeningDecorator(rawExecutor);
        ApplicationId appId = ApplicationId.newInstance(10000, 1);
        TaskExecutionTestHelpers.TezTaskUmbilicalForTest umbilical = new TaskExecutionTestHelpers.TezTaskUmbilicalForTest();
        TaskReporter taskReporter = createTaskReporter(appId, umbilical);

        TezTaskRunner2 taskRunner = createTaskRunner(appId, umbilical, taskReporter, executor,
                TestProcessor.CONF_SIGNAL_FATAL_AND_THROW);
        // Setup the executor
        Future<TaskRunner2Result> taskRunnerFuture = taskExecutor
                .submit(new TaskRunnerCallable2ForTest(taskRunner));
        // Signal the processor to go through
        TestProcessor.awaitStart();
        TestProcessor.signal();

        TaskRunner2Result result = taskRunnerFuture.get();
        verifyTaskRunnerResult(result, EndReason.TASK_ERROR, createProcessorIOException(), false,
                TaskFailureType.FATAL);

        TestProcessor.awaitCompletion();
        assertNull(taskReporter.currentCallable);
        umbilical.verifyTaskFailedEvent(FAILURE_START_STRING,
                IOException.class.getName() + ": " + IOException.class.getSimpleName(), TaskFailureType.FATAL);
        assertTrue(TestProcessor.wasAborted());
    } finally {
        executor.shutdownNow();
    }
}