How to run Testcontainers with in-memory filesystem TMPFS set in Quarkus
Asked Answered
A

2

8

I have the following issue.

In order to speed up the integration test pipeline I want to run testcontainers with Quarkus with TMPFS option set. This will force testcontainers to run the DB with a in-memory file system.

This can be easily done according to testcontainers website like this ...

To pass this option to the container, add TC_TMPFS parameter to the URL as follows: jdbc:tc:postgresql:9.6.8:///databasename?TC_TMPFS=/testtmpfs:rw

Seems like problem solved. This is how it should work with Spring Boot

However, with Quarkus in their docs it says the following ...

All services based on containers are ran using testcontainers. Even though extra URL properties can be set in your application.properties file, specific testcontainers properties such as TC_INITSCRIPT, TC_INITFUNCTION, TC_DAEMON, TC_TMPFS are not supported.

And my question is:

How can you work around this ? How can I run my testcontainer which will be mounted on TMPFS ?

Arminius answered 24/11, 2021 at 13:18 Comment(0)
H
5

You can try to set the TMPFS using a QuarkusTestResourceLifecycleManager guide.

Quarkus Kotlin example:


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
    }
}
Hydantoin answered 22/9, 2022 at 15:10 Comment(3)
Yup, in the end, I went with withTmpFs. Thanks for posting it -- I didn't have the time to do it myself.Deel
@Andreas Did you test that it works or this is just a suggestion ?Arminius
Tested and working @ArthurKlezovich Needed to add the line .withEnv(mapOf("PGDATA" to "/var/lib/postgresql/data")) to work properly.Hydantoin
B
1

You could try using the following configuration:

quarkus.datasource.url=jdbc:tc:postgresql:9.6.8:///databasename?TC_TMPFS=/testtmpfs:rw
Blague answered 19/9, 2022 at 0:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.