Skip to content

Commit 6b2b4cb

Browse files
committed
validate results
1 parent 8831df7 commit 6b2b4cb

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

core/src/test/java/com/airwallex/airskiff/FlinkWindowPerformanceTest.java

+31-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import java.util.List;
1616
import java.util.Random;
1717

18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
1820
public class FlinkWindowPerformanceTest {
1921

2022
private List<Tuple2<Long, TestInputData>> data;
@@ -49,7 +51,7 @@ private List<Tuple2<Long, TestInputData>> generateData() {
4951
return generatedData;
5052
}
5153

52-
private void runWindowTest(String version) throws Exception {
54+
private List<Tuple2<Long, TestInputData>> runWindowTest(String version) throws Exception {
5355
TestRunner runner = new TestRunner();
5456
var config = new TestFlinkConfig<>(data, TestInputData.class);
5557
var source = new SourceStream<>(config);
@@ -75,20 +77,44 @@ private void runWindowTest(String version) throws Exception {
7577
var result = stream.executeAndCollect(DATA_SIZE);
7678

7779
long endTime = System.nanoTime();
78-
long duration = (endTime - startTime) / 1_000_000; // Convert to milliseconds
80+
long duration = (endTime - startTime) / 1_000_000;
7981

8082
System.out.println("Window function " + version + " execution time: " + duration + " ms");
8183
System.out.println("Result size: " + result.size());
84+
85+
return result;
86+
}
87+
88+
private void compareResults(List<Tuple2<Long, TestInputData>> result1, List<Tuple2<Long, TestInputData>> result2, String version1, String version2) {
89+
assertEquals(result1.size(), result2.size(), "Result sizes differ between " + version1 + " and " + version2);
90+
91+
for (int i = 0; i < result1.size(); i++) {
92+
Tuple2<Long, TestInputData> r1 = result1.get(i);
93+
Tuple2<Long, TestInputData> r2 = result2.get(i);
94+
95+
assertEquals(r1.f0, r2.f0, "Timestamps differ at index " + i + " between " + version1 + " and " + version2);
96+
assertEquals(r1.f1.a, r2.f1.a, "Aggregated values differ at index " + i + " between " + version1 + " and " + version2);
97+
assertEquals(r1.f1.b, r2.f1.b, "Keys differ at index " + i + " between " + version1 + " and " + version2);
98+
}
99+
100+
System.out.println("Results are identical between " + version1 + " and " + version2);
82101
}
83102

84103
@Test
85104
public void testWindowPerformance() throws Exception {
86105
var rounds = 5;
87106
while (rounds > 0) {
88-
runWindowTest("v1");
89-
runWindowTest("v2");
90-
runWindowTest("v3");
107+
List<Tuple2<Long, TestInputData>> resultV1 = runWindowTest("v1");
108+
List<Tuple2<Long, TestInputData>> resultV2 = runWindowTest("v2");
109+
List<Tuple2<Long, TestInputData>> resultV3 = runWindowTest("v3");
110+
111+
compareResults(resultV1, resultV2, "v1", "v2");
112+
compareResults(resultV1, resultV3, "v1", "v3");
113+
compareResults(resultV2, resultV3, "v2", "v3");
114+
115+
System.out.println("Round " + (6 - rounds) + " completed\n");
91116
rounds--;
92117
}
93118
}
119+
94120
}

0 commit comments

Comments
 (0)