fix(接口定义): 执行方法修改

This commit is contained in:
fit2-zhao 2020-11-27 14:22:07 +08:00
parent dd5cdad759
commit c9e2e3e489
1 changed files with 10 additions and 3 deletions

View File

@ -14,6 +14,7 @@ import org.apache.jorphan.collections.HashTree;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.io.File;
import java.io.InputStream;
@ -25,14 +26,18 @@ public class JMeterService {
@Resource
private JmeterProperties jmeterProperties;
public void run(String testId, String debugReportId, InputStream is) {
@PostConstruct
public void init() {
String JMETER_HOME = getJmeterHome();
String JMETER_PROPERTIES = JMETER_HOME + "/bin/jmeter.properties";
JMeterUtils.loadJMeterProperties(JMETER_PROPERTIES);
JMeterUtils.setJMeterHome(JMETER_HOME);
JMeterUtils.setLocale(LocaleContextHolder.getLocale());
}
public void run(String testId, String debugReportId, InputStream is) {
init();
try {
Object scriptWrapper = SaveService.loadElement(is);
HashTree testPlan = getHashTree(scriptWrapper);
@ -66,13 +71,14 @@ public class JMeterService {
return (HashTree) field.get(scriptWrapper);
}
private void addBackendListener(String testId, String debugReportId,String runMode, HashTree testPlan) {
private void addBackendListener(String testId, String debugReportId, String runMode, HashTree testPlan) {
BackendListener backendListener = new BackendListener();
backendListener.setName(testId);
Arguments arguments = new Arguments();
arguments.addArgument(APIBackendListenerClient.TEST_ID, testId);
if (StringUtils.isNotBlank(runMode)) {
arguments.addArgument("runMode",runMode); }
arguments.addArgument("runMode", runMode);
}
if (StringUtils.isNotBlank(debugReportId)) {
arguments.addArgument("debugReportId", debugReportId);
}
@ -83,6 +89,7 @@ public class JMeterService {
public void runDefinition(String testId, HashTree testPlan, String debugReportId, String runMode) {
try {
init();
JMeterVars.addJSR223PostProcessor(testPlan);
addBackendListener(testId, debugReportId, runMode, testPlan);
LocalRunner runner = new LocalRunner(testPlan);