Search in sources :

Example 1 with ExecutionLockService

use of com.netflix.conductor.service.ExecutionLockService 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));
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Configuration(com.netflix.conductor.core.config.Configuration) DeciderService(com.netflix.conductor.core.execution.DeciderService) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) ExecutionLockService(com.netflix.conductor.service.ExecutionLockService) QueueDAO(com.netflix.conductor.dao.QueueDAO) MetadataMapperService(com.netflix.conductor.core.metadata.MetadataMapperService) WorkflowStatusListener(com.netflix.conductor.core.execution.WorkflowStatusListener) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ParametersUtils(com.netflix.conductor.core.execution.ParametersUtils) WorkflowExecutor(com.netflix.conductor.core.execution.WorkflowExecutor) ExecutionDAOFacade(com.netflix.conductor.core.orchestration.ExecutionDAOFacade) HashMap(java.util.HashMap) Map(java.util.Map) MetadataDAO(com.netflix.conductor.dao.MetadataDAO) Before(org.junit.Before)

Example 2 with ExecutionLockService

use of com.netflix.conductor.service.ExecutionLockService in project conductor by Netflix.

the class TestWorkflowExecutor method init.

@Before
public void init() {
    TestConfiguration config = new TestConfiguration();
    executionDAOFacade = mock(ExecutionDAOFacade.class);
    metadataDAO = mock(MetadataDAO.class);
    queueDAO = mock(QueueDAO.class);
    workflowStatusListener = mock(WorkflowStatusListener.class);
    ExternalPayloadStorageUtils externalPayloadStorageUtils = mock(ExternalPayloadStorageUtils.class);
    executionLockService = mock(ExecutionLockService.class);
    ObjectMapper objectMapper = new JsonMapperProvider().get();
    ParametersUtils parametersUtils = new ParametersUtils();
    Map<String, TaskMapper> taskMappers = new HashMap<>();
    taskMappers.put("DECISION", new DecisionTaskMapper());
    taskMappers.put("DYNAMIC", new DynamicTaskMapper(parametersUtils, metadataDAO));
    taskMappers.put("FORK_JOIN", new ForkJoinTaskMapper());
    taskMappers.put("JOIN", new JoinTaskMapper());
    taskMappers.put("FORK_JOIN_DYNAMIC", new ForkJoinDynamicTaskMapper(parametersUtils, objectMapper, metadataDAO));
    taskMappers.put("USER_DEFINED", new UserDefinedTaskMapper(parametersUtils, metadataDAO));
    taskMappers.put("SIMPLE", new SimpleTaskMapper(parametersUtils));
    taskMappers.put("SUB_WORKFLOW", new SubWorkflowTaskMapper(parametersUtils, metadataDAO));
    taskMappers.put("EVENT", new EventTaskMapper(parametersUtils));
    taskMappers.put("WAIT", new WaitTaskMapper(parametersUtils));
    taskMappers.put("HTTP", new HTTPTaskMapper(parametersUtils, metadataDAO));
    taskMappers.put("LAMBDA", new LambdaTaskMapper(parametersUtils, metadataDAO));
    new SubWorkflow(new JsonMapperProvider().get());
    new Lambda();
    DeciderService deciderService = new DeciderService(parametersUtils, metadataDAO, externalPayloadStorageUtils, taskMappers, config);
    MetadataMapperService metadataMapperService = new MetadataMapperService(metadataDAO);
    workflowExecutor = new WorkflowExecutor(deciderService, metadataDAO, queueDAO, metadataMapperService, workflowStatusListener, executionDAOFacade, config, executionLockService, parametersUtils);
}
Also used : LambdaTaskMapper(com.netflix.conductor.core.execution.mapper.LambdaTaskMapper) SubWorkflowTaskMapper(com.netflix.conductor.core.execution.mapper.SubWorkflowTaskMapper) HashMap(java.util.HashMap) WaitTaskMapper(com.netflix.conductor.core.execution.mapper.WaitTaskMapper) ExternalPayloadStorageUtils(com.netflix.conductor.core.utils.ExternalPayloadStorageUtils) SimpleTaskMapper(com.netflix.conductor.core.execution.mapper.SimpleTaskMapper) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ExecutionLockService(com.netflix.conductor.service.ExecutionLockService) QueueDAO(com.netflix.conductor.dao.QueueDAO) ForkJoinDynamicTaskMapper(com.netflix.conductor.core.execution.mapper.ForkJoinDynamicTaskMapper) Lambda(com.netflix.conductor.core.execution.tasks.Lambda) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MetadataDAO(com.netflix.conductor.dao.MetadataDAO) SimpleTaskMapper(com.netflix.conductor.core.execution.mapper.SimpleTaskMapper) LambdaTaskMapper(com.netflix.conductor.core.execution.mapper.LambdaTaskMapper) ForkJoinTaskMapper(com.netflix.conductor.core.execution.mapper.ForkJoinTaskMapper) HTTPTaskMapper(com.netflix.conductor.core.execution.mapper.HTTPTaskMapper) TaskMapper(com.netflix.conductor.core.execution.mapper.TaskMapper) ForkJoinDynamicTaskMapper(com.netflix.conductor.core.execution.mapper.ForkJoinDynamicTaskMapper) UserDefinedTaskMapper(com.netflix.conductor.core.execution.mapper.UserDefinedTaskMapper) WaitTaskMapper(com.netflix.conductor.core.execution.mapper.WaitTaskMapper) JoinTaskMapper(com.netflix.conductor.core.execution.mapper.JoinTaskMapper) SubWorkflowTaskMapper(com.netflix.conductor.core.execution.mapper.SubWorkflowTaskMapper) DecisionTaskMapper(com.netflix.conductor.core.execution.mapper.DecisionTaskMapper) DynamicTaskMapper(com.netflix.conductor.core.execution.mapper.DynamicTaskMapper) EventTaskMapper(com.netflix.conductor.core.execution.mapper.EventTaskMapper) EventTaskMapper(com.netflix.conductor.core.execution.mapper.EventTaskMapper) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) UserDefinedTaskMapper(com.netflix.conductor.core.execution.mapper.UserDefinedTaskMapper) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) ForkJoinTaskMapper(com.netflix.conductor.core.execution.mapper.ForkJoinTaskMapper) DecisionTaskMapper(com.netflix.conductor.core.execution.mapper.DecisionTaskMapper) MetadataMapperService(com.netflix.conductor.core.metadata.MetadataMapperService) HTTPTaskMapper(com.netflix.conductor.core.execution.mapper.HTTPTaskMapper) ForkJoinDynamicTaskMapper(com.netflix.conductor.core.execution.mapper.ForkJoinDynamicTaskMapper) DynamicTaskMapper(com.netflix.conductor.core.execution.mapper.DynamicTaskMapper) ForkJoinTaskMapper(com.netflix.conductor.core.execution.mapper.ForkJoinTaskMapper) JoinTaskMapper(com.netflix.conductor.core.execution.mapper.JoinTaskMapper) ExecutionDAOFacade(com.netflix.conductor.core.orchestration.ExecutionDAOFacade) Before(org.junit.Before)

