refactor(性能测试): 手动停止测试发送通知修改

This commit is contained in:
Captain.B 2021-02-25 13:27:47 +08:00
parent 26d67b166b
commit 198bb154c4
3 changed files with 22 additions and 82 deletions

View File

@ -12,7 +12,7 @@ import javax.annotation.Resource;
@Service
public class LoadTestProducer {
@Value("${kafka.topic}")
@Value("${kafka.log.topic}")
private String topic;
@Resource
private KafkaTemplate<String, Object> kafkaTemplate;
@ -20,11 +20,15 @@ public class LoadTestProducer {
private ObjectMapper objectMapper;
public void sendMessage(String reportId) {
Metric metric = new Metric();
metric.setReportId(reportId);
metric.setThreadName("tearDown Thread Group"); // 发送停止消息
Log log = Log.builder()
.reportId(reportId)
.resourceId("none")
.resourceIndex(0)
.content("Notifying test listeners of end of test")
.build();
try {
this.kafkaTemplate.send(topic, objectMapper.writeValueAsString(metric));
this.kafkaTemplate.send(topic, objectMapper.writeValueAsString(log));
} catch (JsonProcessingException e) {
LogUtil.error("发送停止消息失败", e);
}

View File

@ -0,0 +1,13 @@
package io.metersphere.performance.engine.producer;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class Log {
private String reportId;
private String resourceId;
private int resourceIndex;
private String content;
}

View File

@ -1,77 +0,0 @@
package io.metersphere.performance.engine.producer;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
public class Metric {
@JsonProperty("test.id")
private String testId;
@JsonProperty("test.name")
private String testName;
@JsonProperty("test.startTime")
private Long clusterStartTime;
@JsonProperty("test.reportId")
private String reportId;
@JsonProperty("ContentType")
private String contentType;
@JsonProperty("IdleTime")
private Integer idleTime;
@JsonProperty("ElapsedTime")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZZ")
private Date elapsedTime;
@JsonProperty("ErrorCount")
private Integer errorCount;
@JsonProperty("Timestamp")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZZ")
private Date timestamp;
@JsonProperty("URL")
private String url;
@JsonProperty("SampleStartTime")
private String sampleStartTime;
@JsonProperty("Success")
private Boolean success;
@JsonProperty("Bytes")
private Integer bytes;
@JsonProperty("SentBytes")
private Integer sentBytes;
@JsonProperty("AllThreads")
private Integer allThreads;
@JsonProperty("TestElement.name")
private String testElementName;
@JsonProperty("DataType")
private String dataType;
@JsonProperty("ResponseTime")
private Integer responseTime;
@JsonProperty("SampleCount")
private Integer sampleCount;
@JsonProperty("FailureMessage")
private String failureMessage;
@JsonProperty("ConnectTime")
private Integer connectTime;
@JsonProperty("ResponseCode")
private String responseCode;
@JsonProperty("TestStartTime")
private Long testStartTime;
@JsonProperty("AssertionResults")
private List<Object> assertionResults;
@JsonProperty("Latency")
private Integer latency;
@JsonProperty("InjectorHostname")
private String injectorHostname;
@JsonProperty("GrpThreads")
private Integer grpThreads;
@JsonProperty("SampleEndTime")
private String sampleEndTime;
@JsonProperty("BodySize")
private Long bodySize;
@JsonProperty("ThreadName")
private String threadName;
@JsonProperty("SampleLabel")
private String sampleLabel;
}