|
39 | 39 | import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableList; |
40 | 40 | import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.Lists; |
41 | 41 | import org.junit.Before; |
| 42 | +import org.junit.Rule; |
42 | 43 | import org.junit.Test; |
43 | 44 | import org.junit.experimental.categories.Category; |
| 45 | +import org.junit.rules.TestWatcher; |
| 46 | +import org.junit.runner.Description; |
44 | 47 | import org.junit.runner.RunWith; |
45 | 48 | import org.junit.runners.JUnit4; |
46 | 49 |
|
47 | 50 | /** Tests for {@link LineageRegistrar} ServiceLoader discovery and DirectRunner integration. */ |
48 | 51 | @RunWith(JUnit4.class) |
49 | 52 | public class LineageRegistrarTest { |
50 | 53 |
|
| 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 | + |
51 | 83 | @Before |
52 | 84 | public void setUp() { |
53 | 85 | // Clear any recorded lineage from previous tests |
|
0 commit comments