Bug 65688 - The Jmeter function is unavailable via spring-boot
Summary: The Jmeter function is unavailable via spring-boot
Status: RESOLVED INVALID
Alias: None
Product: JMeter
Classification: Unclassified
Component: HTTP (show other bugs)
Version: 5.1.1
Hardware: PC All
: P2 normal (vote)
Target Milestone: JMETER_5.5
Assignee: JMeter issues mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-11-18 09:22 UTC by WL
Modified: 2021-11-22 07:03 UTC (History)
1 user (show)



Attachments
spring-boot-pomfile (5.10 KB, text/xml)
2021-11-18 09:25 UTC, WL
Details

Note You need to log in before you can comment on or make changes to this bug.
Description WL 2021-11-18 09:22:21 UTC
Steps to Reproduce:
1. In Jmeter GUI, I create a test.jmx
2. In the script, use CSVRead function in the http request, e.g.  servername: ${__CSVRead(../data/config.csv,4)}
3. Use GUI mode, the test.jmx work fine.
4. But I need to run this jmx file by java spring-boot, below is my primary code:

        String mysqlJars = jmxWorkDir + "\\lib\\ext\\mysql-connector-java-5.1.18.jar";
        String pathToJmeterJDBCJars = jmxWorkDir + "\\lib\\ext\\ApacheJMeter_jdbc.jar";
        String pathToJmeterComponentsJars = jmxWorkDir + "\\lib\\ext\\ApacheJMeter_components.jar";
        String pathToJmeterHttpJars = jmxWorkDir + "\\lib\\ext\\ApacheJMeter_http.jar";
        String pathToJmeterPlugManagerJars = jmxWorkDir + "\\lib\\ext\\jmeter-plugins-manager-1.6.jar";
        String pathToJmeterFunctionsJars = jmxWorkDir + "\\lib\\ext\\ApacheJMeter_functions.jar";

        String pathCoreJars = jmxWorkDir + "\\lib\\ext\\ApacheJMeter_core.jar";
        String pathJavaJars = jmxWorkDir + "\\lib\\ext\\ApacheJMeter_java.jar";

        //String pathToJmeterJars = pathToJmeterFunctionsJars;
        String pathToJmeterJars = pathToJmeterFunctionsJars + ";" + pathToJmeterHttpJars
                + ";" + pathToJmeterJDBCJars + ";" + pathToJmeterComponentsJars + ";" + pathToJmeterPlugManagerJars +
                    ";" + mysqlJars;

        System.setProperty("java.class.path", pathToJmeterJars);
        //JMeterUtils.setProperty("search_paths", pathToJmeterJars);

        //JMeterUtils.set
        String logFile = jmxWorkDir + "\\result\\" + jmxFileName.replace(".jmx","") + ".jtl";
        System.out.println("logFile===" + logFile);
        Utility.delFile(logFile);

        File jmxfile = null;

        // JMeter Engine
        StandardJMeterEngine jmeter = new StandardJMeterEngine();

        // Initialize Properties, logging, locale, etc.
        JMeterUtils.loadJMeterProperties(jmxWorkDir + "\\bin\\jmeter.properties");
        JMeterUtils.setJMeterHome(jmxWorkDir);
        //JMeterUtils.initLogging();// you can comment this line out to see extra log messages of i.e. DEBUG level
        JMeterUtils.initLocale();

        // Initialize JMeter SaveService
        try {
            SaveService.loadProperties();
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        // Load existing .jmx Test Plan
        //FileInputStream in = new FileInputStream(jmxfile);
        HashTree testPlanTree = null;

        try {
            //testPlanTree = (ScriptWrapper) SaveService.loadloadElement(in);
            jmxfile = new File(jmxWorkDir + "\\script\\" + jmxFileName);
            //System.out.println("jmx===" + Utility.readFileContent(jmxWorkDir + "\\script\\" + jmxFileName));
            testPlanTree = SaveService.loadTree(jmxfile);

            // Remove disabled test elements
            testPlanTree = FJmeter.convertSubTree(testPlanTree, true);
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            //in.close();
        }

        //report
        Summariser summer = null;
        String summariserName = JMeterUtils.getPropDefault("summariser.name", "summary");//$NON-NLS-1$
        if (summariserName.length() > 0) {
            summer = new Summariser(summariserName);
        }

        ResultCollector logger = new ResultCollector(summer);
        logger.setFilename(logFile);
        testPlanTree.add(testPlanTree.getArray()[0], logger);

        // Run JMeter Test
        jmeter.configure(testPlanTree);

        jmeter.run();

        List<Integer> durationList = new ArrayList<Integer>();
        durationList.add(10);

        String result = new JtlResolver().resloveJtl(logFile, durationList);
        System.out.println("result===" + result);

5.  The jtl report file content is:
timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect
2021-11-18 16:44:14,0,"1.0Test1-${__CSVRead(../data/config-Tag.csv,4)}",Non HTTP response code: java.net.URISyntaxException,"Non HTTP response message: Illegal character in authority at index 7: http://${__CSVRead(../data/config.csv,4)}/tag/tag/add",thread 1-1,text,false,"Test failed: text expected to contain /""code"":1/",1145,0,1,1,"http://${__CSVRead(../data/config.csv,4)}/add",0,0,0

These JMeter functions should also be available via Java code.
Comment 1 WL 2021-11-18 09:25:30 UTC
Created attachment 38093 [details]
spring-boot-pomfile
Comment 2 WL 2021-11-18 09:28:31 UTC
(In reply to WL from comment #1)
> Created attachment 38093 [details]
> spring-boot-pomfile
Comment 3 WL 2021-11-18 09:32:44 UTC
The Step 5 should be 

5.  The jtl report file content is:
timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect
2021-11-18 16:44:14,0,"1.0Test1-${__CSVRead(../data/config.csv,4)}",Non HTTP response code: java.net.URISyntaxException,"Non HTTP response message: Illegal character in authority at index 7: http://${__CSVRead(../data/config.csv,4)}/tag/tag/add",thread 1-1,text,false,"Test failed: text expected to contain /""code"":1/",1145,0,1,1,"http://${__CSVRead(../data/config.csv,4)}/add",0,0,0
Comment 4 Philippe Mouawad 2021-11-21 18:00:38 UTC
This is a question for user mailing list.
Comment 5 WL 2021-11-22 03:11:01 UTC
The problem described is not a bug???    @Philippe Mouawad
Comment 6 WL 2021-11-22 07:03:45 UTC
Thank you very much for helping to solve this problem,
But I'm rather confused about the state of the problem being 'RESOLVED-INVALID',
I will be appreciate your help. @p.mouawad@ubik-ingenierie.com