问题
I'd like to run neo4j 2.3 completely in-memory as a standalone executable with a configurable port for test suites. My project's test suites are written in another language (NOT Java!), and will communicate with neo via the HTTP API.
Here is what I've discovered so far:
- The files in the standard build
conf/
directory don't seem to have a way to configure this. - There is a class CommunityServerBuilder that a public
build
method that returns aTestCommunityNeoServer
server that is pre-configured to be in-memory.
How would I go about using CommunityServerBuilder
to create and run an in-memory neo4j database? Or is there a config property within conf/
that will accomplish the same thing?
回答1:
You can set up a temporary in-memory filesystem (sometimes called a "RAM disk") and point your neo4j server to that (or a "subdirectory") for the DB location.
On Linux, you have several choices for setting up a RAM disk, including ramfs
and tmpfs
. Here is a write-up.
On OSX, there is a nice script for mounting a RAM disk. In the Finder, the RAM disk shows up as a device (probably with the name of "untitled") in the Devices list.
On Windows, there are many commercial packages for creating RAM disks, but this article shows how to use a free tool.
回答2:
For tests requiring a server instance use TestServerBuilder
or (when using junit) the test rule @Neo4jRule
. Both provide a in-process server suitable for testing. See code examples on its usage on http://neo4j.com/docs/stable/server-unmanaged-extensions-testing.html.
回答3:
Instead of going the custom CE route, how about the Java-based version?
- Download and unzip the java application.
- Use this to create your standard database configuration in a single directory tree
When you need to test,
- Create a RAM disk,
- Copy the standard database configuration to the RAM disk
- Alter the port in the neo4j-server.properties config file
org.neo4j.server.webserver.port=7474
- Start the server
- Conduct your test
- Stop the server / delete the RAM disk
来源:https://stackoverflow.com/questions/36361120/set-up-in-memory-database-instance-of-neo4j