refactor(性能测试): 增加上传资源文件的类型, 合并 csv 和 jar 的保存方式统一使用 resourceFiles

This commit is contained in:
Captain.B 2021-03-11 14:05:52 +08:00
parent 496816d288
commit 353e6bed77
3 changed files with 13 additions and 40 deletions

View File

@ -14,8 +14,7 @@ public class EngineContext {
private String reportId;
private Integer resourceIndex;
private Map<String, Object> properties = new HashMap<>();
private Map<String, String> testData = new HashMap<>();
private Map<String, byte[]> testJars = new HashMap<>();
private Map<String, byte[]> testResourceFiles = new HashMap<>();
public String getTestId() {
return testId;
@ -69,14 +68,6 @@ public class EngineContext {
this.fileType = fileType;
}
public Map<String, String> getTestData() {
return testData;
}
public void setTestData(Map<String, String> testData) {
this.testData = testData;
}
public String getResourcePoolId() {
return resourcePoolId;
}
@ -111,11 +102,11 @@ public class EngineContext {
}
public Map<String, byte[]> getTestJars() {
return testJars;
public Map<String, byte[]> getTestResourceFiles() {
return testResourceFiles;
}
public void setTestJars(Map<String, byte[]> testJars) {
this.testJars = testJars;
public void setTestResourceFiles(Map<String, byte[]> testResourceFiles) {
this.testResourceFiles = testResourceFiles;
}
}

View File

@ -92,8 +92,7 @@ public class EngineFactory {
}
List<FileMetadata> jmxFiles = fileMetadataList.stream().filter(f -> StringUtils.equalsIgnoreCase(f.getType(), FileType.JMX.name())).collect(Collectors.toList());
List<FileMetadata> csvFiles = fileMetadataList.stream().filter(f -> StringUtils.equalsIgnoreCase(f.getType(), FileType.CSV.name())).collect(Collectors.toList());
List<FileMetadata> jarFiles = fileMetadataList.stream().filter(f -> StringUtils.equalsIgnoreCase(f.getType(), FileType.JAR.name())).collect(Collectors.toList());
List<FileMetadata> resourceFiles = fileMetadataList.stream().filter(f -> !StringUtils.equalsIgnoreCase(f.getType(), FileType.JMX.name())).collect(Collectors.toList());
// 合并上传的jmx
byte[] jmxBytes = mergeJmx(jmxFiles);
final EngineContext engineContext = new EngineContext();
@ -156,22 +155,13 @@ public class EngineFactory {
MSException.throwException(e);
}
if (CollectionUtils.isNotEmpty(csvFiles)) {
Map<String, String> data = new HashMap<>();
csvFiles.forEach(cf -> {
FileContent csvContent = fileService.getFileContent(cf.getId());
data.put(cf.getName(), new String(csvContent.getFile()));
});
engineContext.setTestData(data);
}
if (CollectionUtils.isNotEmpty(jarFiles)) {
if (CollectionUtils.isNotEmpty(resourceFiles)) {
Map<String, byte[]> data = new HashMap<>();
jarFiles.forEach(jf -> {
FileContent content = fileService.getFileContent(jf.getId());
data.put(jf.getName(), content.getFile());
resourceFiles.forEach(cf -> {
FileContent csvContent = fileService.getFileContent(cf.getId());
data.put(cf.getName(), csvContent.getFile());
});
engineContext.setTestJars(data);
engineContext.setTestResourceFiles(data);
}
return engineContext;

View File

@ -51,17 +51,9 @@ public class JmeterFileService {
// 每个测试生成一个文件夹
files.put(fileName, context.getContent().getBytes(StandardCharsets.UTF_8));
// 保存测试数据文件
Map<String, String> testData = context.getTestData();
if (!CollectionUtils.isEmpty(testData)) {
for (String k : testData.keySet()) {
String v = testData.get(k);
files.put(k, v.getBytes(StandardCharsets.UTF_8));
}
}
// 保存 byte[] jar
Map<String, byte[]> jarFiles = context.getTestJars();
// 保存 byte[]
Map<String, byte[]> jarFiles = context.getTestResourceFiles();
if (!CollectionUtils.isEmpty(jarFiles)) {
for (String k : jarFiles.keySet()) {
byte[] v = jarFiles.get(k);