diff --git a/backend/src/main/java/io/metersphere/base/domain/TestCase.java b/backend/src/main/java/io/metersphere/base/domain/TestCase.java index 2585f68787..0fbe689c3d 100644 --- a/backend/src/main/java/io/metersphere/base/domain/TestCase.java +++ b/backend/src/main/java/io/metersphere/base/domain/TestCase.java @@ -31,5 +31,7 @@ public class TestCase implements Serializable { private String testId; + private Integer sort; + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/domain/TestCaseExample.java b/backend/src/main/java/io/metersphere/base/domain/TestCaseExample.java index 1196b8477b..6576f8f575 100644 --- a/backend/src/main/java/io/metersphere/base/domain/TestCaseExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/TestCaseExample.java @@ -385,142 +385,142 @@ public class TestCaseExample { } public Criteria andNameIsNull() { - addCriterion("name is null"); + addCriterion("`name` is null"); return (Criteria) this; } public Criteria andNameIsNotNull() { - addCriterion("name is not null"); + addCriterion("`name` is not null"); return (Criteria) this; } public Criteria andNameEqualTo(String value) { - addCriterion("name =", value, "name"); + addCriterion("`name` =", value, "name"); return (Criteria) this; } public Criteria andNameNotEqualTo(String value) { - addCriterion("name <>", value, "name"); + addCriterion("`name` <>", value, "name"); return (Criteria) this; } public Criteria andNameGreaterThan(String value) { - addCriterion("name >", value, "name"); + addCriterion("`name` >", value, "name"); return (Criteria) this; } public Criteria andNameGreaterThanOrEqualTo(String value) { - addCriterion("name >=", value, "name"); + addCriterion("`name` >=", value, "name"); return (Criteria) this; } public Criteria andNameLessThan(String value) { - addCriterion("name <", value, "name"); + addCriterion("`name` <", value, "name"); return (Criteria) this; } public Criteria andNameLessThanOrEqualTo(String value) { - addCriterion("name <=", value, "name"); + addCriterion("`name` <=", value, "name"); return (Criteria) this; } public Criteria andNameLike(String value) { - addCriterion("name like", value, "name"); + addCriterion("`name` like", value, "name"); return (Criteria) this; } public Criteria andNameNotLike(String value) { - addCriterion("name not like", value, "name"); + addCriterion("`name` not like", value, "name"); return (Criteria) this; } public Criteria andNameIn(List values) { - addCriterion("name in", values, "name"); + addCriterion("`name` in", values, "name"); return (Criteria) this; } public Criteria andNameNotIn(List values) { - addCriterion("name not in", values, "name"); + addCriterion("`name` not in", values, "name"); return (Criteria) this; } public Criteria andNameBetween(String value1, String value2) { - addCriterion("name between", value1, value2, "name"); + addCriterion("`name` between", value1, value2, "name"); return (Criteria) this; } public Criteria andNameNotBetween(String value1, String value2) { - addCriterion("name not between", value1, value2, "name"); + addCriterion("`name` not between", value1, value2, "name"); return (Criteria) this; } public Criteria andTypeIsNull() { - addCriterion("type is null"); + addCriterion("`type` is null"); return (Criteria) this; } public Criteria andTypeIsNotNull() { - addCriterion("type is not null"); + addCriterion("`type` is not null"); return (Criteria) this; } public Criteria andTypeEqualTo(String value) { - addCriterion("type =", value, "type"); + addCriterion("`type` =", value, "type"); return (Criteria) this; } public Criteria andTypeNotEqualTo(String value) { - addCriterion("type <>", value, "type"); + addCriterion("`type` <>", value, "type"); return (Criteria) this; } public Criteria andTypeGreaterThan(String value) { - addCriterion("type >", value, "type"); + addCriterion("`type` >", value, "type"); return (Criteria) this; } public Criteria andTypeGreaterThanOrEqualTo(String value) { - addCriterion("type >=", value, "type"); + addCriterion("`type` >=", value, "type"); return (Criteria) this; } public Criteria andTypeLessThan(String value) { - addCriterion("type <", value, "type"); + addCriterion("`type` <", value, "type"); return (Criteria) this; } public Criteria andTypeLessThanOrEqualTo(String value) { - addCriterion("type <=", value, "type"); + addCriterion("`type` <=", value, "type"); return (Criteria) this; } public Criteria andTypeLike(String value) { - addCriterion("type like", value, "type"); + addCriterion("`type` like", value, "type"); return (Criteria) this; } public Criteria andTypeNotLike(String value) { - addCriterion("type not like", value, "type"); + addCriterion("`type` not like", value, "type"); return (Criteria) this; } public Criteria andTypeIn(List values) { - addCriterion("type in", values, "type"); + addCriterion("`type` in", values, "type"); return (Criteria) this; } public Criteria andTypeNotIn(List values) { - addCriterion("type not in", values, "type"); + addCriterion("`type` not in", values, "type"); return (Criteria) this; } public Criteria andTypeBetween(String value1, String value2) { - addCriterion("type between", value1, value2, "type"); + addCriterion("`type` between", value1, value2, "type"); return (Criteria) this; } public Criteria andTypeNotBetween(String value1, String value2) { - addCriterion("type not between", value1, value2, "type"); + addCriterion("`type` not between", value1, value2, "type"); return (Criteria) this; } @@ -665,72 +665,72 @@ public class TestCaseExample { } public Criteria andMethodIsNull() { - addCriterion("method is null"); + addCriterion("`method` is null"); return (Criteria) this; } public Criteria andMethodIsNotNull() { - addCriterion("method is not null"); + addCriterion("`method` is not null"); return (Criteria) this; } public Criteria andMethodEqualTo(String value) { - addCriterion("method =", value, "method"); + addCriterion("`method` =", value, "method"); return (Criteria) this; } public Criteria andMethodNotEqualTo(String value) { - addCriterion("method <>", value, "method"); + addCriterion("`method` <>", value, "method"); return (Criteria) this; } public Criteria andMethodGreaterThan(String value) { - addCriterion("method >", value, "method"); + addCriterion("`method` >", value, "method"); return (Criteria) this; } public Criteria andMethodGreaterThanOrEqualTo(String value) { - addCriterion("method >=", value, "method"); + addCriterion("`method` >=", value, "method"); return (Criteria) this; } public Criteria andMethodLessThan(String value) { - addCriterion("method <", value, "method"); + addCriterion("`method` <", value, "method"); return (Criteria) this; } public Criteria andMethodLessThanOrEqualTo(String value) { - addCriterion("method <=", value, "method"); + addCriterion("`method` <=", value, "method"); return (Criteria) this; } public Criteria andMethodLike(String value) { - addCriterion("method like", value, "method"); + addCriterion("`method` like", value, "method"); return (Criteria) this; } public Criteria andMethodNotLike(String value) { - addCriterion("method not like", value, "method"); + addCriterion("`method` not like", value, "method"); return (Criteria) this; } public Criteria andMethodIn(List values) { - addCriterion("method in", values, "method"); + addCriterion("`method` in", values, "method"); return (Criteria) this; } public Criteria andMethodNotIn(List values) { - addCriterion("method not in", values, "method"); + addCriterion("`method` not in", values, "method"); return (Criteria) this; } public Criteria andMethodBetween(String value1, String value2) { - addCriterion("method between", value1, value2, "method"); + addCriterion("`method` between", value1, value2, "method"); return (Criteria) this; } public Criteria andMethodNotBetween(String value1, String value2) { - addCriterion("method not between", value1, value2, "method"); + addCriterion("`method` not between", value1, value2, "method"); return (Criteria) this; } @@ -993,6 +993,66 @@ public class TestCaseExample { addCriterion("test_id not between", value1, value2, "testId"); return (Criteria) this; } + + public Criteria andSortIsNull() { + addCriterion("sort is null"); + return (Criteria) this; + } + + public Criteria andSortIsNotNull() { + addCriterion("sort is not null"); + return (Criteria) this; + } + + public Criteria andSortEqualTo(Integer value) { + addCriterion("sort =", value, "sort"); + return (Criteria) this; + } + + public Criteria andSortNotEqualTo(Integer value) { + addCriterion("sort <>", value, "sort"); + return (Criteria) this; + } + + public Criteria andSortGreaterThan(Integer value) { + addCriterion("sort >", value, "sort"); + return (Criteria) this; + } + + public Criteria andSortGreaterThanOrEqualTo(Integer value) { + addCriterion("sort >=", value, "sort"); + return (Criteria) this; + } + + public Criteria andSortLessThan(Integer value) { + addCriterion("sort <", value, "sort"); + return (Criteria) this; + } + + public Criteria andSortLessThanOrEqualTo(Integer value) { + addCriterion("sort <=", value, "sort"); + return (Criteria) this; + } + + public Criteria andSortIn(List values) { + addCriterion("sort in", values, "sort"); + return (Criteria) this; + } + + public Criteria andSortNotIn(List values) { + addCriterion("sort not in", values, "sort"); + return (Criteria) this; + } + + public Criteria andSortBetween(Integer value1, Integer value2) { + addCriterion("sort between", value1, value2, "sort"); + return (Criteria) this; + } + + public Criteria andSortNotBetween(Integer value1, Integer value2) { + addCriterion("sort not between", value1, value2, "sort"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/src/main/java/io/metersphere/base/mapper/TestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/TestCaseMapper.xml index 6c2936ce2c..fae25c14d2 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/TestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/TestCaseMapper.xml @@ -15,6 +15,7 @@ + @@ -79,8 +80,8 @@ - id, node_id, node_path, project_id, name, type, maintainer, priority, method, prerequisite, - create_time, update_time, test_id + id, node_id, node_path, project_id, `name`, `type`, maintainer, priority, `method`, + prerequisite, create_time, update_time, test_id, sort remark, steps @@ -135,17 +136,17 @@ insert into test_case (id, node_id, node_path, - project_id, name, type, - maintainer, priority, method, + project_id, `name`, `type`, + maintainer, priority, `method`, prerequisite, create_time, update_time, - test_id, remark, steps - ) + test_id, sort, remark, + steps) values (#{id,jdbcType=VARCHAR}, #{nodeId,jdbcType=VARCHAR}, #{nodePath,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, #{maintainer,jdbcType=VARCHAR}, #{priority,jdbcType=VARCHAR}, #{method,jdbcType=VARCHAR}, #{prerequisite,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, - #{testId,jdbcType=VARCHAR}, #{remark,jdbcType=LONGVARCHAR}, #{steps,jdbcType=LONGVARCHAR} - ) + #{testId,jdbcType=VARCHAR}, #{sort,jdbcType=INTEGER}, #{remark,jdbcType=LONGVARCHAR}, + #{steps,jdbcType=LONGVARCHAR}) insert into test_case @@ -163,10 +164,10 @@ project_id, - name, + `name`, - type, + `type`, maintainer, @@ -175,7 +176,7 @@ priority, - method, + `method`, prerequisite, @@ -189,6 +190,9 @@ test_id, + + sort, + remark, @@ -236,6 +240,9 @@ #{testId,jdbcType=VARCHAR}, + + #{sort,jdbcType=INTEGER}, + #{remark,jdbcType=LONGVARCHAR}, @@ -266,10 +273,10 @@ project_id = #{record.projectId,jdbcType=VARCHAR}, - name = #{record.name,jdbcType=VARCHAR}, + `name` = #{record.name,jdbcType=VARCHAR}, - type = #{record.type,jdbcType=VARCHAR}, + `type` = #{record.type,jdbcType=VARCHAR}, maintainer = #{record.maintainer,jdbcType=VARCHAR}, @@ -278,7 +285,7 @@ priority = #{record.priority,jdbcType=VARCHAR}, - method = #{record.method,jdbcType=VARCHAR}, + `method` = #{record.method,jdbcType=VARCHAR}, prerequisite = #{record.prerequisite,jdbcType=VARCHAR}, @@ -292,6 +299,9 @@ test_id = #{record.testId,jdbcType=VARCHAR}, + + sort = #{record.sort,jdbcType=INTEGER}, + remark = #{record.remark,jdbcType=LONGVARCHAR}, @@ -309,15 +319,16 @@ node_id = #{record.nodeId,jdbcType=VARCHAR}, node_path = #{record.nodePath,jdbcType=VARCHAR}, project_id = #{record.projectId,jdbcType=VARCHAR}, - name = #{record.name,jdbcType=VARCHAR}, - type = #{record.type,jdbcType=VARCHAR}, + `name` = #{record.name,jdbcType=VARCHAR}, + `type` = #{record.type,jdbcType=VARCHAR}, maintainer = #{record.maintainer,jdbcType=VARCHAR}, priority = #{record.priority,jdbcType=VARCHAR}, - method = #{record.method,jdbcType=VARCHAR}, + `method` = #{record.method,jdbcType=VARCHAR}, prerequisite = #{record.prerequisite,jdbcType=VARCHAR}, create_time = #{record.createTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT}, test_id = #{record.testId,jdbcType=VARCHAR}, + sort = #{record.sort,jdbcType=INTEGER}, remark = #{record.remark,jdbcType=LONGVARCHAR}, steps = #{record.steps,jdbcType=LONGVARCHAR} @@ -330,15 +341,16 @@ node_id = #{record.nodeId,jdbcType=VARCHAR}, node_path = #{record.nodePath,jdbcType=VARCHAR}, project_id = #{record.projectId,jdbcType=VARCHAR}, - name = #{record.name,jdbcType=VARCHAR}, - type = #{record.type,jdbcType=VARCHAR}, + `name` = #{record.name,jdbcType=VARCHAR}, + `type` = #{record.type,jdbcType=VARCHAR}, maintainer = #{record.maintainer,jdbcType=VARCHAR}, priority = #{record.priority,jdbcType=VARCHAR}, - method = #{record.method,jdbcType=VARCHAR}, + `method` = #{record.method,jdbcType=VARCHAR}, prerequisite = #{record.prerequisite,jdbcType=VARCHAR}, create_time = #{record.createTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT}, - test_id = #{record.testId,jdbcType=VARCHAR} + test_id = #{record.testId,jdbcType=VARCHAR}, + sort = #{record.sort,jdbcType=INTEGER} @@ -356,10 +368,10 @@ project_id = #{projectId,jdbcType=VARCHAR}, - name = #{name,jdbcType=VARCHAR}, + `name` = #{name,jdbcType=VARCHAR}, - type = #{type,jdbcType=VARCHAR}, + `type` = #{type,jdbcType=VARCHAR}, maintainer = #{maintainer,jdbcType=VARCHAR}, @@ -368,7 +380,7 @@ priority = #{priority,jdbcType=VARCHAR}, - method = #{method,jdbcType=VARCHAR}, + `method` = #{method,jdbcType=VARCHAR}, prerequisite = #{prerequisite,jdbcType=VARCHAR}, @@ -382,6 +394,9 @@ test_id = #{testId,jdbcType=VARCHAR}, + + sort = #{sort,jdbcType=INTEGER}, + remark = #{remark,jdbcType=LONGVARCHAR}, @@ -396,15 +411,16 @@ set node_id = #{nodeId,jdbcType=VARCHAR}, node_path = #{nodePath,jdbcType=VARCHAR}, project_id = #{projectId,jdbcType=VARCHAR}, - name = #{name,jdbcType=VARCHAR}, - type = #{type,jdbcType=VARCHAR}, + `name` = #{name,jdbcType=VARCHAR}, + `type` = #{type,jdbcType=VARCHAR}, maintainer = #{maintainer,jdbcType=VARCHAR}, priority = #{priority,jdbcType=VARCHAR}, - method = #{method,jdbcType=VARCHAR}, + `method` = #{method,jdbcType=VARCHAR}, prerequisite = #{prerequisite,jdbcType=VARCHAR}, create_time = #{createTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT}, test_id = #{testId,jdbcType=VARCHAR}, + sort = #{sort,jdbcType=INTEGER}, remark = #{remark,jdbcType=LONGVARCHAR}, steps = #{steps,jdbcType=LONGVARCHAR} where id = #{id,jdbcType=VARCHAR} @@ -414,15 +430,16 @@ set node_id = #{nodeId,jdbcType=VARCHAR}, node_path = #{nodePath,jdbcType=VARCHAR}, project_id = #{projectId,jdbcType=VARCHAR}, - name = #{name,jdbcType=VARCHAR}, - type = #{type,jdbcType=VARCHAR}, + `name` = #{name,jdbcType=VARCHAR}, + `type` = #{type,jdbcType=VARCHAR}, maintainer = #{maintainer,jdbcType=VARCHAR}, priority = #{priority,jdbcType=VARCHAR}, - method = #{method,jdbcType=VARCHAR}, + `method` = #{method,jdbcType=VARCHAR}, prerequisite = #{prerequisite,jdbcType=VARCHAR}, create_time = #{createTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT}, - test_id = #{testId,jdbcType=VARCHAR} + test_id = #{testId,jdbcType=VARCHAR}, + sort = #{sort,jdbcType=INTEGER} where id = #{id,jdbcType=VARCHAR} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java b/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java index 6c4a991e79..5922cf6e4c 100644 --- a/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java +++ b/backend/src/main/java/io/metersphere/excel/listener/TestCaseDataListener.java @@ -10,6 +10,7 @@ import io.metersphere.i18n.Translator; import io.metersphere.track.service.TestCaseService; import org.apache.commons.lang3.StringUtils; +import java.util.Collections; import java.util.List; import java.util.Set; import java.util.UUID; @@ -72,6 +73,8 @@ public class TestCaseDataListener extends EasyExcelListener { return; } + Collections.reverse(list); + List result = list.stream() .map(item -> this.convert2TestCase(item)) .collect(Collectors.toList()); diff --git a/backend/src/main/java/io/metersphere/performance/controller/PerformanceReportController.java b/backend/src/main/java/io/metersphere/performance/controller/PerformanceReportController.java index 9656ff0451..b3d806ef85 100644 --- a/backend/src/main/java/io/metersphere/performance/controller/PerformanceReportController.java +++ b/backend/src/main/java/io/metersphere/performance/controller/PerformanceReportController.java @@ -20,9 +20,8 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.List; - import javax.annotation.Resource; +import java.util.List; @RestController @RequestMapping(value = "performance/report") @@ -63,7 +62,7 @@ public class PerformanceReportController { @GetMapping("/content/{reportId}") public List getReportContent(@PathVariable String reportId) { - return reportService.getReport(reportId); + return reportService.getReportStatistics(reportId); } @GetMapping("/content/errors/{reportId}") diff --git a/backend/src/main/java/io/metersphere/performance/service/ReportService.java b/backend/src/main/java/io/metersphere/performance/service/ReportService.java index b88ba8e864..5f3e3a66ad 100644 --- a/backend/src/main/java/io/metersphere/performance/service/ReportService.java +++ b/backend/src/main/java/io/metersphere/performance/service/ReportService.java @@ -108,7 +108,7 @@ public class ReportService { return loadTestReportResults.get(0).getReportValue(); } - public List getReport(String id) { + public List getReportStatistics(String id) { checkReportStatus(id); String reportValue = getContent(id, ReportKeys.RequestStatistics); return JSON.parseArray(reportValue, Statistics.class); @@ -209,4 +209,8 @@ public class ReportService { String content = loadTestReportLogs.stream().map(LoadTestReportLog::getContent).reduce("", (a, b) -> a + b); return content.getBytes(); } + + public LoadTestReport getReport(String reportId) { + return loadTestReportMapper.selectByPrimaryKey(reportId); + } } diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java index b66be54637..ac35d83aab 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -35,6 +35,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @Service @@ -121,7 +122,13 @@ public class TestCaseService { } public List listTestCase(QueryTestCaseRequest request) { - request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); + List orderList = ServiceUtils.getDefaultOrder(request.getOrders()); + OrderRequest order = new OrderRequest(); + // 对模板导入的测试用例排序 + order.setName("sort"); + order.setType("desc"); + orderList.add(order); + request.setOrders(orderList); return extTestCaseMapper.list(request); } @@ -176,7 +183,7 @@ public class TestCaseService { TestCaseExample testCaseExample = new TestCaseExample(); testCaseExample.createCriteria().andProjectIdIn(projectIds); - testCaseExample.setOrderByClause("update_time desc"); + testCaseExample.setOrderByClause("update_time desc, sort desc"); return testCaseMapper.selectByExample(testCaseExample); } @@ -235,8 +242,10 @@ public class TestCaseService { SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); TestCaseMapper mapper = sqlSession.getMapper(TestCaseMapper.class); if (!testCases.isEmpty()) { + AtomicInteger sort = new AtomicInteger(); testCases.forEach(testcase -> { testcase.setNodeId(nodePathMap.get(testcase.getNodePath())); + testcase.setSort(sort.getAndIncrement()); mapper.insert(testcase); }); } diff --git a/backend/src/main/java/io/metersphere/websocket/ReportWebSocket.java b/backend/src/main/java/io/metersphere/websocket/ReportWebSocket.java new file mode 100644 index 0000000000..c8f6aff33d --- /dev/null +++ b/backend/src/main/java/io/metersphere/websocket/ReportWebSocket.java @@ -0,0 +1,97 @@ +package io.metersphere.websocket; + +import io.metersphere.base.domain.LoadTestReport; +import io.metersphere.commons.constants.PerformanceTestStatus; +import io.metersphere.commons.utils.LogUtil; +import io.metersphere.performance.service.ReportService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import javax.websocket.*; +import javax.websocket.server.PathParam; +import javax.websocket.server.ServerEndpoint; +import java.io.IOException; + +@ServerEndpoint("/performance/report/{reportId}") +@Component +public class ReportWebSocket { + + private static ReportService reportService; + + @Resource + public void setReportService(ReportService reportService) { + ReportWebSocket.reportService = reportService; + } + + /** + * 开启连接的操作 + */ + @OnOpen + public void onOpen(@PathParam("reportId") String reportId, Session session) throws IOException { + //开启一个线程对数据库中的数据进行轮询 + ReportThread reportThread = new ReportThread(session, reportId); + Thread thread = new Thread(reportThread); + thread.start(); + } + + /** + * 连接关闭的操作 + */ + @OnClose + public void onClose(Session session) { + + } + + /** + * 给服务器发送消息告知数据库发生变化 + */ + @OnMessage + public void onMessage(Session session, String message) { + } + + /** + * 出错的操作 + */ + @OnError + public void onError(Throwable error) { + System.out.println(error); + error.printStackTrace(); + } + + public static class ReportThread implements Runnable { + private boolean stopMe = true; + private final String reportId; + private final Session session; + private int refresh; + + public ReportThread(Session session, String reportId) { + this.session = session; + this.reportId = reportId; + this.refresh = 0; + } + + public void stopMe() { + stopMe = false; + } + + public void run() { + while (stopMe) { + try { + LoadTestReport report = reportService.getReport(reportId); + if (StringUtils.equalsAny(report.getStatus(), PerformanceTestStatus.Completed.name(), PerformanceTestStatus.Error.name())) { + this.stopMe(); + session.close(); + break; + } + if (PerformanceTestStatus.Running.name().equals(report.getStatus())) { + session.getBasicRemote().sendText("refresh-" + this.refresh++); + } + Thread.sleep(20 * 1000L); + } catch (Exception e) { + LogUtil.error(e); + } + } + } + } +} \ No newline at end of file diff --git a/backend/src/main/resources/db/migration/V5__schedule.sql b/backend/src/main/resources/db/migration/V5__schedule.sql index 2d7302148a..41f7e62cd6 100644 --- a/backend/src/main/resources/db/migration/V5__schedule.sql +++ b/backend/src/main/resources/db/migration/V5__schedule.sql @@ -170,4 +170,6 @@ ALTER TABLE `load_test` DROP COLUMN `schedule`; ALTER TABLE `api_test_report` ADD `trigger_mode` varchar(64) NULL; ALTER TABLE `load_test_report` ADD `trigger_mode` varchar(64) NULL; UPDATE `api_test_report` SET `trigger_mode` = 'MANUAL' WHERE 1; -UPDATE `load_test_report` SET `trigger_mode` = 'MANUAL' WHERE 1; \ No newline at end of file +UPDATE `load_test_report` SET `trigger_mode` = 'MANUAL' WHERE 1; + +alter table test_case add sort int null comment 'Import test case sort'; \ No newline at end of file diff --git a/frontend/src/business/components/performance/report/PerformanceReportView.vue b/frontend/src/business/components/performance/report/PerformanceReportView.vue index c48d8264a9..c386006ec5 100644 --- a/frontend/src/business/components/performance/report/PerformanceReportView.vue +++ b/frontend/src/business/components/performance/report/PerformanceReportView.vue @@ -101,7 +101,8 @@ seconds: '0', title: 'Logging', report: {}, - isReadOnly: false + isReadOnly: false, + websocket: null } }, methods: { @@ -136,6 +137,14 @@ }) } }, + initWebSocket() { + const uri = "ws://" + window.location.host + "/performance/report/" + this.reportId; + this.websocket = new WebSocket(uri); + this.websocket.onmessage = this.onMessage; + this.websocket.onopen = this.onOpen; + this.websocket.onerror = this.onError; + this.websocket.onclose = this.onClose; + }, checkReportStatus(status) { switch (status) { case 'Error': @@ -170,6 +179,20 @@ }).catch(() => { }); }, + onOpen() { + window.console.log("open WebSocket"); + }, + onError(e) { + window.console.error(e) + }, + onMessage(e) { + this.$set(this.report, "refresh", e.data); // 触发刷新 + this.initReportTimeInfo(); + }, + onClose(e) { + this.$set(this.report, "refresh", e.data); // 触发刷新 + this.initReportTimeInfo(); + } }, created() { this.isReadOnly = false; @@ -188,7 +211,10 @@ } }) this.initBreadcrumb(); - + this.initWebSocket(); + }, + beforeDestroy() { + this.websocket.close() //离开路由之后断开websocket连接 }, watch: { '$route'(to) {