All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.adven27.env.mq.kafka.FastDataDevKafkaContainerSystem.kt Maven / Gradle / Ivy

There is a newer version: 5.5.0
Show newest version
package io.github.adven27.env.mq.kafka

import io.github.adven27.env.core.ExternalSystem
import io.github.adven27.env.core.ExternalSystemConfig
import mu.KLogging
import org.testcontainers.containers.GenericContainer
import org.testcontainers.utility.DockerImageName
import java.time.Duration.ofSeconds

@Suppress("unused")
open class FastDataDevKafkaContainerSystem @JvmOverloads constructor(
    dockerImageName: DockerImageName = DockerImageName.parse(IMAGE),
    private val defaultPort: Int = PORT,
    private val defaultPortAdm: Int = PORT_ADM,
    private val afterStart: FastDataDevKafkaContainerSystem.() -> Unit = { }
) : GenericContainer(dockerImageName), ExternalSystem {
    override lateinit var config: Config

    override fun start(fixedEnv: Boolean) {
        withEnv("ADV_HOST", "127.0.0.1")
        withExposedPorts(PORT, PORT_ADM)
        withStartupTimeout(ofSeconds(STARTUP_TIMEOUT))
        if (fixedEnv) {
            addFixedExposedPort(defaultPort, PORT)
            addFixedExposedPort(defaultPortAdm, PORT_ADM)
        }
        start()
    }

    override fun start() {
        super.start()
        config = Config(host, getMappedPort(PORT))
        apply(afterStart)
    }

    override fun running() = isRunning

    data class Config @JvmOverloads constructor(
        val host: String = "localhost",
        val port: Int = PORT
    ) : ExternalSystemConfig("env.mq.kafka.host" to host, "env.mq.kafka.port" to port.toString())

    companion object : KLogging() {
        private const val PORT = 9092
        private const val PORT_ADM = 3030
        private const val IMAGE = "lensesio/fast-data-dev"
        private const val STARTUP_TIMEOUT = 30L
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy