Skip to content

Instantly share code, notes, and snippets.

@schrepfler
Last active June 15, 2019 22:25
Show Gist options
  • Save schrepfler/8092ccc2f77eaf3945e066be0a73c1b4 to your computer and use it in GitHub Desktop.
Save schrepfler/8092ccc2f77eaf3945e066be0a73c1b4 to your computer and use it in GitHub Desktop.
Scala testcontainers Kafka wrapper
import com.dimafeng.testcontainers.SingleContainer
import org.testcontainers.containers.{KafkaContainer => OTCKafkaContainer}
import org.testcontainers.containers.{GenericContainer => OTCGenericContainer}
class KafkaContainer(confluentPlatformVersion: Option[String] = None,
externalZookeeper: Option[String] = None) extends SingleContainer[OTCGenericContainer[_]] {
type OTCContainer = OTCGenericContainer[T] forSome {type T <: OTCKafkaContainer}
var kafkaContainer: OTCKafkaContainer = null
if (confluentPlatformVersion.isEmpty) {
kafkaContainer = new OTCKafkaContainer()
} else {
kafkaContainer = new OTCKafkaContainer(confluentPlatformVersion.get)
}
if (externalZookeeper.isEmpty) {
kafkaContainer.withEmbeddedZookeeper()
} else {
kafkaContainer.withExternalZookeeper(externalZookeeper.get)
}
override val container: OTCKafkaContainer = kafkaContainer
}
object KafkaContainer {
def apply(confluentPlatformVersion: String = null, externalZookeeper: String = null): KafkaContainer = new KafkaContainer(Option(confluentPlatformVersion), Option(externalZookeeper))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment