Search in sources :

Example 1 with RunTaskContext

use of alluxio.job.RunTaskContext in project alluxio by Alluxio.

the class ReplicateDefinitionTest method runTaskReplicateTestHelper.

/**
 * Helper function to run a replicate task.
 *
 * @param blockWorkers available block workers
 * @param mockInStream mock blockInStream returned by the Block Store
 * @param mockOutStream mock blockOutStream returned by the Block Store
 */
private void runTaskReplicateTestHelper(List<BlockWorkerInfo> blockWorkers, BlockInStream mockInStream, BlockOutStream mockOutStream) throws Exception {
    when(mMockFileSystem.getStatus(any(AlluxioURI.class))).thenReturn(mTestStatus);
    when(mMockFileSystemContext.getCachedWorkers()).thenReturn(blockWorkers);
    when(mMockBlockStore.getInStream(anyLong(), any(InStreamOptions.class))).thenReturn(mockInStream);
    when(mMockBlockStore.getInStream(any(BlockInfo.class), any(InStreamOptions.class), any(Map.class))).thenReturn(mockInStream);
    PowerMockito.mockStatic(BlockInStream.class);
    when(BlockInStream.create(any(FileSystemContext.class), any(BlockInfo.class), any(WorkerNetAddress.class), any(BlockInStreamSource.class), any(InStreamOptions.class))).thenReturn(mockInStream);
    when(mMockBlockStore.getOutStream(eq(TEST_BLOCK_ID), eq(TEST_BLOCK_SIZE), eq(LOCAL_ADDRESS), any(OutStreamOptions.class))).thenReturn(mockOutStream);
    when(mMockBlockStore.getInfo(TEST_BLOCK_ID)).thenReturn(mTestBlockInfo.setLocations(Lists.newArrayList(new BlockLocation().setWorkerAddress(ADDRESS_1))));
    PowerMockito.mockStatic(AlluxioBlockStore.class);
    when(AlluxioBlockStore.create(any(FileSystemContext.class))).thenReturn(mMockBlockStore);
    ReplicateConfig config = new ReplicateConfig(TEST_PATH, TEST_BLOCK_ID, 1);
    ReplicateDefinition definition = new ReplicateDefinition();
    definition.runTask(config, null, new RunTaskContext(1, 1, mMockJobServerContext));
}
Also used : OutStreamOptions(alluxio.client.file.options.OutStreamOptions) RunTaskContext(alluxio.job.RunTaskContext) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockInStreamSource(alluxio.client.block.stream.BlockInStream.BlockInStreamSource) FileSystemContext(alluxio.client.file.FileSystemContext) BlockLocation(alluxio.wire.BlockLocation) Map(java.util.Map) AlluxioURI(alluxio.AlluxioURI) InStreamOptions(alluxio.client.file.options.InStreamOptions)

Example 2 with RunTaskContext

use of alluxio.job.RunTaskContext 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 3 with RunTaskContext

use of alluxio.job.RunTaskContext 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)

Aggregations

RunTaskContext (alluxio.job.RunTaskContext)3 RunTaskCommand (alluxio.grpc.RunTaskCommand)2 JobConfig (alluxio.job.JobConfig)2 SleepJobConfig (alluxio.job.SleepJobConfig)2 Serializable (java.io.Serializable)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 AlluxioURI (alluxio.AlluxioURI)1 BlockInStreamSource (alluxio.client.block.stream.BlockInStream.BlockInStreamSource)1 FileSystemContext (alluxio.client.file.FileSystemContext)1 InStreamOptions (alluxio.client.file.options.InStreamOptions)1 OutStreamOptions (alluxio.client.file.options.OutStreamOptions)1 BlockInfo (alluxio.wire.BlockInfo)1 BlockLocation (alluxio.wire.BlockLocation)1 FileBlockInfo (alluxio.wire.FileBlockInfo)1 WorkerNetAddress (alluxio.wire.WorkerNetAddress)1 Map (java.util.Map)1