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

fix(base): 修改了socket出参没有统一格式的情况

上级 c0080236
......@@ -120,7 +120,6 @@ public class TestController {
" }\n" +
" ]\n" +
"}";
System.out.println(json);
TestCase testCase = new TestCase();
testCase.setName("name");
testCase.setType(1);
......@@ -134,6 +133,5 @@ public class TestController {
testCaseBTO.setTestCase(testCase);
testCaseBTO.setTestData(testData);
TestDataExecuteResult testDataExecuteResult = caseActuator.executeTestCase(testCaseBTO, 1L, 1L);
System.out.println(testDataExecuteResult);
}
}
......@@ -7,20 +7,20 @@ package org.matrix.exception;
* @since 2022/1/19 at 12:53 PM
* Suffering is the most powerful teacher of life.
*/
public class ExecutionRunningException extends RuntimeException {
public ExecutionRunningException(String message) {
public class JobOrCaseRunningException extends RuntimeException {
public JobOrCaseRunningException(String message) {
super(message);
}
public ExecutionRunningException(String message, Throwable cause) {
public JobOrCaseRunningException(String message, Throwable cause) {
super(message, cause);
}
public ExecutionRunningException(Throwable cause) {
public JobOrCaseRunningException(Throwable cause) {
super(cause);
}
public ExecutionRunningException() {
public JobOrCaseRunningException() {
super();
}
}
......@@ -100,7 +100,7 @@ public class ExecutionSocketHandler extends TextWebSocketHandler {
TestCase testCase = BeanUtil.mapToBean(objectMap, TestCase.class, false);
List<TestData> testDataList = testDataService.list(Wrappers.lambdaQuery(TestData.class).eq(TestData::getTestCaseId, testCase.getId()));
if (testDataList.size()==0){
throw new GlobalException(String.format("执行错误,测试任务ID:%s 用例Id:%s 用例名:%s 中不存在需要测试的数据组",caseExecuteVo.getJobId(),testCase.getId(),testCase.getName()));
throw new GlobalException(String.format("执行错误,测试任务ID:%s 用例Id:%s 用例名:%s \r\n 该用例中不存在需要测试的数据组",caseExecuteVo.getJobId(),testCase.getId(),testCase.getName()));
}
TestCaseListDataBto testCaseListDataBto = new TestCaseListDataBto();
testCaseListDataBto.setTestCase(testCase);
......
......@@ -14,6 +14,7 @@ import org.matrix.socket.enums.ExecuteStatusSendMessageType;
import org.matrix.socket.pool.MonitorSocketPool;
import org.matrix.socket.vo.ExecutionStatusMonitorVo;
import org.matrix.socket.vo.ExecutionStatusSendMessageVo;
import org.matrix.socket.vo.SocketResponseMessage;
import org.matrix.socket.vo.TestExecuteLog;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.CloseStatus;
......@@ -74,7 +75,7 @@ public class ExecutionStatusMonitorSocketHandler extends TextWebSocketHandler {
}
}
} else {
session.sendMessage(new TextMessage("入参不符合规定"));
session.sendMessage(new TextMessage(SocketResponseMessage.fail("入参不符合规定")));
}
}
......@@ -94,7 +95,7 @@ public class ExecutionStatusMonitorSocketHandler extends TextWebSocketHandler {
List<WebSocketSession> webSocketSessions = EXECUTE_MONITOR_SOCKET_POOL.get(uniqueKey);
if (webSocketSessions!=null){
for (WebSocketSession webSocketSession : webSocketSessions) {
webSocketSession.sendMessage(new TextMessage(JSONObject.toJSONString(sendMessageVo)));
webSocketSession.sendMessage(new TextMessage(SocketResponseMessage.success(JSONObject.toJSONString(sendMessageVo))));
}
}
}
......@@ -132,7 +133,7 @@ public class ExecutionStatusMonitorSocketHandler extends TextWebSocketHandler {
);
if (webSocketSessions!=null){
for (WebSocketSession webSocketSession : webSocketSessions) {
webSocketSession.sendMessage(new TextMessage(JSONObject.toJSONString(sendMessageVo)));
webSocketSession.sendMessage(new TextMessage(SocketResponseMessage.success(JSONObject.toJSONString(sendMessageVo))));
}
}
......
......@@ -3,14 +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.sql.SqlExpActuator;
import org.matrix.actuators.util.ThreadUtil;
import org.matrix.database.entity.ExecutionRecord;
import org.matrix.database.service.IExecutionRecordService;
import org.matrix.enums.ModuleType;
import org.matrix.exception.ExecutionRunningException;
import org.matrix.exception.JobOrCaseRunningException;
import org.matrix.exception.GlobalException;
import org.matrix.socket.ExecutionSocketHandler;
import org.matrix.socket.vo.SocketResponseMessage;
import org.matrix.socket.vo.TestExecuteLog;
import org.matrix.socket.enums.TestExecuteType;
import org.matrix.socket.pool.TestCaseExecuteSocketPool;
......@@ -117,9 +117,7 @@ public class LogQueueRuntime {
private static void socketSendMessage(WebSocketSession socketSession, String message) {
try {
if (socketSession != null && socketSession.isOpen()) {
socketSession.sendMessage(new TextMessage(
message
));
socketSession.sendMessage(new TextMessage(SocketResponseMessage.success(message)));
}
} catch (IOException e) {
LogFactory.get().log(Level.INFO, "发送socket消息失败,socket已经断开连接");
......@@ -134,7 +132,7 @@ public class LogQueueRuntime {
testExecuteLog.setType(type);
testExecuteLog.setUniqueKey(uniqueKey);
if (checkIsInRun(testExecuteLog)) {
throw new ExecutionRunningException("当前 任务/用例 正在执行中");
throw new JobOrCaseRunningException("当前 任务/用例 正在执行中");
}
LogQueueRuntime.put(ThreadUtil.currentThreadId(), testExecuteLog);
}
......
......@@ -17,12 +17,15 @@ public class SocketResponseMessage {
private String message;
public static String success(String message){
return JSONObject.toJSONString(new SocketResponseMessage(HttpStatus.HTTP_OK,message));
}
/**
* 慎用,假如返回500的话证明这个socket已经执行不下去了,假如时用例执行的时候,产生的错误日志请不要用这个fail抛出
* @param message
* @return
*/
public static String fail(String message){
return JSONObject.toJSONString(new SocketResponseMessage(HttpStatus.HTTP_INTERNAL_ERROR,message));
}
......
......@@ -124,7 +124,6 @@ public class TreeUtils {
StringJoiner joiner = new StringJoiner("\t");
IntStream.range(0, stackDepth).mapToObj(i -> "").forEach(joiner::add);
joiner.add(printProperty.apply(rootNode).toString());
System.out.println(joiner.toString());
for (T childNode : getChild.apply(rootNode)) {
int currentLevel = stackDepth + 1;
printTreeNode(childNode, printProperty, getChild, currentLevel);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论