All Projects → bwaldvogel → Mongo Java Server

bwaldvogel / Mongo Java Server

Licence: bsd-3-clause
Fake implementation of MongoDB in Java that speaks the wire protocol.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Mongo Java Server

Spring Dubbo Service
微服务 spring dubbo项目:dubbo rpc;druid数据源连接池;mybatis配置集成,多数据源;jmx监控MBean;定时任务;aop;ftp;测试;Metrics监控;参数验证;跨域处理;shiro权限控制;consul服务注册,发现;redis分布式锁;SPI服务机制;cat监控;netty服务代理;websocket;disconf;mongodb集成;rest;docker;fescar
Stars: ✭ 224 (+6.16%)
Mutual labels:  mongodb, netty
Tutorial
Java全栈知识架构体系总结
Stars: ✭ 407 (+92.89%)
Mutual labels:  mongodb, netty
Vertx Zero
Zero Framework:http://www.vertxup.cn
Stars: ✭ 320 (+51.66%)
Mutual labels:  mongodb, netty
Springboot Templates
springboot和dubbo、netty的集成,redis mongodb的nosql模板, kafka rocketmq rabbit的MQ模板, solr solrcloud elasticsearch查询引擎
Stars: ✭ 100 (-52.61%)
Mutual labels:  mongodb, netty
Clusterdevicecontrolplatform
Java & Vue.js 全栈「集群设备管理云平台『后端部分』」,使用 Spring Boot、Netty 搭建 TCP 服务器与上万设备的集群通信,基于 JavaFX 的 GUI 应用程序模拟上万台设备的行为,并可对服务器进行压力测试。
Stars: ✭ 330 (+56.4%)
Mutual labels:  mongodb, netty
Almost Famous
🌟 Almost-Famous(成名之路) ——卡牌游戏开源项目,架构使用SpringBoot+Netty+Maven+SpringCloud来搭建多进程分布式框架,包括Cloud、Unique、Login、Game、Match、Battle 等服务。
Stars: ✭ 131 (-37.91%)
Mutual labels:  mongodb, netty
Trunk
Make bazel an out of box solution for C++/Java developers
Stars: ✭ 203 (-3.79%)
Mutual labels:  netty
Endb
Key-value storage for multiple databases. Supports MongoDB, MySQL, Postgres, Redis, and SQLite.
Stars: ✭ 208 (-1.42%)
Mutual labels:  mongodb
Koolreport
This is an Open Source PHP Reporting Framework which you can use to write perfect data reports or to construct awesome dashboards using PHP
Stars: ✭ 204 (-3.32%)
Mutual labels:  mongodb
Hivemq Mqtt Tensorflow Kafka Realtime Iot Machine Learning Training Inference
Real Time Big Data / IoT Machine Learning (Model Training and Inference) with HiveMQ (MQTT), TensorFlow IO and Apache Kafka - no additional data store like S3, HDFS or Spark required
Stars: ✭ 204 (-3.32%)
Mutual labels:  mongodb
Helidon
Java libraries for writing microservices
Stars: ✭ 2,554 (+1110.43%)
Mutual labels:  netty
Aspnetcore.identity.mongodb
MongoDB Data Store Adaptor for ASP.NET Core Identity
Stars: ✭ 210 (-0.47%)
Mutual labels:  mongodb
Mgodatagen
Generate random data for MongoDB
Stars: ✭ 206 (-2.37%)
Mutual labels:  mongodb
Mongoke
Instant Graphql for MongoDb (active branch is golang, rewrite in process)
Stars: ✭ 203 (-3.79%)
Mutual labels:  mongodb
Blackbelt Aks Hackfest
Microsoft Intelligent Cloud Blackbelt Team :: Hackfest Repo
Stars: ✭ 209 (-0.95%)
Mutual labels:  mongodb
Thunder
⚡️ Nepxion Thunder is a distribution RPC framework based on Netty + Hessian + Kafka + ActiveMQ + Tibco + Zookeeper + Redis + Spring Web MVC + Spring Boot + Docker 多协议、多组件、多序列化的分布式RPC调用框架
Stars: ✭ 204 (-3.32%)
Mutual labels:  netty
Mern Boilerplate
MERN stack project boilerplate
Stars: ✭ 211 (+0%)
Mutual labels:  mongodb
Gopush
分布式消息推送服务,可以用于客服、推送、聊天等诸多系统的 核心组件服务!
Stars: ✭ 204 (-3.32%)
Mutual labels:  netty
Mongodb.entities
A data access library for MongoDB with an elegant api, LINQ support and built-in entity relationship management
Stars: ✭ 204 (-3.32%)
Mutual labels:  mongodb
Inversify Express Example
The official express + inversify+ inversify-express-utils examples
Stars: ✭ 210 (-0.47%)
Mutual labels:  mongodb

CI Maven Central Coverage Status BSD 3-Clause License Donate

MongoDB Java Server

Fake implementation of the core MongoDB server in Java that can be used for integration tests.

Think of H2/HSQLDB/SQLite but for MongoDB.

The MongoDB Wire Protocol is implemented with Netty. Different backends are possible and can be extended.

In-Memory backend

