java.lang.RuntimeException:无法读取JMeter属性文件

6kkfgxo0  于 12个月前  发布在  Java
关注(0)|答案(1)|浏览(158)

我目前正在尝试开发一个AWS lambda函数,它从github获取Jmeter文件并执行它。我构建了一个Java jar文件并上传了一个S3 bucket。lambda从这个bucket中提取代码。我试图执行它,但我收到了下面的错误:

Jmeter execution function started.
java.lang.RuntimeException: Could not read JMeter properties file:/tmp/var/task/jmeter_properties/bin/jmeter.properties
at org.apache.jmeter.util.JMeterUtils.loadJMeterProperties(JMeterUtils.java:218)
at sta.JmeterUtility.executeTest(JmeterUtility.java:23)
at sta.App.executeProcess(App.java:54)
at sta.App.handleRequest(App.java:42)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at com.amazonaws.services.lambda.runtime.api.client.EventHandlerLoader$PojoMethodRequestHandler.handleRequest(EventHandlerLoader.java:285)
at com.amazonaws.services.lambda.runtime.api.client.EventHandlerLoader$PojoHandlerAsStreamHandler.handleRequest(EventHandlerLoader.java:202)
at com.amazonaws.services.lambda.runtime.api.client.EventHandlerLoader$2.call(EventHandlerLoader.java:905)
at com.amazonaws.services.lambda.runtime.api.client.AWSLambda.startRuntime(AWSLambda.java:245)
at com.amazonaws.services.lambda.runtime.api.client.AWSLambda.startRuntime(AWSLambda.java:197)
at com.amazonaws.services.lambda.runtime.api.client.AWSLambda.main(AWSLambda.java:187)
JMeter execution finished

字符串
我试图将此jmeter.properties文件上传到S3存储桶,并给予必要的访问权限来读取它,还试图将其放在资源下,但无论其位置如何,我都收到此错误。
执行JMeter的Java代码:

private static final String TMP_FOLDER = "/tmp";
    private static final String WORKING_FOLDER = "/tmp/var/task";

    void executeTest(TriggerData event) throws IOException {
        System.out.println("Jmeter execution function started.");

        // Initialize JMeter engine
        StandardJMeterEngine jmeter = new StandardJMeterEngine();
        JMeterUtils.loadJMeterProperties(WORKING_FOLDER + "/jmeter_properties/bin/jmeter.properties");
        JMeterUtils.setJMeterHome(WORKING_FOLDER + "/jmeter_properties");
        SaveService.loadProperties();

        // you can comment this line out to see extra log messages of i.e. DEBUG level
        JMeterUtils.initLogging();

        // Load existing .jmx Test Plan
        HashTree testPlanTree = SaveService
                .loadTree(new File(TMP_FOLDER + "/" + event.getJmeterTest() + ".jmx"));

        // Run Test Plan
        jmeter.configure(testPlanTree);
        jmeter.run();
        jmeter.exit();

        System.out.println("jmeter completed for Service: " + event.getServiceName() + " - " + event.getEnv()+"_" + event.getRegion() + " and stopped");
    }


当我跟踪代码时,它总是卡住:

JMeterUtils.loadJMeterProperties(WORKING_FOLDER + "/jmeter_properties/bin/jmeter.properties");


你对这个问题有什么想法吗?先谢谢你了。

enyaitl3

enyaitl31#

查看加载属性的函数:

public static void loadJMeterProperties(String file) {
    Properties p = new Properties(System.getProperties());
    try (InputStream is = new FileInputStream(new File(file))) {
        p.load(is);
    } catch (IOException e) {
        try (InputStream is = ClassLoader.getSystemResourceAsStream(
                    "org/apache/jmeter/jmeter.properties")) { // $NON-NLS-1$
            if (is == null) {
                throw new RuntimeException("Could not read JMeter properties file:" + file);
            }
            p.load(is);
        } catch (IOException ex) {
            throw new RuntimeException("Could not read JMeter properties file:" + file);
        }
    }
    appProperties = p;
}

字符串
你会得到一个IOException,所以文件很可能不在那里。
你需要有一个完整的JMeter安装,以便能够以你的方式运行测试。我不确定在Lambda中这样做是否是一个好主意,但如果你真的想要这样-你可以考虑以不同的方式运行测试,例如:

两者都能够下载/配置JMeter示例并执行测试计划。

相关问题