use of com.netflix.conductor.common.metadata.events.EventExecution in project conductor by Netflix.
the class CassandraDAOTest method testEventExecutionCRUD.
@Test
public void testEventExecutionCRUD() throws Exception {
String event = "test-event";
String executionId1 = "id_1";
String messageId1 = "message1";
String eventHandler1 = "test_eh_1";
EventExecution eventExecution1 = getEventExecution(executionId1, messageId1, eventHandler1, event);
// create event execution explicitly in test
// since, embedded Cassandra server does not support LWT required for this API.
addEventExecution(eventExecution1);
// fetch executions
List<EventExecution> eventExecutionList = executionDAO.getEventExecutions(eventHandler1, event, messageId1);
assertNotNull(eventExecutionList);
assertEquals(1, eventExecutionList.size());
assertEquals(eventExecution1, eventExecutionList.get(0));
// add a different execution for same message
String executionId2 = "id_2";
EventExecution eventExecution2 = getEventExecution(executionId2, messageId1, eventHandler1, event);
addEventExecution(eventExecution2);
// fetch executions
eventExecutionList = executionDAO.getEventExecutions(eventHandler1, event, messageId1);
assertNotNull(eventExecutionList);
assertEquals(2, eventExecutionList.size());
assertEquals(eventExecution1, eventExecutionList.get(0));
assertEquals(eventExecution2, eventExecutionList.get(1));
// update the second execution
eventExecution2.setStatus(COMPLETED);
executionDAO.updateEventExecution(eventExecution2);
// fetch executions
eventExecutionList = executionDAO.getEventExecutions(eventHandler1, event, messageId1);
assertNotNull(eventExecutionList);
assertEquals(2, eventExecutionList.size());
assertEquals(COMPLETED, eventExecutionList.get(1).getStatus());
// sleep for 5 seconds (TTL)
Thread.sleep(5000L);
eventExecutionList = executionDAO.getEventExecutions(eventHandler1, event, messageId1);
assertNotNull(eventExecutionList);
assertEquals(1, eventExecutionList.size());
// delete event execution
executionDAO.removeEventExecution(eventExecution1);
eventExecutionList = executionDAO.getEventExecutions(eventHandler1, event, messageId1);
assertNotNull(eventExecutionList);
assertEquals(0, eventExecutionList.size());
}
use of com.netflix.conductor.common.metadata.events.EventExecution in project conductor by Netflix.
the class CassandraDAOTest method getEventExecution.
private EventExecution getEventExecution(String id, String msgId, String name, String event) {
EventExecution eventExecution = new EventExecution(id, msgId);
eventExecution.setName(name);
eventExecution.setEvent(event);
eventExecution.setStatus(EventExecution.Status.IN_PROGRESS);
return eventExecution;
}
use of com.netflix.conductor.common.metadata.events.EventExecution 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