Search in sources :

Example 1 with TestConfiguration

use of com.netflix.conductor.core.execution.TestConfiguration in project conductor by Netflix.

the class TestEvent method test.

@SuppressWarnings("unchecked")
@Test
public void test() {
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(testWorkflowDefinition);
    Task task = new Task();
    task.getInputData().put("sink", "conductor");
    task.setReferenceTaskName("task0");
    task.setTaskId("task_id_0");
    QueueDAO dao = mock(QueueDAO.class);
    String[] publishedQueue = new String[1];
    List<Message> publishedMessages = new LinkedList<>();
    doAnswer((Answer<Void>) invocation -> {
        String queueName = invocation.getArgument(0, String.class);
        System.out.println(queueName);
        publishedQueue[0] = queueName;
        List<Message> messages = invocation.getArgument(1, List.class);
        publishedMessages.addAll(messages);
        return null;
    }).when(dao).push(any(), any());
    doAnswer((Answer<Boolean>) invocation -> {
        String messageId = invocation.getArgument(1, String.class);
        if (publishedMessages.get(0).getId().equals(messageId)) {
            publishedMessages.remove(0);
            return true;
        }
        return null;
    }).when(dao).ack(any(), any());
    Map<String, EventQueueProvider> providers = new HashMap<>();
    providers.put("conductor", new DynoEventQueueProvider(dao, new TestConfiguration(), Schedulers.from(Executors.newSingleThreadExecutor())));
    eventQueues = new EventQueues(providers, parametersUtils);
    Event event = new Event(eventQueues, parametersUtils, objectMapper);
    event.start(workflow, task, null);
    assertEquals(Task.Status.COMPLETED, task.getStatus());
    assertNotNull(task.getOutputData());
    assertEquals("conductor:" + workflow.getWorkflowName() + ":" + task.getReferenceTaskName(), task.getOutputData().get("event_produced"));
    assertEquals(task.getOutputData().get("event_produced"), "conductor:" + publishedQueue[0]);
    assertEquals(1, publishedMessages.size());
    assertEquals(task.getTaskId(), publishedMessages.get(0).getId());
    assertNotNull(publishedMessages.get(0).getPayload());
    event.cancel(workflow, task, null);
    assertTrue(publishedMessages.isEmpty());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TestConfiguration(com.netflix.conductor.core.execution.TestConfiguration) Status(com.netflix.conductor.common.metadata.tasks.Task.Status) HashMap(java.util.HashMap) Task(com.netflix.conductor.common.metadata.tasks.Task) ParametersUtils(com.netflix.conductor.core.execution.ParametersUtils) Answer(org.mockito.stubbing.Answer) EventQueueProvider(com.netflix.conductor.core.events.EventQueueProvider) Workflow(com.netflix.conductor.common.run.Workflow) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Schedulers(rx.schedulers.Schedulers) LinkedList(java.util.LinkedList) Before(org.junit.Before) Message(com.netflix.conductor.core.events.queue.Message) MockQueueProvider(com.netflix.conductor.core.events.MockQueueProvider) DynoEventQueueProvider(com.netflix.conductor.core.events.queue.dyno.DynoEventQueueProvider) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) EventQueues(com.netflix.conductor.core.events.EventQueues) Executors(java.util.concurrent.Executors) QueueDAO(com.netflix.conductor.dao.QueueDAO) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) TaskType(com.netflix.conductor.common.metadata.workflow.TaskType) 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) Task(com.netflix.conductor.common.metadata.tasks.Task) DynoEventQueueProvider(com.netflix.conductor.core.events.queue.dyno.DynoEventQueueProvider) Message(com.netflix.conductor.core.events.queue.Message) HashMap(java.util.HashMap) EventQueueProvider(com.netflix.conductor.core.events.EventQueueProvider) DynoEventQueueProvider(com.netflix.conductor.core.events.queue.dyno.DynoEventQueueProvider) TestConfiguration(com.netflix.conductor.core.execution.TestConfiguration) Workflow(com.netflix.conductor.common.run.Workflow) LinkedList(java.util.LinkedList) QueueDAO(com.netflix.conductor.dao.QueueDAO) EventQueues(com.netflix.conductor.core.events.EventQueues) LinkedList(java.util.LinkedList) List(java.util.List) Test(org.junit.Test)

Example 2 with TestConfiguration

use of com.netflix.conductor.core.execution.TestConfiguration 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());
}
Also used : Action(com.netflix.conductor.common.metadata.events.EventHandler.Action) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) TaskDetails(com.netflix.conductor.common.metadata.events.EventHandler.TaskDetails) TestConfiguration(com.netflix.conductor.core.execution.TestConfiguration) EventHandler(com.netflix.conductor.common.metadata.events.EventHandler) Test(org.junit.Test)

Example 3 with TestConfiguration

use of com.netflix.conductor.core.execution.TestConfiguration in project conductor by Netflix.

the class TestSimpleEventProcessor method testEventHandlerWithCondition.

