From 25abe21823da39d9c3b92c3320a82d42441e842c Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Wed, 27 Jan 2021 09:39:41 +0800 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20=E4=BF=AE=E6=94=B9=E4=B8=8B?= =?UTF-8?q?=E8=BD=BDzip=E7=9A=84=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=8E=BB?= =?UTF-8?q?=E6=8E=89threadnum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/JmeterFileController.java | 5 +-- .../service/JmeterFileService.java | 38 +------------------ 2 files changed, 3 insertions(+), 40 deletions(-) diff --git a/backend/src/main/java/io/metersphere/performance/controller/JmeterFileController.java b/backend/src/main/java/io/metersphere/performance/controller/JmeterFileController.java index b4f66783f0..f39070d3b8 100644 --- a/backend/src/main/java/io/metersphere/performance/controller/JmeterFileController.java +++ b/backend/src/main/java/io/metersphere/performance/controller/JmeterFileController.java @@ -21,9 +21,8 @@ public class JmeterFileController { @GetMapping("download") public ResponseEntity 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\"") diff --git a/backend/src/main/java/io/metersphere/performance/service/JmeterFileService.java b/backend/src/main/java/io/metersphere/performance/service/JmeterFileService.java index 3a5782eb5b..ad918d1740 100644 --- a/backend/src/main/java/io/metersphere/performance/service/JmeterFileService.java +++ b/backend/src/main/java/io/metersphere/performance/service/JmeterFileService.java @@ -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"; From f84db83a4c5314f66cd6ec7847ad7a04167cc044 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 27 Jan 2021 11:16:54 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):?= =?UTF-8?q?=20=E5=BF=AB=E6=8D=B7=E8=B0=83=E8=AF=95=E5=8F=A6=E5=AD=98?= =?UTF-8?q?=E4=B8=BA=E7=94=A8=E4=BE=8B=EF=BC=8C=E5=B9=B6=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E4=B8=80=E6=9D=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/definition/components/ApiConfig.vue | 25 ++----------- .../components/case/ApiCaseItem.vue | 37 ++++++++++++++++++- .../components/case/ApiCaseList.vue | 6 +++ .../components/debug/DebugDubboPage.vue | 12 +++++- .../components/debug/DebugHttpPage.vue | 21 ++++++++--- .../components/debug/DebugJdbcPage.vue | 11 +++++- .../components/debug/DebugTcpPage.vue | 17 ++++++++- 7 files changed, 95 insertions(+), 34 deletions(-) diff --git a/frontend/src/business/components/api/definition/components/ApiConfig.vue b/frontend/src/business/components/api/definition/components/ApiConfig.vue index bbd76219c8..be68994833 100644 --- a/frontend/src/business/components/api/definition/components/ApiConfig.vue +++ b/frontend/src/business/components/api/definition/components/ApiConfig.vue @@ -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; diff --git a/frontend/src/business/components/api/definition/components/case/ApiCaseItem.vue b/frontend/src/business/components/api/definition/components/case/ApiCaseItem.vue index 6edfb4b64e..d68dcb94f8 100644 --- a/frontend/src/business/components/api/definition/components/case/ApiCaseItem.vue +++ b/frontend/src/business/components/api/definition/components/case/ApiCaseItem.vue @@ -108,7 +108,7 @@