de.bwaldvogel.mongo.InMemoryMongoServer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mongo-java-server-memory-backend Show documentation
Show all versions of mongo-java-server-memory-backend Show documentation
Fake implementation of MongoDB in Java that speaks the wire protocol
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