From f24ecff840da133e1ef1d26ff6bf27c2fb112737 Mon Sep 17 00:00:00 2001 From: Simon <3656562@qq.com> Date: Sat, 6 Mar 2021 14:25:00 +0800 Subject: [PATCH] [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 --- .../dao/entity/ProcessTaskRelation.java | 20 +- .../dao/entity/ProcessTaskRelationLog.java | 4 +- .../dao/mapper/ProcessTaskRelationMapper.java | 2 +- .../dao/mapper/ProcessDefinitionLogMapper.xml | 2 +- .../dao/mapper/ProcessTaskRelationMapper.xml | 5 +- .../ProcessDefinitionLogMapperTest.java | 174 ++++++++++++++++++ .../ProcessTaskRelationLogMapperTest.java | 71 +++++++ .../mapper/ProcessTaskRelationMapperTest.java | 94 ++++++++++ .../service/process/ProcessService.java | 12 +- 9 files changed, 361 insertions(+), 23 deletions(-) create mode 100644 dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapperTest.java create mode 100644 dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationLogMapperTest.java create mode 100644 dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapperTest.java diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessTaskRelation.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessTaskRelation.java index 9633abefc0..9c04a67a5f 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessTaskRelation.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessTaskRelation.java @@ -73,7 +73,7 @@ public class ProcessTaskRelation { /** * pre node version */ - private int preNodeVersion; + private int preTaskVersion; /** * post task code @@ -83,7 +83,7 @@ public class ProcessTaskRelation { /** * post node version */ - private int postNodeVersion; + private int postTaskVersion; /** * condition type @@ -259,19 +259,19 @@ public class ProcessTaskRelation { this.conditionType = conditionType; } - public int getPreNodeVersion() { - return preNodeVersion; + public int getPreTaskVersion() { + return preTaskVersion; } - public void setPreNodeVersion(int preNodeVersion) { - this.preNodeVersion = preNodeVersion; + public void setPreTaskVersion(int preTaskVersion) { + this.preTaskVersion = preTaskVersion; } - public int getPostNodeVersion() { - return postNodeVersion; + public int getPostTaskVersion() { + return postTaskVersion; } - public void setPostNodeVersion(int postNodeVersion) { - this.postNodeVersion = postNodeVersion; + public void setPostTaskVersion(int postTaskVersion) { + this.postTaskVersion = postTaskVersion; } } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessTaskRelationLog.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessTaskRelationLog.java index 812c501051..36e67a60a0 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessTaskRelationLog.java +++ b/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.setProjectCode(processTaskRelation.getProjectCode()); this.setPreTaskCode(processTaskRelation.getPreTaskCode()); - this.setPreNodeVersion(processTaskRelation.getPreNodeVersion()); + this.setPreTaskVersion(processTaskRelation.getPreTaskVersion()); this.setPostTaskCode(processTaskRelation.getPostTaskCode()); - this.setPostNodeVersion(processTaskRelation.getPostNodeVersion()); + this.setPostTaskVersion(processTaskRelation.getPostTaskVersion()); this.setConditionType(processTaskRelation.getConditionType()); this.setConditionParams(processTaskRelation.getConditionParams()); this.setConditionParamList(processTaskRelation.getConditionParamList()); diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.java index 5e5fd3138f..9330d2c1f8 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.java @@ -47,7 +47,7 @@ public interface ProcessTaskRelationMapper extends BaseMapper queryByTaskCodes(@Param("taskCodes") Collection taskCodes); + List queryByTaskCodes(@Param("taskCodes") Long[] taskCodes); /** * process task relation by taskCode diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.xml index 436a668633..401e458e23 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapper.xml @@ -40,7 +40,7 @@ select from t_ds_process_definition_log - WHERE pd.code = #{processDefinitionCode} + WHERE code = #{processDefinitionCode} @@ -44,7 +44,7 @@ from t_ds_process_task_relation WHERE 1 = 1 - (and pre_task_code in + and pre_task_code in #{i} @@ -52,7 +52,6 @@ #{i} - ) diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionLogMapperTest.java new file mode 100644 index 0000000000..b294eeeb4c --- /dev/null +++ b/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 processDefinitionLogs = processDefinitionLogMapper + .queryByDefinitionName(1L, "def 1"); + Assert.assertEquals(0, processDefinitionLogs.size()); + + } + + @Test + public void testQueryByDefinitionCode() { + ProcessDefinitionLog processDefinitionLog = insertOne(); + + List 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 page = new Page(1, 3); + IPage processDefinitionLogs = processDefinitionLogMapper.queryProcessDefinitionVersionsPaging(page, 1L); + Assert.assertNotEquals(processDefinitionLogs.getTotal(), 0); + } + + @Test + public void testDeleteByProcessDefinitionCodeAndVersion() { + ProcessDefinitionLog processDefinitionLog = insertOne(); + Page page = new Page(1, 3); + int processDefinitionLogs = processDefinitionLogMapper.deleteByProcessDefinitionCodeAndVersion(1L, 1); + Assert.assertNotEquals(processDefinitionLogs, 0); + } + +} diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationLogMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationLogMapperTest.java new file mode 100644 index 0000000000..c2bb3ab938 --- /dev/null +++ b/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 processTaskRelationLogs = processTaskRelationLogMapper + .queryByProcessCodeAndVersion(1L, 1); + Assert.assertNotEquals(processTaskRelationLogs.size(), 0); + } + +} diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapperTest.java new file mode 100644 index 0000000000..8ece9fe29b --- /dev/null +++ b/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 processTaskRelations = processTaskRelationMapper.queryByProcessCode(1L, 1L); + Assert.assertNotEquals(processTaskRelations.size(), 0); + } + + @Test + public void testQueryByTaskCode() { + ProcessTaskRelation processTaskRelation = insertOne(); + List processTaskRelations = processTaskRelationMapper.queryByTaskCode(2L); + Assert.assertNotEquals(processTaskRelations.size(), 0); + } + + @Test + public void testQueryByTaskCodes() { + ProcessTaskRelation processTaskRelation = insertOne(); + + Long[] codes = Arrays.array(1L, 2L); + List 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); + } + +} diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java index 981767a38b..13eb7266c8 100644 --- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java +++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java @@ -354,7 +354,7 @@ public class ProcessService { Set taskDefinitionSet = new HashSet<>(); for (ProcessTaskRelationLog processTaskRelation : processTaskRelations) { if (processTaskRelation.getPostTaskCode() > 0) { - taskDefinitionSet.add(new TaskDefinition(processTaskRelation.getPostTaskCode(), processTaskRelation.getPostNodeVersion())); + taskDefinitionSet.add(new TaskDefinition(processTaskRelation.getPostTaskCode(), processTaskRelation.getPostTaskVersion())); } } List taskDefinitionLogs = taskDefinitionLogMapper.queryByTaskDefinitions(taskDefinitionSet); @@ -2413,25 +2413,25 @@ public class ProcessService { Map taskNodeMap = new HashMap<>(); for (ProcessTaskRelationLog processTaskRelation : processTaskRelations) { if (processTaskRelation.getPreTaskCode() > 0) { - taskDefinitionSet.add(new TaskDefinition(processTaskRelation.getPreTaskCode(), processTaskRelation.getPreNodeVersion())); + taskDefinitionSet.add(new TaskDefinition(processTaskRelation.getPreTaskCode(), processTaskRelation.getPreTaskVersion())); } 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) -> { if (v == null) { v = new TaskNode(); v.setCode(processTaskRelation.getPostTaskCode()); - v.setVersion(processTaskRelation.getPostNodeVersion()); + v.setVersion(processTaskRelation.getPostTaskVersion()); v.setConditionResult(processTaskRelation.getConditionParams()); List preTaskNodeList = new ArrayList<>(); if (processTaskRelation.getPreTaskCode() > 0) { - preTaskNodeList.add(new PreviousTaskNode(processTaskRelation.getPreTaskCode(), "", processTaskRelation.getPreNodeVersion())); + preTaskNodeList.add(new PreviousTaskNode(processTaskRelation.getPreTaskCode(), "", processTaskRelation.getPreTaskVersion())); } v.setPreTaskNodeList(preTaskNodeList); } else { List preTaskDefinitionList = v.getPreTaskNodeList(); - preTaskDefinitionList.add(new PreviousTaskNode(processTaskRelation.getPreTaskCode(), "", processTaskRelation.getPreNodeVersion())); + preTaskDefinitionList.add(new PreviousTaskNode(processTaskRelation.getPreTaskCode(), "", processTaskRelation.getPreTaskVersion())); } return v; });