confluentinc / openmessaging-benchmark

Apache License 2.0
5 stars 59 forks source link

Fix NullPointerException when writing json result if not using --output parameter #9

Open jingerbread opened 4 years ago

jingerbread commented 4 years ago

When user doesn't specify --output file parameter, json file won't be written because of java.lang.NullPointerException:

bin/benchmark --drivers driver-kafka/kafka-0.yaml workloads/100-partitions-1000K-rate-4-producer.yaml 2>&1 | tee test3.log && grep Aggregated test3.log
...
10:54:22.257 [main] ERROR - Failed to run the workload '100 partitions 1000K rate 4 producer' for driver 'driver-kafka/kafka-0.yaml'
java.lang.NullPointerException: null
        at io.openmessaging.benchmark.Benchmark.lambda$null$0(Benchmark.java:155) [io.openmessaging.benchmark-benchmark-framework-0.0.1-SNAPSHOT.jar:?]
        at java.util.ArrayList.forEach(ArrayList.java:1541) [?:?]
        at io.openmessaging.benchmark.Benchmark.lambda$main$1(Benchmark.java:138) [io.openmessaging.benchmark-benchmark-framework-0.0.1-SNAPSHOT.jar:?]
        at java.util.TreeMap.forEach(TreeMap.java:1002) [?:?]
        at io.openmessaging.benchmark.Benchmark.main(Benchmark.java:129) [io.openmessaging.benchmark-benchmark-framework-0.0.1-SNAPSHOT.jar:?]

Need to fix followig line:

String fileName = arguments.output.length() > 0 ? arguments.output

F.e for

boolean useOutput = (arguments.output != null) && (arguments.output.length() > 0);
String fileName = useOutput? arguments.output: String.format("%s-%s-%s.json", workloadName, driverConfiguration.name,
                                    dateFormat.format(new Date()));
zcola commented 2 years ago

+1