14

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

prasanna chouta
  • 149
  • 1
  • 4

2 Answers2

1

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.

peyman gilmour
  • 1,168
  • 2
  • 16
  • 35
  • Do you know if this has a java equivalent? – aemorales1 Oct 09 '20 at 14:12
  • 1
    @aemorales1 I am not sure but what a bout this : https://learn.microsoft.com/en-us/azure/cosmos-db/local-emulator?tabs=cli%2Cssl-netstd21 The downside of this approach is you have to install something on the local machine. – peyman gilmour Oct 10 '20 at 17:10
  • 1
    Thanks! I've started using test containers. Works for my needs. https://www.testcontainers.org/modules/databases/mongodb/ – aemorales1 Oct 13 '20 at 18:49
  • @peymangilmour how did you use CosmosClient with Mogo2Go? i am facing error "only https schemes are allowed" – Gurpreet Nov 10 '21 at 14:36
  • @Gurpreet 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? – peyman gilmour Nov 17 '21 at 11:47
  • @peymangilmour no it starts with mongodb://localhost – Gurpreet Nov 18 '21 at 13:16
  • @Gurpreet Probably using MongoClient is the key point. If you use Azure DevOps, please look at this link: https://learn.microsoft.com/en-us/azure/cosmos-db/tutorial-setup-ci-cd – peyman gilmour Nov 19 '21 at 13:03
  • @Gurpreet 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. – peyman gilmour Nov 19 '21 at 13:07
0

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.
jeancallisti
  • 1,046
  • 1
  • 11
  • 21