Comprehensive testing utilities for Apache Flink stream and batch processing applications
—
Comprehensive utilities for comparing and validating test results across various data formats including text files, collections, tuples, and numeric data with delta comparisons. These utilities enable thorough verification of Flink job outputs and intermediate results.
Compare result collections with custom comparators, supporting ordered and unordered comparisons with detailed error reporting.
public static <T> void compareResultCollections(
List<T> expected, List<T> actual, Comparator<T> comparator);import org.apache.flink.test.util.TestBaseUtils;
import java.util.Arrays;
import java.util.List;
List<String> expected = Arrays.asList("apple", "banana", "cherry");
List<String> actual = getJobResults();
TestBaseUtils.compareResultCollections(expected, actual, String::compareTo);Compare results stored in files against expected text content, supporting both ordered and unordered comparisons.
public static void compareResultsByLinesInMemory(String expected, String resultPath)
throws IOException;
public static void compareResultsByLinesInMemoryWithStrictOrder(
String expected, String resultPath) throws IOException;// Compare without strict ordering
String expected = "line1\nline2\nline3";
TestBaseUtils.compareResultsByLinesInMemory(expected, "/path/to/output.txt");
// Compare with strict ordering
TestBaseUtils.compareResultsByLinesInMemoryWithStrictOrder(expected, "/path/to/output.txt");Validate result files against regular expression patterns for flexible content verification.
public static void checkLinesAgainstRegexp(String resultPath, String regexp)
throws IOException;// Validate that all lines match a numeric pattern
TestBaseUtils.checkLinesAgainstRegexp("/path/to/output.txt", "\\d+\\.\\d+");Compare key-value pair results with numeric delta tolerance for floating-point comparisons.
public static void compareKeyValuePairsWithDelta(
String expected, String resultPath, String delimiter, double maxDelta)
throws IOException;// Compare key-value pairs with 0.01 tolerance
String expected = "key1,1.234\nkey2,5.678";
TestBaseUtils.compareKeyValuePairsWithDelta(
expected, "/path/to/output.txt", ",", 0.01);Convert and compare results as Flink tuples with automatic string parsing and tuple creation.
public static <T> void compareResultAsTuples(List<T> result, String expected);List<Tuple2<String, Integer>> results = getJobResults();
String expected = "(apple,5)\n(banana,3)\n(cherry,8)";
TestBaseUtils.compareResultAsTuples(results, expected);Compare result collections as text representation with flexible formatting support.
public static <T> void compareResultAsText(List<T> result, String expected);
public static <T> void compareOrderedResultAsText(List<T> result, String expected);
public static <T> void containsResultAsText(List<T> result, String expected);List<String> results = Arrays.asList("apple", "banana", "cherry");
// Unordered comparison
TestBaseUtils.compareResultAsText(results, "banana\napple\ncherry");
// Ordered comparison
TestBaseUtils.compareOrderedResultAsText(results, "apple\nbanana\ncherry");
// Contains check
TestBaseUtils.containsResultAsText(results, "apple\nbanana");Utility methods for file path handling and conversion between string paths and File objects.
public static File asFile(String path);Custom comparator for Flink Tuple types supporting generic tuple comparison with field-by-field comparison logic.
public static class TupleComparator<T extends Tuple> implements Comparator<T> {
@Override
public int compare(T o1, T o2);
}List<Tuple2<String, Integer>> results = getJobResults();
List<Tuple2<String, Integer>> expected = Arrays.asList(
new Tuple2<>("apple", 5),
new Tuple2<>("banana", 3)
);
TestBaseUtils.TupleComparator<Tuple2<String, Integer>> comparator =
new TestBaseUtils.TupleComparator<>();
TestBaseUtils.compareResultCollections(expected, results, comparator);All comparison methods throw descriptive exceptions when comparisons fail, providing detailed information about:
The error messages are designed to facilitate quick debugging of test failures by clearly indicating what was expected and what was actually received.
Install with Tessl CLI
npx tessl i tessl/maven-org-apache-flink--flink-test-utils