Last active
August 27, 2016 09:51
-
-
Save codingtim/9f53ff83172ad23f87055db463db1871 to your computer and use it in GitHub Desktop.
InMemoryMongo for elastic 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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