@Test
public void testEventHandlerWithCondition() {
    EventHandler eventHandler = new EventHandler();
    eventHandler.setName("cms_intermediate_video_ingest_handler");
    eventHandler.setActive(true);
    eventHandler.setEvent("sqs:dev_cms_asset_ingest_queue");
    eventHandler.setCondition("$.Message.testKey1 == 'level1' && $.Message.metadata.testKey2 == 123456");
    Map<String, Object> startWorkflowInput = new LinkedHashMap<>();
    startWorkflowInput.put("param1", "${Message.metadata.testKey2}");
    startWorkflowInput.put("param2", "SQS-${MessageId}");
    Action startWorkflowAction = new Action();
    startWorkflowAction.setAction(Type.start_workflow);
    startWorkflowAction.setStart_workflow(new StartWorkflow());
    startWorkflowAction.getStart_workflow().setName("cms_artwork_automation");
    startWorkflowAction.getStart_workflow().setVersion(1);
    startWorkflowAction.getStart_workflow().setInput(startWorkflowInput);
    startWorkflowAction.setExpandInlineJSON(true);
    eventHandler.getActions().add(startWorkflowAction);
    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), eq(null));
    WorkflowDef workflowDef = new WorkflowDef();
    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());
    Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
    assertTrue(started.get());
}
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) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) TestConfiguration(com.netflix.conductor.core.execution.TestConfiguration) EventHandler(com.netflix.conductor.common.metadata.events.EventHandler) LinkedHashMap(java.util.LinkedHashMap) StartWorkflow(com.netflix.conductor.common.metadata.events.EventHandler.StartWorkflow) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 4 with TestConfiguration

use of com.netflix.conductor.core.execution.TestConfiguration in project conductor by Netflix.

the class ExecutionDAOFacadeTest method setUp.

@Before
public void setUp() {
    executionDAO = mock(ExecutionDAO.class);
    queueDAO = mock(QueueDAO.class);
    indexDAO = mock(IndexDAO.class);
    rateLimitingDao = mock(RateLimitingDAO.class);
    pollDataDAO = mock(PollDataDAO.class);
    objectMapper = new JsonMapperProvider().get();
    Configuration configuration = new TestConfiguration();
    executionDAOFacade = new ExecutionDAOFacade(executionDAO, queueDAO, indexDAO, rateLimitingDao, pollDataDAO, objectMapper, configuration);
}
Also used : QueueDAO(com.netflix.conductor.dao.QueueDAO) PollDataDAO(com.netflix.conductor.dao.PollDataDAO) ExecutionDAO(com.netflix.conductor.dao.ExecutionDAO) TestConfiguration(com.netflix.conductor.core.execution.TestConfiguration) Configuration(com.netflix.conductor.core.config.Configuration) TestConfiguration(com.netflix.conductor.core.execution.TestConfiguration) RateLimitingDAO(com.netflix.conductor.dao.RateLimitingDAO) IndexDAO(com.netflix.conductor.dao.IndexDAO) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) Before(org.junit.Before)

Example 5 with TestConfiguration

use of com.netflix.conductor.core.execution.TestConfiguration in project conductor by Netflix.

the class PerformanceTest method setUp.

@Before
public void setUp() {
    TestConfiguration testConfiguration = new TestConfiguration();
    configuration = new TestPostgresConfiguration(testConfiguration, "jdbc:postgresql://localhost:54320/conductor?charset=utf8&parseTime=true&interpolateParams=true", 10, 2);
    PostgresDataSourceProvider dataSource = new PostgresDataSourceProvider(configuration);
    this.dataSource = dataSource.get();
    resetAllData(this.dataSource);
    flywayMigrate(this.dataSource);
    final ObjectMapper objectMapper = new JsonMapperProvider().get();
    Q = new PostgresQueueDAO(objectMapper, this.dataSource);
    E = new PostgresExecutionDAO(objectMapper, this.dataSource);
}
Also used : PostgresExecutionDAO(com.netflix.conductor.dao.postgres.PostgresExecutionDAO) TestConfiguration(com.netflix.conductor.core.execution.TestConfiguration) PostgresQueueDAO(com.netflix.conductor.dao.postgres.PostgresQueueDAO) PostgresDataSourceProvider(com.netflix.conductor.postgres.PostgresDataSourceProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) Before(org.junit.Before)

Aggregations

TestConfiguration (com.netflix.conductor.core.execution.TestConfiguration)12 JsonMapperProvider (com.netflix.conductor.common.utils.JsonMapperProvider)10 Before (org.junit.Before)10 Test (org.junit.Test)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 EventHandler (com.netflix.conductor.common.metadata.events.EventHandler)7 Action (com.netflix.conductor.common.metadata.events.EventHandler.Action)7 TaskDetails (com.netflix.conductor.common.metadata.events.EventHandler.TaskDetails)7 Task (com.netflix.conductor.common.metadata.tasks.Task)7 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)7 Workflow (com.netflix.conductor.common.run.Workflow)7 Message (com.netflix.conductor.core.events.queue.Message)7 ObservableQueue (com.netflix.conductor.core.events.queue.ObservableQueue)7 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)7 ParametersUtils (com.netflix.conductor.core.execution.ParametersUtils)7 Collections (java.util.Collections)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 Assert.assertEquals (org.junit.Assert.assertEquals)7 Assert.assertNotNull (org.junit.Assert.assertNotNull)7