CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-apache-flink--flink-test-utils

Comprehensive testing utilities for Apache Flink stream and batch processing applications

Pending
Overview
Eval results
Files

result-verification.mddocs/

Result Verification

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.

Capabilities

Collection Comparison

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);

Usage Example

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);

Text-Based Result Comparison

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;

Usage Example

// 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");

Regular Expression Validation

Validate result files against regular expression patterns for flexible content verification.

public static void checkLinesAgainstRegexp(String resultPath, String regexp) 
    throws IOException;

Usage Example

// Validate that all lines match a numeric pattern
TestBaseUtils.checkLinesAgainstRegexp("/path/to/output.txt", "\\d+\\.\\d+");

Key-Value Pair Comparison with Delta

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;

Usage Example

// 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);

Tuple Result Comparison

Convert and compare results as Flink tuples with automatic string parsing and tuple creation.

public static <T> void compareResultAsTuples(List<T> result, String expected);

Usage Example

List<Tuple2<String, Integer>> results = getJobResults();
String expected = "(apple,5)\n(banana,3)\n(cherry,8)";
TestBaseUtils.compareResultAsTuples(results, expected);

Text Result Comparison

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);

Usage Example

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");

File Utilities

Utility methods for file path handling and conversion between string paths and File objects.

public static File asFile(String path);

Tuple Comparator

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);
}

Usage Example

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);

Error Handling

All comparison methods throw descriptive exceptions when comparisons fail, providing detailed information about:

  • Expected vs actual values
  • Line numbers for file-based comparisons
  • Delta violations for numeric comparisons
  • Missing or extra elements in collections

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

docs

index.md

metrics-testing.md

minicluster-management.md

result-verification.md

specialized-connectors.md

test-data-sources.md

test-environments.md

validation-utilities.md

tile.json