【问题标题】:How run testcontainers with in-memory filesystem TMPFS set in Quarkus如何使用 Quarkus 中设置的内存文件系统 TMPFS 运行测试容器
【发布时间】:2022-09-23 03:00:19
【问题描述】:

我有以下问题。

为了加速集成测试管道,我想运行 testcontainersQuarkusTMPFS 选项集。这将强制测试容器使用内存文件系统运行数据库。

这可以根据testcontainers这样的网站轻松完成...

要将此选项传递给容器,请将 TC_TMPFS 参数添加到 URL,如下所示: jdbc:tc:postgresql:9.6.8:///databasename?TC_TMPFS=/testtmpfs:rw

好像问题解决了。这就是它应该如何与Spring Boot一起工作

但是,Quarkus 在他们的docs 中表示以下内容......

所有基于容器的服务都使用测试容器运行。尽管可以在 application.properties 文件中设置额外的 URL 属性,但不支持特定的测试容器属性,例如 TC_INITSCRIPT、TC_INITFUNCTION、TC_DAEMON、TC_TMPFS。

我的问题是:

你怎么能解决这个问题?如何运行将安装在 TMPFS 上的测试容器?

    标签: java spring-boot kotlin quarkus testcontainers


    【解决方案1】:

    您可以尝试使用 QuarkusTestResourceLifecycleManager guide 设置 TMPFS。

    Quarkus Kotlin 示例:

    
    class DatabaseTestLifeCycleManager : QuarkusTestResourceLifecycleManager {
        private val postgresDockerImage = DockerImageName.parse("postgres:latest")
    
        override fun start(): MutableMap<String, String>? {
            val container = startPostgresContainer()
    
            return mutableMapOf(
                "quarkus.datasource.username" to container.username,
                "quarkus.datasource.password" to container.password,
                "quarkus.datasource.jdbc.url" to container.jdbcUrl
            )
        }
    
        private fun startPostgresContainer(): PostgreSQLContainer<out PostgreSQLContainer<*>> {
            val container = PostgreSQLContainer(postgresDockerImage)
                .withDatabaseName("dataBaseName")
                .withUsername("username")
                .withPassword("password")
                .withEnv(mapOf("PGDATA" to "/var/lib/postgresql/data"))
                .withTmpFs(mapOf("/var/lib/postgresql/data" to "rw"))
            container.start()
            return container
        }
    
        override fun stop() {
            // close container
        }
    }
    

    【讨论】:

    • 是的,最后,我选择了withTmpFs。感谢您发布它 - 我没有时间自己做。
    • @Andreas您是否测试过它是否有效,或者这只是一个建议?
    • 经过测试和工作@ArthurKlezovich 需要添加行.withEnv(mapOf("PGDATA" to "/var/lib/postgresql/data")) 才能正常工作。
    【解决方案2】:

    您可以尝试使用以下配置:

    quarkus.datasource.url=jdbc:tc:postgresql:9.6.8:///databasename?TC_TMPFS=/testtmpfs:rw
    

    【讨论】:

      猜你喜欢
      • 2019-10-15
      • 1970-01-01
      • 1970-01-01
      • 2020-05-06
      • 2019-12-15
      • 2018-08-25
      • 2021-10-26
      • 1970-01-01
      • 2020-07-11
      相关资源
      最近更新 更多