功能单元测试补齐
This commit is contained in:
parent
4a535b48ad
commit
17dc808d21
@ -43,12 +43,14 @@ public class MemoryLogManager implements LoggerManager {
|
|||||||
private PipTaskLogDao logDao;
|
private PipTaskLogDao logDao;
|
||||||
@Override
|
@Override
|
||||||
public SseEmitter subscribe(String taskId,HttpServletRequest request) {
|
public SseEmitter subscribe(String taskId,HttpServletRequest request) {
|
||||||
|
if (request!=null) {
|
||||||
String ipAddr = IpUtil.getIpAddr(request);
|
String ipAddr = IpUtil.getIpAddr(request);
|
||||||
|
log.info("当前请求ip:{}",ipAddr);
|
||||||
|
}
|
||||||
SseEmitter emitter = new SseEmitter(30000L);
|
SseEmitter emitter = new SseEmitter(30000L);
|
||||||
emitterInit(emitter,taskId);
|
emitterInit(emitter,taskId);
|
||||||
Long loginUserId = WebFrameworkUtils.getLoginUserId();
|
Long loginUserId = WebFrameworkUtils.getLoginUserId();
|
||||||
log.info("SSE连接建立");
|
log.info("SSE连接建立");
|
||||||
log.info("当前请求ip:{}",ipAddr);
|
|
||||||
log.info("当前用户id:{}",loginUserId);
|
log.info("当前用户id:{}",loginUserId);
|
||||||
log.info("当前taskId:{}",loginUserId);
|
log.info("当前taskId:{}",loginUserId);
|
||||||
List<SseEmitter> taskIdSSEList = taskIdSSEMap.computeIfAbsent(taskId, k->new ArrayList<>(1));
|
List<SseEmitter> taskIdSSEList = taskIdSSEMap.computeIfAbsent(taskId, k->new ArrayList<>(1));
|
||||||
|
@ -298,6 +298,8 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
|
|||||||
if (pipStage.getStageSort()>oldStageSort&&pipStage.getStageSort()<=currStageSort) {
|
if (pipStage.getStageSort()>oldStageSort&&pipStage.getStageSort()<=currStageSort) {
|
||||||
pipStage.setStageSort(pipStage.getStageSort()-1);
|
pipStage.setStageSort(pipStage.getStageSort()-1);
|
||||||
}
|
}
|
||||||
|
} else{
|
||||||
|
pipStage.setStageSort(currStageSort);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -307,6 +309,8 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
|
|||||||
if (pipStage.getStageSort()<oldStageSort&&pipStage.getStageSort()>=currStageSort) {
|
if (pipStage.getStageSort()<oldStageSort&&pipStage.getStageSort()>=currStageSort) {
|
||||||
pipStage.setStageSort(pipStage.getStageSort()+1);
|
pipStage.setStageSort(pipStage.getStageSort()+1);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
pipStage.setStageSort(currStageSort);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,20 @@
|
|||||||
package cd.casic.server;
|
package cd.casic.server;
|
||||||
|
|
||||||
|
import cd.casic.ci.process.engine.manager.LoggerManager;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@SpringBootTest(classes = {OpsServerApplication.class})
|
||||||
|
@ActiveProfiles("local")
|
||||||
public class LogTest {
|
public class LogTest {
|
||||||
public static void main(String[] args) {
|
@Resource
|
||||||
|
LoggerManager loggerManager;
|
||||||
|
@Test
|
||||||
|
public void getLogContent(){
|
||||||
|
String logContent = loggerManager.getLogContent("712969147377651712");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
package cd.casic.server;
|
||||||
|
|
||||||
|
import cd.casic.ci.process.engine.executor.PipelineExecutor;
|
||||||
|
import cd.casic.ci.process.process.service.pipeline.PipelineService;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
|
||||||
|
@SpringBootTest(classes = {OpsServerApplication.class})
|
||||||
|
@ActiveProfiles("local")
|
||||||
|
public class PipelineExecuteTest {
|
||||||
|
@Resource
|
||||||
|
PipelineExecutor pipelineExecutor;
|
||||||
|
@Resource
|
||||||
|
PipelineService pipelineService;
|
||||||
|
// 执行pipeline
|
||||||
|
@Test
|
||||||
|
public void executePipeline(){
|
||||||
|
pipelineExecutor.execute("716299522803896320");
|
||||||
|
}
|
||||||
|
// 获取pipeline执行状态
|
||||||
|
@Test
|
||||||
|
public void getRunState(){
|
||||||
|
pipelineService.getPipelineRunState("716299522803896320");
|
||||||
|
}
|
||||||
|
}
|
31
ops-server/src/test/java/cd/casic/server/SSETest.java
Normal file
31
ops-server/src/test/java/cd/casic/server/SSETest.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package cd.casic.server;
|
||||||
|
|
||||||
|
import cd.casic.ci.process.engine.manager.LoggerManager;
|
||||||
|
import cd.casic.ci.process.engine.manager.RunContextManager;
|
||||||
|
import cd.casic.ci.process.engine.message.TaskRunMessage;
|
||||||
|
import cd.casic.ci.process.engine.runContext.PipelineRunContext;
|
||||||
|
import cd.casic.ci.process.engine.runContext.SecondStageRunContext;
|
||||||
|
import cd.casic.ci.process.engine.runContext.TaskRunContext;
|
||||||
|
import cd.casic.ci.process.process.dataObject.pipeline.PipPipeline;
|
||||||
|
import cd.casic.ci.process.process.dataObject.stage.PipStage;
|
||||||
|
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||||
|
import cd.casic.framework.mq.redis.core.RedisMQTemplate;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@SpringBootTest(classes = {OpsServerApplication.class})
|
||||||
|
@ActiveProfiles("local")
|
||||||
|
public class SSETest {
|
||||||
|
@Resource
|
||||||
|
LoggerManager loggerManager;
|
||||||
|
@Test
|
||||||
|
public void subscribe(){
|
||||||
|
loggerManager.subscribe("716299524330622976",null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
50
ops-server/src/test/java/cd/casic/server/StageTest.java
Normal file
50
ops-server/src/test/java/cd/casic/server/StageTest.java
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package cd.casic.server;
|
||||||
|
|
||||||
|
import cd.casic.ci.process.dal.req.stage.StageUpdateReq;
|
||||||
|
import cd.casic.ci.process.process.service.stage.StageService;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
|
||||||
|
@SpringBootTest(classes = {OpsServerApplication.class})
|
||||||
|
@ActiveProfiles("local")
|
||||||
|
public class StageTest {
|
||||||
|
@Resource
|
||||||
|
StageService stageService;
|
||||||
|
@Test
|
||||||
|
public void getStageRunState(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改名称
|
||||||
|
@Test
|
||||||
|
public void updateStage(){
|
||||||
|
String reqStr = "{\n" +
|
||||||
|
" \"id\": \"716299524129296385\",\n" +
|
||||||
|
" \"stageName\": \"测试用例生成1\"\n" +
|
||||||
|
"}";
|
||||||
|
StageUpdateReq req = JSON.parseObject(reqStr, StageUpdateReq.class);
|
||||||
|
stageService.updateStagesTask(req);
|
||||||
|
}
|
||||||
|
// 修改阶段排序
|
||||||
|
@Test
|
||||||
|
public void updateStage2(){
|
||||||
|
StageUpdateReq req = new StageUpdateReq();
|
||||||
|
req.setPipelineId("716299522803896320");
|
||||||
|
req.setId("716299524129296385");
|
||||||
|
req.setStageSort(3);
|
||||||
|
stageService.updateStagesTask(req);
|
||||||
|
}
|
||||||
|
// 复制阶段
|
||||||
|
@Test
|
||||||
|
public void copyStage(){
|
||||||
|
stageService.copyStage("716299524133490688");
|
||||||
|
}
|
||||||
|
// 删除阶段
|
||||||
|
@Test
|
||||||
|
public void deleteStage(){
|
||||||
|
stageService.deleteFirstStage("717473535303487488");
|
||||||
|
}
|
||||||
|
}
|
96
ops-server/src/test/java/cd/casic/server/TaskTest.java
Normal file
96
ops-server/src/test/java/cd/casic/server/TaskTest.java
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
package cd.casic.server;
|
||||||
|
|
||||||
|
import cd.casic.ci.process.dal.req.stage.StageCreateReq;
|
||||||
|
import cd.casic.ci.process.dal.req.task.TaskUpdateReq;
|
||||||
|
import cd.casic.ci.process.engine.manager.RunContextManager;
|
||||||
|
import cd.casic.ci.process.engine.message.TaskRunMessage;
|
||||||
|
import cd.casic.ci.process.engine.runContext.PipelineRunContext;
|
||||||
|
import cd.casic.ci.process.engine.runContext.SecondStageRunContext;
|
||||||
|
import cd.casic.ci.process.engine.runContext.TaskRunContext;
|
||||||
|
import cd.casic.ci.process.process.dataObject.pipeline.PipPipeline;
|
||||||
|
import cd.casic.ci.process.process.dataObject.stage.PipStage;
|
||||||
|
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||||
|
import cd.casic.ci.process.process.service.stage.StageService;
|
||||||
|
import cd.casic.ci.process.process.service.task.TaskService;
|
||||||
|
import cd.casic.framework.mq.redis.core.RedisMQTemplate;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.scheduling.TaskScheduler;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@SpringBootTest(classes = {OpsServerApplication.class})
|
||||||
|
@ActiveProfiles("local")
|
||||||
|
public class TaskTest {
|
||||||
|
@Resource
|
||||||
|
StageService stageService;
|
||||||
|
@Resource
|
||||||
|
TaskService taskService;
|
||||||
|
// 添加串行任务
|
||||||
|
@Test
|
||||||
|
public void createStageAndTask1(){
|
||||||
|
// 传入一级stageid ,传入task所属二级stageId,因为结合sort 创建task
|
||||||
|
String reqStr = "{\n" +
|
||||||
|
" \"stageId\": \"716299524129296385\",\n" +
|
||||||
|
" \"task\": {\n" +
|
||||||
|
" \"taskType\": \"AFL\",\n" +
|
||||||
|
" \"taskSort\": 2,\n" +
|
||||||
|
" \"stageId\": \"716299524129296386\",\n" +
|
||||||
|
" \"taskName\": \"AFL执行\",\n" +
|
||||||
|
" \"taskProperties\": {},\n" +
|
||||||
|
" \"pipelineId\": \"716299522803896320\"\n" +
|
||||||
|
" }\n" +
|
||||||
|
"}";
|
||||||
|
StageCreateReq req = JSON.parseObject(reqStr,StageCreateReq.class);
|
||||||
|
stageService.createStagesOrTask(req);
|
||||||
|
}
|
||||||
|
// 添加并行任务
|
||||||
|
@Test
|
||||||
|
public void createStageAndTask2(){
|
||||||
|
// 因为添加并行任务添加顺序固定,而且需要创建二级stage所以不传二级stageid,且不传sort
|
||||||
|
String reqStr = "{\n" +
|
||||||
|
" \"stageId\": \"716299524129296385\",\n" +
|
||||||
|
" \"task\": {\n" +
|
||||||
|
" \"taskType\": \"AFL\",\n" +
|
||||||
|
" \"taskName\": \"AFL执行\",\n" +
|
||||||
|
" \"taskProperties\": {},\n" +
|
||||||
|
" \"pipelineId\": \"716299522803896320\"\n" +
|
||||||
|
" }\n" +
|
||||||
|
"}";
|
||||||
|
StageCreateReq req = JSON.parseObject(reqStr,StageCreateReq.class);
|
||||||
|
stageService.createStagesOrTask(req);
|
||||||
|
}
|
||||||
|
// 添加阶段并添加task
|
||||||
|
@Test
|
||||||
|
public void createStageAndTask3(){
|
||||||
|
// 添加阶段所以一级stageId 不传,改为传stageSort,因为二级stage,task永远是第一个,所以都taskSort,和二级stage的stageSort都不需要传
|
||||||
|
String reqStr = "{\n" +
|
||||||
|
" \"stageSort\": 4,\n" +
|
||||||
|
" \"task\": {\n" +
|
||||||
|
" \"taskType\": \"AFL\",\n" +
|
||||||
|
" \"taskName\": \"AFL执行\",\n" +
|
||||||
|
" \"taskProperties\": {},\n" +
|
||||||
|
" \"pipelineId\": \"716299522803896320\"\n" +
|
||||||
|
" }\n" +
|
||||||
|
"}";
|
||||||
|
StageCreateReq req = JSON.parseObject(reqStr,StageCreateReq.class);
|
||||||
|
stageService.createStagesOrTask(req);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void updateTask(){
|
||||||
|
String reqStr = "{\n" +
|
||||||
|
" \"id\": \"716299524330622976\",\n" +
|
||||||
|
" \"taskType\": \"TEST_CASE_GENERATION\",\n" +
|
||||||
|
" \"taskName\": \"测试用例生成\",\n" +
|
||||||
|
" \"taskProperties\": {\n" +
|
||||||
|
" \"buildScript\": \"cd /home/casic/706/yunqi/CaseGenerator\\nPYTHONPATH=$PWD/src python3 ./src/CaseGenerator/main.py --work-dir ./testdata/libpng/libpng/ --binary ./testdata/libpng/libpng/pngfix --output-dir ../case --count 100\"\n" +
|
||||||
|
" }\n" +
|
||||||
|
"}";
|
||||||
|
TaskUpdateReq req = JSON.parseObject(reqStr, TaskUpdateReq.class);
|
||||||
|
taskService.updateTask(req);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user