use of com.netflix.conductor.common.metadata.events.EventHandler.TaskDetails in project conductor by Netflix.
the class TestSimpleEventProcessor method testEventProcessorWithRetriableError.
@Test
public void testEventProcessorWithRetriableError() {
EventHandler eventHandler = new EventHandler();
eventHandler.setName(UUID.randomUUID().toString());
eventHandler.setActive(true);
eventHandler.setEvent(event);
Action completeTaskAction = new Action();
completeTaskAction.setAction(Type.complete_task);
completeTaskAction.setComplete_task(new TaskDetails());
completeTaskAction.getComplete_task().setTaskRefName("task_x");
completeTaskAction.getComplete_task().setWorkflowId(UUID.randomUUID().toString());
completeTaskAction.getComplete_task().setOutput(new HashMap<>());
eventHandler.getActions().add(completeTaskAction);
when(queue.rePublishIfNoAck()).thenReturn(false);
when(metadataService.getAllEventHandlers()).thenReturn(Collections.singletonList(eventHandler));
when(metadataService.getEventHandlersForEvent(event, true)).thenReturn(Collections.singletonList(eventHandler));
when(executionService.addEventExecution(any())).thenReturn(true);
when(actionProcessor.execute(any(), any(), any(), any())).thenThrow(new ApplicationException(ApplicationException.Code.BACKEND_ERROR, "some retriable error"));
SimpleEventProcessor eventProcessor = new SimpleEventProcessor(executionService, metadataService, actionProcessor, eventQueues, jsonUtils, new TestConfiguration(), objectMapper);
assertNotNull(eventProcessor.getQueues());
assertEquals(1, eventProcessor.getQueues().size());
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
verify(queue, never()).ack(any());
verify(queue, never()).publish(any());
}
use of com.netflix.conductor.common.metadata.events.EventHandler.TaskDetails in project conductor by Netflix.
the class TestSimpleActionProcessor method testCompleteTaskByTaskId.
@Test
public void testCompleteTaskByTaskId() throws Exception {
TaskDetails taskDetails = new TaskDetails();
taskDetails.setWorkflowId("${workflowId}");
taskDetails.setTaskId("${taskId}");
Action action = new Action();
action.setAction(Type.complete_task);
action.setComplete_task(taskDetails);
Object payload = objectMapper.readValue("{\"workflowId\":\"workflow_1\", \"taskId\":\"task_1\"}", Object.class);
Task task = new Task();
task.setTaskId("task_1");
task.setReferenceTaskName("testTask");
when(workflowExecutor.getTask(eq("task_1"))).thenReturn(task);
actionProcessor.execute(action, payload, "testEvent", "testMessage");
ArgumentCaptor<TaskResult> argumentCaptor = ArgumentCaptor.forClass(TaskResult.class);
verify(workflowExecutor).updateTask(argumentCaptor.capture());
assertEquals(Status.COMPLETED, argumentCaptor.getValue().getStatus());
assertEquals("testMessage", argumentCaptor.getValue().getOutputData().get("conductor.event.messageId"));
assertEquals("testEvent", argumentCaptor.getValue().getOutputData().get("conductor.event.name"));
assertEquals("workflow_1", argumentCaptor.getValue().getOutputData().get("workflowId"));
assertEquals("task_1", argumentCaptor.getValue().getOutputData().get("taskId"));
}
use of com.netflix.conductor.common.metadata.events.EventHandler.TaskDetails in project conductor by Netflix.
the class TestSimpleActionProcessor method testCompleteTask.
@Test
public void testCompleteTask() throws Exception {
TaskDetails taskDetails = new TaskDetails();
taskDetails.setWorkflowId("${workflowId}");
taskDetails.setTaskRefName("testTask");
taskDetails.getOutput().put("someNEKey", "${Message.someNEKey}");
taskDetails.getOutput().put("someKey", "${Message.someKey}");
taskDetails.getOutput().put("someNullKey", "${Message.someNullKey}");
Action action = new Action();
action.setAction(Type.complete_task);
action.setComplete_task(taskDetails);
String payloadJson = "{\"workflowId\":\"workflow_1\",\"Message\":{\"someKey\":\"someData\",\"someNullKey\":null}}";
Object payload = objectMapper.readValue(payloadJson, Object.class);
Task task = new Task();
task.setReferenceTaskName("testTask");
Workflow workflow = new Workflow();
workflow.getTasks().add(task);
when(workflowExecutor.getWorkflow(eq("workflow_1"), anyBoolean())).thenReturn(workflow);
actionProcessor.execute(action, payload, "testEvent", "testMessage");
ArgumentCaptor<TaskResult> argumentCaptor = ArgumentCaptor.forClass(TaskResult.class);
verify(workflowExecutor).updateTask(argumentCaptor.capture());
assertEquals(Status.COMPLETED, argumentCaptor.getValue().getStatus());
assertEquals("testMessage", argumentCaptor.getValue().getOutputData().get("conductor.event.messageId"));
assertEquals("testEvent", argumentCaptor.getValue().getOutputData().get("conductor.event.name"));
assertEquals("workflow_1", argumentCaptor.getValue().getOutputData().get("workflowId"));
assertEquals("testTask", argumentCaptor.getValue().getOutputData().get("taskRefName"));
assertEquals("someData", argumentCaptor.getValue().getOutputData().get("someKey"));
// Assert values not in message are evaluated to null
assertTrue("testTask", argumentCaptor.getValue().getOutputData().containsKey("someNEKey"));
// Assert null values from message are kept
assertTrue("testTask", argumentCaptor.getValue().getOutputData().containsKey("someNullKey"));
assertNull("testTask", argumentCaptor.getValue().getOutputData().get("someNullKey"));
}
use of com.netflix.conductor.common.metadata.events.EventHandler.TaskDetails in project conductor by Netflix.
the class TestSimpleEventProcessor method testEventProcessor.
@Test
public void testEventProcessor() {
// setup event handler
EventHandler eventHandler = new EventHandler();
eventHandler.setName(UUID.randomUUID().toString());
eventHandler.setActive(true);
Map<String, String> taskToDomain = new HashMap<>();
taskToDomain.put("*", "dev");
Action startWorkflowAction = new Action();
startWorkflowAction.setAction(Type.start_workflow);
startWorkflowAction.setStart_workflow(new StartWorkflow());
startWorkflowAction.getStart_workflow().setName("workflow_x");
startWorkflowAction.getStart_workflow().setVersion(1);
startWorkflowAction.getStart_workflow().setTaskToDomain(taskToDomain);
eventHandler.getActions().add(startWorkflowAction);
Action completeTaskAction = new Action();
completeTaskAction.setAction(Type.complete_task);
completeTaskAction.setComplete_task(new TaskDetails());
completeTaskAction.getComplete_task().setTaskRefName("task_x");
completeTaskAction.getComplete_task().setWorkflowId(UUID.randomUUID().toString());
completeTaskAction.getComplete_task().setOutput(new HashMap<>());
eventHandler.getActions().add(completeTaskAction);
eventHandler.setEvent(event);
when(metadataService.getAllEventHandlers()).thenReturn(Collections.singletonList(eventHandler));
when(metadataService.getEventHandlersForEvent(event, true)).thenReturn(Collections.singletonList(eventHandler));
when(executionService.addEventExecution(any())).thenReturn(true);
when(queue.rePublishIfNoAck()).thenReturn(false);
String id = UUID.randomUUID().toString();
AtomicBoolean started = new AtomicBoolean(false);
doAnswer((Answer<String>) invocation -> {
started.set(true);
return id;
}).when(workflowExecutor).startWorkflow(eq(startWorkflowAction.getStart_workflow().getName()), eq(startWorkflowAction.getStart_workflow().getVersion()), eq(startWorkflowAction.getStart_workflow().getCorrelationId()), anyMap(), eq(null), eq(event), anyMap());
AtomicBoolean completed = new AtomicBoolean(false);
doAnswer((Answer<String>) invocation -> {
completed.set(true);
return null;
}).when(workflowExecutor).updateTask(any());
Task task = new Task();
task.setReferenceTaskName(completeTaskAction.getComplete_task().getTaskRefName());
Workflow workflow = new Workflow();
workflow.setTasks(Collections.singletonList(task));
when(workflowExecutor.getWorkflow(completeTaskAction.getComplete_task().getWorkflowId(), true)).thenReturn(workflow);
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setVersion(startWorkflowAction.getStart_workflow().getVersion());
workflowDef.setName(startWorkflowAction.getStart_workflow().getName());
when(metadataService.getWorkflowDef(any(), any())).thenReturn(workflowDef);
SimpleActionProcessor actionProcessor = new SimpleActionProcessor(workflowExecutor, parametersUtils, jsonUtils);
SimpleEventProcessor eventProcessor = new SimpleEventProcessor(executionService, metadataService, actionProcessor, eventQueues, jsonUtils, new TestConfiguration(), objectMapper);
assertNotNull(eventProcessor.getQueues());
assertEquals(1, eventProcessor.getQueues().size());
String queueEvent = eventProcessor.getQueues().keySet().iterator().next();
assertEquals(eventHandler.getEvent(), queueEvent);
String eventProcessorQueue = eventProcessor.getQueues().values().iterator().next();
assertEquals(queueURI, eventProcessorQueue);
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
assertTrue(started.get());
assertTrue(completed.get());
verify(queue, atMost(1)).ack(any());
verify(queue, never()).publish(any());
}
use of com.netflix.conductor.common.metadata.events.EventHandler.TaskDetails in project conductor by Netflix.
the class TestSimpleEventProcessor method testEventProcessorWithNonRetriableError.
@Test
public void testEventProcessorWithNonRetriableError() {
EventHandler eventHandler = new EventHandler();
eventHandler.setName(UUID.randomUUID().toString());
eventHandler.setActive(true);
eventHandler.setEvent(event);
Action completeTaskAction = new Action();
completeTaskAction.setAction(Type.complete_task);
completeTaskAction.setComplete_task(new TaskDetails());
completeTaskAction.getComplete_task().setTaskRefName("task_x");
completeTaskAction.getComplete_task().setWorkflowId(UUID.randomUUID().toString());
completeTaskAction.getComplete_task().setOutput(new HashMap<>());
eventHandler.getActions().add(completeTaskAction);
when(metadataService.getAllEventHandlers()).thenReturn(Collections.singletonList(eventHandler));
when(metadataService.getEventHandlersForEvent(event, true)).thenReturn(Collections.singletonList(eventHandler));
when(executionService.addEventExecution(any())).thenReturn(true);
when(actionProcessor.execute(any(), any(), any(), any())).thenThrow(new ApplicationException(ApplicationException.Code.INVALID_INPUT, "some non-retriable error"));
SimpleEventProcessor eventProcessor = new SimpleEventProcessor(executionService, metadataService, actionProcessor, eventQueues, jsonUtils, new TestConfiguration(), objectMapper);
assertNotNull(eventProcessor.getQueues());
assertEquals(1, eventProcessor.getQueues().size());
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
verify(queue, atMost(1)).ack(any());
verify(queue, never()).publish(any());
}
Aggregations