Last active
February 3, 2026 20:26
-
-
Save dacr/5416fcf6272cd91e91ffb462ff9a47ba to your computer and use it in GitHub Desktop.
Hello world embedded kafka test script using scalatest-embedded-kafka. / published by https://github.com/dacr/code-examples-manager #671230f8-20da-456c-ad5a-e2bbb0dc7377/eb7b88ac077ce572647a8ce107c6d8dd5db9d945
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // summary : Hello world embedded kafka test script using scalatest-embedded-kafka. | |
| // keywords : scala, scalatest, kafka, embedded-kafka | |
| // publish : gist | |
| // authors : David Crosson | |
| // license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // id : 671230f8-20da-456c-ad5a-e2bbb0dc7377 | |
| // created-on : 2018-10-10T08:45:12+02:00 | |
| // managed-by : https://github.com/dacr/code-examples-manager | |
| // run-with : cs launch --scala 2.13 com.lihaoyi:::ammonite:2.4.0 -M ammonite.Main -- $file | |
| import $ivy.`org.scalatest::scalatest:3.2.9` | |
| import $ivy.`io.github.embeddedkafka::embedded-kafka:2.8.0` | |
| import $ivy.`org.apache.logging.log4j:log4j-api:2.14.1` | |
| import $ivy.`org.apache.logging.log4j:log4j-core:2.14.1` | |
| import $ivy.`org.apache.logging.log4j:log4j-slf4j-impl:2.14.1` | |
| import org.scalatest._, wordspec._, matchers._, OptionValues._ | |
| import io.github.embeddedkafka._ | |
| import org.apache.kafka.common.serialization.{StringSerializer, StringDeserializer} | |
| org.apache.logging.log4j.core.config.Configurator.setRootLevel(org.apache.logging.log4j.Level.ERROR) | |
| class KafkaHelloTest extends AnyWordSpec with should.Matchers with EmbeddedKafka { | |
| override val suiteName = "KafkaHelloTest" | |
| "Kafka embedded" should { | |
| "work to send and receive a message within a test" in | |
| withRunningKafka { | |
| implicit val serializer = new StringSerializer | |
| implicit val deserializer = new StringDeserializer | |
| publishToKafka("news", "Hello world !") | |
| consumeFirstMessageFrom("news") should include regex "(?i)hello" | |
| } | |
| } | |
| } | |
| org.scalatest.tools.Runner.main(Array("-oDF", "-s", classOf[KafkaHelloTest].getName)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment