DEV Community

silaev
silaev

Posted on

Free alternative to MongoDB Atlas for testing and learning failures

Overview of My Submission

To test features like restartPrimaries with MongoDB Atlas one needs to use Dedicated Clusters requiring payments at hourly rates. This project is aimed to test and learn the behaviour of MongoDB while dealing with different failures locally completely for free. By writing a simple test case in Java, one can configure and create a replica set with a handy builder, use a bunch of helper methods like disconnectNodeFromNetwork, waitForMasterReelection, connectNodeToNetwork etc. and assert some possible changes in data or debug the pipeline to see what’s going on under the hood. An automatically initialised replica set also allows to test MongoDB version 4+ transactions. The project supports MongoDB versions from 3.6.14 up to the latest 5.0.5.

Submission Category:

Choose Your Own Adventure: Run MongoDB Atlas locally for testing.

Link to Code

GitHub logo silaev / mongodb-replica-set

Run MongoDB Atlas locally for testing

Run MongoDB Atlas locally for testing

build codecov

Prerequisite

  • Java 8+

  • Docker

  • Chart shows local and remote docker support for replicaSetNumber

    replicaSetNumber local docker host local docker host running tests from inside a container with mapping the Docker socket remote docker daemon availability of an arbiter node
    1 + + + -
    from 2 to 7 (including) only if adding either host.docker.internal (your Docker version should support it) or dockerhost to the OS host file. See Supported features for details + + +

Tip A single node replica set is the fastest among others. That is the default mode for MongoDbReplicaSet However, to use only it, consider the Testcontainers MongoDB module on GitHub

Getting it

  • Gradle:
dependencies {
    testCompile("com.github.silaev:mongodb-replica-set:${LATEST_RELEASE}")
}
Enter fullscreen mode Exit fullscreen mode
  • Maven:
<dependencies&gt
    <dependency>
        <groupId>com.github.silaev</groupId>
        <artifactId>mongodb-replica-set</artifactId>
        <version>${LATEST_RELEASE}</version>
        <scope>test</
Enter fullscreen mode Exit fullscreen mode

Additional Resources / Info

Discussion (0)