Browse Source

[Feature][jsonsplit]add mapper module ut and some bugfix (#4957)

* Modify Project and ProjectUser Mapper

* Modify Project and ProjectUser Mapper

* project_code is bigint(20)

* modify ERROR name

* modify saveProcessDefine, remove the duplicate code with createTaskAndRelation

* modify import/export processdefinition, add genProcessData

* fix ut and bug

* code style

* repalce project_id with code

* conflicts solve

* conflicts solve

* conflicts solve

* bugfix

* modify listResources mothod and remove getResourceIds mothod

* 1

* conflicts solve

* modify listResources mothod and remove getResourceIds mothod

* modify listResources mothod and remove getResourceIds mothod

* replace processDefinitionVersion with processDefinitionLog

* codestyle

* codestyle

* add mapper module ut

* codestyle
pull/3/MERGE
Simon 4 years ago committed by GitHub
parent
commit
f24ecff840
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessTaskRelation.java
  2. 4
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessTaskRelationLog.java
  3. 2
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.java
  4. 2
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.xml
  5. 5
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.xml
  6. 174
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapperTest.java
  7. 71
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationLogMapperTest.java
  8. 94
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapperTest.java
  9. 12
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java

20
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessTaskRelation.java

@ -73,7 +73,7 @@ public class ProcessTaskRelation {
/** /**
* pre node version * pre node version
*/ */
private int preNodeVersion; private int preTaskVersion;
/** /**
* post task code * post task code
@ -83,7 +83,7 @@ public class ProcessTaskRelation {
/** /**
* post node version * post node version
*/ */
private int postNodeVersion; private int postTaskVersion;
/** /**
* condition type * condition type
@ -259,19 +259,19 @@ public class ProcessTaskRelation {
this.conditionType = conditionType; this.conditionType = conditionType;
} }
public int getPreNodeVersion() { public int getPreTaskVersion() {
return preNodeVersion; return preTaskVersion;
} }
public void setPreNodeVersion(int preNodeVersion) { public void setPreTaskVersion(int preTaskVersion) {
this.preNodeVersion = preNodeVersion; this.preTaskVersion = preTaskVersion;
} }
public int getPostNodeVersion() { public int getPostTaskVersion() {
return postNodeVersion; return postTaskVersion;
} }
public void setPostNodeVersion(int postNodeVersion) { public void setPostTaskVersion(int postTaskVersion) {
this.postNodeVersion = postNodeVersion; this.postTaskVersion = postTaskVersion;
} }
} }

4
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessTaskRelationLog.java

@ -51,9 +51,9 @@ public class ProcessTaskRelationLog extends ProcessTaskRelation {
this.setProcessDefinitionVersion(processTaskRelation.getProcessDefinitionVersion()); this.setProcessDefinitionVersion(processTaskRelation.getProcessDefinitionVersion());
this.setProjectCode(processTaskRelation.getProjectCode()); this.setProjectCode(processTaskRelation.getProjectCode());
this.setPreTaskCode(processTaskRelation.getPreTaskCode()); this.setPreTaskCode(processTaskRelation.getPreTaskCode());
this.setPreNodeVersion(processTaskRelation.getPreNodeVersion()); this.setPreTaskVersion(processTaskRelation.getPreTaskVersion());
this.setPostTaskCode(processTaskRelation.getPostTaskCode()); this.setPostTaskCode(processTaskRelation.getPostTaskCode());
this.setPostNodeVersion(processTaskRelation.getPostNodeVersion()); this.setPostTaskVersion(processTaskRelation.getPostTaskVersion());
this.setConditionType(processTaskRelation.getConditionType()); this.setConditionType(processTaskRelation.getConditionType());
this.setConditionParams(processTaskRelation.getConditionParams()); this.setConditionParams(processTaskRelation.getConditionParams());
this.setConditionParamList(processTaskRelation.getConditionParamList()); this.setConditionParamList(processTaskRelation.getConditionParamList());

2
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.java

@ -47,7 +47,7 @@ public interface ProcessTaskRelationMapper extends BaseMapper<ProcessTaskRelatio
* @param taskCodes taskCode list * @param taskCodes taskCode list
* @return ProcessTaskRelation * @return ProcessTaskRelation
*/ */
List<ProcessTaskRelation> queryByTaskCodes(@Param("taskCodes") Collection<Long> taskCodes); List<ProcessTaskRelation> queryByTaskCodes(@Param("taskCodes") Long[] taskCodes);
/** /**
* process task relation by taskCode * process task relation by taskCode

2
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.xml

@ -40,7 +40,7 @@
select select
<include refid="baseSql"/> <include refid="baseSql"/>
from t_ds_process_definition_log from t_ds_process_definition_log
WHERE pd.code = #{processDefinitionCode} WHERE code = #{processDefinitionCode}
</select> </select>
<select id="queryByDefinitionCodeAndVersion" <select id="queryByDefinitionCodeAndVersion"
resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinitionLog"> resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinitionLog">

5
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.xml

@ -34,7 +34,7 @@
<include refid="baseSql"/> <include refid="baseSql"/>
from t_ds_process_task_relation from t_ds_process_task_relation
WHERE pre_task_code = #{taskCode} WHERE pre_task_code = #{taskCode}
<if test="postTaskCode != 0"> <if test="taskCode != 0">
or post_task_code = #{taskCode} or post_task_code = #{taskCode}
</if> </if>
</select> </select>
@ -44,7 +44,7 @@
from t_ds_process_task_relation from t_ds_process_task_relation
WHERE 1 = 1 WHERE 1 = 1
<if test="taskCodes != null and taskCodes.length != 0"> <if test="taskCodes != null and taskCodes.length != 0">
(and pre_task_code in and pre_task_code in
<foreach collection="taskCodes" index="index" item="i" open="(" separator="," close=")"> <foreach collection="taskCodes" index="index" item="i" open="(" separator="," close=")">
#{i} #{i}
</foreach> </foreach>
@ -52,7 +52,6 @@
<foreach collection="taskCodes" index="index" item="i" open="(" separator="," close=")"> <foreach collection="taskCodes" index="index" item="i" open="(" separator="," close=")">
#{i} #{i}
</foreach> </foreach>
)
</if> </if>
</select> </select>
<delete id="deleteByCode"> <delete id="deleteByCode">

174
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapperTest.java

@ -0,0 +1,174 @@
/*
* 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.dao.mapper;
import org.apache.dolphinscheduler.common.enums.UserType;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinitionLog;
import org.apache.dolphinscheduler.dao.entity.Project;
import org.apache.dolphinscheduler.dao.entity.User;
import java.util.Date;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
@Rollback(true)
public class ProcessDefinitionLogMapperTest {
@Autowired
ProcessDefinitionMapper processDefinitionMapper;
@Autowired
UserMapper userMapper;
@Autowired
QueueMapper queueMapper;
@Autowired
TenantMapper tenantMapper;
@Autowired
ProjectMapper projectMapper;
@Autowired
ProcessDefinitionLogMapper processDefinitionLogMapper;
/**
* insert
*
* @return ProcessDefinition
*/
private ProcessDefinitionLog insertOne() {
//insertOne
ProcessDefinitionLog processDefinitionLog = new ProcessDefinitionLog();
processDefinitionLog.setCode(1L);
processDefinitionLog.setName("def 1");
processDefinitionLog.setProjectCode(1L);
processDefinitionLog.setUserId(101);
processDefinitionLog.setVersion(1);
processDefinitionLog.setUpdateTime(new Date());
processDefinitionLog.setCreateTime(new Date());
processDefinitionLogMapper.insert(processDefinitionLog);
return processDefinitionLog;
}
/**
* insert
*
* @return ProcessDefinition
*/
private ProcessDefinitionLog insertTwo() {
//insertOne
ProcessDefinitionLog processDefinitionLog = new ProcessDefinitionLog();
processDefinitionLog.setCode(1L);
processDefinitionLog.setName("def 2");
processDefinitionLog.setProjectCode(1L);
processDefinitionLog.setUserId(101);
processDefinitionLog.setVersion(2);
processDefinitionLog.setUpdateTime(new Date());
processDefinitionLog.setCreateTime(new Date());
processDefinitionLogMapper.insert(processDefinitionLog);
return processDefinitionLog;
}
@Test
public void testInsert() {
ProcessDefinitionLog processDefinitionLog = insertOne();
Assert.assertNotEquals(processDefinitionLog.getId(), 0);
}
@Test
public void testQueryByDefinitionName() {
ProcessDefinitionLog processDefinitionLog = insertOne();
Project project = new Project();
project.setCode(1L);
project.setName("ut project");
project.setUserId(101);
project.setCreateTime(new Date());
projectMapper.insert(project);
User user = new User();
user.setUserName("hello");
user.setUserPassword("pwd");
user.setUserType(UserType.GENERAL_USER);
user.setId(101);
userMapper.insert(user);
List<ProcessDefinitionLog> processDefinitionLogs = processDefinitionLogMapper
.queryByDefinitionName(1L, "def 1");
Assert.assertEquals(0, processDefinitionLogs.size());
}
@Test
public void testQueryByDefinitionCode() {
ProcessDefinitionLog processDefinitionLog = insertOne();
List<ProcessDefinitionLog> processDefinitionLogs = processDefinitionLogMapper
.queryByDefinitionCode(1L);
Assert.assertNotEquals(0, processDefinitionLogs.size());
}
@Test
public void testQueryByDefinitionCodeAndVersion() {
ProcessDefinitionLog processDefinitionLog = insertOne();
ProcessDefinitionLog processDefinitionLogs = processDefinitionLogMapper
.queryByDefinitionCodeAndVersion(1L, 1);
Assert.assertNotEquals(null, processDefinitionLogs);
}
@Test
public void testQueryMaxVersionForDefinition() {
ProcessDefinitionLog processDefinitionLog = insertOne();
ProcessDefinitionLog processDefinitionLog1 = insertTwo();
int version = processDefinitionLogMapper.queryMaxVersionForDefinition(1L);
Assert.assertEquals(2, version);
}
@Test
public void testQueryProcessDefinitionVersionsPaging() {
ProcessDefinitionLog processDefinitionLog = insertOne();
Page<ProcessDefinitionLog> page = new Page(1, 3);
IPage<ProcessDefinitionLog> processDefinitionLogs = processDefinitionLogMapper.queryProcessDefinitionVersionsPaging(page, 1L);
Assert.assertNotEquals(processDefinitionLogs.getTotal(), 0);
}
@Test
public void testDeleteByProcessDefinitionCodeAndVersion() {
ProcessDefinitionLog processDefinitionLog = insertOne();
Page<ProcessDefinitionLog> page = new Page(1, 3);
int processDefinitionLogs = processDefinitionLogMapper.deleteByProcessDefinitionCodeAndVersion(1L, 1);
Assert.assertNotEquals(processDefinitionLogs, 0);
}
}

71
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationLogMapperTest.java

@ -0,0 +1,71 @@
/*
* 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.dao.mapper;
import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog;
import java.util.Date;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
@Rollback(true)
public class ProcessTaskRelationLogMapperTest {
@Autowired
ProcessTaskRelationLogMapper processTaskRelationLogMapper;
/**
* insert
*
* @return ProcessDefinition
*/
private ProcessTaskRelationLog insertOne() {
//insertOne
ProcessTaskRelationLog processTaskRelationLog = new ProcessTaskRelationLog();
processTaskRelationLog.setName("def 1");
processTaskRelationLog.setProcessDefinitionVersion(1);
processTaskRelationLog.setProjectCode(1L);
processTaskRelationLog.setProcessDefinitionCode(1L);
processTaskRelationLog.setPostTaskCode(3L);
processTaskRelationLog.setPreTaskCode(2L);
processTaskRelationLog.setUpdateTime(new Date());
processTaskRelationLog.setCreateTime(new Date());
processTaskRelationLogMapper.insert(processTaskRelationLog);
return processTaskRelationLog;
}
@Test
public void testQueryByProcessCodeAndVersion() {
ProcessTaskRelationLog processTaskRelationLog = insertOne();
List<ProcessTaskRelationLog> processTaskRelationLogs = processTaskRelationLogMapper
.queryByProcessCodeAndVersion(1L, 1);
Assert.assertNotEquals(processTaskRelationLogs.size(), 0);
}
}

