Merge branch 'master' of https://github.com/metersphere/server
This commit is contained in:
commit
4001c981ff
|
@ -3,16 +3,20 @@ package io.metersphere.api.jmeter;
|
|||
import io.metersphere.api.service.APIReportService;
|
||||
import io.metersphere.api.service.APITestService;
|
||||
import io.metersphere.base.domain.ApiTestReport;
|
||||
import io.metersphere.base.domain.Notice;
|
||||
import io.metersphere.commons.constants.APITestStatus;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.notice.service.MailService;
|
||||
import io.metersphere.notice.service.NoticeService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.jmeter.assertions.AssertionResult;
|
||||
import org.apache.jmeter.samplers.SampleResult;
|
||||
import org.apache.jmeter.visualizers.backend.AbstractBackendListenerClient;
|
||||
import org.apache.jmeter.visualizers.backend.BackendListenerContext;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
|
@ -113,9 +117,12 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
|||
report = apiReportService.getRunningReport(testResult.getTestId());
|
||||
}
|
||||
apiReportService.complete(testResult, report);
|
||||
|
||||
queue.clear();
|
||||
super.teardownTest(context);
|
||||
NoticeService noticeService = CommonBeanFactory.getBean(NoticeService.class);
|
||||
List<Notice> notice = noticeService.queryNotice(testResult.getTestId());
|
||||
MailService mailService = CommonBeanFactory.getBean(MailService.class);
|
||||
mailService.sendHtml(report.getId(), notice, report.getStatus(), "api");
|
||||
}
|
||||
|
||||
private RequestResult getRequestResult(SampleResult result) {
|
||||
|
|
|
@ -223,10 +223,10 @@ public class APITestService {
|
|||
apiTest.setUserId(request.getUserId());
|
||||
}
|
||||
String reportId = apiReportService.create(apiTest, request.getTriggerMode());
|
||||
if (request.getTriggerMode().equals("SCHEDULE")) {
|
||||
/*if (request.getTriggerMode().equals("SCHEDULE")) {
|
||||
List<Notice> notice = noticeService.queryNotice(request.getId());
|
||||
mailService.sendHtml(reportId,notice,"api");
|
||||
}
|
||||
}*/
|
||||
changeStatus(request.getId(), APITestStatus.Running);
|
||||
jMeterService.run(request.getId(), null, is);
|
||||
return reportId;
|
||||
|
|
|
@ -9,6 +9,7 @@ import io.metersphere.commons.utils.LogUtil;
|
|||
import io.metersphere.dto.LoadTestDTO;
|
||||
import io.metersphere.service.SystemParameterService;
|
||||
import io.metersphere.service.UserService;
|
||||
import org.springframework.mail.MailException;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -30,7 +31,7 @@ public class MailService {
|
|||
@Resource
|
||||
private SystemParameterService systemParameterService;
|
||||
|
||||
public void sendHtml(String id, List<Notice> notice,String type) {
|
||||
public void sendHtml(String id, List<Notice> notice, String status, String type) {
|
||||
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
|
||||
List<SystemParameter> paramList = systemParameterService.getParamList(ParamConstants.Classify.MAIL.getValue());
|
||||
javaMailSender.setDefaultEncoding("UTF-8");
|
||||
|
@ -58,15 +59,12 @@ public class MailService {
|
|||
javaMailSender.setJavaMailProperties(props);
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
String testName = "";
|
||||
String state = "";
|
||||
if (type.equals("api")) {
|
||||
APIReportResult reportResult = apiAndPerformanceHelper.getApi(id);
|
||||
testName = reportResult.getTestName();
|
||||
state = reportResult.getStatus();
|
||||
} else if (type.equals("performance")) {
|
||||
LoadTestDTO performanceResult = apiAndPerformanceHelper.getPerformance(id);
|
||||
testName = performanceResult.getName();
|
||||
state = performanceResult.getStatus();
|
||||
}
|
||||
String html1 = "<!DOCTYPE html>\n" +
|
||||
"<html lang=\"en\">\n" +
|
||||
|
@ -115,7 +113,7 @@ public class MailService {
|
|||
LogUtil.error("Recipient information is empty");
|
||||
}
|
||||
|
||||
if(state.equals("success")){
|
||||
if (status.equals("Success")) {
|
||||
users = successEmailList.toArray(new String[successEmailList.size()]);
|
||||
helper.setText(html2, true);
|
||||
} else {
|
||||
|
@ -124,11 +122,15 @@ public class MailService {
|
|||
|
||||
}
|
||||
helper.setTo(users);
|
||||
javaMailSender.send(mimeMessage);
|
||||
|
||||
} catch (MessagingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
javaMailSender.send(mimeMessage);
|
||||
} catch (MailException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,30 +16,54 @@ import java.util.List;
|
|||
public class NoticeService {
|
||||
@Resource
|
||||
private NoticeMapper noticeMapper;
|
||||
|
||||
public void saveNotice(NoticeRequest noticeRequest) {
|
||||
Notice notice = new Notice();
|
||||
NoticeExample example = new NoticeExample();
|
||||
example.createCriteria().andTestIdEqualTo(noticeRequest.getTestId());
|
||||
List<Notice> notices = noticeMapper.selectByExample(example);
|
||||
if (notices != null) {
|
||||
if (notices.size() > 0) {
|
||||
noticeMapper.deleteByExample(example);
|
||||
noticeRequest.getNotices().forEach(notice -> {
|
||||
for(String x:notice.getNames()){
|
||||
notice.setEvent(notice.getEvent());
|
||||
notice.setEmail(notice.getEmail());
|
||||
notice.setEnable(notice.getEnable());
|
||||
noticeRequest.getNotices().forEach(n -> {
|
||||
if (n.getNames().length > 0) {
|
||||
for (String x : n.getNames()) {
|
||||
notice.setEvent(n.getEvent());
|
||||
notice.setEmail(n.getEmail());
|
||||
notice.setEnable(n.getEnable());
|
||||
notice.setTestId(noticeRequest.getTestId());
|
||||
notice.setName(x);
|
||||
noticeMapper.insert(notice);
|
||||
}
|
||||
} else {
|
||||
notice.setEvent(n.getEvent());
|
||||
notice.setEmail(n.getEmail());
|
||||
notice.setEnable(n.getEnable());
|
||||
notice.setTestId(noticeRequest.getTestId());
|
||||
notice.setName("");
|
||||
noticeMapper.insert(notice);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
noticeRequest.getNotices().forEach(notice -> {
|
||||
notice.setEvent(noticeRequest.getEvent());
|
||||
noticeRequest.getNotices().forEach(n -> {
|
||||
if (n.getNames().length > 0) {
|
||||
for (String x : n.getNames()) {
|
||||
notice.setEvent(n.getEvent());
|
||||
notice.setEmail(n.getEmail());
|
||||
notice.setEnable(n.getEnable());
|
||||
notice.setTestId(noticeRequest.getTestId());
|
||||
notice.setName(x);
|
||||
noticeMapper.insert(notice);
|
||||
}
|
||||
} else {
|
||||
notice.setEvent(n.getEvent());
|
||||
notice.setEmail(n.getEmail());
|
||||
notice.setEnable(n.getEnable());
|
||||
notice.setTestId(noticeRequest.getTestId());
|
||||
notice.setName("");
|
||||
noticeMapper.insert(notice);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<Notice> queryNotice(String id) {
|
||||
|
|
|
@ -442,8 +442,10 @@ public class JmeterDocumentParser implements DocumentParser {
|
|||
// 增加一个response_timeout,避免目标网站不反回结果导致测试不能结束
|
||||
if (item instanceof Element && nodeNameEquals(item, STRING_PROP)
|
||||
&& StringUtils.equals(((Element) item).getAttribute("name"), "HTTPSampler.response_timeout")) {
|
||||
if (context.getProperty("responseTimeout") != null) {
|
||||
removeChildren(item);
|
||||
item.appendChild(ele.getOwnerDocument().createTextNode(""));
|
||||
item.appendChild(ele.getOwnerDocument().createTextNode(context.getProperty("responseTimeout").toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -239,7 +239,7 @@ public class PerformanceTestService {
|
|||
startEngine(loadTest, engine, request.getTriggerMode());
|
||||
if (request.getTriggerMode().equals("SCHEDULE")) {
|
||||
List<Notice> notice = noticeService.queryNotice(request.getId());
|
||||
mailService.sendHtml(engine.getReportId(),notice,"performance");
|
||||
mailService.sendHtml(engine.getReportId(), notice, "success", "performance");
|
||||
}
|
||||
return engine.getReportId();
|
||||
}
|
||||
|
|
|
@ -71,6 +71,7 @@
|
|||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-button type="primary" @click="saveNotice">{{$t('commons.save')}}</el-button>
|
||||
</template>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
|
@ -206,9 +207,11 @@
|
|||
return false;
|
||||
}
|
||||
});
|
||||
},
|
||||
saveNotice(){
|
||||
let param = this.buildParam();
|
||||
this.result = this.$post("notice/save", param, () => {
|
||||
|
||||
this.$success(this.$t('commons.save_success'));
|
||||
})
|
||||
},
|
||||
close() {
|
||||
|
|
|
@ -90,6 +90,20 @@
|
|||
</el-form-item>
|
||||
</el-form>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form :inline="true">
|
||||
<el-form-item>
|
||||
<div>{{ $t('load_test.response_timeout') }}</div>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-input-number :disabled="readOnly" size="mini" v-model="responseTimeout" :min="10"
|
||||
:max="100000"></el-input-number>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
ms
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="8">
|
||||
|
@ -117,6 +131,7 @@
|
|||
data() {
|
||||
return {
|
||||
timeout: 2000,
|
||||
responseTimeout: null,
|
||||
statusCode: [],
|
||||
domains: [],
|
||||
params: [],
|
||||
|
@ -148,12 +163,11 @@
|
|||
if (response.data) {
|
||||
let data = JSON.parse(response.data);
|
||||
this.timeout = data.timeout || 10;
|
||||
this.responseTimeout = data.responseTimeout;
|
||||
this.statusCode = data.statusCode || [];
|
||||
this.statusCodeStr = this.statusCode.join(',');
|
||||
this.domains = data.domains || [];
|
||||
this.params = data.params || [];
|
||||
/*this.domains.forEach(d => d.edit = false);
|
||||
this.params.forEach(d => d.edit = false);*/
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -236,6 +250,7 @@
|
|||
}
|
||||
return {
|
||||
timeout: this.timeout,
|
||||
responseTimeout: this.responseTimeout,
|
||||
statusCode: statusCode,
|
||||
params: this.params,
|
||||
domains: this.domains,
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 0a375848d034d20eaf05caf11769e1c75c39235c
|
||||
Subproject commit f2d5a342c82e629f510550d5778d752bb73bf5e7
|
|
@ -378,6 +378,7 @@ export default {
|
|||
domain_ip_is_empty: 'Domain and IP cannot be empty',
|
||||
param_name_value_is_empty: 'Parameters cannot be empty',
|
||||
connect_timeout: 'Timeout to establish a connection',
|
||||
response_timeout: 'Timeout to response',
|
||||
custom_http_code: 'Custom HTTP response success status code',
|
||||
separated_by_commas: 'Separated by commas',
|
||||
create: 'Create Test',
|
||||
|
|
|
@ -377,6 +377,7 @@ export default {
|
|||
domain_ip_is_empty: '域名和IP不能为空',
|
||||
param_name_value_is_empty: '参数名和参数值不能为空',
|
||||
connect_timeout: '建立连接超时时间',
|
||||
response_timeout: '响应超时时间',
|
||||
custom_http_code: '自定义 HTTP 响应成功状态码',
|
||||
separated_by_commas: '按逗号分隔',
|
||||
create: '创建测试',
|
||||
|
|
|
@ -377,6 +377,7 @@ export default {
|
|||
domain_ip_is_empty: '域名和IP不能為空',
|
||||
param_name_value_is_empty: '參數名和參數值不能為空',
|
||||
connect_timeout: '建立連接超時時間',
|
||||
response_timeout: '響應超時時間',
|
||||
custom_http_code: '自定義 HTTP 響應成功狀態碼',
|
||||
separated_by_commas: '按逗號分隔',
|
||||
create: '創建測試',
|
||||
|
|
Loading…
Reference in New Issue