Jmeter random function is not working from java application

家住魔仙堡 提交于 2019-12-11 14:18:17

问题


I want to make use of Jmeter Random function (${__RandomString(10,0123456789,Value)}) in my java application for load testing.

Below is maven dependency

<dependency>
    <groupId>org.apache.jmeter</groupId>
    <artifactId>ApacheJMeter_functions</artifactId>
    <version>4.0</version>
</dependency>

It is working properly If I add ApacheJMeter_functions jar to class path but the same is not working if I use Maven dependency.

Note : Works fine if I add jar to classpath without version name.

pom :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>performance-api</artifactId>
    <version>0.1</version>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.jmeter</groupId>
            <artifactId>ApacheJMeter_core</artifactId>
            <version>4.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.jmeter</groupId>
            <artifactId>ApacheJMeter_http</artifactId>
            <version>4.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.jmeter</groupId>
            <artifactId>ApacheJMeter_functions</artifactId>
            <version>4.0</version>
            </dependency>
    </dependencies>
    <build>
        <plugins>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
</project>

Response when added ApacheJMeter_functions jar to class path without version name

Response when added ApacheJMeter_functions dependency jar into pom


回答1:


Below solution helped me in resolving issue

When Jmeter functions are used in the Java code, Jmeter tries to compare the function related classes from java class path with classes from the 'search_path' (Reads classes from the jars). So Jmeter function works only if required function class is present in both the path (Jmeter has seperate class for each function).

This is why we need to make sure the 'ApacheJMeter_functions' jar added in the pom (which will be added in class path ) and the path to jmeter functions jar is set to 'search_path'.Both should have same version.

But in case of spring boot application, along adding dependency to pom we also need to append the path to jmeter functions jar explicitly to the class path like below

System.setProperty("java.class.path", System.getProperty("java.class.path") + PathToJmeterFunctionJars );


来源:https://stackoverflow.com/questions/51552096/jmeter-random-function-is-not-working-from-java-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!