Composer

class Composer(name: String, containers: Container)

Composer composes many Containers together to use in a unit test.

The Containers are networked using a dedicated Docker network. Tests need to expose ports in order for the test to communicate with the containers over 127.0.0.1.

The following example composes Kafka and Zookeeper containers for testing. Kafka is exposed to the jUnit test via 127.0.0.1:9102. In this example, Zookeeper is not exposed to the test.

    val zkContainer = Container {
withImage("confluentinc/cp-zookeeper")
withName("zookeeper")
withEnv("ZOOKEEPER_CLIENT_PORT=2181")
}
val kafka = Container {
withImage("confluentinc/cp-kafka")
withName("kafka")
withExposedPorts(ExposedPort.tcp(port))
withPortBindings(Ports().apply {
bind(ExposedPort.tcp(9102), Ports.Binding.bindPort(9102))
})
withEnv(
"KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181",
"KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9102")
}
val composer = Composer("e-kafka", zkContainer, kafka)
composer.start()

Constructors

Link copied to clipboard
fun Composer(name: String, vararg containers: Container)

Functions

Link copied to clipboard
fun start()
Link copied to clipboard
fun stop()

Properties

Link copied to clipboard
val running: AtomicBoolean