refactor(性能测试): 性能测试支持覆盖jmeter中的system.properties

This commit is contained in:
CaptainB 2022-01-13 18:46:49 +08:00 committed by 刘瑞斌
parent 154a4297d2
commit 25be141c04
2 changed files with 218 additions and 112 deletions

View File

@ -215,9 +215,12 @@ public class EngineFactory {
*/
Map<String, byte[]> testResourceFiles = new HashMap<>();
byte[] props = getJMeterProperties(loadTestReport, engineContext);
byte[] sysProps = getSystemProperties(loadTestReport, engineContext);
byte[] hosts = getDNSConfig(loadTestReport, engineContext);
// JMeter Properties
testResourceFiles.put("ms.properties", props);
// System Properties
testResourceFiles.put("sys.properties", sysProps);
// DNS
testResourceFiles.put("hosts", hosts);
@ -287,6 +290,25 @@ public class EngineFactory {
return props.toString().getBytes(StandardCharsets.UTF_8);
}
private static byte[] getSystemProperties(LoadTestReportWithBLOBs loadTestReportWithBLOBs, EngineContext engineContext) {
StringBuilder props = new StringBuilder("# System Properties\n");
if (StringUtils.isNotEmpty(loadTestReportWithBLOBs.getAdvancedConfiguration())) {
JSONObject advancedConfiguration = JSONObject.parseObject(loadTestReportWithBLOBs.getAdvancedConfiguration());
engineContext.addProperties(advancedConfiguration);
JSONArray systemProperties = advancedConfiguration.getJSONArray("systemProperties");
if (systemProperties != null) {
for (int i = 0; i < systemProperties.size(); i++) {
JSONObject prop = systemProperties.getJSONObject(i);
if (!prop.getBoolean("enable")) {
continue;
}
props.append(prop.getString("name")).append("=").append(prop.getString("value")).append("\n");
}
}
}
return props.toString().getBytes(StandardCharsets.UTF_8);
}
public static byte[] mergeJmx(List<FileMetadata> jmxFiles) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

View File

@ -327,6 +327,79 @@
</el-col>
</el-row>
<!-- System Properties -->
<el-row>
<el-col :span="8">
<h3>System Properties</h3>
<el-button icon="el-icon-circle-plus-outline"
:disabled="isReadOnly"
plain size="mini" @click="add('systemProperties')">
{{ $t('commons.add') }}
</el-button>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-table :data="systemProperties" 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="!isReadOnly"
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
:label="$t('load_test.param_value')"
show-overflow-tooltip align="center">
<template v-slot:default="{row}">
<el-input
size="mini"
v-if="!isReadOnly"
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.enable')"
show-overflow-tooltip>
<template v-slot:default="{row}">
<el-switch
:disabled="isReadOnly"
size="mini"
v-model="row.enable"
inactive-color="#DCDFE6">
</el-switch>
</template>
</el-table-column>
<el-table-column align="center" :label="$t('load_test.operating')">
<template v-slot:default="{row, $index}">
<ms-table-operator-button :tip="$t('commons.delete')" icon="el-icon-delete"
type="danger"
:disabled="isReadOnly"
@exec="del(row, 'systemProperties', $index)"/>
</template>
</el-table-column>
</el-table>
</el-col>
</el-row>
<!-- 监控配置 -->
<el-row>
<el-col :span="8">
@ -402,6 +475,7 @@ export default {
domains: [],
params: [],
properties: [],
systemProperties: [],
monitorParams: [],
csvFiles: [],
csvConfig: [],
@ -472,6 +546,7 @@ export default {
this.granularity = data.granularity;
this.monitorParams = data.monitorParams || [];
this.properties = data.properties || [];
this.systemProperties = data.systemProperties || [];
this.csvConfig = data.csvConfig;
}
});
@ -501,6 +576,14 @@ export default {
edit: true,
});
}
if (dataName === 'systemProperties') {
this[dataName].push({
name: 'prop1',
enable: true,
value: '0',
edit: true,
});
}
},
edit(row) {
row.edit = !row.edit;
@ -574,6 +657,7 @@ export default {
statusCode: statusCode,
params: this.params,
properties: this.properties,
systemProperties: this.systemProperties,
csvConfig: this.csvFiles.reduce((result, curr) => {
result[curr.name] = {csvHasHeader: curr.csvHasHeader, csvSplit: curr.csvSplit};
return result;