In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
1. In the process of performance testing, sometimes the developer wants to test the performance of the JAVA code. Jmeter supports the performance test of the Java request, but if you need to develop and package the code to be tested, you can test the performance of the java method in the Java request.
2. The example given in this article is that the Java implementation writes the value to the file by passing in two parameters
Development ideas
1. Use Eclipse to create Maven projects, configure Pom files, and introduce dependency packages needed by Jmeter to develop Java requests.
2. Create input parameter class and test class, and then inherit JavaSamplerClient to implement four main methods
3. Compile and package the written project
4. Put the packaged function in the jmeter extension directory, call the Java request, and test the encapsulated Java method; JDK environment Jmeter depends on the package version Maven repository version 1.84.03.5.3
For the download method of the complete Java_Sample project, please see the introduction at the end of the article.
I. New Maven project
1.File "New" Project, select Maven "Maven Project, and keep clicking on Next
two。 Configure the Pom file, the Jmeter4.0 version of the Pom file configuration. As long as the Pom file is saved, the system will automatically download and associate the corresponding jar package. The Pom configuration file is as follows:
3. After saving the Pom file, the system will automatically download the associated dependent file. The ApacheJMeter_core-4.0.jar and ApacheJMeter_java-4.0.jar will be used as shown below:
Before saving:
After saving:
4. At this point, due to the changes made to the pom file, an x will appear at the top of the project, and the compilation may report an error, so you need to execute Maven "Update Project to update the externally dependent Jar package.
Before updating:
After the update, the compilation and packaging are normal:
Second, write input parameter classes and test classes
1.1. Enter the parameter class, which is the java method being tested. The main purpose is to write the parameters to the file. The code is as follows:
1.2. To test the class, first create a class under the com.xiet.Java_Sample package named Jmeter_Test, which needs to inherit the JavaSamplerClient class, then implement the four methods of the parent class, and a main method
The main main method is mainly used for local debugging, and is used to test whether the encapsulated Java method functions properly. If it can achieve the normal function, it can be compiled, packaged and called in Jmeter.
The setupTest method is an initialization method. In actual operation, each thread executes only once, and before the test method runs, it can be left empty by default.
The runTest method is a test method, which is used to pass in the input parameters, and then call the parameter class to test
The teardownTest method is an end method. In actual operation, each thread is executed only once. After the end of the test method, it can be left empty by default.
The getDefaultParameters method sets the parameters passed in, and you can set multiple parameters. The parameters that have been set will be displayed in the parameter list of Jmeter.
As follows:
III. Compilation and packaging
After writing the code, you can compile and package it. Right-click on the project "Run As" Maven build
Type package in Goals, and then click Apply "Run to compile and package."
After compilation and packaging, a jar package is generated in the target directory, as shown in the following figure
Verify whether the developed function is normal or not
First put the Java_Sample_0.1.jar function in the jmeter\ lib\ ext directory
Then start Jmeter, thread group "add" Sample "Java request
Select the encapsulated Java class in the class name, which is com.xiet.Java_Sample.Jmeter_Test, and the class name is package name + class name
This time, set 2 threads and 2 loops. Click the execute button, and the execution result is as follows:
***
The complete source code is as follows:
if the article is helpful to you, you can click on the follow function in the lower right corner. Welcome to forward and clap the brick. I will continue to launch articles related to the test and share the testing technology with you. Every original article is written attentively to put an end to plagiarism and copying. The official Wechat account is synchronized with the articles on this platform for easy reference.
QQ technology exchange group: please enter the verification information 51CTO to add the group.
Wechat QR code follow official account:
After following, reply to the resource download, and you can get the download address of all kinds of resources shared by yourself.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.