Repository: apache/kafka
File: streams/src/test/java/org/apache/kafka/streams/tests/SmokeTestDriver.java (Java)

Code before:
                        return false;
                    } else {
                        resultStream.printf("duplicated detected (ok for ALOS): resultCount=%d expectedCount=%s%n\tresult=%s%n\texpected=%s%n",
                            outputEvents.size(), inputData.size(), outputEvents.keySet(), inputData.keySet());
                    }
                }
            }

            for (final Map.Entry<String, LinkedList<ConsumerRecord<String, Number>>> entry : outputEvents.entrySet()) {
                final String key = entry.getKey();
                final Number expected = keyToExpectation.apply(key);
                final Number actual = entry.getValue().getLast().value();
                if (!validationPredicate.test(expected, actual)) {
                    resultStream.printf("%s fail: key=%s actual=%s expected=%s%n", topic, key, actual, expected);

                    if (printResults) {
                        resultStream.printf("\t inputEvents=%n%s%n\t" +
                                "echoEvents=%n%s%n\tmaxEvents=%n%s%n\tminEvents=%n%s%n\tdifEvents=%n%s%n\tcntEvents=%n%s%n\ttaggEvents=%n%s%n",
                            indent("\t\t", observedInputEvents.get(key)),
                            indent("\t\t", events.getOrDefault("echo", emptyMap()).getOrDefault(key, new LinkedList<>())),
                            indent("\t\t", events.getOrDefault("max", emptyMap()).getOrDefault(key, new LinkedList<>())),
                            indent("\t\t", events.getOrDefault("min", emptyMap()).getOrDefault(key, new LinkedList<>())),
                            indent("\t\t", events.getOrDefault("dif", emptyMap()).getOrDefault(key, new LinkedList<>())),
                            indent("\t\t", events.getOrDefault("cnt", emptyMap()).getOrDefault(key, new LinkedList<>())),
                            indent("\t\t", events.getOrDefault("tagg", emptyMap()).getOrDefault(key, new LinkedList<>())));

                        if (!Set.of("echo", "max", "min", "dif", "cnt", "tagg").contains(topic))
                            resultStream.printf("%sEvents=%n%s%n", topic, indent("\t\t", entry.getValue()));
                    }

                    return false;
                }
            }
            return true;
        }
    }

    private static boolean lessEquals(final Number expected, final Number actual) {
        if (actual instanceof Integer && expected instanceof Integer) {
            return actual.intValue() >= expected.intValue();
        } else if (actual instanceof Long && expected instanceof Long) {
            return actual.longValue() >= expected.longValue();
        } else if (actual instanceof Double && expected instanceof Double) {
            return actual.doubleValue() >= expected.doubleValue();
        } else {
            throw new IllegalArgumentException("Unexpected type: " + actual.getClass());
        }
    }

    private static boolean verifySuppressed(final PrintStream resultStream,
                                            @SuppressWarnings("SameParameterValue") final String topic,

Review comment (performance):
Instead of creating a new LinkedList for each missing key, consider using Collections.emptyList() to avoid unnecessary allocations.

Code after:
                if (outputEvents.size() < inputData.size()) {
                    resultStream.println("fail: missing result data; got " + inputData.size() + " keys, expected: " + outputEvents.size() + " keys");
                    return false;
                } else {
                    if (eosEnabled) {
                        resultStream.printf("fail: resultCount=%d expectedCount=%s%n\tresult=%s%n\texpected=%s%n",
                            outputEvents.size(), inputData.size(), outputEvents.keySet(), inputData.keySet());
                        return false;
                    } else {
                        resultStream.printf("duplicated detected (ok for ALOS): resultCount=%d expectedCount=%s%n\tresult=%s%n\texpected=%s%n",
                            outputEvents.size(), inputData.size(), outputEvents.keySet(), inputData.keySet());
                    }
                }
            }

            for (final Map.Entry<String, LinkedList<ConsumerRecord<String, Number>>> entry : outputEvents.entrySet()) {
                final String key = entry.getKey();
                final Number expected = keyToExpectation.apply(key);
                final Number actual = entry.getValue().getLast().value();
                if (!validationPredicate.test(expected, actual)) {
                    resultStream.printf("%s fail: key=%s actual=%s expected=%s%n", topic, key, actual, expected);

                    if (printResults) {
                        resultStream.printf("\t inputEvents=%n%s%n\t" +
                                "echoEvents=%n%s%n\tmaxEvents=%n%s%n\tminEvents=%n%s%n\tdifEvents=%n%s%n\tcntEvents=%n%s%n\ttaggEvents=%n%s%n",
                            indent("\t\t", observedInputEvents.getOrDefault(key, new LinkedList<>())),
                            indent("\t\t", events.getOrDefault("echo", emptyMap()).getOrDefault(key, new LinkedList<>())),
                            indent("\t\t", events.getOrDefault("max", emptyMap()).getOrDefault(key, new LinkedList<>())),
                            indent("\t\t", events.getOrDefault("min", emptyMap()).getOrDefault(key, new LinkedList<>())),
                            indent("\t\t", events.getOrDefault("dif", emptyMap()).getOrDefault(key, new LinkedList<>())),
                            indent("\t\t", events.getOrDefault("cnt", emptyMap()).getOrDefault(key, new LinkedList<>())),
                            indent("\t\t", events.getOrDefault("tagg", emptyMap()).getOrDefault(key, new LinkedList<>())));

                        if (!Set.of("echo", "max", "min", "dif", "cnt", "tagg").contains(topic))
                            resultStream.printf("%sEvents=%n%s%n", topic, indent("\t\t", entry.getValue()));
                    }

                    return false;
                }
            }
            return true;
        }
    }

    private static boolean lessEquals(final Number expected, final Number actual) {
        if (actual instanceof Integer && expected instanceof Integer) {
            return actual.intValue() >= expected.intValue();
        } else if (actual instanceof Long && expected instanceof Long) {
            return actual.longValue() >= expected.longValue();
        } else if (actual instanceof Double && expected instanceof Double) {
            return actual.doubleValue() >= expected.doubleValue();