Browse Source

[Feature][jsonsplit]add WorkFlowLineageMapperTest/WorkFlowLineageServiceTest (#5047)

* 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

* Refactor process lineage

* Refactor process lineage

* codestyle

* codestyle

* Refactor process lineage

* Refactor process lineage

* add WorkFlowLineageMapperTest/WorkFlowLineageServiceTest

* add WorkFlowLineageMapperTest/WorkFlowLineageServiceTest
pull/3/MERGE
Simon 4 years ago committed by GitHub
parent
commit
00dcc3f78e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 69
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkFlowLineageServiceTest.java
  2. 311
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinitionVersion.java
  3. 11
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/ProcessDefinitionDao.java
  4. 126
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/WorkFlowLineageMapperTest.java
  5. 17
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/upgrade/WorkerGroupDaoTest.java

69
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkFlowLineageServiceTest.java

@ -21,11 +21,15 @@ import static org.mockito.Mockito.when;
import org.apache.dolphinscheduler.api.service.impl.WorkFlowLineageServiceImpl; import org.apache.dolphinscheduler.api.service.impl.WorkFlowLineageServiceImpl;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.dao.entity.ProcessLineage;
import org.apache.dolphinscheduler.dao.entity.Project;
import org.apache.dolphinscheduler.dao.entity.WorkFlowLineage; import org.apache.dolphinscheduler.dao.entity.WorkFlowLineage;
import org.apache.dolphinscheduler.dao.entity.WorkFlowRelation; import org.apache.dolphinscheduler.dao.entity.WorkFlowRelation;
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
import org.apache.dolphinscheduler.dao.mapper.WorkFlowLineageMapper; import org.apache.dolphinscheduler.dao.mapper.WorkFlowLineageMapper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -36,6 +40,7 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
/** /**
@ -50,10 +55,30 @@ public class WorkFlowLineageServiceTest {
@Mock @Mock
private WorkFlowLineageMapper workFlowLineageMapper; private WorkFlowLineageMapper workFlowLineageMapper;
@Mock
private ProjectMapper projectMapper;
/**
* get mock Project
*
* @param projectName projectName
* @return Project
*/
private Project getProject(String projectName) {
Project project = new Project();
project.setCode(1L);
project.setId(1);
project.setName(projectName);
project.setUserId(1);
return project;
}
@Test @Test
public void testQueryWorkFlowLineageByName() { public void testQueryWorkFlowLineageByName() {
Project project = getProject("test");
String searchVal = "test"; String searchVal = "test";
when(workFlowLineageMapper.queryByName(searchVal, 1L)).thenReturn(getWorkFlowLineages()); when(projectMapper.selectById(1)).thenReturn(project);
when(workFlowLineageMapper.queryByName(Mockito.any(), Mockito.any())).thenReturn(getWorkFlowLineages());
Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByName(searchVal, 1); Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByName(searchVal, 1);
List<WorkFlowLineage> workFlowLineageList = (List<WorkFlowLineage>) result.get(Constants.DATA_LIST); List<WorkFlowLineage> workFlowLineageList = (List<WorkFlowLineage>) result.get(Constants.DATA_LIST);
Assert.assertTrue(workFlowLineageList.size() > 0); Assert.assertTrue(workFlowLineageList.size() > 0);
@ -61,15 +86,42 @@ public class WorkFlowLineageServiceTest {
@Test @Test
public void testQueryWorkFlowLineageByIds() { public void testQueryWorkFlowLineageByIds() {
Set<Integer> ids = new HashSet<>(); Set<Integer> ids = new HashSet<>();
ids.add(1); ids.add(1);
ids.add(2); ids.add(2);
Project project = getProject("test");
List<ProcessLineage> processLineages = new ArrayList<>();
ProcessLineage processLineage = new ProcessLineage();
processLineage.setPreTaskVersion(1);
processLineage.setPreTaskCode(1L);
processLineage.setPostTaskCode(2L);
processLineage.setPostTaskVersion(1);
processLineage.setProcessDefinitionCode(1111L);
processLineage.setProcessDefinitionVersion(1);
processLineage.setProjectCode(1111L);
processLineages.add(processLineage);
WorkFlowLineage workFlowLineage = new WorkFlowLineage();
workFlowLineage.setSourceWorkFlowId("");
when(projectMapper.selectById(1)).thenReturn(project);
when(workFlowLineageMapper.queryRelationByIds(ids, project.getCode())).thenReturn(processLineages);
when(workFlowLineageMapper.queryCodeRelation(processLineage.getPostTaskCode()
, processLineage.getPreTaskVersion()
, processLineage.getProcessDefinitionCode()
, processLineage.getProjectCode()))
.thenReturn(processLineages);
when(workFlowLineageMapper
.queryWorkFlowLineageByCode(processLineage.getProcessDefinitionCode(), processLineage.getProjectCode()))
.thenReturn(workFlowLineage);
Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByIds(ids, 1); Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByIds(ids, 1);
Map<String, Object> workFlowLists = (Map<String, Object>) result.get(Constants.DATA_LIST); Map<String, Object> workFlowLists = (Map<String, Object>) result.get(Constants.DATA_LIST);
List<WorkFlowLineage> workFlowLineages = (List<WorkFlowLineage>)workFlowLists.get("workFlowList"); Collection<WorkFlowLineage> workFlowLineages = (Collection<WorkFlowLineage>) workFlowLists.get(Constants.WORKFLOW_LIST);
List<WorkFlowRelation> workFlowRelations = (List<WorkFlowRelation>)workFlowLists.get("workFlowRelationList"); Set<WorkFlowRelation> workFlowRelations = (Set<WorkFlowRelation>) workFlowLists.get(Constants.WORKFLOW_RELATION_LIST);
Assert.assertTrue(workFlowLineages.size() > 0); Assert.assertTrue(workFlowLineages.size() > 0);
Assert.assertTrue(workFlowRelations.size() > 0); Assert.assertTrue(workFlowRelations.size() > 0);
} }
@ -83,13 +135,4 @@ public class WorkFlowLineageServiceTest {
return workFlowLineages; return workFlowLineages;
} }
private List<WorkFlowRelation> getWorkFlowRelation(){
List<WorkFlowRelation> workFlowRelations = new ArrayList<>();
WorkFlowRelation workFlowRelation = new WorkFlowRelation();
workFlowRelation.setSourceWorkFlowId(1);
workFlowRelation.setTargetWorkFlowId(2);
workFlowRelations.add(workFlowRelation);
return workFlowRelations;
}
} }

311
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinitionVersion.java

@ -1,311 +0,0 @@
/*
* 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.entity;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
/**
* process definition version
*/
@TableName("t_ds_process_definition_version")
public class ProcessDefinitionVersion {
/**
* id
*/
@TableId(value = "id", type = IdType.AUTO)
private int id;
/**
* process definition id
*/
private int processDefinitionId;
/**
* version
*/
private long version;
/**
* definition json string
*/
private String processDefinitionJson;
/**
* description
*/
private String description;
/**
* process warning time out. unit: minute
*/
private int timeout;
/**
* resource ids
*/
private String resourceIds;
/**
* create time
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
/**
* user defined parameters
*/
private String globalParams;
/**
* locations array for web
*/
private String locations;
/**
* connects array for web
*/
private String connects;
/**
* warningGroupId
*/
@TableField(exist = false)
private int warningGroupId;
public String getGlobalParams() {
return globalParams;
}
public void setGlobalParams(String globalParams) {
this.globalParams = globalParams;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getProcessDefinitionId() {
return processDefinitionId;
}
public void setProcessDefinitionId(int processDefinitionId) {
this.processDefinitionId = processDefinitionId;
}
public long getVersion() {
return version;
}
public void setVersion(long version) {
this.version = version;
}
public String getProcessDefinitionJson() {
return processDefinitionJson;
}
public void setProcessDefinitionJson(String processDefinitionJson) {
this.processDefinitionJson = processDefinitionJson;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getLocations() {
return locations;
}
public void setLocations(String locations) {
this.locations = locations;
}
public String getConnects() {
return connects;
}
public void setConnects(String connects) {
this.connects = connects;
}
public int getTimeout() {
return timeout;
}
public void setTimeout(int timeout) {
this.timeout = timeout;
}
public String getResourceIds() {
return resourceIds;
}
public void setResourceIds(String resourceIds) {
this.resourceIds = resourceIds;
}
public int getWarningGroupId() {
return warningGroupId;
}
public void setWarningGroupId(int warningGroupId) {
this.warningGroupId = warningGroupId;
}
@Override
public String toString() {
return "ProcessDefinitionVersion{"
+ "id=" + id
+ ", processDefinitionId=" + processDefinitionId
+ ", version=" + version
+ ", processDefinitionJson='" + processDefinitionJson + '\''
+ ", description='" + description + '\''
+ ", globalParams='" + globalParams + '\''
+ ", createTime=" + createTime
+ ", locations='" + locations + '\''
+ ", connects='" + connects + '\''
+ ", timeout=" + timeout
+ ", warningGroupId=" + warningGroupId
+ ", resourceIds='" + resourceIds + '\''
+ '}';
}
public static Builder newBuilder() {
return new Builder();
}
public static final class Builder {
private int id;
private int processDefinitionId;
private long version;
private String processDefinitionJson;
private String description;
private String globalParams;
private Date createTime;
private String locations;
private String connects;
private int timeout;
private int warningGroupId;
private String resourceIds;
private Builder() {
}
public Builder id(int id) {
this.id = id;
return this;
}
public Builder processDefinitionId(int processDefinitionId) {
this.processDefinitionId = processDefinitionId;
return this;
}
public Builder version(long version) {
this.version = version;
return this;
}
public Builder processDefinitionJson(String processDefinitionJson) {
this.processDefinitionJson = processDefinitionJson;
return this;
}
public Builder description(String description) {
this.description = description;
return this;
}
public Builder globalParams(String globalParams) {
this.globalParams = globalParams;
return this;
}
public Builder createTime(Date createTime) {
this.createTime = createTime;
return this;
}
public Builder locations(String locations) {
this.locations = locations;
return this;
}
public Builder connects(String connects) {
this.connects = connects;
return this;
}
public Builder timeout(int timeout) {
this.timeout = timeout;
return this;
}
public Builder warningGroupId(int warningGroupId) {
this.warningGroupId = warningGroupId;
return this;
}
public Builder resourceIds(String resourceIds) {
this.resourceIds = resourceIds;
return this;
}
public ProcessDefinitionVersion build() {
ProcessDefinitionVersion processDefinitionVersion = new ProcessDefinitionVersion();
processDefinitionVersion.setId(id);
processDefinitionVersion.setProcessDefinitionId(processDefinitionId);
processDefinitionVersion.setVersion(version);
processDefinitionVersion.setProcessDefinitionJson(processDefinitionJson);
processDefinitionVersion.setDescription(description);
processDefinitionVersion.setGlobalParams(globalParams);
processDefinitionVersion.setCreateTime(createTime);
processDefinitionVersion.setLocations(locations);
processDefinitionVersion.setConnects(connects);
processDefinitionVersion.setTimeout(timeout);
processDefinitionVersion.setWarningGroupId(warningGroupId);
processDefinitionVersion.setResourceIds(resourceIds);
return processDefinitionVersion;
}
}
}

11
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/ProcessDefinitionDao.java

@ -18,14 +18,15 @@
package org.apache.dolphinscheduler.dao.upgrade; package org.apache.dolphinscheduler.dao.upgrade;
import org.apache.dolphinscheduler.common.utils.ConnectionUtils; import org.apache.dolphinscheduler.common.utils.ConnectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.util.HashMap;
import java.util.*; import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ProcessDefinitionDao { public class ProcessDefinitionDao {
@ -34,6 +35,7 @@ public class ProcessDefinitionDao {
/** /**
* queryAllProcessDefinition * queryAllProcessDefinition
*
* @param conn jdbc connection * @param conn jdbc connection
* @return ProcessDefinition Json List * @return ProcessDefinition Json List
*/ */
@ -67,6 +69,7 @@ public class ProcessDefinitionDao {
/** /**
* updateProcessDefinitionJson * updateProcessDefinitionJson
*
* @param conn jdbc connection * @param conn jdbc connection
* @param processDefinitionJsonMap processDefinitionJsonMap * @param processDefinitionJsonMap processDefinitionJsonMap
*/ */

126
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/WorkFlowLineageMapperTest.java

@ -16,8 +16,19 @@
*/ */
package org.apache.dolphinscheduler.dao.mapper; package org.apache.dolphinscheduler.dao.mapper;
import org.apache.dolphinscheduler.common.enums.FailureStrategy;
import org.apache.dolphinscheduler.common.enums.ReleaseState;
import org.apache.dolphinscheduler.common.enums.WarningType;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.entity.ProcessLineage;
import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation;
import org.apache.dolphinscheduler.dao.entity.Schedule;
import org.apache.dolphinscheduler.dao.entity.WorkFlowLineage; import org.apache.dolphinscheduler.dao.entity.WorkFlowLineage;
import org.apache.dolphinscheduler.dao.entity.WorkFlowRelation;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -27,21 +38,124 @@ import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest @SpringBootTest
@Transactional @Transactional
@Rollback(true) @Rollback(true)
public class WorkFlowLineageMapperTest { public class WorkFlowLineageMapperTest {
@Autowired @Autowired
private WorkFlowLineageMapper workFlowLineageMapper; private WorkFlowLineageMapper workFlowLineageMapper;
@Autowired
private ProcessDefinitionMapper processDefinitionMapper;
@Autowired
private ScheduleMapper scheduleMapper;
@Autowired
ProcessTaskRelationMapper processTaskRelationMapper;
/**
* insert
*
* @return ProcessDefinition
*/
private ProcessTaskRelation insertOneProcessTaskRelation() {
//insertOne
ProcessTaskRelation processTaskRelation = new ProcessTaskRelation();
processTaskRelation.setName("def 1");
processTaskRelation.setProjectCode(1L);
processTaskRelation.setProcessDefinitionCode(1L);
processTaskRelation.setPostTaskCode(3L);
processTaskRelation.setPostTaskVersion(1);
processTaskRelation.setPreTaskCode(2L);
processTaskRelation.setPreTaskVersion(1);
processTaskRelation.setUpdateTime(new Date());
processTaskRelation.setCreateTime(new Date());
processTaskRelationMapper.insert(processTaskRelation);
return processTaskRelation;
}
/**
* insert
*
* @return ProcessDefinition
*/
private ProcessDefinition insertOneProcessDefinition() {
//insertOne
ProcessDefinition processDefinition = new ProcessDefinition();
processDefinition.setCode(1L);
processDefinition.setName("def 1");
processDefinition.setProjectCode(1L);
processDefinition.setUserId(101);
processDefinition.setUpdateTime(new Date());
processDefinition.setCreateTime(new Date());
processDefinitionMapper.insert(processDefinition);
return processDefinition;
}
/**
* insert
*
* @return Schedule
*/
private Schedule insertOneSchedule(int id) {
//insertOne
Schedule schedule = new Schedule();
schedule.setStartTime(new Date());
schedule.setEndTime(new Date());
schedule.setCrontab("");
schedule.setFailureStrategy(FailureStrategy.CONTINUE);
schedule.setReleaseState(ReleaseState.OFFLINE);
schedule.setWarningType(WarningType.NONE);
schedule.setCreateTime(new Date());
schedule.setUpdateTime(new Date());
schedule.setProcessDefinitionId(id);
scheduleMapper.insert(schedule);
return schedule;
}
@Test @Test
public void testQueryByName() { public void testQueryByName() {
List<WorkFlowLineage> workFlowLineages = workFlowLineageMapper.queryByName("test",1L); insertOneProcessDefinition();
ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(1L);
insertOneSchedule(processDefinition.getId());
List<WorkFlowLineage> workFlowLineages = workFlowLineageMapper.queryByName(processDefinition.getName(), processDefinition.getProjectCode());
Assert.assertNotEquals(workFlowLineages.size(), 0);
}
@Test
public void testQueryCodeRelation() {
ProcessTaskRelation processTaskRelation = insertOneProcessTaskRelation();
List<ProcessLineage> workFlowLineages = workFlowLineageMapper.queryCodeRelation(processTaskRelation.getPreTaskCode()
, processTaskRelation.getPreTaskVersion(), 11L, 1L);
Assert.assertNotEquals(workFlowLineages.size(), 0); Assert.assertNotEquals(workFlowLineages.size(), 0);
} }
@Test
public void testQueryRelationByIds() {
insertOneProcessDefinition();
ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(1L);
insertOneProcessTaskRelation();
HashSet<Integer> set = new HashSet<>();
set.add(processDefinition.getId());
List<ProcessLineage> workFlowLineages = workFlowLineageMapper.queryRelationByIds(set, processDefinition.getProjectCode());
Assert.assertNotEquals(workFlowLineages.size(), 0);
}
@Test
public void testQueryWorkFlowLineageByCode() {
insertOneProcessDefinition();
ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(1L);
insertOneSchedule(processDefinition.getId());
WorkFlowLineage workFlowLineages = workFlowLineageMapper.queryWorkFlowLineageByCode(processDefinition.getCode(), processDefinition.getProjectCode());
Assert.assertNotNull(workFlowLineages);
}
} }

17
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/upgrade/WokrerGrouopDaoTest.java → dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/upgrade/WorkerGroupDaoTest.java

@ -16,19 +16,18 @@
*/ */
package org.apache.dolphinscheduler.dao.upgrade; package org.apache.dolphinscheduler.dao.upgrade;
import org.junit.Test;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import static org.apache.dolphinscheduler.dao.upgrade.UpgradeDao.getDataSource; import static org.apache.dolphinscheduler.dao.upgrade.UpgradeDao.getDataSource;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
public class WokrerGrouopDaoTest { import java.util.Map;
import javax.sql.DataSource;
import org.junit.Test;
public class WorkerGroupDaoTest {
protected final DataSource dataSource = getDataSource(); protected final DataSource dataSource = getDataSource();
@Test @Test
Loading…
Cancel
Save