Skip to content

Commit 23b45a2

Browse files
committed
Improve test logging
1 parent f02bd4b commit 23b45a2

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

sdks/java/core/src/test/java/org/apache/beam/sdk/lineage/LineageRegistrarTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,47 @@
3939
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableList;
4040
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.Lists;
4141
import org.junit.Before;
42+
import org.junit.Rule;
4243
import org.junit.Test;
4344
import org.junit.experimental.categories.Category;
45+
import org.junit.rules.TestWatcher;
46+
import org.junit.runner.Description;
4447
import org.junit.runner.RunWith;
4548
import org.junit.runners.JUnit4;
4649

4750
/** Tests for {@link LineageRegistrar} ServiceLoader discovery and DirectRunner integration. */
4851
@RunWith(JUnit4.class)
4952
public class LineageRegistrarTest {
5053

54+
/**
55+
* TestWatcher that logs detailed lineage diagnostics only when tests fail.
56+
* This keeps successful test output clean while providing deep debugging for failures.
57+
*/
58+
@Rule
59+
public TestWatcher lineageDebugLogger = new TestWatcher() {
60+
@Override
61+
protected void failed(Throwable e, Description description) {
62+
System.err.println("=== Lineage Test Failure Diagnostics ===");
63+
System.err.println("Test: " + description.getMethodName());
64+
System.err.println("Error: " + e.getMessage());
65+
66+
List<String> sources = TestLineage.getRecordedSources();
67+
List<String> sinks = TestLineage.getRecordedSinks();
68+
69+
System.err.println("\nRecorded Sources (" + sources.size() + "):");
70+
for (int i = 0; i < sources.size(); i++) {
71+
System.err.println(" [" + i + "] \"" + sources.get(i) + "\"");
72+
}
73+
74+
System.err.println("\nRecorded Sinks (" + sinks.size() + "):");
75+
for (int i = 0; i < sinks.size(); i++) {
76+
System.err.println(" [" + i + "] \"" + sinks.get(i) + "\"");
77+
}
78+
79+
System.err.println("========================================");
80+
}
81+
};
82+
5183
@Before
5284
public void setUp() {
5385
// Clear any recorded lineage from previous tests

0 commit comments

Comments
 (0)