面临错误 java.lang.ArrayIndexOutOfBoundsException:-1

Facing error java.lang.ArrayIndexOutOfBoundsException: -1

我遇到错误 java.lang.ArrayIndexOutOfBoundsException: -1 at for (int i= 2; i

PFB代码块:

private CategoryDataset createDataset(String path){
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    List<String[]> datasetData = FileOperations.getInstance().readCSV(path);
    for (int i= 2; i<datasetData.get((datasetData.size()-1)).length; i++) {
        dataset.setValue(Integer.parseInt(datasetData.get((datasetData.size()-1))[i]), "Requests", datasetData.get(0)[i]);          
    }
    return dataset;
}

我正在尝试 运行 来自 https://github.com/dmarcas/locustapitest

的代码

PFB 完整错误日志:

------------------------------------------------------- T E S T S ------------------------------------------------------- Forking command line: /bin/sh -c cd /home/sonali/locustapitest && /opt/jdk/jdk1.8.0_251/jre/bin/java -jar /home/sonali/locustapitest/target/surefire/surefirebooter4278625619835674105.jar /home/sonali/locustapitest/target/surefire/surefire5330964498682944855tmp /home/sonali/locustapitest/target/surefire/surefire_0265241717012809196tmp Running runner.TestRunner Jul 06, 2020 6:53:47 PM helpers.FileOperations readCSV SEVERE: Something went wrong reading the CSV Report file Jul 06, 2020 6:53:47 PM performance.LocustOperations checkMaxResponseTime SEVERE: Something went wrong cheking the MaxResponseTime Jul 06, 2020 6:53:47 PM helpers.FileOperations readCSV SEVERE: Something went wrong reading the CSV Report file Jul 06, 2020 6:54:57 PM helpers.FileOperations readCSV SEVERE: Something went wrong reading the CSV Report file Jul 06, 2020 6:54:57 PM performance.LocustOperations checkMaxResponseTime SEVERE: Something went wrong cheking the MaxResponseTime Jul 06, 2020 6:54:57 PM helpers.FileOperations readCSV SEVERE: Something went wrong reading the CSV Report file

Failed scenarios: test.feature:14 # Scenario Outline: Request a forced answer test.feature:15 # Scenario Outline: Request a forced answer

2 Scenarios (2 failed) 4 Steps (4 passed) 2m20.234s

java.lang.ArrayIndexOutOfBoundsException: -1 at java.util.ArrayList.elementData(ArrayList.java:422) at java.util.ArrayList.get(ArrayList.java:435) at graph.LocustBarChart.createDataset(LocustBarChart.java:58) at graph.LocustBarChart.createChart(LocustBarChart.java:44) at stepsdefinition.Hooks.AfterSteps(Hooks.java:28)

从错误来看,datasetData似乎是空的。它是在这一行创建的:

List<String[]> datasetData = FileOperations.getInstance().readCSV(path);

所以在读取文件时“有些东西”出错了。例如,也许路径是错误的。可能文件放错地方了。也许文件是空的。

我通过做一些改变解决了以下问题:

问题 1: mvn clean install 完成后文件夹 target/csvlocustsresults 没有自动创建,所以我通过在 pom.xml。另外,因为我在 python 版本 3.5 上有 locust 0.13.5 运行 并且分发和请求 CSV 正在使用另一个名称创建,因此在 src/main/resources/configs/config.properties

requestsReportLocation=target/csvlocustsresults/performanceResults_stats.csv
distributionReportLocation=target/csvlocustsresults/performanceResults_stats_history.csv

问题 2: 我遇到了 NumberFormatException:通过在方法 createDataset() 和 checkMaxResponseTime()

中将解析从 Integer 更改为 Float 来解决这个问题

问题 3: 虚拟 python 文件中未提及等待时间。在 class Dummy(Locust)

下添加 wait_time = between(5, 9)