All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.bwaldvogel.mongo.InMemoryMongoServer Maven / Gradle / Ivy

There is a newer version: 1.46.0
Show newest version
package de.bwaldvogel.mongo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.bwaldvogel.mongo.backend.memory.MemoryBackend;

public class InMemoryMongoServer extends MongoServer {

    private static final Logger log = LoggerFactory.getLogger(InMemoryMongoServer.class);

    public static void main(String[] args) throws Exception {
        final MongoServer mongoServer = new InMemoryMongoServer();
        mongoServer.bind("localhost", 27017);
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                log.info("shutting down {}", mongoServer);
                mongoServer.shutdownNow();
            }
        });
    }

    /**
     * creates a mongo server with in-memory backend
     */
    public InMemoryMongoServer() {
        super(new MemoryBackend());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy