MINOR: Prevent NPE in SmokeTestDriver (fix flaky test)
SmokeTestDriverIntegrationTest.java can be flaky because a NullPointerException prevents the retry mechanism that is added to prevent flakiness for this test. This change, prevents the NullPointerException and hence, allows the test to retry itself.
Reviewers: Luke Chen Lucas Brutschy
@@ -420,6 +420,7 @@ public class SmokeTestDriver extends SmokeTestUtil {
}
}
consumer.close();
+
final long finished = System.currentTimeMillis() - start;
System.out.println("Verification time=" + finished);
System.out.println("-------------------");
@@ -434,19 +435,9 @@ public class SmokeTestDriver extends SmokeTestUtil {
System.out.println("PROCESSED-LESS-THAN-GENERATED");
}
- boolean success;
-
- final Map<String, Set<Number>> received =
- events.get("echo")
- .entrySet()
- .stream()
- .map(entry -> mkEntry(
- entry.getKey(),
- entry.getValue().stream().map(ConsumerRecord::value).collect(Collectors.toSet()))
- )
- .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+ final Map<String, Set<Number>> received = parseRecordsForEchoTopic(events);
- success = inputs.equals(received);
+ boolean success = inputs.equals(received);
if (success) {
System.out.println("ALL-RECORDS-DELIVERED");
@@ -470,6 +461,19 @@ public class SmokeTestDriver extends SmokeTestUtil {
return verificationResult;
}
+ private static Map<String, Set<Number>> parseRecordsForEchoTopic(
+ final Map<String, Map<String, LinkedList<ConsumerRecord<String, Number>>>> events) {
+ return events.containsKey("echo") ?
+ events.get("echo")
+ .entrySet()
+ .stream()
+ .map(entry -> mkEntry(
+ entry.getKey(),
+ entry.getValue().stream().map(ConsumerRecord::value).collect(Collectors.toSet()))
+ )
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)) : Collections.emptyMap();
+ }
+
public static class VerificationResult {
private final boolean passed;
private final String result;
