Last active
June 15, 2019 22:25
-
-
Save schrepfler/8092ccc2f77eaf3945e066be0a73c1b4 to your computer and use it in GitHub Desktop.
Scala testcontainers Kafka wrapper
This file contains 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
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