Example 3 with ExecutionLockService

use of com.netflix.conductor.service.ExecutionLockService in project conductor by Netflix.

the class ZookeeperLockTest method testExecutionLockService.

@Ignore
public void testExecutionLockService() throws Exception {
    int numLocks = 10;
    int contentionFactor = 4;
    int numThreads = 10;
    List<String> locksIDs = new ArrayList<>(numLocks * 2 ^ (contentionFactor - 1));
    for (int i = 0; i < numLocks; i++) {
        locksIDs.add("testlock-" + i);
    }
    for (int i = 0; i < contentionFactor; i++) {
        locksIDs.addAll(locksIDs);
    }
    List<MultiLockWorker> workers = new ArrayList<>(numThreads);
    ExecutionLockService executionLock = new ExecutionLockService(zkConfig, mockProvider);
    for (int i = 0; i < numThreads; i++) {
        List<String> workerLockIDs = new ArrayList<>(locksIDs);
        Collections.shuffle(workerLockIDs);
        MultiLockWorker lockWorker = new MultiLockWorker(executionLock, workerLockIDs);
        lockWorker.start();
        workers.add(lockWorker);
    }
    for (int i = 0; i < numThreads; i++) {
        for (MultiLockWorker worker : workers) {
            worker.join();
            Assert.assertTrue(worker.isFinishedSuccessfully());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ExecutionLockService(com.netflix.conductor.service.ExecutionLockService) Ignore(org.junit.Ignore)

Aggregations

ExecutionLockService (com.netflix.conductor.service.ExecutionLockService)3 MetadataMapperService (com.netflix.conductor.core.metadata.MetadataMapperService)2 ExecutionDAOFacade (com.netflix.conductor.core.orchestration.ExecutionDAOFacade)2 MetadataDAO (com.netflix.conductor.dao.MetadataDAO)2 QueueDAO (com.netflix.conductor.dao.QueueDAO)2 HashMap (java.util.HashMap)2 Before (org.junit.Before)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Task (com.netflix.conductor.common.metadata.tasks.Task)1 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)1 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)1 Workflow (com.netflix.conductor.common.run.Workflow)1 JsonMapperProvider (com.netflix.conductor.common.utils.JsonMapperProvider)1 Configuration (com.netflix.conductor.core.config.Configuration)1 DeciderService (com.netflix.conductor.core.execution.DeciderService)1 ParametersUtils (com.netflix.conductor.core.execution.ParametersUtils)1 WorkflowExecutor (com.netflix.conductor.core.execution.WorkflowExecutor)1 WorkflowStatusListener (com.netflix.conductor.core.execution.WorkflowStatusListener)1 DecisionTaskMapper (com.netflix.conductor.core.execution.mapper.DecisionTaskMapper)1 DynamicTaskMapper (com.netflix.conductor.core.execution.mapper.DynamicTaskMapper)1