Yes, it does. If need be, you can separate data via a database name.
If you don’t use a framework, you are free to go with MongoClient#getDatabase("my-db").
However, a framework (for instance, Spring Data MongoDB) might get a db name from a url, that one can get via MongoDBContainer#getReplicaSetUrl(). There are 2 choices:
1) add as a workaround your db name to a url, like MongoDBContainer#getReplicaSetUrl() + "-my-db", which, for example, results in mongodb://localhost:32880/test-my-db. Just make sure that such a db name is unique for each test;
2) wait for this PR to be merged.
Tried your workaround solution on your PatchProductLoadITTest and ProductControllerITTest by adding:
testcontainers.reuse.enable=true to .testcontainers.properties
.withReuse(true) to MONGO_DB_CONTAINER
MONGO_DB_CONTAINER.getReplicaSetUrl()+"-my-db-N" to both tests (N=1 for PatchProductLoadITTest and N=2 for ProductControllerITTest)
But a container is not reused. How can I make it work?
Put it simply, my tests stop each MongoDBContainer in @AfterAll methods. I’ve added if (!MONGO_DB_CONTAINER.isShouldBeReused()) statement to stop MongoDBContainer only if we do not use Testcontainers' reusable feature. See this commit for more details. Thanks for you comment.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Yes, it does. If need be, you can separate data via a database name.
If you don’t use a framework, you are free to go with
MongoClient#getDatabase("my-db")
.However, a framework (for instance, Spring Data MongoDB) might get a db name from a url, that one can get via
MongoDBContainer#getReplicaSetUrl()
. There are 2 choices:1) add as a workaround your db name to a url, like
MongoDBContainer#getReplicaSetUrl() + "-my-db"
, which, for example, results inmongodb://localhost:32880/test-my-db
. Just make sure that such a db name is unique for each test;2) wait for this PR to be merged.
Tried your workaround solution on your PatchProductLoadITTest and ProductControllerITTest by adding:
Put it simply, my tests stop each
MongoDBContainer
in@AfterAll
methods. I’ve addedif (!MONGO_DB_CONTAINER.isShouldBeReused())
statement to stopMongoDBContainer
only if we do not use Testcontainers' reusable feature. See this commit for more details. Thanks for you comment.