je-ik commented on code in PR #39273:
URL: https://github.com/apache/beam/pull/39273#discussion_r3586181073


##########
runners/kafka-streams/src/test/java/org/apache/beam/runners/kafka/streams/translation/FlattenTest.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.runners.kafka.streams.translation;
+
+import static org.hamcrest.CoreMatchers.hasItems;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.List;
+import org.apache.beam.runners.kafka.streams.KafkaStreamsTestRunner;
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.transforms.Create;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.Flatten;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionList;
+import org.junit.Test;
+
+/**
+ * End-to-end test for {@link FlattenTranslator}: two branches are flattened 
into one PCollection
+ * and a recording ParDo sees every element from both.
+ *
+ * <p>Each branch is a {@code Create -> identity ParDo}, so its producer 
feeding the Flatten is an
+ * {@link ExecutableStageProcessor} — the same shape PAssert's {@code 
GroupGlobally} produces. This
+ * exercises the per-producing-transform watermark aggregation: each branch's 
producer stamps its
+ * own transform id on its watermark, and the Flatten holds its output 
watermark until every
+ * upstream transform it expects has reported. Without that, the Flatten would 
release its watermark
+ * after the first branch drained and the downstream stage's bundle would 
close early, dropping the
+ * second branch's elements.
+ */
+public class FlattenTest {
+
+  private static class IdentityFn extends DoFn<Integer, Integer> {
+    @ProcessElement
+    public void processElement(@Element Integer input, OutputReceiver<Integer> 
out) {
+      out.output(input);
+    }
+  }
+
+  /** Records every element the harness feeds it so the test can assert the 
flatten's union. */
+  private static class RecordingFn extends DoFn<Integer, Integer> {
+    private final SharedTestCollector<Integer> collector;
+
+    RecordingFn(SharedTestCollector<Integer> collector) {
+      this.collector = collector;
+    }
+
+    @ProcessElement
+    public void processElement(@Element Integer input, OutputReceiver<Integer> 
out) {
+      collector.record(input);
+      out.output(input);
+    }
+  }
+
+  @Test
+  public void flattenUnionsEveryBranch() {
+    try (SharedTestCollector<Integer> collector = 
SharedTestCollector.create()) {
+      Pipeline pipeline = 
Pipeline.create(KafkaStreamsTestRunner.testOptions());
+      PCollection<Integer> a =
+          pipeline.apply("createA", Create.of(1, 2)).apply("idA", ParDo.of(new 
IdentityFn()));
+      PCollection<Integer> b =
+          pipeline.apply("createB", Create.of(3, 4)).apply("idB", ParDo.of(new 
IdentityFn()));
+      PCollectionList.of(a)
+          .and(b)
+          .apply("flatten", Flatten.pCollections())
+          .apply("record", ParDo.of(new RecordingFn(collector)));
+
+      KafkaStreamsTestRunner.run(pipeline);
+
+      List<Integer> recorded = collector.recorded();
+      assertThat(recorded.size(), is(4));
+      assertThat(recorded, hasItems(1, 2, 3, 4));
+    }
+  }
+
+  @Test
+  public void pCollectionFeedingTwoFlattensIsSupported() {
+    // je-ik's #39273 case: input2 feeds both flattens. Per-Flatten branch 
numbering could not

Review Comment:
   I think we don't need to attribute test cases like this. :)



##########
runners/kafka-streams/src/test/java/org/apache/beam/runners/kafka/streams/translation/FlattenTest.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.runners.kafka.streams.translation;
+
+import static org.hamcrest.CoreMatchers.hasItems;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.List;
+import org.apache.beam.runners.kafka.streams.KafkaStreamsTestRunner;
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.transforms.Create;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.Flatten;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionList;
+import org.junit.Test;
+
+/**
+ * End-to-end test for {@link FlattenTranslator}: two branches are flattened 
into one PCollection
+ * and a recording ParDo sees every element from both.
+ *
+ * <p>Each branch is a {@code Create -> identity ParDo}, so its producer 
feeding the Flatten is an
+ * {@link ExecutableStageProcessor} — the same shape PAssert's {@code 
GroupGlobally} produces. This
+ * exercises the per-producing-transform watermark aggregation: each branch's 
producer stamps its
+ * own transform id on its watermark, and the Flatten holds its output 
watermark until every
+ * upstream transform it expects has reported. Without that, the Flatten would 
release its watermark
+ * after the first branch drained and the downstream stage's bundle would 
close early, dropping the
+ * second branch's elements.
+ */
+public class FlattenTest {

Review Comment:
   These tests verify only how we propagate data, we could add test that will 
check the watermark propagation. One way would be to add GBK after Flatten, 
because that should fire only if the watermark is propagated through. Or 
alternatively extract the Topology and add custom watermark-tracking processor 
after Flatten directly.



-- 
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]

Reply via email to