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 javax.xml.transform.stream.StreamResult;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; 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}]} {"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())) { if (StringUtils.isNotEmpty(loadTest.getAdvancedConfiguration())) {
JSONObject advancedConfiguration = JSONObject.parseObject(loadTest.getAdvancedConfiguration()); JSONObject advancedConfiguration = JSONObject.parseObject(loadTest.getAdvancedConfiguration());
engineContext.addProperties(advancedConfiguration); 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()); final EngineSourceParser engineSourceParser = EngineSourceParserFactory.createEngineSourceParser(engineContext.getFileType());
@ -168,13 +183,12 @@ public class EngineFactory {
} }
if (CollectionUtils.isNotEmpty(resourceFiles)) { if (CollectionUtils.isNotEmpty(resourceFiles)) {
Map<String, byte[]> data = new HashMap<>();
resourceFiles.forEach(cf -> { resourceFiles.forEach(cf -> {
FileContent csvContent = fileService.getFileContent(cf.getId()); 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)) { try (ByteArrayInputStream source = new ByteArrayInputStream(jmxBytes)) {
String content = engineSourceParser.parse(engineContext, source); String content = engineSourceParser.parse(engineContext, source);

View File

@ -113,7 +113,6 @@
</el-button> </el-button>
</el-col> </el-col>
</el-row> </el-row>
<!-- -->
<el-row> <el-row>
<el-col :span="24"> <el-col :span="24">
<el-table :data="params" size="mini" class="tb-edit" align="center" border highlight-current-row> <el-table :data="params" size="mini" class="tb-edit" align="center" border highlight-current-row>
@ -179,6 +178,81 @@
</el-col> </el-col>
</el-row> </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-row>
<el-col :span="8"> <el-col :span="8">
<h3>{{ $t('commons.monitor') }}</h3> <h3>{{ $t('commons.monitor') }}</h3>
@ -192,7 +266,6 @@
</el-col> </el-col>
</el-row> </el-row>
<el-row> <el-row>
<el-col :span="24"> <el-col :span="24">
<el-table :data="monitorParams" size="mini" class="tb-edit" border highlight-current-row> <el-table :data="monitorParams" size="mini" class="tb-edit" border highlight-current-row>
<el-table-column <el-table-column
@ -264,6 +337,7 @@ export default {
statusCode: [], statusCode: [],
domains: [], domains: [],
params: [], params: [],
properties: [],
monitorParams: [], monitorParams: [],
csvFiles: [], csvFiles: [],
csvConfig: [], csvConfig: [],
@ -320,6 +394,7 @@ export default {
this.params = data.params || []; this.params = data.params || [];
this.granularity = data.granularity; this.granularity = data.granularity;
this.monitorParams = data.monitorParams || []; this.monitorParams = data.monitorParams || [];
this.properties = data.properties || [];
this.csvConfig = data.csvConfig; this.csvConfig = data.csvConfig;
} }
}); });
@ -341,6 +416,14 @@ export default {
edit: true, edit: true,
}); });
} }
if (dataName === 'properties') {
this[dataName].push({
name: 'prop1',
enable: true,
value: '0',
edit: true,
});
}
}, },
edit(row) { edit(row) {
row.edit = !row.edit; row.edit = !row.edit;
@ -377,6 +460,13 @@ export default {
return false; 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) { if (this.domains.filter(d => !d.domain || !d.ip).length > 0) {
this.$error(this.$t('load_test.domain_ip_is_empty')); this.$error(this.$t('load_test.domain_ip_is_empty'));
return false; return false;
@ -406,6 +496,7 @@ export default {
responseTimeout: this.responseTimeout, responseTimeout: this.responseTimeout,
statusCode: statusCode, statusCode: statusCode,
params: this.params, params: this.params,
properties: this.properties,
csvConfig: this.csvFiles.reduce((result, curr) => { csvConfig: this.csvFiles.reduce((result, curr) => {
result[curr.name] = {csvHasHeader: curr.csvHasHeader, csvSplit: curr.csvSplit}; result[curr.name] = {csvHasHeader: curr.csvHasHeader, csvSplit: curr.csvSplit};
return result; return result;

View File

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

View File

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