Add support for initialization scripts#11331
Add support for initialization scripts#11331taole33 wants to merge 7 commits intotestcontainers:mainfrom
Conversation
Running initialization scripts in MongoDB causes the container to restart, which previously required manual WaitStrategy adjustment. This commit adds 'withInitScript(String)' to automatically handle the script copy and adjust the WaitStrategy to expect two startup log messages. Fixes testcontainers#3066
There was a problem hiding this comment.
org.testcontainers.containers.MongoDBContainer is deprecated. can you moved to org.testcontainers.mongodb.MongoDBContainer?
There was a problem hiding this comment.
I moved to org.testcontainers.mongodb.MongoDBContainer.
Also, For the tests, instead of creating a new file named MongoDBInitScriptTest.java, I added the test cases directly to MongoDBContainerTest.java.
6665ad7 to
67088da
Compare
67088da to
e81a2ac
Compare
|
does this work with ReplicaSet and Sharded mode? New MongoDBContainer implementation has |
|
I updated In these modes, the default entrypoint mechanism conflicts with the cluster initialization scripts or is ignored. To fix this, I modified the logic to isolate the init script from the default directory when running in Cluster mode, and instead execute it manually after the container has started. ReasonIn Cluster modes (ReplicaSet/Sharding), relying on the default
Changes
Fixes #3066 |
There was a problem hiding this comment.
Can we use plain english, please?
There was a problem hiding this comment.
let's remove it. There is no difference with the previous test
There was a problem hiding this comment.
let's remove it. There is no difference with the previous test
|
@eddumelendez In this update, I also addressed an edge case regarding filenames containing special characters (e.g., I believe this covers all cases. Let me know if you have any further questions. |
Fixes #3066
Description
This PR adds support for initialization scripts in
MongoDBContainer.When an initialization script is placed in
/docker-entrypoint-initdb.d/, the official MongoDB image restarts the container process after executing the script. This behavior previously causedWaitStrategytimeouts because the container would stop and start again.Changes
withInitScript(String scriptPath)method toMongoDBContainer./docker-entrypoint-initdb.d/init.js.WaitStrategyto expect two "waiting for connections" log messages, ensuring the container is fully ready after the restart.Verification
MongoDBInitScriptTestto verify that the container starts successfully with an init script.