[Feature][jsonsplit]add TaskDefinitionLogMapperTest/TaskDefinitionMapperTest and bugfix (#5012)

* 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

* fix ProcessInstanceMapperTest

* codestyle

* conflicts solve

* conflicts solve

* conflicts solve

* conflicts solve

* conflicts solve

* fix ProcessInstanceMapperTest

* fix ProjectMapperTest/ProjectUserMapperTest/ScheduleMapperTest

* fix ProjectMapperTest/ProjectUserMapperTest/ScheduleMapperTest

* fix TaskInstanceMapperTest

* add TaskDefinitionLogMapperTest/TaskDefinitionMapperTest and bugfix

* codestyle

* codestyle
This commit is contained in:
Simon 2021-03-10 10:50:49 +08:00 committed by GitHub
parent 81dcd6873d
commit c4d9ceffd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 194 additions and 20 deletions

View File

@ -51,7 +51,7 @@
<include refid="baseSql"/>
from t_ds_task_definition_log
WHERE 1 = 1
<if test="taskDefinitions != null and taskDefinitions.length != 0">
<if test="taskDefinitions != null and taskDefinitions.size != 0">
and
<foreach collection="taskDefinitions" index="index" item="item" open="(" separator=" or " close=")">
(code = #{item.code}

View File

@ -54,7 +54,7 @@
JOIN t_ds_user tu on tu.id=td.user_id
where 1 = 1
<if test="projectCodes != null and projectCodes.length != 0">
and td.project_id in
and td.project_code in
<foreach collection="projectCodes" index="index" item="i" open="(" separator="," close=")">
#{i}
</foreach>
@ -85,7 +85,7 @@
<select id="listResourcesByUser" resultType="java.util.HashMap">
SELECT id,resource_ids
FROM t_ds_task_definition
WHERE user_id = #{userId} resource_ids is not null and resource_ids != ''
WHERE user_id = #{userId} and resource_ids is not null and resource_ids != ''
</select>
<delete id="deleteByCode">
delete from t_ds_task_definition

View File

@ -18,9 +18,14 @@
package org.apache.dolphinscheduler.dao.mapper;
import org.apache.dolphinscheduler.common.enums.TaskType;
import org.apache.dolphinscheduler.dao.entity.Project;
import org.apache.dolphinscheduler.dao.entity.TaskDefinition;
import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog;
import org.apache.dolphinscheduler.dao.entity.User;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
@ -37,17 +42,29 @@ import org.springframework.transaction.annotation.Transactional;
@Rollback(true)
public class TaskDefinitionLogMapperTest {
@Autowired
TaskDefinitionLogMapper taskDefinitionLogMapper;
@Autowired
TaskDefinitionMapper taskDefinitionMapper;
@Autowired
UserMapper userMapper;
@Autowired
ProjectMapper projectMapper;
public TaskDefinitionLog insertOne() {
return insertOne(99);
}
public TaskDefinitionLog insertOne(int userId) {
TaskDefinitionLog taskDefinition = new TaskDefinitionLog();
taskDefinition.setCode(888888L);
taskDefinition.setName("unit-test");
taskDefinition.setProjectCode(111111L);
taskDefinition.setProjectCode(1L);
taskDefinition.setTaskType(TaskType.SHELL);
taskDefinition.setUserId(99);
taskDefinition.setUserId(userId);
taskDefinition.setVersion(1);
taskDefinition.setCreateTime(new Date());
taskDefinition.setUpdateTime(new Date());
@ -60,4 +77,59 @@ public class TaskDefinitionLogMapperTest {
TaskDefinitionLog taskDefinitionLog = insertOne();
Assert.assertNotEquals(taskDefinitionLog.getId(), 0);
}
@Test
public void testQueryByDefinitionName() {
User user = new User();
user.setUserName("un");
userMapper.insert(user);
User un = userMapper.queryByUserNameAccurately("un");
Project project = new Project();
project.setCode(1L);
project.setCreateTime(new Date());
project.setUpdateTime(new Date());
projectMapper.insert(project);
TaskDefinitionLog taskDefinitionLog = insertOne(un.getId());
List<TaskDefinitionLog> taskDefinitionLogs = taskDefinitionLogMapper
.queryByDefinitionName(taskDefinitionLog.getProjectCode(), taskDefinitionLog.getName());
Assert.assertNotEquals(taskDefinitionLogs.size(), 0);
}
@Test
public void testQueryMaxVersionForDefinition() {
TaskDefinitionLog taskDefinitionLog = insertOne();
int version = taskDefinitionLogMapper
.queryMaxVersionForDefinition(taskDefinitionLog.getCode());
Assert.assertNotEquals(version, 0);
}
@Test
public void testQueryByDefinitionCodeAndVersion() {
TaskDefinitionLog taskDefinitionLog = insertOne();
TaskDefinitionLog tdl = taskDefinitionLogMapper
.queryByDefinitionCodeAndVersion(taskDefinitionLog.getCode(), taskDefinitionLog.getVersion());
Assert.assertNotNull(tdl);
}
@Test
public void testQueryByTaskDefinitions() {
TaskDefinition taskDefinition = new TaskDefinition();
taskDefinition.setCode(888888L);
taskDefinition.setName("unit-test");
taskDefinition.setProjectCode(1L);
taskDefinition.setTaskType(TaskType.SHELL);
taskDefinition.setUserId(1);
taskDefinition.setResourceIds("1");
taskDefinition.setVersion(1);
ArrayList<TaskDefinition> taskDefinitions = new ArrayList<>();
taskDefinitions.add(taskDefinition);
TaskDefinitionLog taskDefinitionLog = insertOne();
List<TaskDefinitionLog> taskDefinitionLogs = taskDefinitionLogMapper.queryByTaskDefinitions(taskDefinitions);
Assert.assertNotEquals(taskDefinitionLogs.size(), 0);
}
}

View File

@ -18,9 +18,14 @@
package org.apache.dolphinscheduler.dao.mapper;
import org.apache.dolphinscheduler.common.enums.TaskType;
import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser;
import org.apache.dolphinscheduler.dao.entity.Project;
import org.apache.dolphinscheduler.dao.entity.TaskDefinition;
import org.apache.dolphinscheduler.dao.entity.User;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
@ -40,13 +45,24 @@ public class TaskDefinitionMapperTest {
@Autowired
TaskDefinitionMapper taskDefinitionMapper;
@Autowired
UserMapper userMapper;
@Autowired
ProjectMapper projectMapper;
public TaskDefinition insertOne() {
return insertOne(99);
}
public TaskDefinition insertOne(int userId) {
TaskDefinition taskDefinition = new TaskDefinition();
taskDefinition.setCode(888888L);
taskDefinition.setName("unit-test");
taskDefinition.setProjectCode(111111L);
taskDefinition.setProjectCode(1L);
taskDefinition.setTaskType(TaskType.SHELL);
taskDefinition.setUserId(99);
taskDefinition.setUserId(userId);
taskDefinition.setResourceIds("1");
taskDefinition.setVersion(1);
taskDefinition.setCreateTime(new Date());
taskDefinition.setUpdateTime(new Date());
@ -59,4 +75,102 @@ public class TaskDefinitionMapperTest {
TaskDefinition taskDefinition = insertOne();
Assert.assertNotEquals(taskDefinition.getId(), 0);
}
@Test
public void testQueryByDefinitionName() {
TaskDefinition taskDefinition = insertOne();
TaskDefinition result = taskDefinitionMapper.queryByDefinitionName(taskDefinition.getProjectCode()
, taskDefinition.getName());
Assert.assertNotNull(result);
}
@Test
public void testQueryByDefinitionId() {
User user = new User();
user.setUserName("un");
userMapper.insert(user);
User un = userMapper.queryByUserNameAccurately("un");
Project project = new Project();
project.setCode(1L);
project.setCreateTime(new Date());
project.setUpdateTime(new Date());
projectMapper.insert(project);
TaskDefinition taskDefinition = insertOne(un.getId());
TaskDefinition td = taskDefinitionMapper.queryByDefinitionName(taskDefinition.getProjectCode()
, taskDefinition.getName());
TaskDefinition result = taskDefinitionMapper.queryByDefinitionId(td.getId());
Assert.assertNotNull(result);
}
@Test
public void testQueryByDefinitionCode() {
TaskDefinition taskDefinition = insertOne();
TaskDefinition result = taskDefinitionMapper.queryByDefinitionCode(taskDefinition.getCode());
Assert.assertNotNull(result);
}
@Test
public void testQueryAllDefinitionList() {
TaskDefinition taskDefinition = insertOne();
List<TaskDefinition> taskDefinitions = taskDefinitionMapper.queryAllDefinitionList(taskDefinition.getProjectCode());
Assert.assertNotEquals(taskDefinitions.size(), 0);
}
@Test
public void testQueryDefinitionListByIdList() {
TaskDefinition taskDefinition = insertOne();
List<TaskDefinition> taskDefinitions = taskDefinitionMapper.queryDefinitionListByIdList(new Integer[]{taskDefinition.getId()});
Assert.assertNotEquals(taskDefinitions.size(), 0);
}
@Test
public void testCountDefinitionGroupByUser() {
User user = new User();
user.setUserName("un");
userMapper.insert(user);
User un = userMapper.queryByUserNameAccurately("un");
TaskDefinition taskDefinition = insertOne(un.getId());
List<DefinitionGroupByUser> users = taskDefinitionMapper.countDefinitionGroupByUser(new Long[]{taskDefinition.getProjectCode()});
Assert.assertNotEquals(users.size(), 0);
}
@Test
public void testListResources() {
TaskDefinition taskDefinition = insertOne();
List<Map<String, Object>> maps = taskDefinitionMapper.listResources();
Assert.assertNotEquals(maps.size(), 0);
}
@Test
public void testListResourcesByUser() {
User user = new User();
user.setUserName("un");
userMapper.insert(user);
User un = userMapper.queryByUserNameAccurately("un");
TaskDefinition taskDefinition = insertOne(un.getId());
List<Map<String, Object>> maps = taskDefinitionMapper.listResourcesByUser(taskDefinition.getUserId());
Assert.assertNotEquals(maps.size(), 0);
}
@Test
public void testDeleteByCode() {
TaskDefinition taskDefinition = insertOne();
int i = taskDefinitionMapper.deleteByCode(taskDefinition.getCode());
Assert.assertNotEquals(i, 0);
}
}

View File

@ -195,18 +195,6 @@ public class UdfFuncMapperTest {
Assert.assertEquals(delete, 1);
}
/**
* test query
*/
@Test
public void testQuery() {
//insertOne
UdfFunc udfFunc = insertOne();
//query
List<UdfFunc> udfFuncList = udfFuncMapper.selectList(null);
Assert.assertNotEquals(udfFuncList.size(), 0);
}
/**
* test query udf by ids
*/