diff --git a/backend/src/main/java/io/metersphere/base/domain/LoadTest.java b/backend/src/main/java/io/metersphere/base/domain/LoadTest.java index 942c255e4e..9dda60363a 100644 --- a/backend/src/main/java/io/metersphere/base/domain/LoadTest.java +++ b/backend/src/main/java/io/metersphere/base/domain/LoadTest.java @@ -17,6 +17,8 @@ public class LoadTest implements Serializable { private Long updateTime; + private String status; + private static final long serialVersionUID = 1L; public String getId() { @@ -74,4 +76,12 @@ public class LoadTest implements Serializable { public void setUpdateTime(Long updateTime) { this.updateTime = updateTime; } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status == null ? null : status.trim(); + } } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/domain/LoadTestExample.java b/backend/src/main/java/io/metersphere/base/domain/LoadTestExample.java index 7a943c47c7..cd13118eb1 100644 --- a/backend/src/main/java/io/metersphere/base/domain/LoadTestExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/LoadTestExample.java @@ -573,6 +573,76 @@ public class LoadTestExample { addCriterion("update_time not between", value1, value2, "updateTime"); return (Criteria) this; } + + public Criteria andStatusIsNull() { + addCriterion("status is null"); + return (Criteria) this; + } + + public Criteria andStatusIsNotNull() { + addCriterion("status is not null"); + return (Criteria) this; + } + + public Criteria andStatusEqualTo(String value) { + addCriterion("status =", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusNotEqualTo(String value) { + addCriterion("status <>", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusGreaterThan(String value) { + addCriterion("status >", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusGreaterThanOrEqualTo(String value) { + addCriterion("status >=", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusLessThan(String value) { + addCriterion("status <", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusLessThanOrEqualTo(String value) { + addCriterion("status <=", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusLike(String value) { + addCriterion("status like", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusNotLike(String value) { + addCriterion("status not like", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusIn(List values) { + addCriterion("status in", values, "status"); + return (Criteria) this; + } + + public Criteria andStatusNotIn(List values) { + addCriterion("status not in", values, "status"); + return (Criteria) this; + } + + public Criteria andStatusBetween(String value1, String value2) { + addCriterion("status between", value1, value2, "status"); + return (Criteria) this; + } + + public Criteria andStatusNotBetween(String value1, String value2) { + addCriterion("status not between", value1, value2, "status"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/src/main/java/io/metersphere/base/mapper/LoadTestMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/LoadTestMapper.xml index 33eca91b6d..a3e0aec9eb 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/LoadTestMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/LoadTestMapper.xml @@ -9,6 +9,7 @@ + @@ -74,7 +75,8 @@ - id, project_id, name, description, scenario_definition, create_time, update_time + id, project_id, name, description, scenario_definition, create_time, update_time, + status load_configuration, advanced_configuration, schedule @@ -130,12 +132,14 @@ insert into load_test (id, project_id, name, description, scenario_definition, create_time, - update_time, load_configuration, advanced_configuration, - schedule) + update_time, status, load_configuration, + advanced_configuration, schedule + ) values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{scenarioDefinition,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, - #{updateTime,jdbcType=BIGINT}, #{loadConfiguration,jdbcType=LONGVARCHAR}, #{advancedConfiguration,jdbcType=LONGVARCHAR}, - #{schedule,jdbcType=LONGVARCHAR}) + #{updateTime,jdbcType=BIGINT}, #{status,jdbcType=VARCHAR}, #{loadConfiguration,jdbcType=LONGVARCHAR}, + #{advancedConfiguration,jdbcType=LONGVARCHAR}, #{schedule,jdbcType=LONGVARCHAR} + ) insert into load_test @@ -161,6 +165,9 @@ update_time, + + status, + load_configuration, @@ -193,6 +200,9 @@ #{updateTime,jdbcType=BIGINT}, + + #{status,jdbcType=VARCHAR}, + #{loadConfiguration,jdbcType=LONGVARCHAR}, @@ -234,6 +244,9 @@ update_time = #{record.updateTime,jdbcType=BIGINT}, + + status = #{record.status,jdbcType=VARCHAR}, + load_configuration = #{record.loadConfiguration,jdbcType=LONGVARCHAR}, @@ -257,6 +270,7 @@ scenario_definition = #{record.scenarioDefinition,jdbcType=VARCHAR}, create_time = #{record.createTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT}, + status = #{record.status,jdbcType=VARCHAR}, load_configuration = #{record.loadConfiguration,jdbcType=LONGVARCHAR}, advanced_configuration = #{record.advancedConfiguration,jdbcType=LONGVARCHAR}, schedule = #{record.schedule,jdbcType=LONGVARCHAR} @@ -272,7 +286,8 @@ description = #{record.description,jdbcType=VARCHAR}, scenario_definition = #{record.scenarioDefinition,jdbcType=VARCHAR}, create_time = #{record.createTime,jdbcType=BIGINT}, - update_time = #{record.updateTime,jdbcType=BIGINT} + update_time = #{record.updateTime,jdbcType=BIGINT}, + status = #{record.status,jdbcType=VARCHAR} @@ -298,6 +313,9 @@ update_time = #{updateTime,jdbcType=BIGINT}, + + status = #{status,jdbcType=VARCHAR}, + load_configuration = #{loadConfiguration,jdbcType=LONGVARCHAR}, @@ -318,6 +336,7 @@ scenario_definition = #{scenarioDefinition,jdbcType=VARCHAR}, create_time = #{createTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT}, + status = #{status,jdbcType=VARCHAR}, load_configuration = #{loadConfiguration,jdbcType=LONGVARCHAR}, advanced_configuration = #{advancedConfiguration,jdbcType=LONGVARCHAR}, schedule = #{schedule,jdbcType=LONGVARCHAR} @@ -330,7 +349,8 @@ description = #{description,jdbcType=VARCHAR}, scenario_definition = #{scenarioDefinition,jdbcType=VARCHAR}, create_time = #{createTime,jdbcType=BIGINT}, - update_time = #{updateTime,jdbcType=BIGINT} + update_time = #{updateTime,jdbcType=BIGINT}, + status = #{status,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/commons/constants/TestStatus.java b/backend/src/main/java/io/metersphere/commons/constants/TestStatus.java new file mode 100644 index 0000000000..2da73cbeff --- /dev/null +++ b/backend/src/main/java/io/metersphere/commons/constants/TestStatus.java @@ -0,0 +1,5 @@ +package io.metersphere.commons.constants; + +public enum TestStatus { + Running, Completed +} diff --git a/backend/src/main/java/io/metersphere/service/LoadTestService.java b/backend/src/main/java/io/metersphere/service/LoadTestService.java index eacc35d222..e5d9f94121 100644 --- a/backend/src/main/java/io/metersphere/service/LoadTestService.java +++ b/backend/src/main/java/io/metersphere/service/LoadTestService.java @@ -7,6 +7,7 @@ import io.metersphere.base.mapper.LoadTestFileMapper; import io.metersphere.base.mapper.LoadTestMapper; import io.metersphere.base.mapper.ext.ExtLoadTestMapper; import io.metersphere.commons.constants.EngineType; +import io.metersphere.commons.constants.TestStatus; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.LogUtil; import io.metersphere.controller.request.testplan.*; @@ -179,7 +180,9 @@ public class LoadTestService { } engine.start(); - + // 标记running状态 + loadTest.setStatus(TestStatus.Running.name()); + loadTestMapper.updateByPrimaryKeySelective(loadTest); // todo:通过调用stop方法能够停止正在运行的engine,但是如果部署了多个backend实例,页面发送的停止请求如何定位到具体的engine } diff --git a/backend/src/main/resources/db/migration/V2__metersphere_ddl.sql b/backend/src/main/resources/db/migration/V2__metersphere_ddl.sql index 5e3491e7e0..9b2c8ac1dd 100644 --- a/backend/src/main/resources/db/migration/V2__metersphere_ddl.sql +++ b/backend/src/main/resources/db/migration/V2__metersphere_ddl.sql @@ -32,6 +32,7 @@ CREATE TABLE IF NOT EXISTS `load_test` ( `schedule` longtext COMMENT 'Test schedule (cron list)', `create_time` bigint(13) NOT NULL COMMENT 'Create timestamp', `update_time` bigint(13) NOT NULL COMMENT 'Update timestamp', + `status` varchar(64) DEFAULT NULL COMMENT 'Test Status Running, Completed, Error, etc.', PRIMARY KEY (`id`) ) ENGINE = InnoDB