[ 
https://issues.apache.org/jira/browse/BEAM-11411?focusedWorklogId=535346&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-535346
 ]

ASF GitHub Bot logged work on BEAM-11411:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 13/Jan/21 12:24
            Start Date: 13/Jan/21 12:24
    Worklog Time Spent: 10m 
      Work Description: ramazan-yapparov commented on a change in pull request 
#13636:
URL: https://github.com/apache/beam/pull/13636#discussion_r556481572



##########
File path: 
examples/java/src/test/java/org/apache/beam/examples/complete/kafkatopubsub/utils/RunKafkaContainer.java
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.examples.complete.kafkatopubsub.utils;
+
+import java.util.UUID;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.common.serialization.StringSerializer;
+import org.testcontainers.containers.KafkaContainer;
+import org.testcontainers.utility.DockerImageName;
+
+/** Run kafka container in separate thread to produce message. */
+public class RunKafkaContainer {
+
+  private static final String KAFKA_IMAGE_NAME = "confluentinc/cp-kafka:5.4.3";
+  private final String topicName;
+  private final KafkaProducer<String, String> producer;
+  private final String bootstrapServer;
+
+  public RunKafkaContainer(String pubsubMessage) {
+    bootstrapServer = setupKafkaContainer();
+    topicName = "messages-topic";
+    producer =
+        new KafkaProducer<>(
+            ImmutableMap.of(
+                ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,
+                bootstrapServer,
+                ProducerConfig.CLIENT_ID_CONFIG,
+                UUID.randomUUID().toString()),
+            new StringSerializer(),
+            new StringSerializer());
+    Runnable kafkaProducer =
+        () -> {
+          try {
+            producer.send(new ProducerRecord<>(topicName, "testcontainers", 
pubsubMessage)).get();
+            System.out.println("Producer sent");
+          } catch (ExecutionException | InterruptedException e) {
+            throw new RuntimeException("Something went wrong in kafka 
producer", e);
+          }
+        };
+    // Without saving `.schedule(...)` result to variable checkframework will 
fail
+    @SuppressWarnings("unused")
+    ScheduledFuture<?> schedule =
+        Executors.newSingleThreadScheduledExecutor().schedule(kafkaProducer, 
10, TimeUnit.SECONDS);

Review comment:
       Fixed, thanks




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

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 535346)
    Time Spent: 1h  (was: 50m)

> Example of E2E test for Pub/Sub environment
> -------------------------------------------
>
>                 Key: BEAM-11411
>                 URL: https://issues.apache.org/jira/browse/BEAM-11411
>             Project: Beam
>          Issue Type: Improvement
>          Components: examples-java
>            Reporter: Ilya Kozyrev
>            Priority: P2
>          Time Spent: 1h
>  Remaining Estimate: 0h
>
> Kafka to Pub/Sub pipeline [example|https://github.com/apache/beam/pull/13112] 
> needs to have e2e tests. However, in Beam Testing Guide 
> [https://cwiki.apache.org/confluence/display/BEAM/Contribution+Testing+Guide] 
> , we have not found examples or documentation for e2e tests that require a 
> Pub/Sub environment can be set up.
> During the investigation and with the help of our reviewers we found possible 
> approaches for our issue. 
> For Pub/Sub, e2e test could use [Pub/Sub 
> emulator|https://cloud.google.com/pubsub/docs/emulator]
> These e2e test examples can be referenced in the 
> [https://cwiki.apache.org/confluence/display/BEAM/Contribution+Testing+Guide] 
> to serve examples of how customers may approach e2e testing of pipelines in 
> their environments.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to