use of com.netflix.conductor.core.execution.ParametersUtils in project conductor by Netflix.
the class DoWhileTest method setup.
@Before
public void setup() {
workflow = Mockito.mock(Workflow.class);
deciderService = Mockito.mock(DeciderService.class);
metadataDAO = Mockito.mock(MetadataDAO.class);
queueDAO = Mockito.mock(QueueDAO.class);
parametersUtils = Mockito.mock(ParametersUtils.class);
metadataMapperService = Mockito.mock(MetadataMapperService.class);
workflowStatusListener = Mockito.mock(WorkflowStatusListener.class);
executionDAOFacade = Mockito.mock(ExecutionDAOFacade.class);
executionLockService = Mockito.mock(ExecutionLockService.class);
config = Mockito.mock(Configuration.class);
provider = spy(new WorkflowExecutor(deciderService, metadataDAO, queueDAO, metadataMapperService, workflowStatusListener, executionDAOFacade, config, executionLockService, parametersUtils));
loopWorkflowTask1 = new WorkflowTask();
loopWorkflowTask1.setTaskReferenceName("task1");
loopWorkflowTask1.setName("task1");
loopWorkflowTask2 = new WorkflowTask();
loopWorkflowTask2.setTaskReferenceName("task2");
loopWorkflowTask2.setName("task2");
task1 = new Task();
task1.setWorkflowTask(loopWorkflowTask1);
task1.setReferenceTaskName("task1");
task1.setStatus(Task.Status.COMPLETED);
task1.setTaskType(TaskType.HTTP.name());
task1.setInputData(new HashMap<>());
task1.setIteration(1);
task2 = new Task();
task2.setWorkflowTask(loopWorkflowTask2);
task2.setReferenceTaskName("task2");
task2.setStatus(Task.Status.COMPLETED);
task2.setTaskType(TaskType.HTTP.name());
task2.setInputData(new HashMap<>());
task2.setIteration(1);
loopTask = new Task();
loopTask.setReferenceTaskName("loopTask");
loopTask.setTaskType(TaskType.DO_WHILE.name());
loopTask.setInputData(new HashMap<>());
loopTask.setIteration(1);
loopWorkflowTask = new WorkflowTask();
loopWorkflowTask.setTaskReferenceName("loopTask");
loopWorkflowTask.setType(TaskType.DO_WHILE.name());
loopWorkflowTask.setName("loopTask");
loopWorkflowTask.setLoopCondition("if ($.loopTask['iteration'] < 1) { false; } else { true; }");
loopWorkflowTask.setLoopOver(Arrays.asList(task1.getWorkflowTask(), task2.getWorkflowTask()));
loopTask.setWorkflowTask(loopWorkflowTask);
doWhile = new DoWhile();
loopTaskDef = Mockito.mock(TaskDef.class);
Mockito.doReturn(loopTaskDef).when(provider).getTaskDefinition(loopTask);
Mockito.doReturn(task1).when(workflow).getTaskByRefName(task1.getReferenceTaskName());
Mockito.doReturn(task2).when(workflow).getTaskByRefName(task2.getReferenceTaskName());
Mockito.doReturn(task1).when(workflow).getTaskByRefName("task1__2");
Mockito.doReturn(task2).when(workflow).getTaskByRefName("task2__2");
Mockito.doReturn(new HashMap<>()).when(parametersUtils).getTaskInputV2(isA(Map.class), isA(Workflow.class), isA(String.class), isA(TaskDef.class));
}
use of com.netflix.conductor.core.execution.ParametersUtils in project conductor by Netflix.
the class TestEvent method setup.
@Before
public void setup() {
Map<String, EventQueueProvider> providers = new HashMap<>();
providers.put("sqs", new MockQueueProvider("sqs"));
providers.put("conductor", new MockQueueProvider("conductor"));
parametersUtils = new ParametersUtils();
eventQueues = new EventQueues(providers, parametersUtils);
testWorkflowDefinition = new WorkflowDef();
testWorkflowDefinition.setName("testWorkflow");
testWorkflowDefinition.setVersion(2);
}
use of com.netflix.conductor.core.execution.ParametersUtils 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());
}
use of com.netflix.conductor.core.execution.ParametersUtils in project conductor by Netflix.
the class EventTaskMapperTest method getMappedTasks.
@Test
public void getMappedTasks() throws Exception {
ParametersUtils parametersUtils = Mockito.mock(ParametersUtils.class);
EventTaskMapper eventTaskMapper = new EventTaskMapper(parametersUtils);
WorkflowTask taskToBeScheduled = new WorkflowTask();
taskToBeScheduled.setSink("SQSSINK");
String taskId = IDGenerator.generate();
Map<String, Object> eventTaskInput = new HashMap<>();
eventTaskInput.put("sink", "SQSSINK");
when(parametersUtils.getTaskInput(anyMap(), any(Workflow.class), any(TaskDef.class), anyString())).thenReturn(eventTaskInput);
WorkflowDef wd = new WorkflowDef();
Workflow w = new Workflow();
w.setWorkflowDefinition(wd);
TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(wd).withWorkflowInstance(w).withTaskDefinition(new TaskDef()).withTaskToSchedule(taskToBeScheduled).withRetryCount(0).withTaskId(taskId).build();
List<Task> mappedTasks = eventTaskMapper.getMappedTasks(taskMapperContext);
assertEquals(1, mappedTasks.size());
Task eventTask = mappedTasks.get(0);
assertEquals(taskId, eventTask.getTaskId());
}
use of com.netflix.conductor.core.execution.ParametersUtils in project conductor by Netflix.
the class TestSimpleEventProcessor method setup.
@Before
public void setup() {
event = "sqs:arn:account090:sqstest1";
queueURI = "arn:account090:sqstest1";
metadataService = mock(MetadataService.class);
executionService = mock(ExecutionService.class);
workflowExecutor = mock(WorkflowExecutor.class);
actionProcessor = mock(SimpleActionProcessor.class);
parametersUtils = new ParametersUtils();
jsonUtils = new JsonUtils();
EventQueueProvider provider = mock(EventQueueProvider.class);
queue = mock(ObservableQueue.class);
Message[] messages = new Message[1];
messages[0] = new Message("t0", "{\"Type\":\"Notification\",\"MessageId\":\"7e4e6415-01e9-5caf-abaa-37fd05d446ff\",\"Message\":\"{\\n \\\"testKey1\\\": \\\"level1\\\",\\n \\\"metadata\\\": {\\n \\\"testKey2\\\": 123456 }\\n }\",\"Timestamp\":\"2018-08-10T21:22:05.029Z\",\"SignatureVersion\":\"1\"}", "t0");
Observable<Message> msgObservable = Observable.from(messages);
when(queue.observe()).thenReturn(msgObservable);
when(queue.getURI()).thenReturn(queueURI);
when(queue.getName()).thenReturn(queueURI);
when(queue.getType()).thenReturn("sqs");
when(provider.getQueue(queueURI)).thenReturn(queue);
Map<String, EventQueueProvider> providers = new HashMap<>();
providers.put("sqs", provider);
eventQueues = new EventQueues(providers, parametersUtils);
}
Aggregations