94
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapperTest.java

@ -0,0 +1,94 @@
/*
* 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.dao.mapper;
import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation;
import java.util.Date;
import java.util.List;
import org.assertj.core.util.Arrays;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
@Rollback(true)
public class ProcessTaskRelationMapperTest {
@Autowired
ProcessTaskRelationMapper processTaskRelationMapper;
/**
* insert
*
* @return ProcessDefinition
*/
private ProcessTaskRelation insertOne() {
//insertOne
ProcessTaskRelation processTaskRelation = new ProcessTaskRelation();
processTaskRelation.setName("def 1");
processTaskRelation.setProjectCode(1L);
processTaskRelation.setProcessDefinitionCode(1L);
processTaskRelation.setPostTaskCode(3L);
processTaskRelation.setPreTaskCode(2L);
processTaskRelation.setUpdateTime(new Date());
processTaskRelation.setCreateTime(new Date());
processTaskRelationMapper.insert(processTaskRelation);
return processTaskRelation;
}
@Test
public void testQueryByProcessCode() {
ProcessTaskRelation processTaskRelation = insertOne();
List<ProcessTaskRelation> processTaskRelations = processTaskRelationMapper.queryByProcessCode(1L, 1L);
Assert.assertNotEquals(processTaskRelations.size(), 0);
}
@Test
public void testQueryByTaskCode() {
ProcessTaskRelation processTaskRelation = insertOne();
List<ProcessTaskRelation> processTaskRelations = processTaskRelationMapper.queryByTaskCode(2L);
Assert.assertNotEquals(processTaskRelations.size(), 0);
}
@Test
public void testQueryByTaskCodes() {
ProcessTaskRelation processTaskRelation = insertOne();
Long[] codes = Arrays.array(1L, 2L);
List<ProcessTaskRelation> processTaskRelations = processTaskRelationMapper.queryByTaskCodes(codes);
Assert.assertNotEquals(processTaskRelations.size(), 0);
}
@Test
public void testDeleteByCode() {
ProcessTaskRelation processTaskRelation = insertOne();
int i = processTaskRelationMapper.deleteByCode(1L, 1L);
Assert.assertNotEquals(i, 0);
}
}

