junaiddshaukat commented on code in PR #39546: URL: https://github.com/apache/beam/pull/39546#discussion_r3689349946
########## runners/kafka-streams/src/test/java/org/apache/beam/runners/kafka/streams/KafkaStreamsRunnerBrokerIT.java: ########## @@ -0,0 +1,282 @@ +/* + * 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; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.nio.file.Files; +import java.util.UUID; +import org.apache.beam.model.pipeline.v1.RunnerApi; +import org.apache.beam.runners.fnexecution.provisioning.JobInfo; +import org.apache.beam.sdk.Pipeline; +import org.apache.beam.sdk.PipelineResult; +import org.apache.beam.sdk.coders.KvCoder; +import org.apache.beam.sdk.coders.StringUtf8Coder; +import org.apache.beam.sdk.coders.VarIntCoder; +import org.apache.beam.sdk.metrics.Counter; +import org.apache.beam.sdk.metrics.MetricNameFilter; +import org.apache.beam.sdk.metrics.MetricQueryResults; +import org.apache.beam.sdk.metrics.MetricResult; +import org.apache.beam.sdk.metrics.Metrics; +import org.apache.beam.sdk.metrics.MetricsFilter; +import org.apache.beam.sdk.options.PipelineOptionsFactory; +import org.apache.beam.sdk.options.PortablePipelineOptions; +import org.apache.beam.sdk.testing.CrashingRunner; +import org.apache.beam.sdk.transforms.DoFn; +import org.apache.beam.sdk.transforms.GroupByKey; +import org.apache.beam.sdk.transforms.Impulse; +import org.apache.beam.sdk.transforms.ParDo; +import org.apache.beam.sdk.util.construction.Environments; +import org.apache.beam.sdk.util.construction.PipelineOptionsTranslation; +import org.apache.beam.sdk.util.construction.PipelineTranslation; +import org.apache.beam.sdk.util.construction.SplittableParDo; +import org.apache.beam.sdk.values.KV; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.Iterables; +import org.joda.time.Duration; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.testcontainers.containers.KafkaContainer; +import org.testcontainers.utility.DockerImageName; + +/** + * Runs a pipeline through the production {@link KafkaStreamsPipelineRunner} against a real Kafka + * broker, rather than through the {@code TopologyTestDriver} the rest of the suite uses. + * + * <p>The test driver stands in for a broker well enough for translation and windowing logic, but it + * runs one instance in one thread and fakes the topics. Everything that only exists on a real + * cluster is untested by it: the runner creating its own bootstrap and repartition topics, records + * actually round-tripping through a repartition topic, exactly-once processing, the state stores' + * changelog, and the Kafka Streams application lifecycle. This test covers that path. + * + * <p>It needs Docker and so is not part of the default build; the {@code brokerIntegrationTest} + * Gradle task runs it. + */ +@RunWith(JUnit4.class) +public class KafkaStreamsRunnerBrokerIT { + + private static final String NAMESPACE = "brokerIT"; + private static final String GROUPS_COUNTER = "groups"; + + /** How long to wait for the streaming application to work through the pipeline. */ + private static final Duration TIMEOUT = Duration.standardMinutes(2); + + private static KafkaContainer kafka; + + @BeforeClass + public static void startBroker() { + kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.6.1")); Review Comment: Switched. One wrinkle worth flagging: Testcontainers 1.21.4 can't bring up apache/kafka:3.9.0 — the container exits during startup, though the same image runs fine standalone. apache/kafka:4.0.0 works, so the test uses that while the runner's client stays on 3.9.0; a client talking to a newer broker is the direction Kafka supports. Comment in the code explains it. -- 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]
