diff --git a/elasticsearch/src/main/java/com/yahoo/ycsb/db/ElasticsearchClient.java b/elasticsearch/src/main/java/com/yahoo/ycsb/db/ElasticsearchClient.java index 6a95d9cefc64c905ebd7d3a6b2c559bf20e5b2f6..76ddee1d2eade0335f34b8977a5c3cd07dcf6cb9 100644 --- a/elasticsearch/src/main/java/com/yahoo/ycsb/db/ElasticsearchClient.java +++ b/elasticsearch/src/main/java/com/yahoo/ycsb/db/ElasticsearchClient.java @@ -82,20 +82,29 @@ public class ElasticsearchClient extends DB { */ @Override public void init() throws DBException { - Properties props = getProperties(); + final Properties props = getProperties(); + + // Check if transport client needs to be used (To connect to multiple + // elasticsearch nodes) + remoteMode = Boolean.parseBoolean(props.getProperty("es.remote", "false")); + + final String pathHome = props.getProperty("path.home"); + + // when running in embedded mode, require path.home + if (!remoteMode && (pathHome == null || pathHome.isEmpty())) { + throw new IllegalArgumentException("path.home must be specified when running in embedded mode"); + } + this.indexKey = props.getProperty("es.index.key", DEFAULT_INDEX_KEY); int numberOfShards = parseIntegerProperty(props, "es.number_of_shards", NUMBER_OF_SHARDS); int numberOfReplicas = parseIntegerProperty(props, "es.number_of_replicas", NUMBER_OF_REPLICAS); - // Check if transport client needs to be used (To connect to multiple - // elasticsearch nodes) - remoteMode = Boolean.parseBoolean(props.getProperty("es.remote", "false")); Boolean newdb = Boolean.parseBoolean(props.getProperty("es.newdb", "false")); Builder settings = Settings.settingsBuilder() .put("cluster.name", DEFAULT_CLUSTER_NAME) .put("node.local", Boolean.toString(!remoteMode)) - .put("path.home", System.getProperty("java.io.tmpdir")); + .put("path.home", pathHome); // if properties file contains elasticsearch user defined properties // add it to the settings file (will overwrite the defaults). diff --git a/elasticsearch/src/test/java/com/yahoo/ycsb/db/ElasticsearchClientTest.java b/elasticsearch/src/test/java/com/yahoo/ycsb/db/ElasticsearchClientTest.java index 3912c221ed96e816450a48b397a4a1350c72e57e..d1ad64d187e642cfd2bf2eabc50f853c478b2825 100644 --- a/elasticsearch/src/test/java/com/yahoo/ycsb/db/ElasticsearchClientTest.java +++ b/elasticsearch/src/test/java/com/yahoo/ycsb/db/ElasticsearchClientTest.java @@ -29,9 +29,13 @@ import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import java.util.HashMap; +import java.util.Properties; import java.util.Set; import java.util.Vector; @@ -39,6 +43,7 @@ import static org.junit.Assert.assertEquals; public class ElasticsearchClientTest { + @ClassRule public final static TemporaryFolder temp = new TemporaryFolder(); protected final static ElasticsearchClient instance = new ElasticsearchClient(); protected final static HashMap<String, ByteIterator> MOCK_DATA; protected final static String MOCK_TABLE = "MOCK_TABLE"; @@ -55,6 +60,9 @@ public class ElasticsearchClientTest { @BeforeClass public static void setUpClass() throws DBException { + final Properties props = new Properties(); + props.put("path.home", temp.getRoot().toString()); + instance.setProperties(props); instance.init(); }