提交 aa46a4ee authored 作者: 黄夏豪's avatar 黄夏豪

fix(base): 修复了一个单词拼错了的问题

上级 00059943
......@@ -222,7 +222,7 @@ public class CaseActuator implements Actuator {
* 外界如果执行测试用例的话请走这个接口,执行TestCase,并控制运行态日志池,进行日志的生成。
*/
public List<TestCaseExecuteResult> runTestCase(WebSocketSession session, CaseExecuteVo caseExecuteVo) {
String unionKey = UUID.randomUUID().toString();
String uniqueKey = UUID.randomUUID().toString();
Long currentThreadId = ThreadUtil.currentThreadId();
try {
//将websocketSession 加入到socket池子中
......@@ -235,7 +235,7 @@ public class CaseActuator implements Actuator {
}
}
//建立执行历史(ExecutionHistory)
insertExecutionHistory(unionKey, caseExecuteVo);
insertExecutionHistory(uniqueKey, caseExecuteVo);
for (TestCaseListDataBto testCaseListDataBto : testCaseListDataBtoList) {
LogQueueRuntime
.initTestCaseLog(
......@@ -243,7 +243,7 @@ public class CaseActuator implements Actuator {
caseExecuteVo.getUserId()
, testCaseListDataBto.getTestCase().getId()
, caseExecuteVo.getType()
, unionKey
, uniqueKey
);
//执行测试用例
return executeTestCases(testCaseListDataBto, caseExecuteVo.getEnvId(), caseExecuteVo.getProjectId());
......@@ -274,9 +274,8 @@ public class CaseActuator implements Actuator {
return null;
}
public void insertExecutionHistory(String unionKey, CaseExecuteVo caseExecuteVo) {
public void insertExecutionHistory(String uniqueKey, CaseExecuteVo caseExecuteVo) {
List<TestCaseListDataBto> testCaseListDataBtoList = caseExecuteVo.getTestCaseListDataBtoList();
Long firstExecutionKey = getExecutionKey(caseExecuteVo);
List<ExecutionHistory> executionHistories = new ArrayList<>();
for (TestCaseListDataBto testCaseListDataBto : testCaseListDataBtoList) {
......@@ -288,7 +287,7 @@ public class CaseActuator implements Actuator {
executionHistory.setUserId(caseExecuteVo.getUserId());
executionHistory.setCaseId(testCase.getId());
executionHistory.setDataId(testDataList.get(i).getId());
executionHistory.setUnionKey(unionKey);
executionHistory.setUniqueKey(uniqueKey);
executionHistory.setExecutionKey(firstExecutionKey);
if (i==0){
executionHistory.setStartTime(LocalDateTime.now());
......@@ -298,7 +297,7 @@ public class CaseActuator implements Actuator {
}
Long lastExecutionKey = getExecutionKey(caseExecuteVo);
if (!lastExecutionKey.equals(firstExecutionKey)){
insertExecutionHistory(unionKey, caseExecuteVo);
insertExecutionHistory(uniqueKey, caseExecuteVo);
}
executionHistoryService.saveBatch(executionHistories);
}
......@@ -343,7 +342,7 @@ public class CaseActuator implements Actuator {
.eq(ExecutionHistory::getJobId,currentTestExecute.getTestJobId())
.eq(ExecutionHistory::getCaseId,currentTestExecute.getTestCaseId())
.eq(ExecutionHistory::getDataId,currentTestExecute.getTestDataId())
.eq(ExecutionHistory::getUnionKey,currentTestExecute.getUnionKey())
.eq(ExecutionHistory::getUniqueKey,currentTestExecute.getUniqueKey())
.eq(ExecutionHistory::getUserId,currentTestExecute.getUserId())
);
......@@ -363,7 +362,7 @@ public class CaseActuator implements Actuator {
.lambdaUpdate(ExecutionHistory.class)
.eq(ExecutionHistory::getJobId,currentTestExecute.getTestJobId())
.eq(ExecutionHistory::getCaseId,currentTestExecute.getTestCaseId())
.eq(ExecutionHistory::getUnionKey,currentTestExecute.getUnionKey())
.eq(ExecutionHistory::getUniqueKey,currentTestExecute.getUniqueKey())
.eq(ExecutionHistory::getUserId,currentTestExecute.getUserId())
.ne(ExecutionHistory::getStatus,ExecutionHistoryStatus.FINISH)
);
......
......@@ -28,7 +28,7 @@ import java.time.LocalDateTime;
@TableName(value = "kt_execution_history")
public class ExecutionHistory extends BaseEntity {
private String unionKey;
private String uniqueKey;
private Long caseId;
......
......@@ -33,7 +33,7 @@ public class ExecutionRecord extends BaseEntity {
private Long testCaseId;
@ApiModelProperty("key用来记录执行批次")
private String unionKey;
private String uniqueKey;
@ApiModelProperty("类型")
private TestExecuteType type;
......
......@@ -32,10 +32,11 @@ public interface ExecutionHistoryMapper extends BaseMapper<ExecutionHistory> {
@Select("<script>" +
"SELECT\n" +
"\tkeh.id,\n" +
"\tkeh.union_key unionKey,\n" +
"\tkeh.union_key uniqueKey,\n" +
"\tkeh.case_id caseId,\n" +
"\tkeh.data_id dataId,\n" +
"\tkeh.job_id jobId,\n" +
"\tkeh.execution_key executionKey,\n" +
"\tIF(MIN( keh.`status` )= 0 or MIN( keh.`status` ) = 1,1,MAX(keh.`status`)) `status`,\n" +
"\tktc.`name` caseName,\n" +
"\tktd.`name` dataName," +
......@@ -70,10 +71,11 @@ public interface ExecutionHistoryMapper extends BaseMapper<ExecutionHistory> {
@Select("<script>" +
"SELECT\n" +
"\tkeh.id,\n" +
"\tkeh.union_key unionKey,\n" +
"\tkeh.union_key uniqueKey,\n" +
"\tkeh.case_id caseId,\n" +
"\tkeh.data_id dataId,\n" +
"\tkeh.job_id jobId,\n" +
"\tkeh.execution_key executionKey,\n" +
"IF\n" +
"\t(\n" +
"\tMIN( keh.`status` )= 0 or MIN( keh.`status` ) = 1,\n" +
......
......@@ -33,9 +33,9 @@ public interface IExecutionRecordService extends IService<ExecutionRecord> {
void addExecutionRecord(TestExecuteLog testExecuteLog,String log);
/**
* 根据unionKey将对应的执行记录修改为目标状态
* @param unionKey 类似于批次Id的作用,同一批执行拥有相同unionKey
* 根据uniqueKey将对应的执行记录修改为目标状态
* @param uniqueKey 类似于批次Id的作用,同一批执行拥有相同uniqueKey
* @param status 目标状态
*/
void setStatusByUnionKey(String unionKey, ExecutionRecType status);
void setStatusByUniqueKey(String uniqueKey, ExecutionRecType status);
}
......@@ -34,15 +34,15 @@ public class ExecutionRecordImpl extends ServiceImpl<ExecutionRecordMapper, Exec
@Transactional(rollbackFor = Exception.class)
@Override
public void setStatusByUnionKey(String unionKey, ExecutionRecType status) {
boolean emptyIfStr = StrUtil.isEmptyIfStr(unionKey);
public void setStatusByUniqueKey(String uniqueKey, ExecutionRecType status) {
boolean emptyIfStr = StrUtil.isEmptyIfStr(uniqueKey);
if (emptyIfStr){
throw new GlobalException("不能根据空的unionKey修改执行状态");
throw new GlobalException("不能根据空的unique修改执行状态");
}else {
ExecutionRecord executionRecord = new ExecutionRecord();
update(executionRecord,Wrappers
.lambdaUpdate(ExecutionRecord.class)
.eq(ExecutionRecord::getUnionKey,unionKey)
.eq(ExecutionRecord::getUniqueKey,uniqueKey)
);
}
}
......
......@@ -5,7 +5,7 @@ import com.alibaba.fastjson.JSONException;
import org.matrix.actuators.usecase.CaseActuator;
import org.matrix.database.service.ITestDataService;
import org.matrix.socket.enums.SocketType;
import org.matrix.socket.pool.ExecuteMonitorSocketPool;
import org.matrix.socket.pool.MonitorSocketPool;
import org.matrix.socket.vo.CaseExecuteVo;
import org.matrix.socket.vo.ExecuteMonitorVo;
import org.matrix.socket.vo.SocketVo;
......@@ -23,10 +23,11 @@ import org.springframework.web.socket.handler.TextWebSocketHandler;
@Component
public class ExecutionSocketHandler extends TextWebSocketHandler {
public static final MonitorSocketPool EXECUTE_MONITOR_SOCKET_POOL = new MonitorSocketPool();
final CaseActuator caseActuator;
final ITestDataService testDataService;
public ExecutionSocketHandler(CaseActuator caseActuator, ITestDataService testDataService) {
this.caseActuator = caseActuator;
this.testDataService = testDataService;
......@@ -45,7 +46,7 @@ public class ExecutionSocketHandler extends TextWebSocketHandler {
caseActuator.runTestCase(session, caseExecuteVo);
} else if (SocketType.TEST_CASE_MONITOR.equals(socketVo.getSocketType())) {
ExecuteMonitorVo caseExecuteVo = JSON.parseObject(payload, ExecuteMonitorVo.class);
ExecuteMonitorSocketPool.add(caseExecuteVo.getUnionKey(), session);
EXECUTE_MONITOR_SOCKET_POOL.add(caseExecuteVo.getUniqueKey(), session);
} else {
session.sendMessage(new TextMessage("入参不符合规定"));
}
......@@ -57,7 +58,7 @@ public class ExecutionSocketHandler extends TextWebSocketHandler {
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) {
ExecuteMonitorSocketPool.remove(session);
EXECUTE_MONITOR_SOCKET_POOL.remove(session);
}
......
package org.matrix.socket;
import org.matrix.socket.pool.ExecuteMonitorSocketPool;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
......@@ -23,6 +22,6 @@ public class ExecutionStatusMonitorSocketPool extends TextWebSocketHandler {
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) {
ExecuteMonitorSocketPool.remove(session);
}
}
......@@ -11,60 +11,60 @@ import java.util.concurrent.ConcurrentHashMap;
*
* @author huangxiahao
*/
public class ExecuteMonitorSocketPool {
public class MonitorSocketPool {
/**
* unionKey -> socket队列
* key为unionKey value 为 socket队列
* uniqueKey -> socket队列
* key为uniqueKey value 为 socket队列
*/
private static final ConcurrentHashMap<String, List<WebSocketSession>> SOCKET_MAP = new ConcurrentHashMap<>();
private ConcurrentHashMap<String, List<WebSocketSession>> socketMap = new ConcurrentHashMap<>();
/**
* socketId -> unionKey队列
* key为socketId value 为 unionKey队列
* socketId -> uniqueKey队列
* key为socketId value 为 uniqueKey队列
*/
private static final ConcurrentHashMap<String, List<String>> SOCKET_KEY_MAP = new ConcurrentHashMap<>();
private ConcurrentHashMap<String, List<String>> socketKeyMap = new ConcurrentHashMap<>();
public static void add(String key, WebSocketSession clientSocket) {
public void add(String key, WebSocketSession clientSocket) {
if (clientSocket != null & key != null) {
List<WebSocketSession> webSocketSessions = SOCKET_MAP.get(key);
List<WebSocketSession> webSocketSessions = socketMap.get(key);
if (webSocketSessions != null) {
webSocketSessions.add(clientSocket);
} else {
webSocketSessions = new ArrayList<>();
webSocketSessions.add(clientSocket);
SOCKET_MAP.put(key, webSocketSessions);
socketMap.put(key, webSocketSessions);
}
addKeyMap(clientSocket.getId(), key);
}
}
public static void addKeyMap(String socketId, String key) {
public void addKeyMap(String socketId, String key) {
if (socketId != null & key != null) {
List<String> list = SOCKET_KEY_MAP.get(socketId);
List<String> list = socketKeyMap.get(socketId);
if (list != null) {
list.add(key);
} else {
list = new ArrayList<>();
list.add(key);
SOCKET_KEY_MAP.put(socketId, list);
socketKeyMap.put(socketId, list);
}
}
}
public static void remove(WebSocketSession clientSocket) {
public void remove(WebSocketSession clientSocket) {
String socketId = clientSocket.getId();
List<String> list = SOCKET_KEY_MAP.get(socketId);
List<String> list = socketKeyMap.get(socketId);
if (list != null) {
for (String s : list) {
SOCKET_MAP.get(s).remove(clientSocket);
socketMap.get(s).remove(clientSocket);
}
}
SOCKET_KEY_MAP.remove(socketId);
socketKeyMap.remove(socketId);
}
public static List<WebSocketSession> get(String key) {
return SOCKET_MAP.get(key);
public List<WebSocketSession> get(String key) {
return socketMap.get(key);
}
}
\ No newline at end of file
......@@ -3,12 +3,14 @@ package org.matrix.socket.queue;
import cn.hutool.log.LogFactory;
import cn.hutool.log.level.Level;
import com.alibaba.fastjson.JSONObject;
import org.matrix.actuators.httpclient.HttpClientActuator;
import org.matrix.actuators.util.ThreadUtil;
import org.matrix.database.service.IExecutionRecordService;
import org.matrix.exception.GlobalException;
import org.matrix.socket.ExecutionSocketHandler;
import org.matrix.socket.vo.TestExecuteLog;
import org.matrix.socket.enums.TestExecuteType;
import org.matrix.socket.pool.ExecuteMonitorSocketPool;
import org.matrix.socket.pool.MonitorSocketPool;
import org.matrix.socket.pool.TestCaseExecuteSocketPool;
import org.matrix.util.SpringUtils;
import org.springframework.web.socket.TextMessage;
......@@ -63,7 +65,7 @@ public class LogQueueRuntime {
TestExecuteLog testExecuteLog = LOG_MAP.get(currentThreadId);
if (testExecuteLog !=null){
testExecuteLog.addLog(log);
sendMessage(currentThreadId,testExecuteLog.getUnionKey(),log);
sendMessage(currentThreadId,testExecuteLog.getUniqueKey(),log);
addExecutionRecord(testExecuteLog,log);
}else {
throw new GlobalException("该线程中的TestCaseLog对象未初始化,请先调用put方法初始化对象");
......@@ -74,7 +76,7 @@ public class LogQueueRuntime {
LOG_MAP.remove(threadId);
}
public static void sendMessage(Long threadId,String unionKey, Object log) {
public static void sendMessage(Long threadId,String uniqueKey, Object log) {
try {
TestExecuteLog testExecuteLog = LOG_MAP.get(threadId);
// 测试任务ID.测试用例ID.测试数据ID
......@@ -87,8 +89,8 @@ public class LogQueueRuntime {
,testExecuteLog.getTestDataId()
,message.substring(1,message.length()-1)
);
//如果unionKey中存在监听的socket则向该socket发送消息
List<WebSocketSession> webSocketSessions = ExecuteMonitorSocketPool.get(unionKey);
//如果uniqueKey中存在监听的socket则向该socket发送消息
List<WebSocketSession> webSocketSessions = ExecutionSocketHandler.EXECUTE_MONITOR_SOCKET_POOL.get(uniqueKey);
if (webSocketSessions!=null){
for (WebSocketSession webSocketSession : webSocketSessions) {
webSocketSession.sendMessage(new TextMessage(
......@@ -109,13 +111,13 @@ public class LogQueueRuntime {
}
}
public static void initTestCaseLog(Long jobId, Long userId, Long caseId, TestExecuteType type, String unionKey) {
public static void initTestCaseLog(Long jobId, Long userId, Long caseId, TestExecuteType type, String uniqueKey) {
TestExecuteLog testExecuteLog = new TestExecuteLog();
testExecuteLog.setTestJobId(jobId);
testExecuteLog.setTestCaseId(caseId);
testExecuteLog.setUserId(userId);
testExecuteLog.setType(type);
testExecuteLog.setUnionKey(unionKey);
testExecuteLog.setUniqueKey(uniqueKey);
if (checkIsInRun(testExecuteLog)){
throw new GlobalException("当前用例正在执行中");
}
......
......@@ -9,6 +9,6 @@ import lombok.Data;
@Data
public class ExecuteMonitorVo extends SocketVo {
private String unionKey;
private String uniqueKey;
}
package org.matrix.socket.vo;
import lombok.Data;
/**
* 前端需要监听某一个测试任务或者测试用例调试时需要传入的值
* @author huangxiahao
*/
@Data
public class ExecutionStatusMonitorVo {
}
......@@ -19,7 +19,7 @@ public class TestExecuteLog {
/**
* 用于记录执行记录的唯一KEY,同一批次的执行记录应该具有相同的KEY。
*/
private String unionKey;
private String uniqueKey;
private TestExecuteType type = TestExecuteType.TEST_CASE;
......
package org.matrix.autotest.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.*;
import org.matrix.autotest.utils.PageTools;
import org.matrix.database.entity.ExecutionHistory;
import org.matrix.database.entity.ExecutionRecord;
import org.matrix.database.entity.TestData;
import org.matrix.database.service.IExecutionHistoryService;
import org.matrix.database.service.ITestDataService;
import org.matrix.database.vo.CommonResult;
import org.matrix.database.vo.CommonResultObj;
import org.matrix.database.vo.ExecutionHistoryVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* @author hxh
*/
......@@ -20,11 +35,53 @@ public class ExecutionHistoryController {
private final IExecutionHistoryService executionHistoryService;
@Autowired
ITestDataService testDataService;
public ExecutionHistoryController(IExecutionHistoryService executionHistoryService) {
this.executionHistoryService = executionHistoryService;
}
@ApiOperation(value = "分页查询执行历史",notes = "假如查询测试用例的执行历史,请入参caseId,假如查询测试任务的执行历史,请入参jobId")
@ApiOperation(value = "分页查询执行历史详情",notes = "假如查询测试用例的执行历史,请入参caseId,假如查询测试任务的执行历史,请入参jobId")
@GetMapping("/executionHistoryDetail")
@ApiImplicitParams({
@ApiImplicitParam(name="pageSize",value="页码",required=true,paramType="query"),
@ApiImplicitParam(name="pageNum",value="当前页显示调试",required=true,paramType="query"),
@ApiImplicitParam(name="uniqueKey",value="执行历史批次号",paramType="query"),
@ApiImplicitParam(name="jobId",value="测试任务ID",paramType="query"),
@ApiImplicitParam(name="caseId",value="测试用例ID",paramType="query")
})
public ResponseEntity<CommonResultObj<IPage<ExecutionHistoryVo>>> findExecutionHistory(
@RequestParam(defaultValue = "10") int pageSize,
@RequestParam(defaultValue = "1") int pageNum,
@RequestParam(defaultValue = "-1") Long jobId,
Long caseId,
String uniqueKey
){
Page<ExecutionHistory> results = Optional.of(executionHistoryService.page(Page.of(pageNum, pageSize)
, Wrappers.lambdaQuery(ExecutionHistory.class)
.eq(jobId!=null, ExecutionHistory::getJobId, jobId)
.eq(caseId!=null, ExecutionHistory::getCaseId, caseId )
.eq(StringUtils.hasLength(uniqueKey), ExecutionHistory::getUniqueKey, uniqueKey)
)).orElse(new Page<>());
PageTools.pageTool(pageSize, pageNum, results);
List<ExecutionHistory> records = results.getRecords();
List<ExecutionHistoryVo> collect = records.stream().map(executionHistory -> {
ExecutionHistoryVo executionHistoryVo = new ExecutionHistoryVo();
BeanUtils.copyProperties(executionHistory, executionHistoryVo);
TestData byId = testDataService.getById(executionHistory.getDataId());
executionHistoryVo.setDataName(byId.getName());
return executionHistoryVo;
}).collect(Collectors.toList());
Page<ExecutionHistoryVo> resultPage = new Page<>();
BeanUtils.copyProperties(results, resultPage);
resultPage.setRecords(collect);
return resultPage.getRecords().size() != 0
? CommonResult.success(resultPage, "查询成功")
: CommonResult.failed(resultPage, "查询失败或无数据");
}
@ApiOperation(value = "分页查询执行历史缩略",notes = "假如查询测试用例的执行历史,请入参caseId,假如查询测试任务的执行历史,请入参jobId")
@GetMapping("/executionHistory")
@ApiImplicitParams({
@ApiImplicitParam(name="pageSize",value="页码",required=true,paramType="query"),
......
......@@ -10,11 +10,13 @@ import org.matrix.database.service.IExecutionRecordService;
import org.matrix.database.vo.CommonResult;
import org.matrix.database.vo.CommonResultObj;
import org.matrix.enums.ExecutionRecType;
import org.matrix.exception.GlobalException;
import org.matrix.socket.enums.TestExecuteType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
/**
......@@ -40,7 +42,7 @@ public class ExecutionRecordController {
* @param userId 查询条件:用户ID
* @param testDataId 查询条件:测试数据ID
* @param testCaseId 查询条件:测试用例ID
* @param unionKey 查询条件:唯一批次号
* @param uniqueKey 查询条件:唯一批次号
* @param status 查询条件:运行状态
* @param type 查询条件:执行类型
* @return 分页查询的结果, 执行记录
......@@ -53,7 +55,7 @@ public class ExecutionRecordController {
Long userId,
Long testDataId,
Long testCaseId,
String unionKey,
String uniqueKey,
ExecutionRecType status,
TestExecuteType type) {
Page<ExecutionRecord> results = Optional.of(executionRecordService.page(Page.of(pageNum, pageSize)
......@@ -61,7 +63,7 @@ public class ExecutionRecordController {
.eq(userId != null, ExecutionRecord::getUserId, userId)
.eq(testDataId != null, ExecutionRecord::getTestDataId, testDataId)
.eq(testCaseId != null, ExecutionRecord::getTestCaseId, testCaseId)
.eq(StringUtils.hasLength(unionKey), ExecutionRecord::getUnionKey, unionKey)
.eq(StringUtils.hasLength(uniqueKey), ExecutionRecord::getUniqueKey, uniqueKey)
.eq(type != null, ExecutionRecord::getType, type)
)).orElse(new Page<>());
PageTools.pageTool(pageSize, pageNum, results);
......@@ -70,6 +72,39 @@ public class ExecutionRecordController {
: CommonResult.failed(results, "查询失败或无数据");
}
/**
* 分页查询执行记录
*
* @param userId 查询条件:用户ID
* @param testDataId 查询条件:测试数据ID
* @param testCaseId 查询条件:测试用例ID
* @param uniqueKey 查询条件:唯一批次号
* @param status 查询条件:运行状态
* @param type 查询条件:执行类型
* @return 分页查询的结果, 执行记录
*/
@ApiOperation("分页查询执行记录")
@GetMapping("/list")
public ResponseEntity<CommonResultObj<List<ExecutionRecord>>> findListExecutionRecord(
Long userId,
Long testDataId,
Long testCaseId,
String uniqueKey,
ExecutionRecType status,
TestExecuteType type) {
List<ExecutionRecord> results = Optional.of(executionRecordService.list(
Wrappers.lambdaQuery(ExecutionRecord.class)
.eq(userId != null, ExecutionRecord::getUserId, userId)
.eq(testDataId != null, ExecutionRecord::getTestDataId, testDataId)
.eq(testCaseId != null, ExecutionRecord::getTestCaseId, testCaseId)
.eq(StringUtils.hasLength(uniqueKey), ExecutionRecord::getUniqueKey, uniqueKey)
.eq(type != null, ExecutionRecord::getType, type)
)).orElseThrow(()->new GlobalException("xxx"));
return results.size() != 0
? CommonResult.success(results, "查询成功")
: CommonResult.failed(results, "查询失败或无数据");
}
/**
* 添加执行记录
*
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论