Skip to content
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

[Improvement-16725][Master] Add more workflow Integration test cases in master. #16711

Open
wants to merge 63 commits into
base: dev
Choose a base branch
from
Open
Changes from 50 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
9887ee6
Removed Spring-boot-starter-cache dependencies
binitshrest Sep 5, 2024
9dfe630
Removed Spring-boot-starter-cache dependencies
binitshrest Sep 5, 2024
a2f3557
Merge remote-tracking branch 'origin/dev' into dev
binitshrest Sep 5, 2024
9d833b2
Merge branch 'dev' into dev
binitshrest Sep 5, 2024
12ea1d0
Merge remote-tracking branch 'origin/dev' into dev
binitshrest Sep 5, 2024
7fd1501
Merge remote-tracking branch 'origin/dev' into dev
binitshrest Sep 6, 2024
927560b
Removed cacheable and cacheconfig of spring-boot-starter-cache
binitshrest Sep 6, 2024
8f38773
Merge branch 'dev' into dev
binitshrest Sep 6, 2024
7e6f498
Removed cacheable and cacheconfig of removed spring-boot-starter-cach…
binitshrest Sep 6, 2024
5898102
Merge remote-tracking branch 'origin/dev' into dev
binitshrest Sep 6, 2024
e4f4a8d
Removed cacheable and cacheconfig of removed spring-boot-starter-cach…
binitshrest Sep 6, 2024
8c0ae9e
Removed cacheable and cacheconfig of removed spring-boot-starter-cach…
binitshrest Sep 9, 2024
cc81bbb
Removed cacheable and cacheconfig of removed spring-boot-starter-cach…
binitshrest Sep 9, 2024
1ab0f9f
Revert "Reverting some codes that is bugging"
binitshrest Sep 15, 2024
1ac7f40
Revert "Reverting some codes that is bugging"
binitshrest Sep 16, 2024
c1ab3e9
Merge branch 'dev' into dev
SbloodyS Sep 23, 2024
5ff15a1
Merge branch 'dev' into dev
binitshrest Sep 24, 2024
996a3a3
Merge branch 'dev' into dev
SbloodyS Oct 9, 2024
11d1050
renewed monaco-editor version
binitshrest Oct 9, 2024
2d3bc99
Merge remote-tracking branch 'origin/dev' into dev
binitshrest Oct 9, 2024
11f5d16
added some changes that was removed earlier
binitshrest Oct 9, 2024
2f4f8ed
reviewed some changes
binitshrest Oct 9, 2024
a166d16
reviewed some changes and updated it
binitshrest Oct 9, 2024
346b0f0
changes made that was asked
binitshrest Oct 9, 2024
e6506ca
read the documentatation of tools->release and implemented
binitshrest Oct 10, 2024
1d11fe7
kept some files in gitignore
binitshrest Oct 10, 2024
670f1b8
changing readme file
binitshrest Oct 10, 2024
0da86b4
made changes
binitshrest Oct 11, 2024
fd3a408
made changes
binitshrest Oct 11, 2024
3b9c48a
removed extra lines
binitshrest Oct 11, 2024
de40cb0
removed log4j-api mvn repo from dol-dist>release-docs>licence
binitshrest Oct 11, 2024
0fcd236
Removed log4j-api and log4j-to-slf4j from microbench pom.xml i.e tran…
binitshrest Oct 11, 2024
b7cdd41
Merge branch 'dev' into dev
SbloodyS Oct 12, 2024
a8da591
exlcuded all the transitive dependency that has log4j-api and log4j-t…
binitshrest Oct 13, 2024
27af1dd
changes are added
binitshrest Oct 13, 2024
3d13f4a
add some changes
binitshrest Oct 13, 2024
dce0895
optimize codes
binitshrest Oct 14, 2024
fc0b7f2
changes made
binitshrest Oct 14, 2024
beb21c6
made some changes
binitshrest Oct 14, 2024
de811ee
made some changes
binitshrest Oct 14, 2024
0f52a15
made some changes
binitshrest Oct 14, 2024
99321f6
removed duplicate codes
binitshrest Oct 14, 2024
cddfa31
Update pom.xml
binitshrest Oct 14, 2024
af490e2
removed two licence file log4j-api & log4j-to-slf4j as asked
binitshrest Oct 14, 2024
0689b5c
Merge branch 'dev' into dev
ruanwenjun Oct 14, 2024
ac13c0f
Merge branch 'dev' into dev
ruanwenjun Oct 15, 2024
1b4d13a
Merge branch 'dev' into Master-testcase
binitshrest Oct 21, 2024
50b7da4
wrote switchtask testcase
binitshrest Oct 21, 2024
9153cb5
made some changes
binitshrest Oct 21, 2024
8d4eead
Merge branch 'dev' into Master-testcase
SbloodyS Oct 22, 2024
40000ab
check with NullPointerException
binitshrest Oct 26, 2024
0b01617
Merge branch 'Master-testcase' of https://github.com/binitshrest/dolp…
binitshrest Oct 26, 2024
917cfe4
checking NPE while testing
binitshrest Oct 26, 2024
cadaebc
deleted unnecessary lines
binitshrest Oct 26, 2024
38a8db2
made some changes
binitshrest Oct 26, 2024
2353ac5
made some changes
binitshrest Oct 26, 2024
45ee4f8
removed some changes
binitshrest Oct 27, 2024
fe6887f
made some changes
binitshrest Oct 27, 2024
67e5c06
wrote a testcases and debugged and got null in taskParameters
binitshrest Oct 27, 2024
7551676
made some changes
binitshrest Oct 27, 2024
f3ea196
made some changes
binitshrest Oct 27, 2024
c933ee0
made some changes
binitshrest Oct 29, 2024
2d64a9e
made some changes
binitshrest Nov 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package org.apache.dolphinscheduler.server.master.runner.task.switchtask;

