如何使用 groovy 在 jsr223 采样器中将大数字字符串转换为整数

How to convert large number string into integers in jsr223 sampler with groovy

我正在使用 jsr223 采样器读取 jtl 文件并将其分成多个文件,由于某种原因无法使用 csv 数据集配置。我使用 groovy 作为语言

def INPUT_FILE = vars.get("INPUT_FILE");
def lines = new File(INPUT_FILE).readLines();
int start = lines[1].split(',')[0].toInteger(); //taking second line first column and converting to int
log.info("=====read start: " + start); //displaying in logs

出现错误,无法找出解决方法,尝试使用 long、def 数据类型

该值太大而不是整数,maximum value for the 32-bit Integer is 2,147,483,647. Consider using Long class 改为

def INPUT_FILE = vars.get("INPUT_FILE");
def lines = new File(INPUT_FILE).readLines();
long start = lines[1].split(',')[0].toLong(); //taking second line first column and converting to int
log.info("=====read start: " + start); //displaying in logs

另请注意,如果您只想从 CSV 文件中读取值并将其打印到 jmeter.log,您甚至不需要脚本,您可以改用 __CSVRead() and __log() 函数。