Search in sources :

Example 16 with EventExecution

use of com.netflix.conductor.common.metadata.events.EventExecution 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"));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MetadataService(com.netflix.conductor.service.MetadataService) TestConfiguration(com.netflix.conductor.core.execution.TestConfiguration) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Action(com.netflix.conductor.common.metadata.events.EventHandler.Action) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) HashMap(java.util.HashMap) Task(com.netflix.conductor.common.metadata.tasks.Task) StartWorkflow(com.netflix.conductor.common.metadata.events.EventHandler.StartWorkflow) Observable(rx.Observable) ParametersUtils(com.netflix.conductor.core.execution.ParametersUtils) JsonUtils(com.netflix.conductor.core.utils.JsonUtils) LinkedHashMap(java.util.LinkedHashMap) Answer(org.mockito.stubbing.Answer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Workflow(com.netflix.conductor.common.run.Workflow) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) WorkflowExecutor(com.netflix.conductor.core.execution.WorkflowExecutor) EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) Before(org.junit.Before) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Message(com.netflix.conductor.core.events.queue.Message) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) EventHandler(com.netflix.conductor.common.metadata.events.EventHandler) UUID(java.util.UUID) Type(com.netflix.conductor.common.metadata.events.EventHandler.Action.Type) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Mockito.never(org.mockito.Mockito.never) Assert.assertNull(org.junit.Assert.assertNull) Mockito.atMost(org.mockito.Mockito.atMost) TaskDetails(com.netflix.conductor.common.metadata.events.EventHandler.TaskDetails) ExecutionService(com.netflix.conductor.service.ExecutionService) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) Action(com.netflix.conductor.common.metadata.events.EventHandler.Action) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) TestConfiguration(com.netflix.conductor.core.execution.TestConfiguration) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test)

Example 17 with EventExecution

use of com.netflix.conductor.common.metadata.events.EventExecution in project conductor by Netflix.

the class TestElasticSearchDAOV5 method addEventExecution.

@Test
public void addEventExecution() {
    String messageId = "some-message-id";
    EventExecution eventExecution = new EventExecution();
    eventExecution.setId("some-id");
    eventExecution.setMessageId(messageId);
    eventExecution.setAction(Type.complete_task);
    eventExecution.setEvent("some-event");
    eventExecution.setStatus(EventExecution.Status.COMPLETED);
    indexDAO.addEventExecution(eventExecution);
    await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
        SearchResponse searchResponse = search(LOG_INDEX_PREFIX + "*", "messageId='" + messageId + "'", 0, 10000, "*", EVENT_DOC_TYPE);
        assertEquals("search results should be length 1", searchResponse.getHits().getTotalHits(), 1);
        SearchHit searchHit = searchResponse.getHits().getAt(0);
        GetResponse response = elasticSearchClient.prepareGet(searchHit.getIndex(), EVENT_DOC_TYPE, searchHit.getId()).get();
        assertEquals("indexed message id should match", messageId, response.getSource().get("messageId"));
        assertEquals("indexed id should match", "some-id", response.getSource().get("id"));
        assertEquals("indexed status should match", EventExecution.Status.COMPLETED.name(), response.getSource().get("status"));
    });
    List<EventExecution> events = indexDAO.getEventExecutions("some-event");
    assertEquals(1, events.size());
    assertEquals(eventExecution, events.get(0));
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) GetResponse(org.elasticsearch.action.get.GetResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse) Test(org.junit.Test)

Example 18 with EventExecution

use of com.netflix.conductor.common.metadata.events.EventExecution in project conductor by Netflix.

the class ElasticSearchRestDAOV6 method mapEventExecutionsResponse.

private List<EventExecution> mapEventExecutionsResponse(SearchResponse response) throws IOException {
    SearchHit[] hits = response.getHits().getHits();
    List<EventExecution> executions = new ArrayList<>(hits.length);
    for (SearchHit hit : hits) {
        String source = hit.getSourceAsString();
        EventExecution tel = objectMapper.readValue(source, EventExecution.class);
        executions.add(tel);
    }
    return executions;
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) ArrayList(java.util.ArrayList)

Example 19 with EventExecution

use of com.netflix.conductor.common.metadata.events.EventExecution in project conductor by Netflix.

the class TestElasticSearchRestDAOV6 method shouldAddEventExecution.

@Test
public void shouldAddEventExecution() {
    String event = "event";
    EventExecution execution1 = createEventExecution(event);
    EventExecution execution2 = createEventExecution(event);
    indexDAO.addEventExecution(execution1);
    indexDAO.addEventExecution(execution2);
    List<EventExecution> indexedExecutions = tryFindResults(() -> indexDAO.getEventExecutions(event), 2);
    assertEquals(2, indexedExecutions.size());
    assertTrue("Not all event executions was indexed", indexedExecutions.containsAll(Arrays.asList(execution1, execution2)));
}
Also used : EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) Test(org.junit.Test)

Example 20 with EventExecution

use of com.netflix.conductor.common.metadata.events.EventExecution in project conductor by Netflix.

the class TestElasticSearchDAOV6 method createEventExecution.

private EventExecution createEventExecution(String event) {
    EventExecution execution = new EventExecution(uuid(), uuid());
    execution.setName("name");
    execution.setEvent(event);
    execution.setCreated(System.currentTimeMillis());
    execution.setStatus(EventExecution.Status.COMPLETED);
    execution.setAction(EventHandler.Action.Type.start_workflow);
    execution.setOutput(ImmutableMap.of("a", 1, "b", 2, "c", 3));
    return execution;
}
Also used : EventExecution(com.netflix.conductor.common.metadata.events.EventExecution)

Aggregations

EventExecution (com.netflix.conductor.common.metadata.events.EventExecution)28 Test (org.junit.Test)13 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)7 ArrayList (java.util.ArrayList)7 SearchHit (org.elasticsearch.search.SearchHit)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Action (com.netflix.conductor.common.metadata.events.EventHandler.Action)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 EventHandler (com.netflix.conductor.common.metadata.events.EventHandler)4 Message (com.netflix.conductor.core.events.queue.Message)4 ObservableQueue (com.netflix.conductor.core.events.queue.ObservableQueue)4 JsonUtils (com.netflix.conductor.core.utils.JsonUtils)4 ExecutionService (com.netflix.conductor.service.ExecutionService)4 MetadataService (com.netflix.conductor.service.MetadataService)4 Collections (java.util.Collections)4 TimeUnit (java.util.concurrent.TimeUnit)4 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)3 Type (com.netflix.conductor.common.metadata.events.EventHandler.Action.Type)3 StartWorkflow (com.netflix.conductor.common.metadata.events.EventHandler.StartWorkflow)3