use of org.apache.helix.task.TaskConfig in project helix by apache.
the class TestTaskErrorReporting method test.
@Test
public void test() throws Exception {
int taskRetryCount = 1;
int num_tasks = 5;
String jobResource = TestHelper.getTestMethodName();
JobConfig.Builder jobBuilder = new JobConfig.Builder();
jobBuilder.setCommand(MockTask.TASK_COMMAND).setTimeoutPerTask(10000).setMaxAttemptsPerTask(taskRetryCount).setFailureThreshold(Integer.MAX_VALUE);
// create each task configs.
final int abortedTask = 1;
final int failedTask = 2;
final int exceptionTask = 3;
final String abortedMsg = "This task aborted, some terrible things must happened.";
final String failedMsg = "This task failed, something may be wrong.";
final String exceptionMsg = "This task throws exception.";
final String successMsg = "Yes, we did it!";
List<TaskConfig> taskConfigs = new ArrayList<TaskConfig>();
for (int j = 0; j < num_tasks; j++) {
TaskConfig.Builder configBuilder = new TaskConfig.Builder().setTaskId("task_" + j);
switch(j) {
case abortedTask:
configBuilder.addConfig(MockTask.TASK_RESULT_STATUS, TaskResult.Status.FATAL_FAILED.name()).addConfig(MockTask.ERROR_MESSAGE, abortedMsg);
break;
case failedTask:
configBuilder.addConfig(MockTask.TASK_RESULT_STATUS, TaskResult.Status.FAILED.name()).addConfig(MockTask.ERROR_MESSAGE, failedMsg);
break;
case exceptionTask:
configBuilder.addConfig(MockTask.THROW_EXCEPTION, Boolean.TRUE.toString()).addConfig(MockTask.ERROR_MESSAGE, exceptionMsg);
break;
default:
configBuilder.addConfig(MockTask.ERROR_MESSAGE, successMsg);
break;
}
configBuilder.setTargetPartition(String.valueOf(j));
taskConfigs.add(configBuilder.build());
}
jobBuilder.addTaskConfigs(taskConfigs);
Workflow flow = WorkflowGenerator.generateSingleJobWorkflowBuilder(jobResource, jobBuilder).build();
_driver.start(flow);
// Wait until the job completes.
_driver.pollForWorkflowState(jobResource, TaskState.COMPLETED);
JobContext ctx = _driver.getJobContext(TaskUtil.getNamespacedJobName(jobResource));
for (int i = 0; i < num_tasks; i++) {
TaskPartitionState state = ctx.getPartitionState(i);
String taskId = ctx.getTaskIdForPartition(i);
String errMsg = ctx.getPartitionInfo(i);
if (taskId.equals("task_" + abortedTask)) {
Assert.assertEquals(state, TaskPartitionState.TASK_ABORTED);
Assert.assertEquals(errMsg, abortedMsg);
} else if (taskId.equals("task_" + failedTask)) {
Assert.assertEquals(state, TaskPartitionState.TASK_ERROR);
Assert.assertEquals(errMsg, failedMsg);
} else if (taskId.equals("task_" + exceptionTask)) {
Assert.assertEquals(state, TaskPartitionState.TASK_ERROR);
Assert.assertTrue(errMsg.contains(exceptionMsg));
} else {
Assert.assertEquals(state, TaskPartitionState.COMPLETED);
Assert.assertEquals(errMsg, successMsg);
}
}
}
use of org.apache.helix.task.TaskConfig in project helix by apache.
the class TestGenericTaskAssignmentCalculator method testMultipleTaskAssignment.
@Test
public void testMultipleTaskAssignment() throws InterruptedException {
failTask = false;
String workflowName = TestHelper.getTestMethodName();
Workflow.Builder workflowBuilder = new Workflow.Builder(workflowName);
List<TaskConfig> taskConfigs = Lists.newArrayListWithCapacity(20);
for (int i = 0; i < 50; i++) {
Map<String, String> taskConfigMap = Maps.newHashMap();
taskConfigs.add(new TaskConfig("TaskOne", taskConfigMap));
}
JobConfig.Builder jobBuilder = new JobConfig.Builder().setCommand("DummyCommand").setJobCommandConfigMap(_jobCommandMap).addTaskConfigs(taskConfigs);
workflowBuilder.addJob("JOB", jobBuilder);
_driver.start(workflowBuilder.build());
_driver.pollForWorkflowState(workflowName, TaskState.COMPLETED);
Assert.assertEquals(_runCounts.size(), 5);
}
use of org.apache.helix.task.TaskConfig in project helix by apache.
the class TestGenericTaskAssignmentCalculator method testAbortTaskForWorkflowFail.
@Test
public void testAbortTaskForWorkflowFail() throws InterruptedException {
failTask = true;
String workflowName = TestHelper.getTestMethodName();
Workflow.Builder workflowBuilder = new Workflow.Builder(workflowName);
List<TaskConfig> taskConfigs = Lists.newArrayListWithCapacity(1);
taskConfigs.add(_taskConfig);
JobConfig.Builder jobBuilder = new JobConfig.Builder().setCommand("DummyCommand").addTaskConfigs(taskConfigs).setJobCommandConfigMap(_jobCommandMap);
for (int i = 0; i < 5; i++) {
workflowBuilder.addJob("JOB" + i, jobBuilder);
}
_driver.start(workflowBuilder.build());
_driver.pollForWorkflowState(workflowName, TaskState.FAILED);
int abortedTask = 0;
for (TaskState jobState : _driver.getWorkflowContext(workflowName).getJobStates().values()) {
if (jobState == TaskState.ABORTED) {
abortedTask++;
}
}
Assert.assertEquals(abortedTask, 4);
}
use of org.apache.helix.task.TaskConfig in project helix by apache.
the class TestIndependentTaskRebalancer method testThresholdFailure.
@Test
public void testThresholdFailure() throws Exception {
// Create a job with two different tasks
String jobName = TestHelper.getTestMethodName();
Workflow.Builder workflowBuilder = new Workflow.Builder(jobName);
List<TaskConfig> taskConfigs = Lists.newArrayListWithCapacity(2);
Map<String, String> taskConfigMap = Maps.newHashMap(ImmutableMap.of("fail", "" + true));
TaskConfig taskConfig1 = new TaskConfig("TaskOne", taskConfigMap);
TaskConfig taskConfig2 = new TaskConfig("TaskTwo", null);
taskConfigs.add(taskConfig1);
taskConfigs.add(taskConfig2);
Map<String, String> jobConfigMap = Maps.newHashMap();
jobConfigMap.put("Timeout", "1000");
JobConfig.Builder jobBuilder = new JobConfig.Builder().setCommand("DummyCommand").setFailureThreshold(1).addTaskConfigs(taskConfigs).setJobCommandConfigMap(jobConfigMap);
workflowBuilder.addJob(jobName, jobBuilder);
_driver.start(workflowBuilder.build());
// Ensure the job completes
_driver.pollForWorkflowState(jobName, TaskState.IN_PROGRESS);
_driver.pollForWorkflowState(jobName, TaskState.COMPLETED);
// Ensure that each class was invoked
Assert.assertTrue(_invokedClasses.contains(TaskOne.class.getName()));
Assert.assertTrue(_invokedClasses.contains(TaskTwo.class.getName()));
}
use of org.apache.helix.task.TaskConfig in project helix by apache.
the class TestIndependentTaskRebalancer method testDelayedRetry.
@Test
public void testDelayedRetry() throws Exception {
// Create a single job with single task, set retry delay
int delay = 3000;
String jobName = TestHelper.getTestMethodName();
Workflow.Builder workflowBuilder = new Workflow.Builder(jobName);
List<TaskConfig> taskConfigs = Lists.newArrayListWithCapacity(1);
Map<String, String> taskConfigMap = Maps.newHashMap();
TaskConfig taskConfig1 = new TaskConfig("SingleFailTask", taskConfigMap);
taskConfigs.add(taskConfig1);
Map<String, String> jobCommandMap = Maps.newHashMap();
JobConfig.Builder jobBuilder = new JobConfig.Builder().setCommand("DummyCommand").setTaskRetryDelay(delay).addTaskConfigs(taskConfigs).setJobCommandConfigMap(jobCommandMap);
workflowBuilder.addJob(jobName, jobBuilder);
SingleFailTask.hasFailed = false;
_driver.start(workflowBuilder.build());
// Ensure completion
_driver.pollForWorkflowState(jobName, TaskState.COMPLETED);
// Ensure a single retry happened
JobContext jobCtx = _driver.getJobContext(jobName + "_" + jobName);
Assert.assertEquals(jobCtx.getPartitionNumAttempts(0), 2);
Assert.assertTrue(jobCtx.getFinishTime() - jobCtx.getStartTime() >= delay);
}
Aggregations