Search in sources :

Example 1 with RunTaskCommand

use of alluxio.grpc.RunTaskCommand in project alluxio by Alluxio.

the class TaskExecutorTest method runCompletion.

@Test
public void runCompletion() throws Exception {
    long jobId = 1;
    long taskId = 2;
    JobConfig jobConfig = mock(JobConfig.class);
    Serializable taskArgs = Lists.newArrayList(1);
    RunTaskContext context = mock(RunTaskContext.class);
    Integer taskResult = 1;
    @SuppressWarnings("unchecked") PlanDefinition<JobConfig, Serializable, Serializable> planDefinition = mock(PlanDefinition.class);
    when(mRegistry.getJobDefinition(any(JobConfig.class))).thenReturn(planDefinition);
    when(planDefinition.runTask(any(JobConfig.class), eq(taskArgs), any(RunTaskContext.class))).thenReturn(taskResult);
    RunTaskCommand command = RunTaskCommand.newBuilder().setJobConfig(ByteString.copyFrom(SerializationUtils.serialize(jobConfig))).setTaskArgs(ByteString.copyFrom(SerializationUtils.serialize(taskArgs))).build();
    TaskExecutor executor = new TaskExecutor(jobId, taskId, command, context, mTaskExecutorManager);
    executor.run();
    verify(planDefinition).runTask(any(JobConfig.class), eq(taskArgs), eq(context));
    verify(mTaskExecutorManager).notifyTaskCompletion(jobId, taskId, taskResult);
}
Also used : RunTaskCommand(alluxio.grpc.RunTaskCommand) Serializable(java.io.Serializable) RunTaskContext(alluxio.job.RunTaskContext) JobConfig(alluxio.job.JobConfig) SleepJobConfig(alluxio.job.SleepJobConfig) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with RunTaskCommand

use of alluxio.grpc.RunTaskCommand in project alluxio by Alluxio.

the class TaskExecutorTest method runFailure.

@Test
public void runFailure() throws Exception {
    long jobId = 1;
    long taskId = 2;
    JobConfig jobConfig = new SleepJobConfig(10);
    Serializable taskArgs = Lists.newArrayList(1);
    RunTaskContext context = mock(RunTaskContext.class);
    @SuppressWarnings("unchecked") PlanDefinition<JobConfig, Serializable, Serializable> planDefinition = mock(PlanDefinition.class);
    when(mRegistry.getJobDefinition(eq(jobConfig))).thenReturn(planDefinition);
    when(planDefinition.runTask(eq(jobConfig), any(Serializable.class), any(RunTaskContext.class))).thenThrow(new UnsupportedOperationException("failure"));
    RunTaskCommand command = RunTaskCommand.newBuilder().setJobConfig(ByteString.copyFrom(SerializationUtils.serialize(jobConfig))).setTaskArgs(ByteString.copyFrom(SerializationUtils.serialize(taskArgs))).build();
    TaskExecutor executor = new TaskExecutor(jobId, taskId, command, context, mTaskExecutorManager);
    executor.run();
    verify(mTaskExecutorManager).notifyTaskFailure(eq(jobId), eq(taskId), any());
}
Also used : RunTaskCommand(alluxio.grpc.RunTaskCommand) Serializable(java.io.Serializable) RunTaskContext(alluxio.job.RunTaskContext) SleepJobConfig(alluxio.job.SleepJobConfig) JobConfig(alluxio.job.JobConfig) SleepJobConfig(alluxio.job.SleepJobConfig) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with RunTaskCommand

use of alluxio.grpc.RunTaskCommand in project alluxio by Alluxio.

the class CommandHandlingExecutorTest method heartbeat.

@Test
public void heartbeat() throws Exception {
    JobCommand.Builder command = JobCommand.newBuilder();
    RunTaskCommand.Builder runTaskCommand = RunTaskCommand.newBuilder();
    long jobId = 1;
    runTaskCommand.setJobId(jobId);
    long taskId = 2;
    runTaskCommand.setTaskId(taskId);
    JobConfig jobConfig = new TestPlanConfig("/test");
    runTaskCommand.setJobConfig(ByteString.copyFrom(SerializationUtils.serialize(jobConfig)));
    Serializable taskArgs = Lists.newArrayList(1);
    runTaskCommand.setTaskArgs(ByteString.copyFrom(SerializationUtils.serialize(taskArgs)));
    command.setRunTaskCommand(runTaskCommand);
    Mockito.when(mJobMasterClient.heartbeat(any(JobWorkerHealth.class), eq(Lists.newArrayList()))).thenReturn(Lists.newArrayList(command.build()));
    mCommandHandlingExecutor.heartbeat();
    ExecutorService executorService = Whitebox.getInternalState(mCommandHandlingExecutor, "mCommandHandlingService");
    executorService.shutdown();
    Assert.assertTrue(executorService.awaitTermination(5000, TimeUnit.MILLISECONDS));
    Mockito.verify(mTaskExecutorManager).getAndClearTaskUpdates();
    Mockito.verify(mTaskExecutorManager).executeTask(Mockito.eq(jobId), Mockito.eq(taskId), Mockito.eq(runTaskCommand.build()), Mockito.any(RunTaskContext.class));
}
Also used : RunTaskCommand(alluxio.grpc.RunTaskCommand) TestPlanConfig(alluxio.job.TestPlanConfig) Serializable(java.io.Serializable) RunTaskContext(alluxio.job.RunTaskContext) JobCommand(alluxio.grpc.JobCommand) ExecutorService(java.util.concurrent.ExecutorService) JobWorkerHealth(alluxio.job.wire.JobWorkerHealth) JobConfig(alluxio.job.JobConfig) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

RunTaskCommand (alluxio.grpc.RunTaskCommand)3 JobConfig (alluxio.job.JobConfig)3 RunTaskContext (alluxio.job.RunTaskContext)3 Serializable (java.io.Serializable)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 SleepJobConfig (alluxio.job.SleepJobConfig)2 JobCommand (alluxio.grpc.JobCommand)1 TestPlanConfig (alluxio.job.TestPlanConfig)1 JobWorkerHealth (alluxio.job.wire.JobWorkerHealth)1 ExecutorService (java.util.concurrent.ExecutorService)1