Browse Source

[Improvement] Avoid using search in for and start using testSaveTaskDefine (#11383)

* [Improvement] Avoid using search in for and start using testSaveTaskDefine()

* [Improvement] not import *

Co-authored-by: zhangshunmin <zhangshunmin@kezaihui.com>
3.1.0-release
longtb 2 years ago committed by GitHub
parent
commit
be66035dee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java
  2. 8
      dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/process/ProcessServiceTest.java

11
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java

@ -2559,8 +2559,16 @@ public class ProcessServiceImpl implements ProcessService {
} }
int insertResult = 0; int insertResult = 0;
int updateResult = 0; int updateResult = 0;
if (!updateTaskDefinitionLogs.isEmpty()) {
List<TaskDefinition> taskDefinitions = taskDefinitionMapper.queryByCodeList(updateTaskDefinitionLogs.stream().map(TaskDefinition::getCode).distinct().collect(Collectors.toList()));
for (TaskDefinitionLog taskDefinitionToUpdate : updateTaskDefinitionLogs) { for (TaskDefinitionLog taskDefinitionToUpdate : updateTaskDefinitionLogs) {
TaskDefinition task = taskDefinitionMapper.queryByCode(taskDefinitionToUpdate.getCode()); TaskDefinition task = null;
for (TaskDefinition taskDefinition : taskDefinitions) {
if (taskDefinitionToUpdate.getCode() == taskDefinition.getCode()) {
task = taskDefinition;
break;
}
}
if (task == null) { if (task == null) {
newTaskDefinitionLogs.add(taskDefinitionToUpdate); newTaskDefinitionLogs.add(taskDefinitionToUpdate);
} else { } else {
@ -2573,6 +2581,7 @@ public class ProcessServiceImpl implements ProcessService {
} }
} }
} }
}
if (!newTaskDefinitionLogs.isEmpty()) { if (!newTaskDefinitionLogs.isEmpty()) {
insertResult += taskDefinitionLogMapper.batchInsert(newTaskDefinitionLogs); insertResult += taskDefinitionLogMapper.batchInsert(newTaskDefinitionLogs);
if (Boolean.TRUE.equals(syncDefine)) { if (Boolean.TRUE.equals(syncDefine)) {

8
dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/process/ProcessServiceTest.java

@ -81,6 +81,7 @@ import org.apache.dolphinscheduler.service.cron.CronUtilsTest;
import org.apache.dolphinscheduler.service.exceptions.CronParseException; import org.apache.dolphinscheduler.service.exceptions.CronParseException;
import org.apache.dolphinscheduler.service.exceptions.ServiceException; import org.apache.dolphinscheduler.service.exceptions.ServiceException;
import org.apache.dolphinscheduler.service.expand.CuringParamsService; import org.apache.dolphinscheduler.service.expand.CuringParamsService;
import org.apache.dolphinscheduler.service.task.TaskPluginManager;
import org.apache.dolphinscheduler.spi.params.base.FormType; import org.apache.dolphinscheduler.spi.params.base.FormType;
import java.util.ArrayList; import java.util.ArrayList;
@ -168,6 +169,9 @@ public class ProcessServiceTest {
@Mock @Mock
CuringParamsService curingGlobalParamsService; CuringParamsService curingGlobalParamsService;
@Mock
TaskPluginManager taskPluginManager;
@Test @Test
public void testCreateSubCommand() { public void testCreateSubCommand() {
ProcessInstance parentInstance = new ProcessInstance(); ProcessInstance parentInstance = new ProcessInstance();
@ -682,6 +686,7 @@ public class ProcessServiceTest {
return list; return list;
} }
@Test
public void testSaveTaskDefine() { public void testSaveTaskDefine() {
User operator = new User(); User operator = new User();
operator.setId(-1); operator.setId(-1);
@ -706,9 +711,10 @@ public class ProcessServiceTest {
taskDefinition.setVersion(1); taskDefinition.setVersion(1);
taskDefinition.setCreateTime(new Date()); taskDefinition.setCreateTime(new Date());
taskDefinition.setUpdateTime(new Date()); taskDefinition.setUpdateTime(new Date());
Mockito.when(taskPluginManager.getParameters(any())).thenReturn(null);
Mockito.when(taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(taskDefinition.getCode(), taskDefinition.getVersion())).thenReturn(taskDefinition); Mockito.when(taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(taskDefinition.getCode(), taskDefinition.getVersion())).thenReturn(taskDefinition);
Mockito.when(taskDefinitionLogMapper.queryMaxVersionForDefinition(taskDefinition.getCode())).thenReturn(1); Mockito.when(taskDefinitionLogMapper.queryMaxVersionForDefinition(taskDefinition.getCode())).thenReturn(1);
Mockito.when(taskDefinitionMapper.queryByCode(taskDefinition.getCode())).thenReturn(taskDefinition); Mockito.when(taskDefinitionMapper.queryByCodeList(Collections.singletonList(taskDefinition.getCode()))).thenReturn(Collections.singletonList(taskDefinition));
int result = processService.saveTaskDefine(operator, projectCode, taskDefinitionLogs, Boolean.TRUE); int result = processService.saveTaskDefine(operator, projectCode, taskDefinitionLogs, Boolean.TRUE);
Assert.assertEquals(0, result); Assert.assertEquals(0, result);
} }

Loading…
Cancel
Save