see-quick commented on code in PR #24133:
URL: https://github.com/apache/kafka/pull/24133#discussion_r4538329988
##########
docker/test/docker_sanity_test.py:
##########
@@ -314,11 +315,73 @@ def tearDown(self) -> None:
def test_bed(self):
self.execute()
+class DockerStreamsTest(unittest.TestCase):
+ IMAGE="apache/kafka"
+ IMAGE_TYPE="jvm"
+ CONTAINER_RUNTIME="docker"
+
+ def run_command(self, command, input_text=None):
+ result = subprocess.run(command, input=input_text,
capture_output=True, text=True, timeout=60)
+ self.assertEqual(result.returncode, 0,
+ f"Command failed: {'
'.join(command)}\n{result.stdout}{result.stderr}")
+ return result.stdout
+
+ def test_wordcount_with_rocksdb(self):
+ if self.IMAGE_TYPE != "jvm":
+ self.skipTest("The native image does not include a JVM or Streams
applications")
+
+ container = f"kafka-streams-test-{uuid.uuid4().hex}"
+ self.addCleanup(
+ subprocess.run,
+ [self.CONTAINER_RUNTIME, "rm", "--force", "--volumes", container],
+ capture_output=True,
+ timeout=30,
+ )
+
+ self.run_command([self.CONTAINER_RUNTIME, "run", "--detach", "--name",
container, self.IMAGE])
+ exec_command = [self.CONTAINER_RUNTIME, "exec", container]
+ bootstrap = ["--bootstrap-server", "localhost:9092"]
+ for topic in ("streams-plaintext-input", "streams-wordcount-output"):
+ self.run_command(exec_command + ["/opt/kafka/bin/kafka-topics.sh"]
+ bootstrap + [
+ "--create", "--topic", topic, "--partitions", "1",
"--replication-factor", "1",
+ ])
+
+ self.run_command([
+ self.CONTAINER_RUNTIME, "exec", "--detach", container, "sh", "-c",
+ "exec /opt/kafka/bin/kafka-run-class.sh "
+ "org.apache.kafka.streams.examples.wordcount.WordCountDemo "
+ "> /tmp/wordcount.log 2>&1",
+ ])
+ try:
+ self.run_command([
+ self.CONTAINER_RUNTIME, "exec", "--interactive", container,
+ "/opt/kafka/bin/kafka-console-producer.sh",
+ ] + bootstrap + ["--topic", "streams-plaintext-input"],
input_text="kafka\n")
+ output = self.run_command(exec_command +
["/opt/kafka/bin/kafka-console-consumer.sh"] + bootstrap + [
+ "--topic", "streams-wordcount-output", "--from-beginning",
"--max-messages", "1",
+ "--timeout-ms", str(constants.CLIENT_TIMEOUT),
+ "--key-deserializer",
"org.apache.kafka.common.serialization.StringDeserializer",
+ "--value-deserializer",
"org.apache.kafka.common.serialization.LongDeserializer",
+ "--formatter-property", "print.key=true",
+ ])
+ # Producing a count requires initializing and updating the RocksDB
store.
+ self.assertEqual(output.strip(), "kafka\t1")
+ finally:
+ try:
+ logs = subprocess.run(exec_command + ["cat",
"/tmp/wordcount.log"],
+ capture_output=True, text=True,
timeout=30)
+ print(logs.stdout + logs.stderr)
+ except (OSError, subprocess.TimeoutExpired) as e:
+ print(f"Failed to collect WordCount logs: {e}")
+
def run_tests(image, mode, fixtures_dir, container_runtime="docker",
compose_command=None):
DockerSanityTest.IMAGE = image
DockerSanityTest.FIXTURES_DIR = fixtures_dir
DockerSanityTest.CONTAINER_RUNTIME = container_runtime
DockerSanityTest.COMPOSE_COMMAND = compose_command or
detect_compose_command(container_runtime)
+ DockerStreamsTest.IMAGE = image
+ DockerStreamsTest.IMAGE_TYPE = mode
+ DockerStreamsTest.CONTAINER_RUNTIME = container_runtime
Review Comment:
Also you don't need to define these ... if you use inheritance.
##########
docker/test/docker_sanity_test.py:
##########
@@ -314,11 +315,73 @@ def tearDown(self) -> None:
def test_bed(self):
self.execute()
+class DockerStreamsTest(unittest.TestCase):
Review Comment:
Why don't you use DockerSanityTest class. You are completely redundantly
writing commands which can be re-used by super-class.
--
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]