The in-memory backend is the default backend that is typically used to fake MongoDB for integration tests. It supports most CRUD operations, commands and the aggregation framework. Some features are not yet implemented, such as full-text search or map/reduce.

Add the following Maven dependency to your project:

<dependency>
    <groupId>de.bwaldvogel</groupId>
    <artifactId>mongo-java-server</artifactId>
    <version>1.37.0</version>
</dependency>

Example

public class SimpleTest {

    private MongoCollection<Document> collection;
    private MongoClient client;
    private MongoServer server;

    @Before
    public void setUp() {
        server = new MongoServer(new MemoryBackend());

        // optionally:
        // server.enableSsl(key, keyPassword, certificate);
        // server.enableOplog();

        // bind on a random local port
        InetSocketAddress serverAddress = server.bind();

        client = new MongoClient(new ServerAddress(serverAddress));
        collection = client.getDatabase("testdb").getCollection("testcollection");
    }

    @After
    public void tearDown() {
        client.close();
        server.shutdown();
    }

    @Test
    public void testSimpleInsertQuery() throws Exception {
        assertEquals(0, collection.count());

        // creates the database and collection in memory and insert the object
        Document obj = new Document("_id", 1).append("key", "value");
        collection.insertOne(obj);

        assertEquals(1, collection.count());
        assertEquals(obj, collection.find().first());
    }

}

Example with SpringBoot

@RunWith(SpringRunner.class)
@SpringBootTest(classes={SimpleSpringBootTest.TestConfiguration.class})
public class SimpleSpringBootTest {

    @Autowired private MyRepository repository;

    @Before
    public void setUp() {
        // initialize your repository with some test data
        repository.deleteAll();
        repository.save(...);
    }

    @Test
    public void testMyRepository() {
        // test your repository ...
        ...
    }

    @Configuration
    @EnableMongoTestServer
    @EnableMongoRepositories(basePackageClasses={MyRepository.class})
    protected static class TestConfiguration {
        // test bean definitions ...
        ...
    }
}

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Import(MongoTestServerConfiguration.class)
public @interface EnableMongoTestServer {

}

public class MongoTestServerConfiguration {
	@Bean
	public MongoTemplate mongoTemplate(MongoDbFactory mongoDbFactory) {
		return new MongoTemplate(mongoDbFactory);
	}

	@Bean
	public MongoDbFactory mongoDbFactory(MongoServer mongoServer) {
		InetSocketAddress serverAddress = mongoServer.getLocalAddress();
		return new SimpleMongoClientDbFactory("mongodb://" + serverAddress.getHostName() + ":" + serverAddress.getPort() + "/test");
	}

	@Bean(destroyMethod = "shutdown")
	public MongoServer mongoServer() {
		MongoServer mongoServer = new MongoServer(new MemoryBackend());
		mongoServer.bind();
		return mongoServer;
	}
}

H2 MVStore backend

The H2 MVStore backend connects the server to a MVStore that can either be in-memory or on-disk.

<dependency>
    <groupId>de.bwaldvogel</groupId>
    <artifactId>mongo-java-server-h2-backend</artifactId>
    <version>1.37.0</version>
</dependency>

Example

public class Application {

    public static void main(String[] args) throws Exception {
        MongoServer server = new MongoServer(new H2Backend("database.mv"));
        server.bind("localhost", 27017);
    }

}

PostgreSQL backend

The PostgreSQL backend is a proof-of-concept implementation that connects the server to a database in a running PostgreSQL 9.5+ instance. Each MongoDB database is mapped to a schema in Postgres and each MongoDB collection is stored as a table.

<dependency>
    <groupId>de.bwaldvogel</groupId>
    <artifactId>mongo-java-server-postgresql-backend</artifactId>
    <version>1.37.0</version>
</dependency>

Example

public class Application {

    public static void main(String[] args) throws Exception {
        DataSource dataSource = new org.postgresql.jdbc3.Jdbc3PoolingDataSource();
        dataSource.setDatabaseName();
        dataSource.setUser();
        dataSource.setPassword();
        MongoServer server = new MongoServer(new PostgresqlBackend(dataSource));
        server.bind("localhost", 27017);
    }

}

Building a "fat" JAR that contains all dependencies

If you want to build a version that is not on Maven Central you can do the following:

  1. Build a "fat" JAR that includes all dependencies using "./gradlew shadowJar"
  2. Copy build/libs/mongo-java-server-[version]-all.jar to your project, e.g. to the libs directory.
  3. Import that folder (e.g. via Gradle using testCompile fileTree(dir: 'libs', include: '*.jar'))

Contributing

Please read the contributing guidelines if you want to contribute code to the project.

If you want to thank the author for this library or want to support the maintenance work, we are happy to receive a donation.

Donate

Ideas for other backends

Faulty backend

A faulty backend could randomly fail queries or cause timeouts. This could be used to test the client for error resilience.

Fuzzy backend

Fuzzing the wire protocol could be used to check the robustness of client drivers.

Related Work

  • Embedded MongoDB

    • Spins up a real MongoDB instance
  • fongo

    • focus on unit testing
    • no wire protocol implementation
    • intercepts the java mongo driver
    • currently used in nosql-unit
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].