-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[Improvement-17057][Master] Check if the WorkflowGraph is a DAG at constructor #18385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shangeyao
wants to merge
4
commits into
apache:dev
Choose a base branch
from
shangeyao:improvement-17057-workflow-graph-dag-check
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+290
−0
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d0e9075
[Improvement-17057][Master] Check if the WorkflowGraph is a DAG at co…
shangeyao 7cbfb43
[Improvement-17057][Master] Fix CodeQL warning for ignored Queue.offe…
shangeyao d50ea75
Merge branch 'dev' into improvement-17057-workflow-graph-dag-check
shangeyao 8af98c0
[Improvement-17057][Master] Include cyclic task details in DAG valida…
shangeyao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
222 changes: 222 additions & 0 deletions
222
...a/org/apache/dolphinscheduler/server/master/engine/graph/WorkflowGraphCheckIfDAGTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,222 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.dolphinscheduler.server.master.engine.graph; | ||
|
|
||
| import org.apache.dolphinscheduler.dao.entity.TaskDefinition; | ||
| import org.apache.dolphinscheduler.dao.entity.WorkflowTaskRelation; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class WorkflowGraphCheckIfDAGTest { | ||
|
|
||
| private List<TaskDefinition> taskDefinitions; | ||
| private List<WorkflowTaskRelation> workflowTaskRelations; | ||
|
|
||
| @BeforeEach | ||
| public void setUp() { | ||
| taskDefinitions = new ArrayList<>(); | ||
| workflowTaskRelations = new ArrayList<>(); | ||
| } | ||
|
|
||
| @Test | ||
| public void checkIfDAGSingleTaskNoException() { | ||
| TaskDefinition taskDefinition = new TaskDefinition(1L, 1); | ||
| taskDefinitions.add(taskDefinition); | ||
|
|
||
| WorkflowTaskRelation relation = new WorkflowTaskRelation(); | ||
| relation.setPreTaskCode(0); | ||
| relation.setPostTaskCode(1); | ||
| workflowTaskRelations.add(relation); | ||
|
|
||
| Assertions.assertDoesNotThrow(() -> new WorkflowGraph(workflowTaskRelations, taskDefinitions)); | ||
| } | ||
|
|
||
| @Test | ||
| public void checkIfDAGSimpleDAGNoException() { | ||
| TaskDefinition task1 = new TaskDefinition(1L, 1); | ||
| task1.setName("task1"); | ||
| TaskDefinition task2 = new TaskDefinition(2L, 1); | ||
| task2.setName("task2"); | ||
| taskDefinitions.add(task1); | ||
| taskDefinitions.add(task2); | ||
|
|
||
| WorkflowTaskRelation relation = new WorkflowTaskRelation(); | ||
| relation.setPreTaskCode(1L); | ||
| relation.setPreTaskVersion(1); | ||
| relation.setPostTaskCode(2L); | ||
| relation.setPostTaskVersion(1); | ||
| workflowTaskRelations.add(relation); | ||
|
|
||
| Assertions.assertDoesNotThrow(() -> new WorkflowGraph(workflowTaskRelations, taskDefinitions)); | ||
| } | ||
|
|
||
| @Test | ||
| public void checkIfDAGCycleThrowsException() { | ||
| TaskDefinition task1 = new TaskDefinition(1L, 1); | ||
| TaskDefinition task2 = new TaskDefinition(2L, 1); | ||
| taskDefinitions.add(task1); | ||
| taskDefinitions.add(task2); | ||
|
|
||
| WorkflowTaskRelation relation1 = new WorkflowTaskRelation(); | ||
| relation1.setPreTaskCode(1L); | ||
| relation1.setPreTaskVersion(1); | ||
| relation1.setPostTaskCode(2L); | ||
| relation1.setPostTaskVersion(1); | ||
| WorkflowTaskRelation relation2 = new WorkflowTaskRelation(); | ||
| relation2.setPreTaskCode(2L); | ||
| relation2.setPreTaskVersion(1); | ||
| relation2.setPostTaskCode(1L); | ||
| relation2.setPostTaskVersion(1); | ||
| workflowTaskRelations.add(relation1); | ||
| workflowTaskRelations.add(relation2); | ||
|
|
||
| Assertions.assertThrows(IllegalArgumentException.class, | ||
| () -> new WorkflowGraph(workflowTaskRelations, taskDefinitions)); | ||
| } | ||
|
|
||
| @Test | ||
| public void checkIfDAGMultipleZeroInDegreeNoException() { | ||
| TaskDefinition task1 = new TaskDefinition(1L, 1); | ||
| task1.setName("task1"); | ||
| TaskDefinition task2 = new TaskDefinition(2L, 1); | ||
| task2.setName("task2"); | ||
| TaskDefinition task3 = new TaskDefinition(3L, 1); | ||
| task3.setName("task3"); | ||
| taskDefinitions.add(task1); | ||
| taskDefinitions.add(task2); | ||
| taskDefinitions.add(task3); | ||
|
|
||
| WorkflowTaskRelation relation1 = new WorkflowTaskRelation(); | ||
| relation1.setPreTaskCode(1L); | ||
| relation1.setPreTaskVersion(1); | ||
| relation1.setPostTaskCode(2L); | ||
| relation1.setPostTaskVersion(1); | ||
| WorkflowTaskRelation relation2 = new WorkflowTaskRelation(); | ||
| relation2.setPreTaskCode(1L); | ||
| relation2.setPreTaskVersion(1); | ||
| relation2.setPostTaskCode(3L); | ||
| relation2.setPostTaskVersion(1); | ||
| workflowTaskRelations.add(relation1); | ||
| workflowTaskRelations.add(relation2); | ||
|
|
||
| Assertions.assertDoesNotThrow(() -> new WorkflowGraph(workflowTaskRelations, taskDefinitions)); | ||
| } | ||
|
|
||
| @Test | ||
| public void checkIfDAGComplexDAGNoException() { | ||
| TaskDefinition task1 = new TaskDefinition(1L, 1); | ||
| task1.setName("task1"); | ||
| TaskDefinition task2 = new TaskDefinition(2L, 1); | ||
| task2.setName("task2"); | ||
| TaskDefinition task3 = new TaskDefinition(3L, 1); | ||
| task3.setName("task3"); | ||
| TaskDefinition task4 = new TaskDefinition(4L, 1); | ||
| task4.setName("task4"); | ||
| taskDefinitions.add(task1); | ||
| taskDefinitions.add(task2); | ||
| taskDefinitions.add(task3); | ||
| taskDefinitions.add(task4); | ||
|
|
||
| WorkflowTaskRelation relation1 = new WorkflowTaskRelation(); | ||
| relation1.setPreTaskCode(1L); | ||
| relation1.setPreTaskVersion(1); | ||
| relation1.setPostTaskCode(2L); | ||
| relation1.setPostTaskVersion(1); | ||
|
|
||
| WorkflowTaskRelation relation2 = new WorkflowTaskRelation(); | ||
| relation2.setPreTaskCode(1L); | ||
| relation2.setPreTaskVersion(1); | ||
| relation2.setPostTaskCode(3L); | ||
| relation2.setPostTaskVersion(1); | ||
|
|
||
| WorkflowTaskRelation relation3 = new WorkflowTaskRelation(); | ||
| relation3.setPreTaskCode(2L); | ||
| relation3.setPreTaskVersion(1); | ||
| relation3.setPostTaskCode(4L); | ||
| relation3.setPostTaskVersion(1); | ||
|
|
||
| WorkflowTaskRelation relation4 = new WorkflowTaskRelation(); | ||
| relation4.setPreTaskCode(3L); | ||
| relation4.setPreTaskVersion(1); | ||
| relation4.setPostTaskCode(4L); | ||
| relation4.setPostTaskVersion(1); | ||
|
|
||
| workflowTaskRelations.add(relation1); | ||
| workflowTaskRelations.add(relation2); | ||
| workflowTaskRelations.add(relation3); | ||
| workflowTaskRelations.add(relation4); | ||
|
|
||
| Assertions.assertDoesNotThrow(() -> new WorkflowGraph(workflowTaskRelations, taskDefinitions)); | ||
| } | ||
|
|
||
| @Test | ||
| public void checkIfDAGComplexDAGThrowsException() { | ||
| TaskDefinition task1 = new TaskDefinition(1L, 1); | ||
| TaskDefinition task2 = new TaskDefinition(2L, 1); | ||
| TaskDefinition task3 = new TaskDefinition(3L, 1); | ||
| TaskDefinition task4 = new TaskDefinition(4L, 1); | ||
| taskDefinitions.add(task1); | ||
| taskDefinitions.add(task2); | ||
| taskDefinitions.add(task3); | ||
| taskDefinitions.add(task4); | ||
|
|
||
| WorkflowTaskRelation relation1 = new WorkflowTaskRelation(); | ||
| relation1.setPreTaskCode(1L); | ||
| relation1.setPreTaskVersion(1); | ||
| relation1.setPostTaskCode(2L); | ||
| relation1.setPostTaskVersion(1); | ||
|
|
||
| WorkflowTaskRelation relation2 = new WorkflowTaskRelation(); | ||
| relation2.setPreTaskCode(1L); | ||
| relation2.setPreTaskVersion(1); | ||
| relation2.setPostTaskCode(3L); | ||
| relation2.setPostTaskVersion(1); | ||
|
|
||
| WorkflowTaskRelation relation3 = new WorkflowTaskRelation(); | ||
| relation3.setPreTaskCode(2L); | ||
| relation3.setPreTaskVersion(1); | ||
| relation3.setPostTaskCode(4L); | ||
| relation3.setPostTaskVersion(1); | ||
|
|
||
| WorkflowTaskRelation relation4 = new WorkflowTaskRelation(); | ||
| relation4.setPreTaskCode(3L); | ||
| relation4.setPreTaskVersion(1); | ||
| relation4.setPostTaskCode(4L); | ||
| relation4.setPostTaskVersion(1); | ||
|
|
||
| WorkflowTaskRelation relation5 = new WorkflowTaskRelation(); | ||
| relation5.setPreTaskCode(4L); | ||
| relation5.setPreTaskVersion(1); | ||
| relation5.setPostTaskCode(3L); | ||
| relation5.setPostTaskVersion(1); | ||
|
|
||
| workflowTaskRelations.add(relation1); | ||
| workflowTaskRelations.add(relation2); | ||
| workflowTaskRelations.add(relation3); | ||
| workflowTaskRelations.add(relation4); | ||
| workflowTaskRelations.add(relation5); | ||
|
|
||
| Assertions.assertThrows(IllegalArgumentException.class, | ||
| () -> new WorkflowGraph(workflowTaskRelations, taskDefinitions)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include details about the relevant tasks in the suggestion error to facilitate quick identification.