fix(接口定义): 执行方法修改
This commit is contained in:
parent
dd5cdad759
commit
c9e2e3e489
|
@ -14,6 +14,7 @@ import org.apache.jorphan.collections.HashTree;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -25,14 +26,18 @@ public class JMeterService {
|
||||||
@Resource
|
@Resource
|
||||||
private JmeterProperties jmeterProperties;
|
private JmeterProperties jmeterProperties;
|
||||||
|
|
||||||
public void run(String testId, String debugReportId, InputStream is) {
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
String JMETER_HOME = getJmeterHome();
|
String JMETER_HOME = getJmeterHome();
|
||||||
|
|
||||||
String JMETER_PROPERTIES = JMETER_HOME + "/bin/jmeter.properties";
|
String JMETER_PROPERTIES = JMETER_HOME + "/bin/jmeter.properties";
|
||||||
JMeterUtils.loadJMeterProperties(JMETER_PROPERTIES);
|
JMeterUtils.loadJMeterProperties(JMETER_PROPERTIES);
|
||||||
JMeterUtils.setJMeterHome(JMETER_HOME);
|
JMeterUtils.setJMeterHome(JMETER_HOME);
|
||||||
JMeterUtils.setLocale(LocaleContextHolder.getLocale());
|
JMeterUtils.setLocale(LocaleContextHolder.getLocale());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run(String testId, String debugReportId, InputStream is) {
|
||||||
|
init();
|
||||||
try {
|
try {
|
||||||
Object scriptWrapper = SaveService.loadElement(is);
|
Object scriptWrapper = SaveService.loadElement(is);
|
||||||
HashTree testPlan = getHashTree(scriptWrapper);
|
HashTree testPlan = getHashTree(scriptWrapper);
|
||||||
|
@ -66,13 +71,14 @@ public class JMeterService {
|
||||||
return (HashTree) field.get(scriptWrapper);
|
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 backendListener = new BackendListener();
|
||||||
backendListener.setName(testId);
|
backendListener.setName(testId);
|
||||||
Arguments arguments = new Arguments();
|
Arguments arguments = new Arguments();
|
||||||
arguments.addArgument(APIBackendListenerClient.TEST_ID, testId);
|
arguments.addArgument(APIBackendListenerClient.TEST_ID, testId);
|
||||||
if (StringUtils.isNotBlank(runMode)) {
|
if (StringUtils.isNotBlank(runMode)) {
|
||||||
arguments.addArgument("runMode",runMode); }
|
arguments.addArgument("runMode", runMode);
|
||||||
|
}
|
||||||
if (StringUtils.isNotBlank(debugReportId)) {
|
if (StringUtils.isNotBlank(debugReportId)) {
|
||||||
arguments.addArgument("debugReportId", debugReportId);
|
arguments.addArgument("debugReportId", debugReportId);
|
||||||
}
|
}
|
||||||
|
@ -83,6 +89,7 @@ public class JMeterService {
|
||||||
|
|
||||||
public void runDefinition(String testId, HashTree testPlan, String debugReportId, String runMode) {
|
public void runDefinition(String testId, HashTree testPlan, String debugReportId, String runMode) {
|
||||||
try {
|
try {
|
||||||
|
init();
|
||||||
JMeterVars.addJSR223PostProcessor(testPlan);
|
JMeterVars.addJSR223PostProcessor(testPlan);
|
||||||
addBackendListener(testId, debugReportId, runMode, testPlan);
|
addBackendListener(testId, debugReportId, runMode, testPlan);
|
||||||
LocalRunner runner = new LocalRunner(testPlan);
|
LocalRunner runner = new LocalRunner(testPlan);
|
||||||
|
|
Loading…
Reference in New Issue