-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to start Kafka and Schema Registry containers in the same Netwo…
…rk using public Interface
- Loading branch information
1 parent
69e5c65
commit 050540d
Showing
2 changed files
with
16 additions
and
11 deletions.
There are no files selected for viewing
23 changes: 14 additions & 9 deletions
23
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,29 +1,34 @@ | ||
package com.dimafeng.testcontainers | ||
|
||
import org.testcontainers.containers.{KafkaContainer => JavaKafkaContainer} | ||
import org.testcontainers.containers.{Network, KafkaContainer => JavaKafkaContainer} | ||
import org.testcontainers.utility.DockerImageName | ||
|
||
case class KafkaContainer(dockerImageName: DockerImageName = DockerImageName.parse(KafkaContainer.defaultDockerImageName) | ||
) extends SingleContainer[JavaKafkaContainer] { | ||
case class KafkaContainer( | ||
override val network: Network = KafkaContainer.defaultNetwork, | ||
dockerImageName: DockerImageName = KafkaContainer.defaultDockerImage | ||
) extends SingleContainer[JavaKafkaContainer] { | ||
|
||
override val container: JavaKafkaContainer = new JavaKafkaContainer(dockerImageName) | ||
override val container: JavaKafkaContainer = new JavaKafkaContainer(dockerImageName).withNetwork(network) | ||
|
||
def bootstrapServers: String = container.getBootstrapServers | ||
} | ||
|
||
object KafkaContainer { | ||
|
||
val defaultImage = "confluentinc/cp-kafka" | ||
val defaultTag = "7.2.0" | ||
val defaultDockerImageName = s"$defaultImage:$defaultTag" | ||
|
||
case class Def(dockerImageName: DockerImageName = DockerImageName.parse(KafkaContainer.defaultDockerImageName) | ||
) extends ContainerDef { | ||
private val defaultDockerImage = DockerImageName.parse(s"confluentinc/cp-kafka:$defaultTag") | ||
private def defaultNetwork: Network = Network.newNetwork() | ||
|
||
case class Def( | ||
network: Network = defaultNetwork, | ||
dockerImageName: DockerImageName = defaultDockerImage | ||
) extends ContainerDef { | ||
|
||
override type Container = KafkaContainer | ||
|
||
override def createContainer(): KafkaContainer = { | ||
new KafkaContainer(dockerImageName) | ||
new KafkaContainer(network, 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