feat(性能测试): 增加JMeter Properties 配置 --story=1002075 --user=刘瑞斌 性能测试支持配置JMet... https://www.tapd.cn/55049933/s/1026273

This commit is contained in:
Captain.B 2021-07-20 16:00:05 +08:00 committed by 刘瑞斌
parent 51d2daedb8
commit 494fde0985
4 changed files with 169 additions and 64 deletions

View File

@ -42,6 +42,7 @@ import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
@ -156,10 +157,24 @@ public class EngineFactory {
/*
{"timeout":10,"statusCode":["302","301"],"params":[{"name":"param1","enable":true,"value":"0","edit":false}],"domains":[{"domain":"baidu.com","enable":true,"ip":"127.0.0.1","edit":false}]}
*/
Map<String, byte[]> testResourceFiles = new HashMap<>();
StringBuilder props = new StringBuilder("# JMeter Properties\n");
if (StringUtils.isNotEmpty(loadTest.getAdvancedConfiguration())) {
JSONObject advancedConfiguration = JSONObject.parseObject(loadTest.getAdvancedConfiguration());
engineContext.addProperties(advancedConfiguration);
JSONArray properties = advancedConfiguration.getJSONArray("properties");
if (properties != null) {
for (int i = 0; i < properties.size(); i++) {
JSONObject prop = properties.getJSONObject(i);
if (!prop.getBoolean("enable")) {
continue;
}
props.append(prop.getString("name")).append("=").append(prop.getString("value")).append("\n");
}
}
}
// JMeter Properties
testResourceFiles.put("ms.properties", props.toString().getBytes(StandardCharsets.UTF_8));
final EngineSourceParser engineSourceParser = EngineSourceParserFactory.createEngineSourceParser(engineContext.getFileType());
@ -168,13 +183,12 @@ public class EngineFactory {
}
if (CollectionUtils.isNotEmpty(resourceFiles)) {
Map<String, byte[]> data = new HashMap<>();
resourceFiles.forEach(cf -> {
FileContent csvContent = fileService.getFileContent(cf.getId());
data.put(cf.getName(), csvContent.getFile());
testResourceFiles.put(cf.getName(), csvContent.getFile());
});
engineContext.setTestResourceFiles(data);
}
engineContext.setTestResourceFiles(testResourceFiles);
try (ByteArrayInputStream source = new ByteArrayInputStream(jmxBytes)) {
String content = engineSourceParser.parse(engineContext, source);

View File

@ -9,8 +9,8 @@
</el-form-item>
<el-form-item>
<el-input-number
:disabled="readOnly" size="mini" v-model="timeout"
:min="0"/>
:disabled="readOnly" size="mini" v-model="timeout"
:min="0"/>
</el-form-item>
<el-form-item>
ms
@ -24,8 +24,8 @@
</el-form-item>
<el-form-item>
<el-input-number
:disabled="readOnly" size="mini" :min="0"
v-model="responseTimeout"/>
:disabled="readOnly" size="mini" :min="0"
v-model="responseTimeout"/>
</el-form-item>
<el-form-item>
ms
@ -38,9 +38,9 @@
<div>
{{ $t('load_test.granularity') }}
<el-popover
placement="left"
width="300"
trigger="hover">
placement="left"
width="300"
trigger="hover">
<el-table :data="granularityData">
<el-table-column property="start" :label="$t('load_test.duration')">
<template v-slot:default="scope">
@ -69,9 +69,9 @@
</el-form-item>
<el-form-item>
<el-input
:disabled="readOnly" size="mini" v-model="statusCodeStr"
:placeholder="$t('load_test.separated_by_commas')"
@input="checkStatusCode"></el-input>
:disabled="readOnly" size="mini" v-model="statusCodeStr"
:placeholder="$t('load_test.separated_by_commas')"
@input="checkStatusCode"></el-input>
</el-form-item>
</el-form>
</el-col>
@ -86,9 +86,9 @@
<el-col :span="24">
<el-table :data="csvFiles" size="mini" class="tb-edit" align="center" border highlight-current-row>
<el-table-column
align="center"
prop="name"
:label="$t('commons.name')">
align="center"
prop="name"
:label="$t('commons.name')">
</el-table-column>
<el-table-column align="center" prop="csvSplit" :label="$t('load_test.csv_split')">
<template v-slot:default="{row}">
@ -113,58 +113,57 @@
</el-button>
</el-col>
</el-row>
<!-- -->
<el-row>
<el-col :span="24">
<el-table :data="params" size="mini" class="tb-edit" align="center" border highlight-current-row>
<el-table-column
align="center"
:label="$t('load_test.param_name')"
show-overflow-tooltip>
align="center"
:label="$t('load_test.param_name')"
show-overflow-tooltip>
<template v-slot:default="{row}">
<el-input
size="mini"
v-if="!readOnly"
type="textarea"
:rows="1"
class="edit-input"
v-model="row.name"
:placeholder="$t('load_test.param_name')"
clearable>
size="mini"
v-if="!readOnly"
type="textarea"
:rows="1"
class="edit-input"
v-model="row.name"
:placeholder="$t('load_test.param_name')"
clearable>
</el-input>
<span>{{ row.name }}</span>
</template>
</el-table-column>
<el-table-column
align="center"
:label="$t('load_test.enable')"
show-overflow-tooltip>
align="center"
:label="$t('load_test.enable')"
show-overflow-tooltip>
<template v-slot:default="{row}">
<el-switch
:disabled="!row.edit || readOnly"
size="mini"
v-model="row.enable"
inactive-color="#DCDFE6">
:disabled="!row.edit || readOnly"
size="mini"
v-model="row.enable"
inactive-color="#DCDFE6">
</el-switch>
</template>
</el-table-column>
<el-table-column
:label="$t('load_test.param_value')"
show-overflow-tooltip align="center">
:label="$t('load_test.param_value')"
show-overflow-tooltip align="center">
<template v-slot:default="{row}">
<!-- <template v-if="row.edit">
<el-input v-model="row.value" class="edit-input" size="mini"/>
</template>
<span v-else>{{ row.value }}</span>-->
<el-input
size="mini"
v-if="!readOnly"
type="textarea"
class="edit-input"
:rows="1"
v-model="row.value"
:placeholder="$t('load_test.param_value')"
clearable></el-input>
size="mini"
v-if="!readOnly"
type="textarea"
class="edit-input"
:rows="1"
v-model="row.value"
:placeholder="$t('load_test.param_value')"
clearable></el-input>
<span>{{ row.value }}</span>
</template>
</el-table-column>
@ -179,6 +178,81 @@
</el-col>
</el-row>
<!-- JMeter Properties -->
<el-row>
<el-col :span="8">
<h3>JMeter Properties</h3>
<el-button :disabled="readOnly" icon="el-icon-circle-plus-outline" plain size="mini" @click="add('properties')">
{{ $t('commons.add') }}
</el-button>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-table :data="properties" size="mini" class="tb-edit" align="center" border highlight-current-row>
<el-table-column
align="center"
:label="$t('load_test.param_name')"
show-overflow-tooltip>
<template v-slot:default="{row}">
<el-input
size="mini"
v-if="!readOnly"
type="textarea"
:rows="1"
class="edit-input"
v-model="row.name"
:placeholder="$t('load_test.param_name')"
clearable>
</el-input>
<span>{{ row.name }}</span>
</template>
</el-table-column>
<el-table-column
align="center"
:label="$t('load_test.enable')"
show-overflow-tooltip>
<template v-slot:default="{row}">
<el-switch
:disabled="!row.edit || readOnly"
size="mini"
v-model="row.enable"
inactive-color="#DCDFE6">
</el-switch>
</template>
</el-table-column>
<el-table-column
:label="$t('load_test.param_value')"
show-overflow-tooltip align="center">
<template v-slot:default="{row}">
<!-- <template v-if="row.edit">
<el-input v-model="row.value" class="edit-input" size="mini"/>
</template>
<span v-else>{{ row.value }}</span>-->
<el-input
size="mini"
v-if="!readOnly"
type="textarea"
class="edit-input"
:rows="1"
v-model="row.value"
:placeholder="$t('load_test.param_value')"
clearable></el-input>
<span>{{ row.value }}</span>
</template>
</el-table-column>
<el-table-column align="center" :label="$t('load_test.operating')">
<template v-slot:default="{row, $index}">
<ms-table-operator-button :disabled="readOnly" :tip="$t('commons.delete')" icon="el-icon-delete"
type="danger"
@exec="del(row, 'properties', $index)"/>
</template>
</el-table-column>
</el-table>
</el-col>
</el-row>
<!-- 监控配置 -->
<el-row>
<el-col :span="8">
<h3>{{ $t('commons.monitor') }}</h3>
@ -192,13 +266,12 @@
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-table :data="monitorParams" size="mini" class="tb-edit" border highlight-current-row>
<el-table-column
align="center"
prop="name"
:label="$t('commons.name')">
align="center"
prop="name"
:label="$t('commons.name')">
</el-table-column>
<!-- <el-table-column-->
<!-- align="center"-->
@ -215,19 +288,19 @@
<!-- prop="monitorStatus"-->
<!-- label="监控状态">-->
<el-table-column
align="center"
prop="ip"
label="IP">
align="center"
prop="ip"
label="IP">
</el-table-column>
<el-table-column
align="center"
prop="port"
label="Port">
align="center"
prop="port"
label="Port">
</el-table-column>
<el-table-column
align="center"
prop="description"
:label="$t('commons.description')">
align="center"
prop="description"
:label="$t('commons.description')">
</el-table-column>
<el-table-column align="center" :label="$t('load_test.operating')">
<template v-slot:default="{row, $index}">
@ -264,6 +337,7 @@ export default {
statusCode: [],
domains: [],
params: [],
properties: [],
monitorParams: [],
csvFiles: [],
csvConfig: [],
@ -320,6 +394,7 @@ export default {
this.params = data.params || [];
this.granularity = data.granularity;
this.monitorParams = data.monitorParams || [];
this.properties = data.properties || [];
this.csvConfig = data.csvConfig;
}
});
@ -341,6 +416,14 @@ export default {
edit: true,
});
}
if (dataName === 'properties') {
this[dataName].push({
name: 'prop1',
enable: true,
value: '0',
edit: true,
});
}
},
edit(row) {
row.edit = !row.edit;
@ -377,6 +460,13 @@ export default {
return false;
}
}
counts = this.groupBy(this.properties, 'name');
for (let c in counts) {
if (counts[c] > 1) {
this.$error(this.$t('load_test.param_is_duplicate'));
return false;
}
}
if (this.domains.filter(d => !d.domain || !d.ip).length > 0) {
this.$error(this.$t('load_test.domain_ip_is_empty'));
return false;
@ -406,6 +496,7 @@ export default {
responseTimeout: this.responseTimeout,
statusCode: statusCode,
params: this.params,
properties: this.properties,
csvConfig: this.csvFiles.reduce((result, curr) => {
result[curr.name] = {csvHasHeader: curr.csvHasHeader, csvSplit: curr.csvSplit};
return result;

View File

@ -633,9 +633,9 @@ export default {
ip: 'IP地址',
input_ip: '请输入正确的IP地址',
input_domain: '请输入正确的域名!',
params: '自定义属性',
param_name: '属性名',
param_value: '属性值',
params: '自定义变量',
param_name: '变量名',
param_value: '变量值',
domain_is_duplicate: '域名不能重复',
param_is_duplicate: '参数名不能重复',
domain_ip_is_empty: '域名和IP不能为空',

View File

@ -633,9 +633,9 @@ export default {
ip: 'IP地址',
input_ip: '請輸入正確的IP地址',
input_domain: '請輸入正確的域名!',
params: '自定義屬性',
param_name: '屬性名',
param_value: '屬性值',
params: '自定義變量',
param_name: '變量名',
param_value: '變量值',
domain_is_duplicate: '域名不能重復',
param_is_duplicate: '參數名不能重復',
domain_ip_is_empty: '域名和IP不能為空',