Giter Site home page Giter Site logo

jovikao / mongo-java-server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bwaldvogel/mongo-java-server

0.0 1.0 0.0 476 KB

Stub implementation of MongoDB in Java, that speaks the wire protocol.

License: BSD 3-Clause "New" or "Revised" License

Java 82.31% JavaScript 17.64% Shell 0.05%

mongo-java-server's Introduction

Build Status

MongoDB Java Server

Stub implementation of the core MongoDB server in Java. The MongoDB Wire Protocol is implemented with Netty. Different backends are possible and can be easily extended.

In-Memory backend

The in-memory backend is the default, such that mongo-java-server can be used as stub in unit tests. It does not support all features of the original MongoDB, and probably never will.

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.

Usage

Add the following Maven dependency to your project:

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

Unit test example

public class SimpleTest {

	private DBCollection collection;
	private MongoClient client;
	private MongoServer server;

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

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

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

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

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

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

		assertEquals(1, collection.count());
		assertEquals(obj, collection.findOne());
	}

}

Related Work

  • jmockmongo

    • shares the basic idea of implementing the wire protocol with Netty
    • focus on in-memory backend for unit testing
  • jongo

    • focus on unit testing
    • no wire protocol implementation
    • intercepts the java mongo driver
    • currently used in nosql-unit

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.