|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.dolphinscheduler.server.master.integration.cases; |
| 19 | + |
| 20 | +import static com.google.common.truth.Truth.assertThat; |
| 21 | +import static org.awaitility.Awaitility.await; |
| 22 | + |
| 23 | +import org.apache.dolphinscheduler.common.enums.Flag; |
| 24 | +import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus; |
| 25 | +import org.apache.dolphinscheduler.common.utils.JSONUtils; |
| 26 | +import org.apache.dolphinscheduler.dao.entity.WorkflowDefinition; |
| 27 | +import org.apache.dolphinscheduler.dao.entity.WorkflowInstance; |
| 28 | +import org.apache.dolphinscheduler.extract.master.command.RunWorkflowCommandParam; |
| 29 | +import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; |
| 30 | +import org.apache.dolphinscheduler.plugin.task.api.model.Property; |
| 31 | +import org.apache.dolphinscheduler.server.master.AbstractMasterIntegrationTestCase; |
| 32 | +import org.apache.dolphinscheduler.server.master.integration.WorkflowOperator; |
| 33 | +import org.apache.dolphinscheduler.server.master.integration.WorkflowTestCaseContext; |
| 34 | + |
| 35 | +import java.time.Duration; |
| 36 | +import java.util.List; |
| 37 | + |
| 38 | +import org.assertj.core.api.Assertions; |
| 39 | +import org.junit.jupiter.api.DisplayName; |
| 40 | +import org.junit.jupiter.api.Test; |
| 41 | + |
| 42 | +/** |
| 43 | + * The integration test for validating sub workflow instances inherit global params from all parent flows. |
| 44 | + * Global params are asserted in each sub workflow instance and the fake_task in the sub-sub-workflow is used to verify the global params. |
| 45 | + */ |
| 46 | +class SubWorkflowInstanceGlobalParamsInheritanceTestCase extends AbstractMasterIntegrationTestCase { |
| 47 | + |
| 48 | + @Test |
| 49 | + @DisplayName("Test subflows inherit global params from all parent flows") |
| 50 | + void testSubflowInheritsGlobalParamsFromParentFlows_with_oneSuccessTask() { |
| 51 | + final String yaml = "/it/start/workflow_with_sub_workflows_with_global_params.yaml"; |
| 52 | + final WorkflowTestCaseContext context = workflowTestCaseContextFactory.initializeContextFromYaml(yaml); |
| 53 | + final WorkflowDefinition parentWorkflow = context.getOneWorkflow(); |
| 54 | + |
| 55 | + final WorkflowOperator.WorkflowTriggerDTO workflowTriggerDTO = WorkflowOperator.WorkflowTriggerDTO.builder() |
| 56 | + .workflowDefinition(parentWorkflow) |
| 57 | + .runWorkflowCommandParam(new RunWorkflowCommandParam()) |
| 58 | + .build(); |
| 59 | + final Integer workflowInstanceId = workflowOperator.manualTriggerWorkflow(workflowTriggerDTO); |
| 60 | + |
| 61 | + await() |
| 62 | + .atMost(Duration.ofMinutes(1)) |
| 63 | + .untilAsserted(() -> { |
| 64 | + Assertions |
| 65 | + .assertThat(repository.queryWorkflowInstance(workflowInstanceId)) |
| 66 | + .matches(workflowInstance -> workflowInstance.getState() == WorkflowExecutionStatus.SUCCESS) |
| 67 | + .matches(workflowInstance -> workflowInstance.getIsSubWorkflow() == Flag.NO); |
| 68 | + |
| 69 | + final List<WorkflowInstance> subWorkflowInstance = |
| 70 | + repository.queryWorkflowInstance(context.getWorkflows().get(1)); |
| 71 | + Assertions |
| 72 | + .assertThat(subWorkflowInstance) |
| 73 | + .hasSize(1) |
| 74 | + .satisfiesExactly(workflowInstance -> { |
| 75 | + assertThat(workflowInstance.getState()).isEqualTo(WorkflowExecutionStatus.SUCCESS); |
| 76 | + assertThat(workflowInstance.getIsSubWorkflow()).isEqualTo(Flag.YES); |
| 77 | + |
| 78 | + Assertions |
| 79 | + .assertThat( |
| 80 | + JSONUtils.toList(workflowInstance.getGlobalParams(), Property.class)) |
| 81 | + .hasSize(1) |
| 82 | + .anySatisfy(property -> { |
| 83 | + assertThat(property.getProp()).isEqualTo("parentWorkflowParam"); |
| 84 | + assertThat(property.getValue()).isEqualTo("parentWorkflowParamValue"); |
| 85 | + }); |
| 86 | + }); |
| 87 | + |
| 88 | + final List<WorkflowInstance> subSubWorkflowInstance = |
| 89 | + repository.queryWorkflowInstance(context.getWorkflows().get(2)); |
| 90 | + Assertions |
| 91 | + .assertThat(subSubWorkflowInstance) |
| 92 | + .hasSize(1) |
| 93 | + .satisfiesExactly(workflowInstance -> { |
| 94 | + assertThat(workflowInstance.getState()).isEqualTo(WorkflowExecutionStatus.SUCCESS); |
| 95 | + assertThat(workflowInstance.getIsSubWorkflow()).isEqualTo(Flag.YES); |
| 96 | + |
| 97 | + Assertions |
| 98 | + .assertThat( |
| 99 | + JSONUtils.toList(workflowInstance.getGlobalParams(), Property.class)) |
| 100 | + .hasSize(2) |
| 101 | + .anySatisfy(property -> { |
| 102 | + assertThat(property.getProp()).isEqualTo("parentWorkflowParam"); |
| 103 | + assertThat(property.getValue()).isEqualTo("parentWorkflowParamValue"); |
| 104 | + }) |
| 105 | + .anySatisfy(property -> { |
| 106 | + assertThat(property.getProp()).isEqualTo("subWorkflowParam"); |
| 107 | + assertThat(property.getValue()).isEqualTo("subWorkflowParamValue"); |
| 108 | + }); |
| 109 | + }); |
| 110 | + |
| 111 | + Assertions |
| 112 | + .assertThat(repository.queryTaskInstance(subSubWorkflowInstance.get(0).getId())) |
| 113 | + .satisfiesExactly(taskInstance -> { |
| 114 | + assertThat(taskInstance.getName()).isEqualTo("fake_task"); |
| 115 | + assertThat(taskInstance.getState()).isEqualTo(TaskExecutionStatus.SUCCESS); |
| 116 | + }); |
| 117 | + }); |
| 118 | + |
| 119 | + masterContainer.assertAllResourceReleased(); |
| 120 | + } |
| 121 | + |
| 122 | +} |
0 commit comments