I am integrated my spring boot application with azure CosmosDB-SQL API and for integration test cases i want to use in memory database but trying with H2 in memory it's not working
what is the compatible in memory db for azure cosmos db
Asked Answered
In my previous project I used CosmosDB
and MongoDriver
. In the integration test I had to use in-memory DB so I used Mongo2Go. It has worked really good.
Do you know if this has a java equivalent? –
Kizzie
@Kizzie I am not sure but what a bout this : learn.microsoft.com/en-us/azure/cosmos-db/… The downside of this approach is you have to install something on the local machine. –
Ocampo
Thanks! I've started using test containers. Works for my needs. testcontainers.org/modules/databases/mongodb –
Kizzie
@peymangilmour how did you use CosmosClient with Mogo2Go? i am facing error "only https schemes are allowed" –
Crawley
@Crawley I use currently MongoDB.Driver version 2.13.0 and Mongo2Go version 2.2.16 in our integration test project. When you start Mongo2Go, Does the URL have Https? –
Ocampo
@peymangilmour no it starts with mongodb://localhost –
Crawley
@Crawley Probably using MongoClient is the key point. If you use Azure DevOps, please look at this link: learn.microsoft.com/en-us/azure/cosmos-db/tutorial-setup-ci-cd –
Ocampo
@Crawley The other approach would be creating docker compose for both your application and container based-CosmosDB. Run it in your pipeline first and then run the integration test. –
Ocampo
Extended answer : For a NoSQL cosmosDb, there is none. , i.e. there is no class library letting you instantiate a noSQL CosmosDb in memory for tests purposes, like you would instantiate, let's say, a SQL server db entirely in-memory.
Howerver, like the comments say, you can run a "CosmosDb emulator" on a machine of your choice, and make your code use it as a fake CosmosDb.
That implies:
- that you can install that emulator on your own machine if you run your test code locally,
OR
- that you can devise a deployment strategy to a container running that emulator (Docker or similar) so that this emulator can be used, for example, in your CD/CI pipeline in case it has a testing step before deployment.
© 2022 - 2024 — McMap. All rights reserved.