Merge remote-tracking branch 'origin/master'

This commit is contained in:
song.tianyang 2021-01-27 11:21:17 +08:00
commit f9eae8c6dd
9 changed files with 99 additions and 75 deletions

View File

@ -21,9 +21,8 @@ public class JmeterFileController {
@GetMapping("download")
public ResponseEntity<byte[]> downloadJmeterFiles(@RequestParam("testId") String testId, @RequestParam("resourceId") String resourceId,
@RequestParam("ratio") double ratio, @RequestParam("startTime") long startTime,
@RequestParam("reportId") String reportId, @RequestParam("resourceIndex") int resourceIndex,
@RequestParam("threadNum") int threadNum) {
byte[] bytes = jmeterFileService.downloadZip(testId, resourceId, ratio, startTime, reportId, resourceIndex, threadNum);
@RequestParam("reportId") String reportId, @RequestParam("resourceIndex") int resourceIndex) {
byte[] bytes = jmeterFileService.downloadZip(testId, resourceId, ratio, startTime, reportId, resourceIndex);
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType("application/octet-stream"))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + testId + ".zip\"")

View File

@ -2,9 +2,6 @@ package io.metersphere.performance.service;
import com.alibaba.excel.util.CollectionUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.base.domain.LoadTestWithBLOBs;
import io.metersphere.base.mapper.LoadTestMapper;
import io.metersphere.commons.exception.MSException;
@ -12,7 +9,6 @@ import io.metersphere.commons.utils.LogUtil;
import io.metersphere.performance.engine.EngineContext;
import io.metersphere.performance.engine.EngineFactory;
import org.apache.commons.lang3.SerializationUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -20,7 +16,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@ -31,12 +26,11 @@ public class JmeterFileService {
@Resource
private LoadTestMapper loadTestMapper;
public byte[] downloadZip(String testId, String resourceId, double ratio, long startTime, String reportId, int resourceIndex, int threadNum) {
public byte[] downloadZip(String testId, String resourceId, double ratio, long startTime, String reportId, int resourceIndex) {
try {
LoadTestWithBLOBs loadTest = loadTestMapper.selectByPrimaryKey(testId);
// deep copy
LoadTestWithBLOBs subTest = SerializationUtils.clone(loadTest);
setThreadNum(subTest, threadNum);
EngineContext context = EngineFactory.createContext(subTest, resourceId, ratio, startTime, reportId, resourceIndex);
return zipFilesToByteArray(context);
} catch (MSException e) {
@ -49,36 +43,6 @@ public class JmeterFileService {
return null;
}
private void setThreadNum(LoadTestWithBLOBs t, Integer limit) {
// 传入limit才去改这个值
if (limit <= 0) {
return;
}
String loadConfiguration = t.getLoadConfiguration();
JSONArray jsonArray = JSON.parseArray(loadConfiguration);
for (int i = 0; i < jsonArray.size(); i++) {
if (jsonArray.get(i) instanceof Map) {
JSONObject o = jsonArray.getJSONObject(i);
if (StringUtils.equals(o.getString("key"), "TargetLevel")) {
o.put("value", limit);
break;
}
}
if (jsonArray.get(i) instanceof List) {
JSONArray o = jsonArray.getJSONArray(i);
for (int j = 0; j < o.size(); j++) {
JSONObject b = o.getJSONObject(j);
if (StringUtils.equals(b.getString("key"), "TargetLevel")) {
b.put("value", limit);
break;
}
}
}
}
// 设置线程数
t.setLoadConfiguration(jsonArray.toJSONString());
}
private byte[] zipFilesToByteArray(EngineContext context) throws IOException {
String testId = context.getTestId();
String fileName = testId + ".jmx";

View File

@ -77,16 +77,16 @@
document.removeEventListener("keydown", this.createCtrlSHandle);
},
createCtrlSHandle(event) {
if(this.$refs.httpApi) {
if (this.$refs.httpApi) {
handleCtrlSEvent(event, this.$refs.httpApi.saveApi);
}
else if(this.$refs.tcpApi) {
else if (this.$refs.tcpApi) {
handleCtrlSEvent(event, this.$refs.tcpApi.saveApi);
}
else if(this.$refs.dubboApi) {
else if (this.$refs.dubboApi) {
handleCtrlSEvent(event, this.$refs.dubboApi.saveApi);
}
else if(this.$refs.sqlApi) {
else if (this.$refs.sqlApi) {
handleCtrlSEvent(event, this.$refs.sqlApi.saveApi);
}
},
@ -192,27 +192,10 @@
let bodyFiles = this.getBodyUploadFiles(data);
this.$fileUpload(this.reqUrl, null, bodyFiles, data, () => {
this.$success(this.$t('commons.save_success'));
if (this.reqUrl.endsWith('/create')) {
this.saveTestCase(data);
}
this.reqUrl = "/api/definition/update";
this.$emit('saveApi', data);
});
},
saveTestCase(row) {
let tmp = {request: JSON.parse(JSON.stringify(row.request))};
tmp.projectId = getCurrentProjectID();
tmp.active = true;
tmp.priority = "P0";
tmp.name = row.name;
tmp.request.path = row.path;
tmp.request.method = row.method;
tmp.apiDefinitionId = row.id;
let bodyFiles = this.getBodyUploadFiles(tmp);
let url = "/api/testcase/create";
this.$fileUpload(url, null, bodyFiles, tmp, (response) => {
});
},
setParameters(data) {
data.projectId = this.projectId;
this.request.name = this.currentApi.name;

View File

@ -108,7 +108,7 @@
</template>
<script>
import {_getBodyUploadFiles, getCurrentProjectID} from "../../../../../../common/js/utils";
import {_getBodyUploadFiles, getCurrentProjectID, getUUID} from "@/common/js/utils";
import {PRIORITY, RESULT_MAP} from "../../model/JsonData";
import MsTag from "../../../../common/components/MsTag";
import MsTipButton from "../../../../common/components/MsTipButton";
@ -236,7 +236,32 @@
this.saveTestCase(row);
}
},
saveTestCase(row) {
setParameters(data) {
data.projectId = getCurrentProjectID();
data.request.name = data.name;
if (data.protocol === "DUBBO" || data.protocol === "dubbo://") {
data.request.protocol = "dubbo://";
} else {
data.request.protocol = data.protocol;
}
data.id = data.request.id;
if (!data.method) {
data.method = data.protocol;
}
},
saveApi(row) {
let data = this.api;
data.name = this.apiCase.name;
this.setParameters(data);
let bodyFiles = this.getBodyUploadFiles(data);
this.$fileUpload("/api/definition/create", null, bodyFiles, data, () => {
if (row) {
this.api.saved = false;
this.saveCase(row);
}
});
},
saveCase(row) {
let tmp = JSON.parse(JSON.stringify(row));
this.isShowInput = false;
if (this.validate(tmp)) {
@ -267,6 +292,14 @@
}
});
},
saveTestCase(row) {
if (this.api.saved) {
this.saveApi(row);
} else {
this.saveCase(row);
}
},
showInput(row) {
// row.type = "create";
this.isShowInput = true;
@ -293,7 +326,7 @@
}
},
showExecResult(item) {
item.active = false;
item.active = true;
item.isActive = true;
},
getBodyUploadFiles(row) {

View File

@ -144,6 +144,12 @@
this.getApiTest(true);
this.visible = true;
},
saveApiAndCase(api) {
this.visible = true;
this.api = api;
console.log(api)
this.addCase();
},
setEnvironment(environment) {
this.environment = environment;
},

View File

@ -26,6 +26,9 @@
<div v-if="scenario">
<el-button style="float: right;margin: 20px" type="primary" @click="handleCommand('save_as')"> {{$t('commons.save')}}</el-button>
</div>
<!-- 加载用例 -->
<ms-api-case-list :loaded="false" ref="caseList"/>
</div>
</template>
@ -40,10 +43,11 @@
import MsRequestResultTail from "../response/RequestResultTail";
import MsBasisParameters from "../request/dubbo/BasisParameters";
import MsJmxStep from "../step/JmxStep";
import MsApiCaseList from "../case/ApiCaseList";
export default {
name: "ApiConfig",
components: {MsRequestResultTail, MsResponseResult, MsRequestMetric, MsResponseText, MsRun, MsBasisParameters, MsJmxStep},
components: {MsRequestResultTail, MsResponseResult, MsRequestMetric, MsResponseText, MsRun, MsBasisParameters, MsJmxStep, MsApiCaseList},
props: {
currentProtocol: String,
scenario: Boolean,
@ -120,7 +124,11 @@
saveAs() {
let obj = {request: this.request};
obj.request.id = getUUID();
this.$emit('saveAs', obj);
obj.saved = true;
obj.protocol = this.currentProtocol;
obj.status = "Underway";
obj.method = this.currentProtocol;
this.$refs.caseList.saveApiAndCase(obj);
}
}
}

View File

@ -41,6 +41,8 @@
<div v-if="scenario">
<el-button style="float: right;margin: 20px" type="primary" @click="handleCommand('save_as')"> {{$t('commons.save')}}</el-button>
</div>
<!-- 加载用例 -->
<ms-api-case-list :loaded="false" ref="caseList"/>
</div>
</template>
@ -56,10 +58,11 @@
import MsRequestResultTail from "../response/RequestResultTail";
import MsJmxStep from "../step/JmxStep";
import {KeyValue} from "../../model/ApiTestModel";
import MsApiCaseList from "../case/ApiCaseList";
export default {
name: "ApiConfig",
components: {MsRequestResultTail, MsResponseResult, MsApiRequestForm, MsRequestMetric, MsResponseText, MsRun, MsJmxStep},
components: {MsRequestResultTail, MsResponseResult, MsApiRequestForm, MsRequestMetric, MsResponseText, MsRun, MsJmxStep, MsApiCaseList},
props: {
currentProtocol: String,
testCase: {},
@ -92,6 +95,7 @@
runData: [],
reportId: "",
reqOptions: REQ_METHOD,
createCase: "",
request: {},
}
},
@ -156,13 +160,17 @@
saveAs() {
this.$refs['debugForm'].validate((valid) => {
if (valid) {
this.debugForm.id = null;
this.request.id = getUUID();
this.request.method = this.debugForm.method;
this.request.path = this.debugForm.path;
this.protocol = this.currentProtocol;
this.debugForm.id = this.request.id;
this.debugForm.request = this.request;
this.debugForm.userId = getCurrentUser().id;
this.debugForm.status = "Underway";
this.debugForm.protocol = this.currentProtocol;
this.$emit('saveAs', this.debugForm);
this.debugForm.saved = true;
this.$refs.caseList.saveApiAndCase(this.debugForm);
}
else {
return false;
@ -170,10 +178,13 @@
})
},
urlChange() {
if (!this.debugForm.url || this.debugForm.url.indexOf('?') === -1) return;
if (!this.debugForm.url) return;
let url = this.getURL(this.addProtocol(this.debugForm.url));
if (url) {
this.debugForm.url = decodeURIComponent(this.debugForm.url.substr(0, this.debugForm.url.indexOf("?")));
if (this.debugForm.url.indexOf('?') != -1) {
this.debugForm.url = decodeURIComponent(this.debugForm.url.substr(0, this.debugForm.url.indexOf("?")));
}
this.debugForm.path = url.pathname;
}
},
addProtocol(url) {

View File

@ -27,6 +27,8 @@
<div v-if="scenario">
<el-button style="float: right;margin: 20px" type="primary" @click="handleCommand('save_as')"> {{$t('commons.save')}}</el-button>
</div>
<!-- 加载用例 -->
<ms-api-case-list :loaded="false" ref="caseList"/>
</div>
@ -43,10 +45,11 @@
import MsRequestResultTail from "../response/RequestResultTail";
import MsBasisParameters from "../request/database/BasisParameters";
import MsJmxStep from "../step/JmxStep";
import MsApiCaseList from "../case/ApiCaseList";
export default {
name: "ApiConfig",
components: {MsRequestResultTail, MsResponseResult, MsRequestMetric, MsResponseText, MsRun, MsBasisParameters, MsJmxStep},
components: {MsRequestResultTail, MsResponseResult, MsRequestMetric, MsResponseText, MsRun, MsBasisParameters, MsJmxStep,MsApiCaseList},
props: {
currentProtocol: String,
scenario: Boolean,
@ -123,7 +126,11 @@
saveAs() {
let obj = {request: this.request};
obj.request.id = getUUID();
this.$emit('saveAs', obj);
obj.saved = true;
obj.protocol = this.currentProtocol;
obj.status = "Underway";
obj.method = this.currentProtocol;
this.$refs.caseList.saveApiAndCase(obj);
}
}
}

View File

@ -37,6 +37,9 @@
<div v-if="scenario">
<el-button style="float: right;margin: 20px" type="primary" @click="handleCommand('save_as')"> {{$t('commons.save')}}</el-button>
</div>
<!-- 加载用例 -->
<ms-api-case-list :loaded="false" ref="caseList"/>
</div>
</template>
@ -53,13 +56,15 @@
import MsRequestResultTail from "../response/RequestResultTail";
import TcpBasisParameters from "../request/tcp/TcpBasisParameters";
import MsJmxStep from "../step/JmxStep";
import MsApiCaseList from "../case/ApiCaseList";
export default {
name: "ApiConfig",
components: {
MsJmxStep,
TcpBasisParameters,
MsRequestResultTail, MsResponseResult, MsApiRequestForm, MsRequestMetric, MsResponseText, MsRun},
MsRequestResultTail, MsResponseResult, MsApiRequestForm, MsRequestMetric, MsResponseText, MsRun, MsApiCaseList
},
props: {
currentProtocol: String,
scenario: Boolean,
@ -135,8 +140,16 @@
},
saveAs() {
let obj = {request: this.request};
obj.request.server = this.debugForm.server;
obj.request.port = this.debugForm.port;
obj.server = this.debugForm.server;
obj.port = this.debugForm.port;
obj.request.id = getUUID();
this.$emit('saveAs', obj);
obj.saved = true;
obj.protocol = this.currentProtocol;
obj.status = "Underway";
obj.method = this.currentProtocol;
this.$refs.caseList.saveApiAndCase(obj);
}
}
}