Browse Source
* add sql * add mapper * add dao * add excutor Co-authored-by: qianl4 <qianl4@cicso.com>3.2.0-release
qianli2022
2 years ago
committed by
GitHub
26 changed files with 842 additions and 7 deletions
@ -0,0 +1,47 @@
|
||||
/* |
||||
* 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.common.enums; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.EnumValue; |
||||
|
||||
/** |
||||
* trigger support type |
||||
*/ |
||||
public enum ApiTriggerType { |
||||
|
||||
PROCESS(0, "process instance"), |
||||
TASK(1, "task node"), |
||||
COMMAND(2, "command"); |
||||
|
||||
ApiTriggerType(int code, String desc) { |
||||
this.code = code; |
||||
this.desc = desc; |
||||
} |
||||
|
||||
@EnumValue |
||||
private final int code; |
||||
private final String desc; |
||||
|
||||
public int getCode() { |
||||
return code; |
||||
} |
||||
|
||||
public String getDesc() { |
||||
return desc; |
||||
} |
||||
} |
@ -0,0 +1,63 @@
|
||||
/* |
||||
* 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 lombok.Data; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
||||
@Data |
||||
@TableName("t_ds_trigger_relation") |
||||
public class TriggerRelation { |
||||
|
||||
/** |
||||
* id |
||||
*/ |
||||
@TableId(value = "id", type = IdType.AUTO) |
||||
private Integer id; |
||||
|
||||
/** |
||||
* trigger code |
||||
*/ |
||||
private long triggerCode; |
||||
|
||||
/** |
||||
* triggerType |
||||
*/ |
||||
private int triggerType; |
||||
|
||||
/** |
||||
* jobId |
||||
*/ |
||||
private Integer jobId; |
||||
|
||||
/** |
||||
* create time |
||||
*/ |
||||
private Date createTime; |
||||
|
||||
/** |
||||
* update time |
||||
*/ |
||||
private Date updateTime; |
||||
|
||||
} |
@ -0,0 +1,72 @@
|
||||
/* |
||||
* 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.TriggerRelation; |
||||
|
||||
import org.apache.ibatis.annotations.Param; |
||||
|
||||
import java.util.List; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
||||
/** |
||||
* triggerRelation mapper interface
|
||||
*/ |
||||
public interface TriggerRelationMapper extends BaseMapper<TriggerRelation> { |
||||
|
||||
/** |
||||
* query by code and id |
||||
* @param triggerType |
||||
* @param jobId |
||||
* @return |
||||
*/ |
||||
TriggerRelation queryByTypeAndJobId(@Param("triggerType") Integer triggerType, @Param("jobId") int jobId); |
||||
|
||||
/** |
||||
* query triggerRelation by code |
||||
* |
||||
* @param triggerCode triggerCode |
||||
* @return triggerRelation |
||||
*/ |
||||
List<TriggerRelation> queryByTriggerRelationCode(@Param("triggerCode") Long triggerCode); |
||||
|
||||
/** |
||||
* query triggerRelation by code |
||||
* |
||||
* @param triggerCode triggerCode |
||||
* @return triggerRelation |
||||
*/ |
||||
List<TriggerRelation> queryByTriggerRelationCodeAndType(@Param("triggerCode") Long triggerCode, |
||||
@Param("triggerType") Integer triggerType); |
||||
|
||||
/** |
||||
* delete triggerRelation by code |
||||
* |
||||
* @param triggerCode triggerCode |
||||
* @return int |
||||
*/ |
||||
int deleteByCode(@Param("triggerCode") Long triggerCode); |
||||
|
||||
/** |
||||
* if exist update else insert |
||||
* |
||||
* @param triggerRelation |
||||
*/ |
||||
void upsert(@Param("triggerRelation") TriggerRelation triggerRelation); |
||||
} |
@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?> |
||||
<!-- |
||||
~ 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. |
||||
--> |
||||
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
||||
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.TriggerRelationMapper"> |
||||
<sql id="baseSql"> |
||||
id, trigger_code, trigger_type, job_id, create_time, update_time |
||||
</sql> |
||||
|
||||
<select id="queryByTypeAndJobId" resultType="org.apache.dolphinscheduler.dao.entity.TriggerRelation"> |
||||
select |
||||
<include refid="baseSql"/> |
||||
from t_ds_trigger_relation |
||||
WHERE trigger_type = #{triggerType} and job_id = #{jobId} |
||||
</select> |
||||
|
||||
<select id="queryByTriggerRelationCode" resultType="org.apache.dolphinscheduler.dao.entity.TriggerRelation"> |
||||
select |
||||
<include refid="baseSql"/> |
||||
from t_ds_trigger_relation |
||||
WHERE trigger_code = #{triggerCode} |
||||
</select> |
||||
|
||||
<select id="queryByTriggerRelationCodeAndType" resultType="org.apache.dolphinscheduler.dao.entity.TriggerRelation"> |
||||
select |
||||
<include refid="baseSql"/> |
||||
from t_ds_trigger_relation |
||||
WHERE trigger_code = #{triggerCode} and trigger_type = #{triggerType} |
||||
</select> |
||||
|
||||
<delete id="deleteByCode"> |
||||
delete from t_ds_trigger_relation where triggerCode = #{triggerCode} |
||||
</delete> |
||||
|
||||
<insert id="upsert"> |
||||
INSERT INTO t_ds_trigger_relation (trigger_code, trigger_type, job_id, create_time, update_time) VALUES( |
||||
#{triggerRelation.triggerCode},#{triggerRelation.triggerType},#{triggerRelation.jobId},#{triggerRelation.createTime},#{triggerRelation.updateTime}) |
||||
ON DUPLICATE KEY UPDATE update_time = #{triggerRelation.updateTime}; |
||||
</insert> |
||||
</mapper> |
@ -0,0 +1,138 @@
|
||||
/* |
||||
* 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.ApiTriggerType; |
||||
import org.apache.dolphinscheduler.common.utils.DateUtils; |
||||
import org.apache.dolphinscheduler.dao.BaseDaoTest; |
||||
import org.apache.dolphinscheduler.dao.entity.TriggerRelation; |
||||
|
||||
import java.util.List; |
||||
|
||||
import org.junit.jupiter.api.Assertions; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
||||
/** |
||||
* trigger mapper test |
||||
*/ |
||||
public class TriggerRelationMapperTest extends BaseDaoTest { |
||||
|
||||
@Autowired |
||||
TriggerRelationMapper triggerRelationMapper; |
||||
|
||||
/** |
||||
* test insert |
||||
* |
||||
* @return |
||||
*/ |
||||
@Test |
||||
public void testInsert() { |
||||
TriggerRelation expectedObj = createTriggerRelation(); |
||||
Assertions.assertTrue(expectedObj.getId() > 0); |
||||
} |
||||
|
||||
/** |
||||
* test select by id |
||||
* |
||||
* @return |
||||
*/ |
||||
@Test |
||||
public void testSelectById() { |
||||
TriggerRelation expectRelation = createTriggerRelation(); |
||||
TriggerRelation actualRelation = triggerRelationMapper.selectById(expectRelation.getId()); |
||||
Assertions.assertEquals(expectRelation, actualRelation); |
||||
} |
||||
|
||||
/** |
||||
* test select by type and job id |
||||
* |
||||
* @return |
||||
*/ |
||||
@Test |
||||
public void testQueryByTypeAndJobId() { |
||||
TriggerRelation expectRelation = createTriggerRelation(); |
||||
TriggerRelation actualRelation = triggerRelationMapper.queryByTypeAndJobId( |
||||
expectRelation.getTriggerType(), expectRelation.getJobId()); |
||||
Assertions.assertEquals(expectRelation, actualRelation); |
||||
} |
||||
|
||||
/** |
||||
* test select by trigger code |
||||
* |
||||
* @return |
||||
*/ |
||||
@Test |
||||
public void testQueryByTriggerRelationCode() { |
||||
TriggerRelation expectRelation = createTriggerRelation(); |
||||
List<TriggerRelation> actualRelations = triggerRelationMapper.queryByTriggerRelationCode( |
||||
expectRelation.getTriggerCode()); |
||||
Assertions.assertEquals(actualRelations.size(), 1); |
||||
} |
||||
|
||||
/** |
||||
* test select by type and trigger code |
||||
* |
||||
* @return |
||||
*/ |
||||
@Test |
||||
public void testQueryByTriggerRelationCodeAndType() { |
||||
TriggerRelation expectRelation = createTriggerRelation(); |
||||
List<TriggerRelation> actualRelations = triggerRelationMapper.queryByTriggerRelationCodeAndType( |
||||
expectRelation.getTriggerCode(), expectRelation.getTriggerType()); |
||||
Assertions.assertEquals(actualRelations.size(), 1); |
||||
} |
||||
|
||||
@Test |
||||
public void testUpsert() { |
||||
TriggerRelation expectRelation = createTriggerRelation(); |
||||
triggerRelationMapper.upsert(expectRelation); |
||||
TriggerRelation actualRelation = triggerRelationMapper.selectById(expectRelation.getId()); |
||||
Assertions.assertEquals(expectRelation, actualRelation); |
||||
} |
||||
|
||||
/** |
||||
* test delete |
||||
*/ |
||||
@Test |
||||
public void testDelete() { |
||||
TriggerRelation expectRelation = createTriggerRelation(); |
||||
triggerRelationMapper.deleteById(expectRelation.getId()); |
||||
TriggerRelation actualRelation = triggerRelationMapper.selectById(expectRelation.getId()); |
||||
Assertions.assertNull(actualRelation); |
||||
} |
||||
|
||||
/** |
||||
* create TriggerRelation and insert |
||||
* |
||||
* @return TriggerRelation |
||||
* @throws Exception |
||||
*/ |
||||
private TriggerRelation createTriggerRelation() { |
||||
TriggerRelation triggerRelation = new TriggerRelation(); |
||||
triggerRelation.setTriggerCode(4567890); |
||||
triggerRelation.setTriggerType(ApiTriggerType.COMMAND.getCode()); |
||||
triggerRelation.setJobId(99); |
||||
triggerRelation.setCreateTime(DateUtils.getCurrentDate()); |
||||
triggerRelation.setUpdateTime(DateUtils.getCurrentDate()); |
||||
|
||||
triggerRelationMapper.insert(triggerRelation); |
||||
return triggerRelation; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,38 @@
|
||||
/* |
||||
* 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.service.process; |
||||
|
||||
import org.apache.dolphinscheduler.common.enums.ApiTriggerType; |
||||
import org.apache.dolphinscheduler.dao.entity.TriggerRelation; |
||||
|
||||
import org.springframework.stereotype.Component; |
||||
|
||||
/** |
||||
* Trigger relation operator to db,because operator command process instance |
||||
*/ |
||||
@Component |
||||
public interface TriggerRelationService { |
||||
|
||||
void saveTriggerToDb(ApiTriggerType type, Long triggerCode, Integer jobId); |
||||
|
||||
TriggerRelation queryByTypeAndJobId(ApiTriggerType apiTriggerType, int jobId); |
||||
|
||||
int saveCommandTrigger(Integer commandId, Integer processInstanceId); |
||||
|
||||
int saveProcessInstanceTrigger(Integer commandId, Integer processInstanceId); |
||||
} |
@ -0,0 +1,73 @@
|
||||
/* |
||||
* 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.service.process; |
||||
|
||||
import org.apache.dolphinscheduler.common.enums.ApiTriggerType; |
||||
import org.apache.dolphinscheduler.dao.entity.TriggerRelation; |
||||
import org.apache.dolphinscheduler.dao.mapper.TriggerRelationMapper; |
||||
|
||||
import java.util.Date; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
/** |
||||
* Trigger relation operator to db |
||||
*/ |
||||
@Component |
||||
public class TriggerRelationServiceImpl implements TriggerRelationService { |
||||
|
||||
@Autowired |
||||
private TriggerRelationMapper triggerRelationMapper; |
||||
|
||||
@Override |
||||
public void saveTriggerToDb(ApiTriggerType type, Long triggerCode, Integer jobId) { |
||||
TriggerRelation triggerRelation = new TriggerRelation(); |
||||
triggerRelation.setTriggerType(type.getCode()); |
||||
triggerRelation.setJobId(jobId); |
||||
triggerRelation.setTriggerCode(triggerCode); |
||||
triggerRelation.setCreateTime(new Date()); |
||||
triggerRelation.setUpdateTime(new Date()); |
||||
triggerRelationMapper.upsert(triggerRelation); |
||||
} |
||||
@Override |
||||
public TriggerRelation queryByTypeAndJobId(ApiTriggerType apiTriggerType, int jobId) { |
||||
return triggerRelationMapper.queryByTypeAndJobId(apiTriggerType.getCode(), jobId); |
||||
} |
||||
|
||||
@Override |
||||
public int saveCommandTrigger(Integer commandId, Integer processInstanceId) { |
||||
TriggerRelation exist = queryByTypeAndJobId(ApiTriggerType.PROCESS, processInstanceId); |
||||
if (exist == null) { |
||||
return 0; |
||||
} |
||||
saveTriggerToDb(ApiTriggerType.COMMAND, exist.getTriggerCode(), commandId); |
||||
return 1; |
||||
} |
||||
|
||||
@Override |
||||
public int saveProcessInstanceTrigger(Integer commandId, Integer processInstanceId) { |
||||
TriggerRelation exist = queryByTypeAndJobId(ApiTriggerType.COMMAND, commandId); |
||||
if (exist == null) { |
||||
return 0; |
||||
} |
||||
saveTriggerToDb(ApiTriggerType.PROCESS, exist.getTriggerCode(), processInstanceId); |
||||
return 1; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,107 @@
|
||||
/* |
||||
* 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.service.process; |
||||
|
||||
import org.apache.dolphinscheduler.common.enums.ApiTriggerType; |
||||
import org.apache.dolphinscheduler.dao.entity.TriggerRelation; |
||||
import org.apache.dolphinscheduler.dao.mapper.TriggerRelationMapper; |
||||
import org.apache.dolphinscheduler.service.cron.CronUtilsTest; |
||||
|
||||
import java.util.Date; |
||||
|
||||
import org.junit.jupiter.api.Assertions; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.extension.ExtendWith; |
||||
import org.mockito.InjectMocks; |
||||
import org.mockito.Mock; |
||||
import org.mockito.Mockito; |
||||
import org.mockito.junit.jupiter.MockitoExtension; |
||||
import org.mockito.junit.jupiter.MockitoSettings; |
||||
import org.mockito.quality.Strictness; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
/** |
||||
* Trigger Relation Service Test |
||||
*/ |
||||
@ExtendWith(MockitoExtension.class) |
||||
@MockitoSettings(strictness = Strictness.LENIENT) |
||||
public class TriggerRelationServiceTest { |
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CronUtilsTest.class); |
||||
|
||||
@InjectMocks |
||||
private TriggerRelationServiceImpl triggerRelationService; |
||||
@Mock |
||||
private TriggerRelationMapper triggerRelationMapper; |
||||
|
||||
@Test |
||||
public void saveTriggerToDb() { |
||||
Mockito.doNothing().when(triggerRelationMapper).upsert(Mockito.any()); |
||||
triggerRelationService.saveTriggerToDb(ApiTriggerType.COMMAND, 1234567890L, 100); |
||||
} |
||||
|
||||
@Test |
||||
public void queryByTypeAndJobId() { |
||||
Mockito.doNothing().when(triggerRelationMapper).upsert(Mockito.any()); |
||||
Mockito.when(triggerRelationMapper.queryByTypeAndJobId(ApiTriggerType.PROCESS.getCode(), 100)) |
||||
.thenReturn(getTriggerTdoDb()); |
||||
|
||||
TriggerRelation triggerRelation1 = triggerRelationService.queryByTypeAndJobId( |
||||
ApiTriggerType.PROCESS, 100); |
||||
Assertions.assertNotNull(triggerRelation1); |
||||
TriggerRelation triggerRelation2 = triggerRelationService.queryByTypeAndJobId( |
||||
ApiTriggerType.PROCESS, 200); |
||||
Assertions.assertNull(triggerRelation2); |
||||
} |
||||
|
||||
@Test |
||||
public void saveCommandTrigger() { |
||||
Mockito.doNothing().when(triggerRelationMapper).upsert(Mockito.any()); |
||||
Mockito.when(triggerRelationMapper.queryByTypeAndJobId(ApiTriggerType.PROCESS.getCode(), 100)) |
||||
.thenReturn(getTriggerTdoDb()); |
||||
int result = -1; |
||||
result = triggerRelationService.saveCommandTrigger(1234567890, 100); |
||||
Assertions.assertTrue(result > 0); |
||||
result = triggerRelationService.saveCommandTrigger(1234567890, 200); |
||||
Assertions.assertTrue(result == 0); |
||||
|
||||
} |
||||
|
||||
@Test |
||||
public void saveProcessInstanceTrigger() { |
||||
Mockito.doNothing().when(triggerRelationMapper).upsert(Mockito.any()); |
||||
Mockito.when(triggerRelationMapper.queryByTypeAndJobId(ApiTriggerType.COMMAND.getCode(), 100)) |
||||
.thenReturn(getTriggerTdoDb()); |
||||
int result = -1; |
||||
result = triggerRelationService.saveProcessInstanceTrigger(100, 1234567890); |
||||
Assertions.assertTrue(result > 0); |
||||
result = triggerRelationService.saveProcessInstanceTrigger(200, 1234567890); |
||||
Assertions.assertTrue(result == 0); |
||||
} |
||||
|
||||
private TriggerRelation getTriggerTdoDb() { |
||||
TriggerRelation triggerRelation = new TriggerRelation(); |
||||
triggerRelation.setTriggerType(ApiTriggerType.PROCESS.getCode()); |
||||
triggerRelation.setJobId(100); |
||||
triggerRelation.setTriggerCode(1234567890L); |
||||
triggerRelation.setCreateTime(new Date()); |
||||
triggerRelation.setUpdateTime(new Date()); |
||||
return triggerRelation; |
||||
} |
||||
} |
Loading…
Reference in new issue