Skip to content

MongoDBContainer: simplify loading and executing java script files to init DB#3869

Closed
silaev wants to merge 51 commits intotestcontainers:mainfrom
silaev:mongodb_add_load_scripts_feature
Closed

MongoDBContainer: simplify loading and executing java script files to init DB#3869
silaev wants to merge 51 commits intotestcontainers:mainfrom
silaev:mongodb_add_load_scripts_feature

Conversation

@silaev
Copy link
Contributor

@silaev silaev commented Mar 10, 2021

MongoDBContainer runs with the --replSet command-line option to support testing features available only for a replica set. At the docker-entrypoint-initdb.d stage, a single replica set node is not yet initialised. For example, an attempt to write and read to non-initalised replica set leads to NotWritablePrimary and NotPrimaryNoSecondaryOk errors respectively. Therefore data manipulation might be done after initialisation stage.

This PR simplifies loading and executing java script files after container start-up. It also adds the fail-fast extra check of the docker-entrypoint-initdb.d directory to be empty before the initialisation of the replica set.

silaev and others added 30 commits October 7, 2019 16:57
…nfiguration for consistency, Move configure() to be a part of constructors
@silaev silaev changed the title Simplify loading and executing java script files MongoDBContainer: simplify loading and executing java script files Mar 10, 2021
@silaev silaev changed the title MongoDBContainer: simplify loading and executing java script files MongoDBContainer: simplify loading and executing java script files to init DB Mar 10, 2021
@stale
Copy link

stale bot commented Jun 18, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this is a mistake, please reply to this comment to keep it open. If there isn't one already, a PR to fix or at least reproduce the problem in a test case will always help us get back on track to tackle this.

@stale stale bot added the stale label Jun 18, 2021
@rnorth rnorth removed the stale label Jun 24, 2021
@liununu
Copy link

liununu commented Apr 25, 2022

Hi @silaev,

Thanks for your work to enhance the process of initialization data.
Before this PR gets merged into the master, may I confirm that if it's a workaround to use withCommand() to override withCommand("--replSet", "docker-rs") in the constructor when create the container instance, but the cost is losing the replica set feature?

Here is the snippet:

private val container: MongoDBContainer = MongoDBContainer("mongo:latest")
    .withCommand()
    .withCopyFileToContainer(
        MountableFile.forClasspathResource("init/init.js"),
        "/docker-entrypoint-initdb.d/init.js"
    )
    .waitingFor(Wait.forLogMessage("(?i).*waiting for connections.*", 2))
    .withStartupTimeout(Duration.ofSeconds(10))

@silaev
Copy link
Contributor Author

silaev commented Aug 8, 2022

Hi @silaev,

Thanks for your work to enhance the process of initialization data. Before this PR gets merged into the master, may I confirm that if it's a workaround to use withCommand() to override withCommand("--replSet", "docker-rs") in the constructor when create the container instance, but the cost is losing the replica set feature?

Here is the snippet:

private val container: MongoDBContainer = MongoDBContainer("mongo:latest")
    .withCommand()
    .withCopyFileToContainer(
        MountableFile.forClasspathResource("init/init.js"),
        "/docker-entrypoint-initdb.d/init.js"
    )
    .waitingFor(Wait.forLogMessage("(?i).*waiting for connections.*", 2))
    .withStartupTimeout(Duration.ofSeconds(10))

Hey there, sorry for answering late. Yes, that's right. Pls, find more on it here

@eddumelendez eddumelendez requested a review from a team November 19, 2024 22:04
@eddumelendez eddumelendez requested a review from a team as a code owner August 19, 2025 16:51
@eddumelendez
Copy link
Member

Superseded by #11331

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants