Skip to content

Instantly share code, notes, and snippets.

@codingtim
Last active August 27, 2016 09:51
Show Gist options
  • Save codingtim/9f53ff83172ad23f87055db463db1871 to your computer and use it in GitHub Desktop.
Save codingtim/9f53ff83172ad23f87055db463db1871 to your computer and use it in GitHub Desktop.
InMemoryMongo for elastic 2
public class InMemoryMongo {
private static final String DATA_PATH = "./target/elasticsearch";
private Node node;
private Client client;
public InMemoryMongo() {
}
public InMemoryMongo start() {
node = NodeBuilder.nodeBuilder()
//.loadConfigSettings(false)
.local(true).data(true).settings(Settings.builder()
.put(ClusterName.SETTING, "loggingTestCluster")
.put("node.name", "loggingTestNode")
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put("discovery.zen.ping.multicast", "false")
.put(EsExecutors.PROCESSORS, 1) // limit the number of threads created
.put("http.enabled", false)
.put("index.store.type", "default")
.put("gateway.type", "default")
.put("path.data", DATA_PATH)
.put("path.home", DATA_PATH)
).build();
node.start();
client = node.client();
return this;
}
public void stop() {
if (client != null) {
client.close();
}
if (node != null && !node.isClosed()) {
node.close();
FileSystemUtils.deleteRecursivly(Paths.get(DATA_PATH));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment