use of com.netflix.conductor.tests.utils.UserTask in project conductor by Netflix.
the class AbstractWorkflowServiceTest method testWorkflowWithConditionalSystemTaskUsingExternalPayloadStorage.
@Test
public void testWorkflowWithConditionalSystemTaskUsingExternalPayloadStorage() {
createConditionalWFWithSystemTask();
WorkflowDef workflowDef = metadataService.getWorkflowDef(CONDITIONAL_SYSTEM_WORKFLOW, 1);
assertNotNull(workflowDef);
String workflowInputPath = INITIAL_WORKFLOW_INPUT_PATH;
String correlationId = "conditional_http_external_storage";
String workflowId = workflowExecutor.startWorkflow(CONDITIONAL_SYSTEM_WORKFLOW, 1, correlationId, null, workflowInputPath, null, null);
assertNotNull(workflowId);
Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertTrue("The workflow input should not be persisted", workflow.getInput().isEmpty());
assertEquals(workflowInputPath, workflow.getExternalInputPayloadStoragePath());
assertEquals(workflow.getReasonForIncompletion(), WorkflowStatus.RUNNING, workflow.getStatus());
assertEquals(1, workflow.getTasks().size());
// Polling for the first task
Task task = workflowExecutionService.poll("junit_task_1", "junit.worker.task_1");
assertNotNull(task);
assertEquals("junit_task_1", task.getTaskType());
assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
assertEquals(workflowId, task.getWorkflowInstanceId());
// update first task with COMPLETED and using external payload storage for output data
String taskOutputPath = TASK_OUTPUT_PATH;
task.setOutputData(null);
task.setExternalOutputPayloadStoragePath(taskOutputPath);
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(workflow.getReasonForIncompletion(), WorkflowStatus.RUNNING, workflow.getStatus());
assertEquals(3, workflow.getTasks().size());
assertEquals(DECISION.name(), workflow.getTasks().get(1).getTaskType());
assertEquals(UserTask.NAME, workflow.getTasks().get(2).getTaskType());
assertEquals(0, workflow.getTasks().get(2).getPollCount());
// simulate the SystemTaskWorkerCoordinator action
String taskId = workflow.getTaskByRefName("user_task").getTaskId();
workflowExecutor.executeSystemTask(userTask, taskId, 1);
task = workflowExecutionService.getTask(taskId);
assertEquals(COMPLETED, task.getStatus());
assertEquals(0, workflow.getTasks().get(2).getPollCount());
assertTrue("The task input should not be persisted", task.getInputData().isEmpty());
assertEquals(INPUT_PAYLOAD_PATH, task.getExternalInputPayloadStoragePath());
assertEquals(104, task.getOutputData().get("size"));
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(workflow.getReasonForIncompletion(), WorkflowStatus.RUNNING, workflow.getStatus());
assertEquals(4, workflow.getTasks().size());
// Polling for the last task
task = workflowExecutionService.poll("junit_task_3", "junit.worker.task_3");
assertNotNull(task);
assertEquals("junit_task_3", task.getTaskType());
assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
assertEquals(workflowId, task.getWorkflowInstanceId());
// update final task with COMPLETED
task.getOutputData().put("op", "success_task3");
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertTrue("The workflow input should not be persisted", workflow.getInput().isEmpty());
assertEquals(workflowInputPath, workflow.getExternalInputPayloadStoragePath());
assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
assertEquals(4, workflow.getTasks().size());
assertTrue(workflow.getOutput().isEmpty());
assertNotNull(workflow.getExternalOutputPayloadStoragePath());
assertEquals(WORKFLOW_OUTPUT_PATH, workflow.getExternalOutputPayloadStoragePath());
}
use of com.netflix.conductor.tests.utils.UserTask in project conductor by Netflix.
the class AbstractWorkflowServiceTest method testRateLimiting.
@Test
public void testRateLimiting() {
// Create a dynamic workflow definition with one simple task
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setName("test_concurrency_limits");
workflowDef.setVersion(1);
TaskDef taskDef = new TaskDef();
taskDef.setName("test_task_with_ratelimits");
taskDef.setRateLimitFrequencyInSeconds(600);
taskDef.setRateLimitPerFrequency(1);
WorkflowTask workflowTask = new WorkflowTask();
workflowTask.setTaskReferenceName("test_task_with_ratelimits");
workflowTask.setName("test_task_with_ratelimits");
workflowTask.setType(UserTask.NAME);
workflowTask.setTaskDefinition(taskDef);
Map<String, Object> userIP = new HashMap<>();
workflowDef.setTasks(Arrays.asList(workflowTask));
String workflowInstanceId1 = workflowExecutor.startWorkflow(workflowDef, new HashMap<>(), "", "", 0, "", "", "", new HashMap<>());
assertNotNull(workflowInstanceId1);
Workflow workflow1 = workflowExecutionService.getExecutionStatus(workflowInstanceId1, true);
assertNotNull(workflow1);
assertEquals(RUNNING, workflow1.getStatus());
// The very first task is the one that should be scheduled.
assertEquals(1, workflow1.getTasks().size());
UserTask userTask = new UserTask();
Task task = workflow1.getTasks().get(0);
workflowExecutor.executeSystemTask(userTask, task.getTaskId(), 30);
workflow1 = workflowExecutionService.getExecutionStatus(workflowInstanceId1, true);
String workflowInstanceId2 = workflowExecutor.startWorkflow(workflowDef, new HashMap<>(), "", "", 0, "", "", "", new HashMap<>());
assertNotNull(workflowInstanceId2);
Workflow workflow2 = workflowExecutionService.getExecutionStatus(workflowInstanceId2, true);
assertNotNull(workflow2);
assertEquals(RUNNING, workflow2.getStatus());
// The very first task is the one that should be scheduled.
assertEquals(1, workflow2.getTasks().size());
// Try to execute second task
Task task2 = workflow2.getTasks().get(0);
workflowExecutor.executeSystemTask(userTask, task2.getTaskId(), 30);
workflow2 = workflowExecutionService.getExecutionStatus(workflowInstanceId2, true);
task2 = workflow2.getTasks().get(0);
assertEquals(SCHEDULED, task2.getStatus());
}
Aggregations