You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bigtop.apache.org by se...@apache.org on 2022/07/04 09:04:52 UTC

[bigtop] branch master updated: BIGTOP-3711: Add read/write smoke tests for Kafka (#922)

This is an automated email from the ASF dual-hosted git repository.

sekikn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bigtop.git


The following commit(s) were added to refs/heads/master by this push:
     new 3531120f BIGTOP-3711: Add read/write smoke tests for Kafka (#922)
3531120f is described below

commit 3531120f73c249ccd5c1c8937683511be067a3f8
Author: Leona Yoda <yo...@oss.nttdata.com>
AuthorDate: Mon Jul 4 18:04:47 2022 +0900

    BIGTOP-3711: Add read/write smoke tests for Kafka (#922)
    
    * Add read/write test for a kafka topic
    
    * reorder import statements
    
    * add a timeout option to consumer
---
 .../smoke-tests/kafka/TestKafkaSmoke.groovy        | 40 ++++++++++++++++++----
 1 file changed, 33 insertions(+), 7 deletions(-)

diff --git a/bigtop-tests/smoke-tests/kafka/TestKafkaSmoke.groovy b/bigtop-tests/smoke-tests/kafka/TestKafkaSmoke.groovy
index a1d1c88a..b36503df 100644
--- a/bigtop-tests/smoke-tests/kafka/TestKafkaSmoke.groovy
+++ b/bigtop-tests/smoke-tests/kafka/TestKafkaSmoke.groovy
@@ -18,21 +18,28 @@
 
 package org.apache.bigtop.itest.kafka
 
-import org.junit.BeforeClass
-import org.junit.AfterClass
-import org.apache.bigtop.itest.shell.Shell
-import static org.junit.Assert.assertNotNull
-import static org.junit.Assert.assertTrue
-import org.junit.Test
 import org.apache.bigtop.itest.JarContent
 import org.apache.bigtop.itest.TestUtils
+import org.apache.bigtop.itest.shell.Shell
+import org.junit.AfterClass
+import org.junit.BeforeClass
+import org.junit.FixMethodOrder
+import org.junit.Test
 import org.junit.runner.RunWith
+import org.junit.runners.MethodSorters
 
+import static org.junit.Assert.assertNotNull
+import static org.junit.Assert.assertTrue
+
+@FixMethodOrder (MethodSorters.NAME_ASCENDING)
 class TestKafkaSmoke {
   static Shell sh = new Shell("/bin/bash -s");
 
   static final String KAFKA_HOME = "/usr/lib/kafka"
   static final String KAFKA_TOPICS = KAFKA_HOME + "/bin/kafka-topics.sh "
+  static final String KAFKA_PRODUCER = KAFKA_HOME + "/bin/kafka-console-producer.sh"
+  static final String KAFKA_CONSUMER = KAFKA_HOME + "/bin/kafka-console-consumer.sh"
+  static final String TEST_MESSAGE = "Hello Bigtop"
 
   @AfterClass
   public static void deleteKafkaTopics() {
@@ -44,9 +51,28 @@ class TestKafkaSmoke {
   }
 
   @Test
-  public void testCreateTopics() {
+  public void test0CreateTopics() {
     sh.exec(KAFKA_TOPICS + " --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test");
     sh.exec(KAFKA_TOPICS + " --list --zookeeper localhost:2181");
     assertTrue(" Create Kafka topics failed. " + sh.getOut() + " " + sh.getErr(), sh.getRet() == 0);
   }
+
+  @Test
+  public void test1WriteKafkaTopics() {
+    sh.exec("echo '" + TEST_MESSAGE + "' | " + KAFKA_PRODUCER + " --broker-list localhost:9092 --topic test");
+    assertTrue(
+      " Write Kafka topics failed. " + sh.getOut() + " " + sh.getErr(),
+      sh.getRet() == 0
+    );
+  }
+
+  @Test
+  public void test2ReadKafkaTopics() {
+    sh.exec(KAFKA_CONSUMER + " --bootstrap-server localhost:9092 --topic test \
+            --partition 0 --offset 0 --max-messages 1 --timeout-ms 10000");
+    assertTrue(
+      " Read Kafka topics failed. " + sh.getOut() + " " + sh.getErr(),
+      sh.getOut() == [TEST_MESSAGE]
+    );
+  }
 }