Abacn commented on code in PR #36781: URL: https://github.com/apache/beam/pull/36781#discussion_r3149441112
########## sdks/java/core/src/test/java/org/apache/beam/sdk/lineage/LineagePluginTest.java: ########## @@ -0,0 +1,298 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.beam.sdk.lineage; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; +import java.util.List; +import org.apache.beam.sdk.PipelineResult; +import org.apache.beam.sdk.metrics.Lineage; +import org.apache.beam.sdk.options.PipelineOptionsFactory; +import org.apache.beam.sdk.testing.NeedsRunner; +import org.apache.beam.sdk.testing.TestPipeline; +import org.apache.beam.sdk.transforms.Create; +import org.apache.beam.sdk.transforms.DoFn; +import org.apache.beam.sdk.transforms.ParDo; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableList; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** Tests for {@link LineageBase} pipeline option selection and DirectRunner integration. */ +@RunWith(JUnit4.class) +public class LineagePluginTest { + + private static final Logger LOG = LoggerFactory.getLogger(LineagePluginTest.class); + + /** + * TestWatcher that logs detailed lineage diagnostics only when tests fail. This keeps successful + * test output clean while providing deep debugging for failures. + */ + @Rule + public TestWatcher lineageDebugLogger = + new TestWatcher() { + @Override + protected void failed(Throwable e, Description description) { + LOG.error("=== Lineage Test Failure Diagnostics ==="); + LOG.error("Test: {}", description.getMethodName()); + LOG.error("Error:", e); + + List<String> sources = TestLineage.getRecordedSources(); + List<String> sinks = TestLineage.getRecordedSinks(); + + LOG.error("Recorded Sources ({}):", sources.size()); + for (int i = 0; i < sources.size(); i++) { + LOG.error(" [{}] \"{}\"", i, sources.get(i)); + } + + LOG.error("Recorded Sinks ({}):", sinks.size()); + for (int i = 0; i < sinks.size(); i++) { + LOG.error(" [{}] \"{}\"", i, sinks.get(i)); + } + + LOG.error("========================================"); + } + }; + + @Before + public void setUp() { + // Clear any recorded lineage from previous tests + TestLineage.clearRecorded(); + } + + /** Helper to create a TestPipeline with test lineage configured. */ + private TestPipeline createTestPipelineWithLineage() { Review Comment: Here it creates TestPipeline in an unconventional way that ignores beamTestPipelineOptions, breaking validate runners At this stage I would suggest we revert this change at the moment, since it breaks multiple tests+misconfigured tests, then split this PR into smaller ones -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
