use of com.netflix.conductor.common.metadata.events.EventHandler.Action in project conductor by Netflix.
the class TestSimpleEventProcessor method testExecuteNonRetriableApplicationException.
@Test
public void testExecuteNonRetriableApplicationException() {
AtomicInteger executeInvoked = new AtomicInteger(0);
doAnswer((Answer<Map<String, Object>>) invocation -> {
executeInvoked.incrementAndGet();
throw new ApplicationException(ApplicationException.Code.INVALID_INPUT, "some non-retriable error");
}).when(actionProcessor).execute(any(), any(), any(), any());
SimpleEventProcessor eventProcessor = new SimpleEventProcessor(executionService, metadataService, actionProcessor, eventQueues, jsonUtils, new TestConfiguration(), objectMapper);
EventExecution eventExecution = new EventExecution("id", "messageId");
eventExecution.setStatus(EventExecution.Status.IN_PROGRESS);
eventExecution.setEvent("event");
eventExecution.setName("handler");
Action action = new Action();
action.setAction(Type.start_workflow);
eventExecution.setAction(Type.start_workflow);
eventProcessor.execute(eventExecution, action, "payload");
assertEquals(1, executeInvoked.get());
assertEquals(EventExecution.Status.FAILED, eventExecution.getStatus());
assertNotNull(eventExecution.getOutput().get("exception"));
}
use of com.netflix.conductor.common.metadata.events.EventHandler.Action 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());
}
use of com.netflix.conductor.common.metadata.events.EventHandler.Action in project conductor by Netflix.
the class SimpleEventProcessor method executeActionsForEventHandler.
/**
* @param eventHandler the {@link EventHandler} for which the actions are to be executed
* @param msg the {@link Message} that triggered the event
* @return a {@link CompletableFuture} holding a list of {@link EventExecution}s for the {@link Action}s executed in the event handler
*/
protected CompletableFuture<List<EventExecution>> executeActionsForEventHandler(EventHandler eventHandler, Message msg) {
List<CompletableFuture<EventExecution>> futuresList = new ArrayList<>();
int i = 0;
for (Action action : eventHandler.getActions()) {
String id = msg.getId() + "_" + i++;
EventExecution eventExecution = new EventExecution(id, msg.getId());
eventExecution.setCreated(System.currentTimeMillis());
eventExecution.setEvent(eventHandler.getEvent());
eventExecution.setName(eventHandler.getName());
eventExecution.setAction(action.getAction());
eventExecution.setStatus(Status.IN_PROGRESS);
if (executionService.addEventExecution(eventExecution)) {
futuresList.add(CompletableFuture.supplyAsync(() -> execute(eventExecution, action, getPayloadObject(msg.getPayload())), executorService));
} else {
logger.warn("Duplicate delivery/execution of message: {}", msg.getId());
}
}
return CompletableFutures.allAsList(futuresList);
}
Aggregations