我正在进行服务电话并尝试处理响应.响应可能有一个列表.该列表可能为null.
此外,如果列表不为null或不为空,则需要对其进行过滤.在代码"entry"中,如果过滤不提供任何内容或响应列表为空或null,则引用可能为null.
目前,当我尝试在空响应列表上使用stream()时,我正在获取NPE.我该如何处理这种情况?
@Getter
public class ServiceResponse {
List<ResponseEntry> entryList;
}
@Getter
public class ResponseEntry {
String value;
}
ServiceResponse serviceResponse = service.getServiceResponse();
ResponseEntry entry = serviceResponse.getEntryList()
.stream()
.filter(e -> "expectedValue".equals(e.getValue()))
.findFirst()
.orElse(null);
if (entry == null) { ... }
Run Code Online (Sandbox Code Playgroud)
我正在尝试编写一个命令来查找 csv 文件中与模式匹配的特定列的行。我正在为该专栏的模式匹配而苦苦挣扎
任务:打印第 5 列(col5date)为 2022 年 6 月、7 月或 8 月的行
示例 csv 文件:
| 第 1 列 | 列2 | 第 3 列 | 第 4 列 | col5日期 | 第 6 栏 |
|---|---|---|---|---|---|
| A B C D | 阿斯德 | 2022年 | 阿斯德 | 22 年 7 月 4 日 | 某物 |
| A B C D | 阿斯德 | 2022年 | 阿斯德 | 10/9/22 | 某物 |
| A B C D | 阿斯德 | 2022年 | 阿斯德 | 12/12/20 | 某物 |
| A B C D | 阿斯德 | 2020年 | 阿斯德 | 2019 年 9 月 1 日 | 某物 |
| A B C … |
我在使用Artillery时正在执行微服务的负载测试并面临问题.读取csv文件时脚本失败.尝试从文件导入输入数据以创建json请求.
最简单的script.yml:
config:
target: "http://localhost:8080"
phases:
- duration: 1
arrivalRate: 1
payload:
path: "input.csv"
fields:
- "flow"
scenarios:
- flow:
- log: "this yml log, flow: {{ flow }}"
Run Code Online (Sandbox Code Playgroud)
input.csv文件位于同一文件夹中:
"flow"
"SomeFlow"
Run Code Online (Sandbox Code Playgroud)
用于执行的最简单的命令:
DEBUG=* artillery run script.yml
Run Code Online (Sandbox Code Playgroud)
错误堆栈跟踪:
artillery:cli Artillery Pro is not installed +0ms
commands:run defaultOptions: {
"_": [
"run",
"script.yml"
]
} +4ms
/Users/someUser/node_modules/csv-parse/lib/index.js:124
throw new Error(`Invalid Option: from_line must be a positive integer greater than 0, got ${JSON.stringify(opts.from_line)}`)
^
Error: Invalid Option: …Run Code Online (Sandbox Code Playgroud) artillery ×1
awk ×1
java ×1
java-8 ×1
java-stream ×1
linux ×1
load-testing ×1
node.js ×1
optional ×1
testing ×1