Search code examples
javaamazon-web-servicesamazon-s3aws-lambdajmeter

java.lang.RuntimeException: Could not read JMeter properties file


I am currently trying to develop an AWS lambda function that fetches a Jmeter file from github and executes it. I built a Java jar file and uploaded a S3 bucket. The lambda pulls the code from this bucket. I tried to execute it but I received the error below:

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

I tried to upload this jmeter.properties file to the S3 bucket too and give necessary access to read it, also tried to put it under the resource but regardless of its location, I received this error.

My Java code that executes the JMeter:

    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");
    }

When I trace the code it always stucks on:

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

Do you have any idea about the problem? Thanks in advance.


Solution

  • Looking into the function which loads the properties:

    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;
    }
    

    you're getting an IOException so the file is most probably not there.

    You need to have a full JMeter installation in order to be able to run tests your way. I'm not sure whether it's a good idea to do this in Lambda in general, but if you really want this - you can consider running your test in a different way, for example:

    both are capable of downloading/configuring a JMeter instance and executing a test plan.