Merge branch 'master' of https://github.com/metersphere/server
This commit is contained in:
commit
ab0790a8a2
|
@ -14,6 +14,7 @@ import org.apache.jorphan.collections.HashTree;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
|
@ -24,14 +25,15 @@ public class JMeterService {
|
|||
private JmeterProperties jmeterProperties;
|
||||
|
||||
public void run(String testId, String debugReportId, InputStream is) {
|
||||
String JMETER_HOME = jmeterProperties.getHome();
|
||||
String JMETER_HOME = getJmeterHome();
|
||||
|
||||
String JMETER_PROPERTIES = JMETER_HOME + "/bin/jmeter.properties";
|
||||
JMeterUtils.loadJMeterProperties(JMETER_PROPERTIES);
|
||||
JMeterUtils.setJMeterHome(JMETER_HOME);
|
||||
try {
|
||||
Object scriptWrapper = SaveService.loadElement(is);
|
||||
HashTree testPlan = getHashTree(scriptWrapper);
|
||||
addBackendListener(testId, debugReportId, testPlan);
|
||||
addBackendListener(testId, debugReportId, testPlan);
|
||||
|
||||
LocalRunner runner = new LocalRunner(testPlan);
|
||||
runner.run();
|
||||
|
@ -41,6 +43,20 @@ public class JMeterService {
|
|||
}
|
||||
}
|
||||
|
||||
private String getJmeterHome() {
|
||||
String home = getClass().getResource("/").getPath() + "jmeter";
|
||||
try {
|
||||
File file = new File(home);
|
||||
if (file.exists()) {
|
||||
return home;
|
||||
} else {
|
||||
return jmeterProperties.getHome();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return jmeterProperties.getHome();
|
||||
}
|
||||
}
|
||||
|
||||
private HashTree getHashTree(Object scriptWrapper) throws Exception {
|
||||
Field field = scriptWrapper.getClass().getDeclaredField("testPlan");
|
||||
field.setAccessible(true);
|
||||
|
|
|
@ -5,7 +5,6 @@ import io.metersphere.base.domain.*;
|
|||
import io.metersphere.base.mapper.LoadTestMapper;
|
||||
import io.metersphere.base.mapper.TestResourceMapper;
|
||||
import io.metersphere.base.mapper.TestResourcePoolMapper;
|
||||
import io.metersphere.commons.constants.PerformanceTestStatus;
|
||||
import io.metersphere.commons.constants.ResourceStatusEnum;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
|
@ -25,7 +24,6 @@ import org.springframework.web.client.RestTemplate;
|
|||
import javax.annotation.Resource;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -70,11 +68,9 @@ public class TestResourcePoolService {
|
|||
}
|
||||
|
||||
public void checkTestStatus(String testResourcePoolId) {
|
||||
List list = Arrays.asList(PerformanceTestStatus.Running, PerformanceTestStatus.Starting, PerformanceTestStatus.Error);
|
||||
LoadTestExample example = new LoadTestExample();
|
||||
example.createCriteria()
|
||||
.andTestResourcePoolIdEqualTo(testResourcePoolId)
|
||||
.andStatusIn(list);
|
||||
.andTestResourcePoolIdEqualTo(testResourcePoolId);
|
||||
if (loadTestMapper.countByExample(example) > 0) {
|
||||
MSException.throwException(Translator.get("test_resource_pool_is_use"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue