-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrii Vasylyna
committed
Feb 13, 2022
1 parent
29e74b2
commit 55c2580
Showing
2 changed files
with
22 additions
and
43 deletions.
There are no files selected for viewing
42 changes: 10 additions & 32 deletions
42
modules/kafka/src/main/scala/com/dimafeng/testcontainers/KafkaContainer.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,29 @@ | ||
package com.dimafeng.testcontainers | ||
|
||
import org.testcontainers.containers.{KafkaContainer => JavaKafkaContainer} | ||
import org.testcontainers.utility.DockerImageName | ||
|
||
class KafkaContainer(confluentPlatformVersion: Option[String] = None, | ||
externalZookeeper: Option[String] = None) extends SingleContainer[JavaKafkaContainer] { | ||
case class KafkaContainer(dockerImageName: DockerImageName = DockerImageName.parse(KafkaContainer.defaultDockerImageName) | ||
) extends SingleContainer[JavaKafkaContainer] { | ||
|
||
@deprecated("Please use reflective methods of the scala container or `configure` method") | ||
val kafkaContainer: JavaKafkaContainer = { | ||
if (confluentPlatformVersion.isEmpty) { | ||
new JavaKafkaContainer() | ||
} else { | ||
new JavaKafkaContainer(confluentPlatformVersion.get) | ||
} | ||
} | ||
|
||
if (externalZookeeper.isEmpty) { | ||
kafkaContainer.withEmbeddedZookeeper() | ||
} else { | ||
kafkaContainer.withExternalZookeeper(externalZookeeper.get) | ||
} | ||
|
||
override val container: JavaKafkaContainer = kafkaContainer | ||
override val container: JavaKafkaContainer = new JavaKafkaContainer(dockerImageName) | ||
|
||
def bootstrapServers: String = container.getBootstrapServers | ||
} | ||
|
||
object KafkaContainer { | ||
|
||
val defaultImage = "confluentinc/cp-kafka" | ||
val defaultTag = "5.2.1" | ||
val defaultDockerImageName = s"$defaultImage:$defaultTag" | ||
|
||
def apply(confluentPlatformVersion: String = null, | ||
externalZookeeper: String = null): KafkaContainer = { | ||
new KafkaContainer(Option(confluentPlatformVersion), Option(externalZookeeper)) | ||
} | ||
|
||
case class Def( | ||
confluentPlatformVersion: String = defaultTag, | ||
externalZookeeper: Option[String] = None | ||
) extends ContainerDef { | ||
case class Def(dockerImageName: DockerImageName = DockerImageName.parse(KafkaContainer.defaultDockerImageName) | ||
) extends ContainerDef { | ||
|
||
override type Container = KafkaContainer | ||
|
||
override def createContainer(): KafkaContainer = { | ||
new KafkaContainer( | ||
confluentPlatformVersion = Some(confluentPlatformVersion), | ||
externalZookeeper = externalZookeeper | ||
) | ||
new KafkaContainer(dockerImageName) | ||
} | ||
} | ||
} | ||
} |
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