12
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java

@ -354,7 +354,7 @@ public class ProcessService {
Set<TaskDefinition> taskDefinitionSet = new HashSet<>(); Set<TaskDefinition> taskDefinitionSet = new HashSet<>();
for (ProcessTaskRelationLog processTaskRelation : processTaskRelations) { for (ProcessTaskRelationLog processTaskRelation : processTaskRelations) {
if (processTaskRelation.getPostTaskCode() > 0) { if (processTaskRelation.getPostTaskCode() > 0) {
taskDefinitionSet.add(new TaskDefinition(processTaskRelation.getPostTaskCode(), processTaskRelation.getPostNodeVersion())); taskDefinitionSet.add(new TaskDefinition(processTaskRelation.getPostTaskCode(), processTaskRelation.getPostTaskVersion()));
} }
} }
List<TaskDefinitionLog> taskDefinitionLogs = taskDefinitionLogMapper.queryByTaskDefinitions(taskDefinitionSet); List<TaskDefinitionLog> taskDefinitionLogs = taskDefinitionLogMapper.queryByTaskDefinitions(taskDefinitionSet);
@ -2413,25 +2413,25 @@ public class ProcessService {
Map<Long, TaskNode> taskNodeMap = new HashMap<>(); Map<Long, TaskNode> taskNodeMap = new HashMap<>();
for (ProcessTaskRelationLog processTaskRelation : processTaskRelations) { for (ProcessTaskRelationLog processTaskRelation : processTaskRelations) {
if (processTaskRelation.getPreTaskCode() > 0) { if (processTaskRelation.getPreTaskCode() > 0) {
taskDefinitionSet.add(new TaskDefinition(processTaskRelation.getPreTaskCode(), processTaskRelation.getPreNodeVersion())); taskDefinitionSet.add(new TaskDefinition(processTaskRelation.getPreTaskCode(), processTaskRelation.getPreTaskVersion()));
} }
if (processTaskRelation.getPostTaskCode() > 0) { if (processTaskRelation.getPostTaskCode() > 0) {
taskDefinitionSet.add(new TaskDefinition(processTaskRelation.getPostTaskCode(), processTaskRelation.getPostNodeVersion())); taskDefinitionSet.add(new TaskDefinition(processTaskRelation.getPostTaskCode(), processTaskRelation.getPostTaskVersion()));
} }
taskNodeMap.compute(processTaskRelation.getPostTaskCode(), (k, v) -> { taskNodeMap.compute(processTaskRelation.getPostTaskCode(), (k, v) -> {
if (v == null) { if (v == null) {
v = new TaskNode(); v = new TaskNode();
v.setCode(processTaskRelation.getPostTaskCode()); v.setCode(processTaskRelation.getPostTaskCode());
v.setVersion(processTaskRelation.getPostNodeVersion()); v.setVersion(processTaskRelation.getPostTaskVersion());
v.setConditionResult(processTaskRelation.getConditionParams()); v.setConditionResult(processTaskRelation.getConditionParams());
List<PreviousTaskNode> preTaskNodeList = new ArrayList<>(); List<PreviousTaskNode> preTaskNodeList = new ArrayList<>();
if (processTaskRelation.getPreTaskCode() > 0) { if (processTaskRelation.getPreTaskCode() > 0) {
preTaskNodeList.add(new PreviousTaskNode(processTaskRelation.getPreTaskCode(), "", processTaskRelation.getPreNodeVersion())); preTaskNodeList.add(new PreviousTaskNode(processTaskRelation.getPreTaskCode(), "", processTaskRelation.getPreTaskVersion()));
} }
v.setPreTaskNodeList(preTaskNodeList); v.setPreTaskNodeList(preTaskNodeList);
} else { } else {
List<PreviousTaskNode> preTaskDefinitionList = v.getPreTaskNodeList(); List<PreviousTaskNode> preTaskDefinitionList = v.getPreTaskNodeList();
preTaskDefinitionList.add(new PreviousTaskNode(processTaskRelation.getPreTaskCode(), "", processTaskRelation.getPreNodeVersion())); preTaskDefinitionList.add(new PreviousTaskNode(processTaskRelation.getPreTaskCode(), "", processTaskRelation.getPreTaskVersion()));
} }
return v; return v;
}); });

Loading…
Cancel
Save