import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
import org.apache.dolphinscheduler.plugin.task.api.model.Property;
import org.apache.dolphinscheduler.plugin.task.api.model.SwitchResultVo;
import org.apache.dolphinscheduler.plugin.task.api.parameters.SwitchParameters;
import org.apache.dolphinscheduler.server.master.engine.workflow.runnable.IWorkflowExecutionRunnable;
import org.apache.dolphinscheduler.server.master.exception.MasterTaskExecuteException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

class SwitchLogicTaskTest {

@Mock
private IWorkflowExecutionRunnable workflowExecutionRunnable;

@Mock
private TaskExecutionContext taskExecutionContext;

@InjectMocks
private SwitchLogicTask switchLogicTask;

private SwitchParameters switchParameters;

@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);

// Mock taskExecutionContext and workflowExecutionRunnable
switchParameters = new SwitchParameters();
when(taskExecutionContext.getTaskParams()).thenReturn("{}"); // mock task params
when(taskExecutionContext.getPrepareParamsMap()).thenReturn(new HashMap<>());
}

@Test
void testHandle_WithMatchingBranch() throws MasterTaskExecuteException {
// Set up switch parameters with matching branch condition
List<SwitchResultVo> switchResultVoList = new ArrayList<>();
SwitchResultVo switchResultVo = new SwitchResultVo();
switchResultVo.setCondition("true"); // simple condition that matches
switchResultVo.setNextNode(123L); // mock next branch node
switchResultVoList.add(switchResultVo);

switchParameters.setSwitchResult(new SwitchParameters.SwitchResult(switchResultVoList, 999L));

// Mock the task instance and context setup
Map<String, Property> globalParams = new HashMap<>();
when(taskExecutionContext.getPrepareParamsMap()).thenReturn(globalParams);

// Execute the handle method
switchLogicTask.handle();

// Verify the task status
assertEquals(TaskExecutionStatus.SUCCESS, taskExecutionContext.getCurrentExecutionStatus());
}

@Test
void testHandle_DefaultBranch_WhenNoConditionMatches() throws MasterTaskExecuteException {
// Set up switch parameters with no matching branch condition
List<SwitchResultVo> switchResultVoList = new ArrayList<>();
SwitchResultVo switchResultVo = new SwitchResultVo();
switchResultVo.setCondition("false"); // condition that doesn't match
switchResultVo.setNextNode(123L); // mock next branch node
switchResultVoList.add(switchResultVo);

switchParameters.setSwitchResult(new SwitchParameters.SwitchResult(switchResultVoList, 999L));

// Execute the handle method
switchLogicTask.handle();

// Verify the task params and status
verify(taskExecutionContext).setCurrentExecutionStatus(TaskExecutionStatus.SUCCESS);
assertEquals(999L, switchParameters.getNextBranch()); // Default branch should be selected
}

@Test
void testHandle_ExceptionThrownWhenBranchDoesNotExist() {
// Mock the scenario where the branch does not exist in the workflow graph
when(workflowExecutionRunnable.getWorkflowExecuteContext()
.getWorkflowGraph()
.getTaskNodeByCode(anyLong())).thenReturn(null);

// Execute the handle method and expect an exception
MasterTaskExecuteException thrown = assertThrows(MasterTaskExecuteException.class, () -> {
switchLogicTask.handle();
});

// Verify that the exception message is as expected
assertTrue(thrown.getMessage().contains("please check the switch task configuration"));
}

@Test
void testHandle_ThrowsExceptionWhenDefaultBranchIsMissing() {
// Set up switch parameters without a default branch
switchParameters.setSwitchResult(new SwitchParameters.SwitchResult(new ArrayList<>(), null));

// Execute the handle method and expect an IllegalArgumentException
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> {
switchLogicTask.handle();
});

// Verify that the exception message is as expected
assertTrue(thrown.getMessage().contains("please check the switch task configuration"));
}

}
Loading