Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testkit: fail better if cluster hasn't started #1492

Merged
merged 2 commits into from
May 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object TestcontainersKafka {
private var kafkaPortInternal: Int = -1

private def requireStarted(): Unit =
require(kafkaPortInternal != -1, "Testcontainers Kafka hasn't been started via `setUp`")
require(cluster != null || kafkaPortInternal != -1, "Testcontainers Kafka hasn't been started via `setUp`")

/**
* Override this to change default settings for starting the Kafka testcontainers cluster.
Expand All @@ -39,18 +39,29 @@ object TestcontainersKafka {
kafkaBootstrapServersInternal
}

def brokerContainers: Vector[AlpakkaKafkaContainer] = cluster.getBrokers.asScala.toVector
def brokerContainers: Vector[AlpakkaKafkaContainer] = {
requireStarted()
cluster.getBrokers.asScala.toVector
}

def zookeeperContainer: GenericContainer[_] = cluster.getZooKeeper
def zookeeperContainer: GenericContainer[_] = {
requireStarted()
cluster.getZooKeeper
}

def schemaRegistryContainer: Option[SchemaRegistryContainer] = cluster.getSchemaRegistry.asScala
def schemaRegistryContainer: Option[SchemaRegistryContainer] = {
requireStarted()
cluster.getSchemaRegistry.asScala
}

def getSchemaRegistryUrl: String =
def getSchemaRegistryUrl: String = {
requireStarted()
cluster.getSchemaRegistry.asScala
.map(_.getSchemaRegistryUrl)
.getOrElse(
throw new RuntimeException("Did you enable schema registry in your KafkaTestkitTestcontainersSettings?")
)
}

def startCluster(): String = startCluster(testcontainersSettings)

Expand Down