解决 jmeter.properties 无法加载的问题
This commit is contained in:
parent
40bbdc0a0e
commit
eb4bfcc08b
|
@ -0,0 +1,44 @@
|
||||||
|
package io.metersphere.commons.utils;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.reflect.FieldUtils;
|
||||||
|
import org.apache.jmeter.util.JMeterUtils;
|
||||||
|
import org.apache.jorphan.util.JOrphanUtils;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class MsJMeterUtils {
|
||||||
|
/**
|
||||||
|
* Load the JMeter properties file; if not found, then
|
||||||
|
* default to "org/apache/jmeter/jmeter.properties" from the classpath
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* c.f. loadProperties
|
||||||
|
*
|
||||||
|
* @param file Name of the file from which the JMeter properties should be loaded
|
||||||
|
*/
|
||||||
|
public static void loadJMeterProperties(String file) {
|
||||||
|
InputStream is = null;
|
||||||
|
try {
|
||||||
|
JMeterUtils.loadJMeterProperties(file);
|
||||||
|
} catch (Exception e) {
|
||||||
|
try {
|
||||||
|
Properties p = new Properties(System.getProperties());
|
||||||
|
// In jar file classpath is
|
||||||
|
is = ClassLoader.getSystemResourceAsStream(
|
||||||
|
"BOOT-INF/classes/org/apache/jmeter/jmeter.properties"); // $NON-NLS-1$
|
||||||
|
if (is == null) {
|
||||||
|
throw new RuntimeException("Could not read JMeter properties file:" + file);
|
||||||
|
}
|
||||||
|
p.load(is);
|
||||||
|
|
||||||
|
FieldUtils.writeStaticField(JMeterUtils.class, "appProperties", p, true);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new RuntimeException("Could not read JMeter properties file:" + file);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
JOrphanUtils.closeQuietly(is);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -3,7 +3,7 @@ package io.metersphere.report;
|
||||||
import com.opencsv.bean.CsvToBean;
|
import com.opencsv.bean.CsvToBean;
|
||||||
import com.opencsv.bean.CsvToBeanBuilder;
|
import com.opencsv.bean.CsvToBeanBuilder;
|
||||||
import com.opencsv.bean.HeaderColumnNameMappingStrategy;
|
import com.opencsv.bean.HeaderColumnNameMappingStrategy;
|
||||||
import io.metersphere.base.domain.LoadTestReportWithBLOBs;
|
import io.metersphere.commons.utils.MsJMeterUtils;
|
||||||
import io.metersphere.report.base.*;
|
import io.metersphere.report.base.*;
|
||||||
import io.metersphere.report.dto.ErrorsTop5DTO;
|
import io.metersphere.report.dto.ErrorsTop5DTO;
|
||||||
import io.metersphere.report.dto.RequestStatisticsDTO;
|
import io.metersphere.report.dto.RequestStatisticsDTO;
|
||||||
|
@ -19,7 +19,6 @@ import org.apache.jmeter.report.processor.graph.AbstractOverTimeGraphConsumer;
|
||||||
import org.apache.jmeter.report.processor.graph.impl.ActiveThreadsGraphConsumer;
|
import org.apache.jmeter.report.processor.graph.impl.ActiveThreadsGraphConsumer;
|
||||||
import org.apache.jmeter.report.processor.graph.impl.HitsPerSecondGraphConsumer;
|
import org.apache.jmeter.report.processor.graph.impl.HitsPerSecondGraphConsumer;
|
||||||
import org.apache.jmeter.report.processor.graph.impl.ResponseTimeOverTimeGraphConsumer;
|
import org.apache.jmeter.report.processor.graph.impl.ResponseTimeOverTimeGraphConsumer;
|
||||||
import org.apache.jmeter.util.JMeterUtils;
|
|
||||||
|
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
@ -500,8 +499,8 @@ public class JtlResolver {
|
||||||
public static Map<String, Object> getResultDataMap(String jtlString, AbstractOverTimeGraphConsumer timeGraphConsumer) {
|
public static Map<String, Object> getResultDataMap(String jtlString, AbstractOverTimeGraphConsumer timeGraphConsumer) {
|
||||||
AbstractOverTimeGraphConsumer abstractOverTimeGraphConsumer = timeGraphConsumer;
|
AbstractOverTimeGraphConsumer abstractOverTimeGraphConsumer = timeGraphConsumer;
|
||||||
abstractOverTimeGraphConsumer.setGranularity(60000);
|
abstractOverTimeGraphConsumer.setGranularity(60000);
|
||||||
// 这个路径不存在
|
// 使用反射获取properties
|
||||||
JMeterUtils.loadJMeterProperties("jmeter.properties");
|
MsJMeterUtils.loadJMeterProperties("jmeter.properties"); // 这个路径不存在
|
||||||
SampleMetadata sampleMetaData = createTestMetaData();
|
SampleMetadata sampleMetaData = createTestMetaData();
|
||||||
SampleContext sampleContext = new SampleContext();
|
SampleContext sampleContext = new SampleContext();
|
||||||
abstractOverTimeGraphConsumer.setSampleContext(sampleContext);
|
abstractOverTimeGraphConsumer.setSampleContext(sampleContext);
|
||||||
|
|
Loading…
Reference in New Issue