or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

index.mdmetrics-testing.mdminicluster-management.mdresult-verification.mdspecialized-connectors.mdtest-data-sources.mdtest-environments.mdvalidation-utilities.md

result-verification.mddocs/

0

# Result Verification

1

2

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.

3

4

## Capabilities

5

6

### Collection Comparison

7

8

Compare result collections with custom comparators, supporting ordered and unordered comparisons with detailed error reporting.

9

10

```java { .api }

11

public static <T> void compareResultCollections(

12

List<T> expected, List<T> actual, Comparator<T> comparator);

13

```

14

15

#### Usage Example

16

17

```java

18

import org.apache.flink.test.util.TestBaseUtils;

19

import java.util.Arrays;

20

import java.util.List;

21

22

List<String> expected = Arrays.asList("apple", "banana", "cherry");

23

List<String> actual = getJobResults();

24

TestBaseUtils.compareResultCollections(expected, actual, String::compareTo);

25

```

26

27

### Text-Based Result Comparison

28

29

Compare results stored in files against expected text content, supporting both ordered and unordered comparisons.

30

31

```java { .api }

32

public static void compareResultsByLinesInMemory(String expected, String resultPath)

33

throws IOException;

34

35

public static void compareResultsByLinesInMemoryWithStrictOrder(

36

String expected, String resultPath) throws IOException;

37

```

38

39

#### Usage Example

40

41

```java

42

// Compare without strict ordering

43

String expected = "line1\nline2\nline3";

44

TestBaseUtils.compareResultsByLinesInMemory(expected, "/path/to/output.txt");

45

46

// Compare with strict ordering

47

TestBaseUtils.compareResultsByLinesInMemoryWithStrictOrder(expected, "/path/to/output.txt");

48

```

49

50

### Regular Expression Validation

51

52

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

53

54

```java { .api }

55

public static void checkLinesAgainstRegexp(String resultPath, String regexp)

56

throws IOException;

57

```

58

59

#### Usage Example

60

61

```java

62

// Validate that all lines match a numeric pattern

63

TestBaseUtils.checkLinesAgainstRegexp("/path/to/output.txt", "\\d+\\.\\d+");

64

```

65

66

### Key-Value Pair Comparison with Delta

67

68

Compare key-value pair results with numeric delta tolerance for floating-point comparisons.

69

70

```java { .api }

71

public static void compareKeyValuePairsWithDelta(

72

String expected, String resultPath, String delimiter, double maxDelta)

73

throws IOException;

74

```

75

76

#### Usage Example

77

78

```java

79

// Compare key-value pairs with 0.01 tolerance

80

String expected = "key1,1.234\nkey2,5.678";

81

TestBaseUtils.compareKeyValuePairsWithDelta(

82

expected, "/path/to/output.txt", ",", 0.01);

83

```

84

85

### Tuple Result Comparison

86

87

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

88

89

```java { .api }

90

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

91

```

92

93

#### Usage Example

94

95

```java

96

List<Tuple2<String, Integer>> results = getJobResults();

97

String expected = "(apple,5)\n(banana,3)\n(cherry,8)";

98

TestBaseUtils.compareResultAsTuples(results, expected);

99

```

100

101

### Text Result Comparison

102

103

Compare result collections as text representation with flexible formatting support.

104

105

```java { .api }

106

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

107

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

108

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

109

```

110

111

#### Usage Example

112

113

```java

114

List<String> results = Arrays.asList("apple", "banana", "cherry");

115

116

// Unordered comparison

117

TestBaseUtils.compareResultAsText(results, "banana\napple\ncherry");

118

119

// Ordered comparison

120

TestBaseUtils.compareOrderedResultAsText(results, "apple\nbanana\ncherry");

121

122

// Contains check

123

TestBaseUtils.containsResultAsText(results, "apple\nbanana");

124

```

125

126

### File Utilities

127

128

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

129

130

```java { .api }

131

public static File asFile(String path);

132

```

133

134

## Tuple Comparator

135

136

Custom comparator for Flink Tuple types supporting generic tuple comparison with field-by-field comparison logic.

137

138

```java { .api }

139

public static class TupleComparator<T extends Tuple> implements Comparator<T> {

140

@Override

141

public int compare(T o1, T o2);

142

}

143

```

144

145

#### Usage Example

146

147

```java

148

List<Tuple2<String, Integer>> results = getJobResults();

149

List<Tuple2<String, Integer>> expected = Arrays.asList(

150

new Tuple2<>("apple", 5),

151

new Tuple2<>("banana", 3)

152

);

153

154

TestBaseUtils.TupleComparator<Tuple2<String, Integer>> comparator =

155

new TestBaseUtils.TupleComparator<>();

156

157

TestBaseUtils.compareResultCollections(expected, results, comparator);

158

```

159

160

## Error Handling

161

162

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

163

164

- Expected vs actual values

165

- Line numbers for file-based comparisons

166

- Delta violations for numeric comparisons

167

- Missing or extra elements in collections

168

169

The error messages are designed to facilitate quick debugging of test failures by clearly indicating what was expected and what was actually received.