下载软件
https://jmeter.apache.org/download_jmeter.cgi
创建Tcp测试用例
添加Thread group
添加Tcp请求样本
设置tcp相关参数
send java: ${javaNumber} send beanshell: ${RANDOM_STRING} send function ${__Random(1,100000000000, LOTTERY )} ?
Java Netty收到的结果
send java: 9 send beanshell: zltaz05321dmishm9dpiu26lsf0ntl6hhg3o send function 1090222003 ?
发送Byte形式
6801153532343330303031303034303030303801010002000601022690011B4C7D
设置发送的内容
- 发送的内容可以参数化。可以使用内置的参数,或者在 BeanShellPreProcessor定义相关参数
- BeanShell 也可以支持直接引用java代码。下面是两种引用的方式,把java运行的结果放到 发送的文本框即可。
BeanShell引用java代码方式一
addClassPath("C:\\");
import JmeterTest;
int c = new JmeterTest().testAdd(3,4);
vars.put("javaNumber" , c.toString());
BeanShell引用java代码方式二
source("C:\\JmeterTest.java");
int c = new JmeterTest().testAdd(3,6);
vars.put("javaNumber" , c.toString());
用Beanshell语法
import java.util.Random;
chars = "1234567890abcdefghiklmnopqrstuvwxyz-";
int string_length = 36;
randomstring ="";
for (int i=0; i < string_length; i++) {
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(chars.length());
randomstring += chars.substring(randomInt,randomInt+1);
}
print(randomstring);
vars.put("RANDOM_STRING",randomstring);
TCPclient className说明
The class names, as they are given in the JMeter documentation, are:
- TCPClientImpl - this is a basic class for implementation of the text messages exchange. Text messages are provided as a constant or variable strings of different charsets in the ‘Text to send’ field of the TCP sampler.
- BinaryTCPClientImpl - this is a class for the implementation of the exchange of the text messages. Binary messages in the form of the hex encoded constant or variable values are provided in the ‘Text to send’ field of the TCP sampler.
- LengthPrefixedBinaryTCPClientImpl - this class is similar to the previous one, but byte data to send is prefixed with the binary length byte.
参考文章
https://jmeter.apache.org/usermanual/functions.html
https://www.blazemeter.com/blog/quick-guide-jmeter-preprocessors
https://dzone.com/articles/how-to-load-test-tcp-protocol-services-with-jmeter
https://www.cnblogs.com/puresoul/p/4949889.html