diff --git a/docs/reference/analysis/tokenfilters/hunspell-tokenfilter.asciidoc b/docs/reference/analysis/tokenfilters/hunspell-tokenfilter.asciidoc index 8108614ab7457..47b247e4bd5ea 100644 --- a/docs/reference/analysis/tokenfilters/hunspell-tokenfilter.asciidoc +++ b/docs/reference/analysis/tokenfilters/hunspell-tokenfilter.asciidoc @@ -3,7 +3,7 @@ Basic support for hunspell stemming. Hunspell dictionaries will be picked up from a dedicated hunspell directory on the filesystem -(defaults to `/hunspell`). Each dictionary is expected to +(`/hunspell`). Each dictionary is expected to have its own directory named after its associated locale (language). This dictionary directory is expected to hold a single `*.aff` and one or more `*.dic` files (all of which will automatically be picked up). @@ -19,10 +19,6 @@ following directory layout will define the `en_US` dictionary: | | |-- en_US.aff -------------------------------------------------- -The location of the hunspell directory can be configured using the -`indices.analysis.hunspell.dictionary.location` settings in -_elasticsearch.yml_. - Each dictionary can be configured with one setting: `ignore_case`:: @@ -91,9 +87,9 @@ the stemming is determined by the quality of the dictionary. [float] ==== Dictionary loading -By default, the configured (`indices.analysis.hunspell.dictionary.location`) -or default Hunspell directory (`config/hunspell/`) is checked for dictionaries -when the node starts up, and any dictionaries are automatically loaded. +By default, the default Hunspell directory (`config/hunspell/`) is checked +for dictionaries when the node starts up, and any dictionaries are +automatically loaded. Dictionary loading can be deferred until they are actually used by setting `indices.analysis.hunspell.dictionary.lazy` to `true`in the config file. diff --git a/docs/reference/migration/migrate_2_0.asciidoc b/docs/reference/migration/migrate_2_0.asciidoc index 292bb633a2975..d940940674241 100644 --- a/docs/reference/migration/migrate_2_0.asciidoc +++ b/docs/reference/migration/migrate_2_0.asciidoc @@ -458,3 +458,8 @@ there is not enough disk space to complete this migration, the upgrade will be cancelled and can only be resumed once enough disk space is made available. The `index.store.distributor` setting has also been removed. + +=== Hunspell dictionary configuration + +The parameter `indices.analysis.hunspell.dictionary.location` has been removed, +and `/hunspell` is always used. diff --git a/src/main/java/org/elasticsearch/client/transport/TransportClient.java b/src/main/java/org/elasticsearch/client/transport/TransportClient.java index 2d62100ef0d08..a39089e9a5abf 100644 --- a/src/main/java/org/elasticsearch/client/transport/TransportClient.java +++ b/src/main/java/org/elasticsearch/client/transport/TransportClient.java @@ -103,14 +103,6 @@ public class TransportClient extends AbstractClient { private final TransportClientNodesService nodesService; private final InternalTransportClient internalClient; - /** - * Constructs a new transport client with settings loaded either from the classpath or the file system (the - * elasticsearch.(yml|json) files optionally prefixed with config/). - */ - public TransportClient() { - this(ImmutableSettings.Builder.EMPTY_SETTINGS, true); - } - /** * Constructs a new transport client with explicit settings and settings loaded either from the classpath or the file * system (the elasticsearch.(yml|json) files optionally prefixed with config/). diff --git a/src/main/java/org/elasticsearch/env/Environment.java b/src/main/java/org/elasticsearch/env/Environment.java index cab04792b5d7a..46947c5667c32 100644 --- a/src/main/java/org/elasticsearch/env/Environment.java +++ b/src/main/java/org/elasticsearch/env/Environment.java @@ -32,7 +32,6 @@ import java.util.ArrayList; import static org.elasticsearch.common.Strings.cleanPath; -import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS; /** * The environment of where things exists. @@ -69,16 +68,12 @@ public class Environment { fileStores = allStores.toArray(new ESFileStore[allStores.size()]); } - public Environment() { - this(EMPTY_SETTINGS); - } - public Environment(Settings settings) { this.settings = settings; if (settings.get("path.home") != null) { homeFile = PathUtils.get(cleanPath(settings.get("path.home"))); } else { - homeFile = PathUtils.get(System.getProperty("user.dir")); + throw new IllegalStateException("path.home is not configured"); } if (settings.get("path.conf") != null) { @@ -175,26 +170,13 @@ public FileStore getFileStore(Path path) throws IOException { } public URL resolveConfig(String path) throws FailedToResolveConfigException { - String origPath = path; - // first, try it as a path on the file system - Path f1 = PathUtils.get(path); - if (Files.exists(f1)) { - try { - return f1.toUri().toURL(); - } catch (MalformedURLException e) { - throw new FailedToResolveConfigException("Failed to resolve path [" + f1 + "]", e); - } - } - if (path.startsWith("/")) { - path = path.substring(1); - } - // next, try it relative to the config location - Path f2 = configFile.resolve(path); - if (Files.exists(f2)) { + // first, try it as a path in the config directory + Path f = configFile.resolve(path); + if (Files.exists(f)) { try { - return f2.toUri().toURL(); + return f.toUri().toURL(); } catch (MalformedURLException e) { - throw new FailedToResolveConfigException("Failed to resolve path [" + f1 + "]", e); + throw new FailedToResolveConfigException("Failed to resolve path [" + f + "]", e); } } // try and load it from the classpath directly @@ -209,6 +191,6 @@ public URL resolveConfig(String path) throws FailedToResolveConfigException { return resource; } } - throw new FailedToResolveConfigException("Failed to resolve config path [" + origPath + "], tried file path [" + f1 + "], path file [" + f2 + "], and classpath"); + throw new FailedToResolveConfigException("Failed to resolve config path [" + path + "], tried config path [" + f + "] and classpath"); } } diff --git a/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java b/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java index ccb49a6fd2a2d..83b9a51b0c8b1 100644 --- a/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java +++ b/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java @@ -74,7 +74,7 @@ public class HunspellService extends AbstractComponent { public final static String HUNSPELL_LAZY_LOAD = "indices.analysis.hunspell.dictionary.lazy"; public final static String HUNSPELL_IGNORE_CASE = "indices.analysis.hunspell.dictionary.ignore_case"; - public final static String HUNSPELL_LOCATION = "indices.analysis.hunspell.dictionary.location"; + private final static String OLD_HUNSPELL_LOCATION = "indices.analysis.hunspell.dictionary.location"; private final LoadingCache dictionaries; private final Map knownDictionaries; @@ -116,9 +116,9 @@ public Dictionary getDictionary(String locale) { } private Path resolveHunspellDirectory(Settings settings, Environment env) { - String location = settings.get(HUNSPELL_LOCATION, null); + String location = settings.get(OLD_HUNSPELL_LOCATION, null); if (location != null) { - return PathUtils.get(location); + throw new IllegalArgumentException("please, put your hunspell dictionaries under config/hunspell !"); } return env.configFile().resolve("hunspell"); } diff --git a/src/main/java/org/elasticsearch/tribe/TribeService.java b/src/main/java/org/elasticsearch/tribe/TribeService.java index 51cb9d0ecab4d..d0cfe76581726 100644 --- a/src/main/java/org/elasticsearch/tribe/TribeService.java +++ b/src/main/java/org/elasticsearch/tribe/TribeService.java @@ -127,6 +127,7 @@ public TribeService(Settings settings, ClusterService clusterService, DiscoveryS for (Map.Entry entry : nodesSettings.entrySet()) { ImmutableSettings.Builder sb = ImmutableSettings.builder().put(entry.getValue()); sb.put("node.name", settings.get("name") + "/" + entry.getKey()); + sb.put("path.home", settings.get("path.home")); // pass through ES home dir sb.put(TRIBE_NAME, entry.getKey()); sb.put("config.ignore_system_properties", true); if (sb.get("http.enabled") == null) { diff --git a/src/main/resources/org/elasticsearch/bootstrap/security.policy b/src/main/resources/org/elasticsearch/bootstrap/security.policy index 438fa87d333a5..993868c18b3b0 100644 --- a/src/main/resources/org/elasticsearch/bootstrap/security.policy +++ b/src/main/resources/org/elasticsearch/bootstrap/security.policy @@ -31,8 +31,9 @@ grant { permission java.io.FilePermission "${java.io.tmpdir}${/}-", "read,write,delete"; // paths used for running tests - // project base directory - permission java.io.FilePermission "${project.basedir}${/}target${/}-", "read"; + // compiled classes + permission java.io.FilePermission "${project.basedir}${/}target${/}classes${/}-", "read"; + permission java.io.FilePermission "${project.basedir}${/}target${/}test-classes${/}-", "read"; // read permission for lib sigar permission java.io.FilePermission "${project.basedir}${/}lib${/}sigar${/}-", "read"; // mvn custom ./m2/repository for dependency jars diff --git a/src/test/java/org/elasticsearch/action/bulk/BulkProcessorTests.java b/src/test/java/org/elasticsearch/action/bulk/BulkProcessorTests.java index e357206bc386d..68a11b0b8e54e 100644 --- a/src/test/java/org/elasticsearch/action/bulk/BulkProcessorTests.java +++ b/src/test/java/org/elasticsearch/action/bulk/BulkProcessorTests.java @@ -29,6 +29,7 @@ import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; @@ -157,7 +158,10 @@ public void testBulkProcessorConcurrentRequests() throws Exception { //https://github.com/elasticsearch/elasticsearch/issues/5038 public void testBulkProcessorConcurrentRequestsNoNodeAvailableException() throws Exception { //we create a transport client with no nodes to make sure it throws NoNodeAvailableException - Client transportClient = new TransportClient(); + Settings settings = ImmutableSettings.builder() + .put("path.home", createTempDir().toString()) + .build(); + Client transportClient = new TransportClient(settings); int bulkActions = randomIntBetween(10, 100); int numDocs = randomIntBetween(bulkActions, bulkActions + 100); diff --git a/src/test/java/org/elasticsearch/action/count/CountRequestBuilderTests.java b/src/test/java/org/elasticsearch/action/count/CountRequestBuilderTests.java index 22387d277e87b..85bb2a384cc8a 100644 --- a/src/test/java/org/elasticsearch/action/count/CountRequestBuilderTests.java +++ b/src/test/java/org/elasticsearch/action/count/CountRequestBuilderTests.java @@ -23,6 +23,8 @@ import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentHelper; @@ -46,7 +48,10 @@ public class CountRequestBuilderTests extends ElasticsearchTestCase { public static void initClient() { //this client will not be hit by any request, but it needs to be a non null proper client //that is why we create it but we don't add any transport address to it - client = new TransportClient(); + Settings settings = ImmutableSettings.builder() + .put("path.home", createTempDir().toString()) + .build(); + client = new TransportClient(settings); } @AfterClass diff --git a/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java b/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java index 57a48bbbcc0bf..9b4b8bc77b874 100644 --- a/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java +++ b/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java @@ -21,6 +21,8 @@ import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentHelper; @@ -45,7 +47,10 @@ public class SearchRequestBuilderTests extends ElasticsearchTestCase { public static void initClient() { //this client will not be hit by any request, but it needs to be a non null proper client //that is why we create it but we don't add any transport address to it - client = new TransportClient(); + Settings settings = ImmutableSettings.builder() + .put("path.home", createTempDir().toString()) + .build(); + client = new TransportClient(settings); } @AfterClass diff --git a/src/test/java/org/elasticsearch/client/AbstractClientHeadersTests.java b/src/test/java/org/elasticsearch/client/AbstractClientHeadersTests.java index e4484ef3177a6..c9c7a9fdf525d 100644 --- a/src/test/java/org/elasticsearch/client/AbstractClientHeadersTests.java +++ b/src/test/java/org/elasticsearch/client/AbstractClientHeadersTests.java @@ -90,8 +90,12 @@ public abstract class AbstractClientHeadersTests extends ElasticsearchTestCase { @Before public void initClient() { + Settings settings = ImmutableSettings.builder() + .put(HEADER_SETTINGS) + .put("path.home", createTempDir().toString()) + .build(); threadPool = new ThreadPool("test-" + getTestName()); - client = buildClient(HEADER_SETTINGS, ACTIONS); + client = buildClient(settings, ACTIONS); } @After diff --git a/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java b/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java index c744c3cd7ee6a..07dd7f9c73d80 100644 --- a/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java +++ b/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java @@ -59,7 +59,7 @@ protected Client buildClient(Settings headersSettings, GenericAction[] testedAct .put("client.transport.sniff", false) .put("node.name", "transport_client_" + this.getTestName()) .put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, InternalTransportService.class.getName()) - .put(HEADER_SETTINGS) + .put(headersSettings) .build()); client.addTransportAddress(address); @@ -75,6 +75,7 @@ public void testWithSniffing() throws Exception { .put("client.transport.nodes_sampler_interval", "1s") .put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, InternalTransportService.class.getName()) .put(HEADER_SETTINGS) + .put("path.home", createTempDir().toString()) .build()); try { client.addTransportAddress(address); diff --git a/src/test/java/org/elasticsearch/client/transport/TransportClientRetryTests.java b/src/test/java/org/elasticsearch/client/transport/TransportClientRetryTests.java index 17e3c0c5d87f1..3e8c2b09f3811 100644 --- a/src/test/java/org/elasticsearch/client/transport/TransportClientRetryTests.java +++ b/src/test/java/org/elasticsearch/client/transport/TransportClientRetryTests.java @@ -62,7 +62,8 @@ public void testRetry() throws IOException, ExecutionException, InterruptedExcep .put("node.mode", InternalTestCluster.nodeMode()) .put("plugins." + PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false) .put(ClusterName.SETTING, internalCluster().getClusterName()) - .put("config.ignore_system_properties", true); + .put("config.ignore_system_properties", true) + .put("path.home", createTempDir()); try (TransportClient transportClient = new TransportClient(builder.build())) { transportClient.addTransportAddresses(addresses); diff --git a/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java b/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java index 8e347935241b0..b540800c5d190 100644 --- a/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java +++ b/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; -import org.elasticsearch.index.store.IndexStoreModule; import org.elasticsearch.node.Node; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope; @@ -35,7 +34,10 @@ import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; import static org.elasticsearch.node.NodeBuilder.nodeBuilder; import static org.elasticsearch.test.ElasticsearchIntegrationTest.Scope; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.startsWith; @ClusterScope(scope = Scope.TEST, numDataNodes = 0, transportClientRatio = 1.0) public class TransportClientTests extends ElasticsearchIntegrationTest { @@ -92,7 +94,8 @@ public void testThatTransportClientSettingIsSet() { @Test public void testThatTransportClientSettingCannotBeChanged() { - try (TransportClient client = new TransportClient(settingsBuilder().put(Client.CLIENT_TYPE_SETTING, "anything"))) { + Settings baseSettings = settingsBuilder().put(Client.CLIENT_TYPE_SETTING, "anything").put("path.home", createTempDir()).build(); + try (TransportClient client = new TransportClient(baseSettings)) { Settings settings = client.injector.getInstance(Settings.class); assertThat(settings.get(Client.CLIENT_TYPE_SETTING), is("transport")); } diff --git a/src/test/java/org/elasticsearch/common/cli/CheckFileCommandTests.java b/src/test/java/org/elasticsearch/common/cli/CheckFileCommandTests.java index 112d8969433a5..0d131af78ae2c 100644 --- a/src/test/java/org/elasticsearch/common/cli/CheckFileCommandTests.java +++ b/src/test/java/org/elasticsearch/common/cli/CheckFileCommandTests.java @@ -54,73 +54,73 @@ private enum Mode { @Test public void testThatCommandLogsErrorMessageOnFail() throws Exception { - executeCommand(jimFsConfiguration, new PermissionCheckFileCommand(captureOutputTerminal, Mode.CHANGE)); + executeCommand(jimFsConfiguration, new PermissionCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.CHANGE)); assertThat(captureOutputTerminal.getTerminalOutput(), hasItem(containsString("Please ensure that the user account running Elasticsearch has read access to this file"))); } @Test public void testThatCommandLogsNothingWhenPermissionRemains() throws Exception { - executeCommand(jimFsConfiguration, new PermissionCheckFileCommand(captureOutputTerminal, Mode.KEEP)); + executeCommand(jimFsConfiguration, new PermissionCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.KEEP)); assertThat(captureOutputTerminal.getTerminalOutput(), hasSize(0)); } @Test public void testThatCommandLogsNothingWhenDisabled() throws Exception { - executeCommand(jimFsConfiguration, new PermissionCheckFileCommand(captureOutputTerminal, Mode.DISABLED)); + executeCommand(jimFsConfiguration, new PermissionCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.DISABLED)); assertThat(captureOutputTerminal.getTerminalOutput(), hasSize(0)); } @Test public void testThatCommandLogsNothingIfFilesystemDoesNotSupportPermissions() throws Exception { - executeCommand(jimFsConfigurationWithoutPermissions, new PermissionCheckFileCommand(captureOutputTerminal, Mode.DISABLED)); + executeCommand(jimFsConfigurationWithoutPermissions, new PermissionCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.DISABLED)); assertThat(captureOutputTerminal.getTerminalOutput(), hasSize(0)); } @Test public void testThatCommandLogsOwnerChange() throws Exception { - executeCommand(jimFsConfiguration, new OwnerCheckFileCommand(captureOutputTerminal, Mode.CHANGE)); + executeCommand(jimFsConfiguration, new OwnerCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.CHANGE)); assertThat(captureOutputTerminal.getTerminalOutput(), hasItem(allOf(containsString("Owner of file ["), containsString("] used to be ["), containsString("], but now is [")))); } @Test public void testThatCommandLogsNothingIfOwnerRemainsSame() throws Exception { - executeCommand(jimFsConfiguration, new OwnerCheckFileCommand(captureOutputTerminal, Mode.KEEP)); + executeCommand(jimFsConfiguration, new OwnerCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.KEEP)); assertThat(captureOutputTerminal.getTerminalOutput(), hasSize(0)); } @Test public void testThatCommandLogsNothingIfOwnerIsDisabled() throws Exception { - executeCommand(jimFsConfiguration, new OwnerCheckFileCommand(captureOutputTerminal, Mode.DISABLED)); + executeCommand(jimFsConfiguration, new OwnerCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.DISABLED)); assertThat(captureOutputTerminal.getTerminalOutput(), hasSize(0)); } @Test public void testThatCommandLogsNothingIfFileSystemDoesNotSupportOwners() throws Exception { - executeCommand(jimFsConfigurationWithoutPermissions, new OwnerCheckFileCommand(captureOutputTerminal, Mode.DISABLED)); + executeCommand(jimFsConfigurationWithoutPermissions, new OwnerCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.DISABLED)); assertThat(captureOutputTerminal.getTerminalOutput(), hasSize(0)); } @Test public void testThatCommandLogsIfGroupChanges() throws Exception { - executeCommand(jimFsConfiguration, new GroupCheckFileCommand(captureOutputTerminal, Mode.CHANGE)); + executeCommand(jimFsConfiguration, new GroupCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.CHANGE)); assertThat(captureOutputTerminal.getTerminalOutput(), hasItem(allOf(containsString("Group of file ["), containsString("] used to be ["), containsString("], but now is [")))); } @Test public void testThatCommandLogsNothingIfGroupRemainsSame() throws Exception { - executeCommand(jimFsConfiguration, new GroupCheckFileCommand(captureOutputTerminal, Mode.KEEP)); + executeCommand(jimFsConfiguration, new GroupCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.KEEP)); assertThat(captureOutputTerminal.getTerminalOutput(), hasSize(0)); } @Test public void testThatCommandLogsNothingIfGroupIsDisabled() throws Exception { - executeCommand(jimFsConfiguration, new GroupCheckFileCommand(captureOutputTerminal, Mode.DISABLED)); + executeCommand(jimFsConfiguration, new GroupCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.DISABLED)); assertThat(captureOutputTerminal.getTerminalOutput(), hasSize(0)); } @Test public void testThatCommandLogsNothingIfFileSystemDoesNotSupportGroups() throws Exception { - executeCommand(jimFsConfigurationWithoutPermissions, new GroupCheckFileCommand(captureOutputTerminal, Mode.DISABLED)); + executeCommand(jimFsConfigurationWithoutPermissions, new GroupCheckFileCommand(createTempDir(), captureOutputTerminal, Mode.DISABLED)); assertThat(captureOutputTerminal.getTerminalOutput(), hasSize(0)); } @@ -130,7 +130,10 @@ public void testThatCommandDoesNotLogAnythingOnFileCreation() throws Exception { try (FileSystem fs = Jimfs.newFileSystem(configuration)) { Path path = fs.getPath(randomAsciiOfLength(10)); - new CreateFileCommand(captureOutputTerminal, path).execute(ImmutableSettings.EMPTY, new Environment(ImmutableSettings.EMPTY)); + Settings settings = ImmutableSettings.builder() + .put("path.home", createTempDir().toString()) + .build(); + new CreateFileCommand(captureOutputTerminal, path).execute(settings, new Environment(settings)); assertThat(Files.exists(path), is(true)); } @@ -145,7 +148,10 @@ public void testThatCommandWorksIfFileIsDeletedByCommand() throws Exception { Path path = fs.getPath(randomAsciiOfLength(10)); Files.write(path, "anything".getBytes(Charsets.UTF_8)); - new DeleteFileCommand(captureOutputTerminal, path).execute(ImmutableSettings.EMPTY, new Environment(ImmutableSettings.EMPTY)); + Settings settings = ImmutableSettings.builder() + .put("path.home", createTempDir().toString()) + .build(); + new DeleteFileCommand(captureOutputTerminal, path).execute(settings, new Environment(settings)); assertThat(Files.exists(path), is(false)); } @@ -163,16 +169,21 @@ abstract class AbstractTestCheckFileCommand extends CheckFileCommand { protected final Mode mode; protected FileSystem fs; protected Path[] paths; + final Path baseDir; - public AbstractTestCheckFileCommand(Terminal terminal, Mode mode) throws IOException { + public AbstractTestCheckFileCommand(Path baseDir, Terminal terminal, Mode mode) throws IOException { super(terminal); this.mode = mode; + this.baseDir = baseDir; } public CliTool.ExitStatus execute(FileSystem fs) throws Exception { this.fs = fs; this.paths = new Path[] { writePath(fs, "p1", "anything"), writePath(fs, "p2", "anything"), writePath(fs, "p3", "anything") }; - return super.execute(ImmutableSettings.EMPTY, new Environment(ImmutableSettings.EMPTY)); + Settings settings = ImmutableSettings.settingsBuilder() + .put("path.home", baseDir.toString()) + .build(); + return super.execute(ImmutableSettings.EMPTY, new Environment(settings)); } private Path writePath(FileSystem fs, String name, String content) throws IOException { @@ -192,8 +203,8 @@ protected Path[] pathsForPermissionsCheck(Settings settings, Environment env) { */ class PermissionCheckFileCommand extends AbstractTestCheckFileCommand { - public PermissionCheckFileCommand(Terminal terminal, Mode mode) throws IOException { - super(terminal, mode); + public PermissionCheckFileCommand(Path baseDir, Terminal terminal, Mode mode) throws IOException { + super(baseDir, terminal, mode); } @Override @@ -221,8 +232,8 @@ public CliTool.ExitStatus doExecute(Settings settings, Environment env) throws E */ class OwnerCheckFileCommand extends AbstractTestCheckFileCommand { - public OwnerCheckFileCommand(Terminal terminal, Mode mode) throws IOException { - super(terminal, mode); + public OwnerCheckFileCommand(Path baseDir, Terminal terminal, Mode mode) throws IOException { + super(baseDir, terminal, mode); } @Override @@ -251,8 +262,8 @@ public CliTool.ExitStatus doExecute(Settings settings, Environment env) throws E */ class GroupCheckFileCommand extends AbstractTestCheckFileCommand { - public GroupCheckFileCommand(Terminal terminal, Mode mode) throws IOException { - super(terminal, mode); + public GroupCheckFileCommand(Path baseDir, Terminal terminal, Mode mode) throws IOException { + super(baseDir, terminal, mode); } @Override diff --git a/src/test/java/org/elasticsearch/common/cli/CliToolTestCase.java b/src/test/java/org/elasticsearch/common/cli/CliToolTestCase.java index df633b57c7b2b..278869388cede 100644 --- a/src/test/java/org/elasticsearch/common/cli/CliToolTestCase.java +++ b/src/test/java/org/elasticsearch/common/cli/CliToolTestCase.java @@ -22,6 +22,8 @@ import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.common.Strings; import org.elasticsearch.test.ElasticsearchTestCase; +import org.junit.After; +import org.junit.Before; import org.junit.Ignore; import java.io.IOException; @@ -37,6 +39,16 @@ @Ignore public abstract class CliToolTestCase extends ElasticsearchTestCase { + @Before + public void setPathHome() { + System.setProperty("es.default.path.home", createTempDir().toString()); + } + + @After + public void clearPathHome() { + System.clearProperty("es.default.path.home"); + } + protected static String[] args(String command) { if (!Strings.hasLength(command)) { return Strings.EMPTY_ARRAY; diff --git a/src/test/java/org/elasticsearch/common/logging/log4j/Log4jESLoggerTests.java b/src/test/java/org/elasticsearch/common/logging/log4j/Log4jESLoggerTests.java index c39c8a5b90f34..24df66c77e8f2 100644 --- a/src/test/java/org/elasticsearch/common/logging/log4j/Log4jESLoggerTests.java +++ b/src/test/java/org/elasticsearch/common/logging/log4j/Log4jESLoggerTests.java @@ -56,6 +56,7 @@ public void setUp() throws Exception { // Need to set custom path.conf so we can use a custom logging.yml file for the test Settings settings = ImmutableSettings.builder() .put("path.conf", configDir.toAbsolutePath()) + .put("path.home", createTempDir().toString()) .build(); LogConfigurator.configure(settings); diff --git a/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java b/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java index b53b434a49241..1010ea734b38c 100644 --- a/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java +++ b/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java @@ -59,6 +59,7 @@ public void testResolveMultipleConfigs() throws Exception { Path configDir = getDataPath("config"); Settings settings = ImmutableSettings.builder() .put("path.conf", configDir.toAbsolutePath()) + .put("path.home", createTempDir().toString()) .build(); LogConfigurator.configure(settings); @@ -87,7 +88,10 @@ public void testResolveJsonLoggingConfig() throws Exception { Path loggingConf = tmpDir.resolve(loggingConfiguration("json")); Files.write(loggingConf, "{\"json\": \"foo\"}".getBytes(StandardCharsets.UTF_8)); Environment environment = new Environment( - ImmutableSettings.builder().put("path.conf", tmpDir.toAbsolutePath()).build()); + ImmutableSettings.builder() + .put("path.conf", tmpDir.toAbsolutePath()) + .put("path.home", createTempDir().toString()) + .build()); ImmutableSettings.Builder builder = ImmutableSettings.builder(); LogConfigurator.resolveConfig(environment, builder); @@ -102,7 +106,10 @@ public void testResolvePropertiesLoggingConfig() throws Exception { Path loggingConf = tmpDir.resolve(loggingConfiguration("properties")); Files.write(loggingConf, "key: value".getBytes(StandardCharsets.UTF_8)); Environment environment = new Environment( - ImmutableSettings.builder().put("path.conf", tmpDir.toAbsolutePath()).build()); + ImmutableSettings.builder() + .put("path.conf", tmpDir.toAbsolutePath()) + .put("path.home", createTempDir().toString()) + .build()); ImmutableSettings.Builder builder = ImmutableSettings.builder(); LogConfigurator.resolveConfig(environment, builder); @@ -119,7 +126,10 @@ public void testResolveYamlLoggingConfig() throws Exception { Files.write(loggingConf1, "yml: bar".getBytes(StandardCharsets.UTF_8)); Files.write(loggingConf2, "yaml: bar".getBytes(StandardCharsets.UTF_8)); Environment environment = new Environment( - ImmutableSettings.builder().put("path.conf", tmpDir.toAbsolutePath()).build()); + ImmutableSettings.builder() + .put("path.conf", tmpDir.toAbsolutePath()) + .put("path.home", createTempDir().toString()) + .build()); ImmutableSettings.Builder builder = ImmutableSettings.builder(); LogConfigurator.resolveConfig(environment, builder); @@ -135,7 +145,10 @@ public void testResolveConfigInvalidFilename() throws Exception { Path invalidSuffix = tmpDir.resolve(loggingConfiguration(randomFrom(LogConfigurator.ALLOWED_SUFFIXES)) + randomInvalidSuffix()); Files.write(invalidSuffix, "yml: bar".getBytes(StandardCharsets.UTF_8)); Environment environment = new Environment( - ImmutableSettings.builder().put("path.conf", invalidSuffix.toAbsolutePath()).build()); + ImmutableSettings.builder() + .put("path.conf", invalidSuffix.toAbsolutePath()) + .put("path.home", createTempDir().toString()) + .build()); ImmutableSettings.Builder builder = ImmutableSettings.builder(); LogConfigurator.resolveConfig(environment, builder); diff --git a/src/test/java/org/elasticsearch/index/analysis/ASCIIFoldingTokenFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/ASCIIFoldingTokenFilterFactoryTests.java index 04413f5d41ef8..70f12cdd401bb 100644 --- a/src/test/java/org/elasticsearch/index/analysis/ASCIIFoldingTokenFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/ASCIIFoldingTokenFilterFactoryTests.java @@ -33,6 +33,7 @@ public class ASCIIFoldingTokenFilterFactoryTests extends ElasticsearchTokenStrea @Test public void testDefault() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_ascii_folding.type", "asciifolding") .build()); TokenFilterFactory tokenFilter = analysisService.tokenFilter("my_ascii_folding"); @@ -46,6 +47,7 @@ public void testDefault() throws IOException { @Test public void testPreserveOriginal() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_ascii_folding.type", "asciifolding") .put("index.analysis.filter.my_ascii_folding.preserve_original", true) .build()); diff --git a/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java b/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java index 81f06ad79d78c..8fb9a29488ff7 100644 --- a/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java @@ -77,8 +77,11 @@ public AnalysisService getAnalysisService(Settings settings) { return injector.getInstance(AnalysisService.class); } - private static Settings loadFromClasspath(String path) { - return settingsBuilder().loadFromClasspath(path).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); + private Settings loadFromClasspath(String path) { + return settingsBuilder().loadFromClasspath(path) + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put("path.home", createTempDir().toString()) + .build(); } @@ -103,8 +106,11 @@ public void testDefaultFactoryTokenFilters() throws IOException { @Test public void testVersionedAnalyzers() throws Exception { - Settings settings2 = settingsBuilder().loadFromClasspath("org/elasticsearch/index/analysis/test1.yml") - .put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_0_90_0).build(); + Settings settings2 = settingsBuilder() + .loadFromClasspath("org/elasticsearch/index/analysis/test1.yml") + .put("path.home", createTempDir().toString()) + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_0_90_0) + .build(); AnalysisService analysisService2 = getAnalysisService(settings2); // indicesanalysisservice always has the current version @@ -121,7 +127,10 @@ public void testVersionedAnalyzers() throws Exception { } private void assertTokenFilter(String name, Class clazz) throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(ImmutableSettings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build()); + Settings settings = ImmutableSettings.settingsBuilder() + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put("path.home", createTempDir().toString()).build(); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter(name); Tokenizer tokenizer = new WhitespaceTokenizer(); tokenizer.setReader(new StringReader("foo bar")); @@ -199,11 +208,14 @@ private void testSimpleConfiguration(Settings settings) { @Test public void testWordListPath() throws Exception { - Environment env = new Environment(ImmutableSettings.Builder.EMPTY_SETTINGS); + Settings settings = ImmutableSettings.builder() + .put("path.home", createTempDir().toString()) + .build(); + Environment env = new Environment(settings); String[] words = new String[]{"donau", "dampf", "schiff", "spargel", "creme", "suppe"}; Path wordListFile = generateWordList(words); - Settings settings = settingsBuilder().loadFromSource("index: \n word_list_path: " + wordListFile.toAbsolutePath()).build(); + settings = settingsBuilder().loadFromSource("index: \n word_list_path: " + wordListFile.toAbsolutePath()).build(); Set wordList = Analysis.getWordSet(env, settings, "index.word_list"); MatcherAssert.assertThat(wordList.size(), equalTo(6)); diff --git a/src/test/java/org/elasticsearch/index/analysis/AnalysisTestsHelper.java b/src/test/java/org/elasticsearch/index/analysis/AnalysisTestsHelper.java index 5a853c8f73869..ea52f71e94ae7 100644 --- a/src/test/java/org/elasticsearch/index/analysis/AnalysisTestsHelper.java +++ b/src/test/java/org/elasticsearch/index/analysis/AnalysisTestsHelper.java @@ -34,11 +34,15 @@ import org.elasticsearch.indices.analysis.IndicesAnalysisModule; import org.elasticsearch.indices.analysis.IndicesAnalysisService; +import java.nio.file.Path; + public class AnalysisTestsHelper { - public static AnalysisService createAnalysisServiceFromClassPath(String resource) { + public static AnalysisService createAnalysisServiceFromClassPath(Path baseDir, String resource) { Settings settings = ImmutableSettings.settingsBuilder() - .loadFromClasspath(resource).build(); + .loadFromClasspath(resource) + .put("path.home", baseDir.toString()) + .build(); return createAnalysisServiceFromSettings(settings); } diff --git a/src/test/java/org/elasticsearch/index/analysis/AnalyzerBackwardsCompatTests.java b/src/test/java/org/elasticsearch/index/analysis/AnalyzerBackwardsCompatTests.java index 880b9d8048954..7254268eb40a9 100644 --- a/src/test/java/org/elasticsearch/index/analysis/AnalyzerBackwardsCompatTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/AnalyzerBackwardsCompatTests.java @@ -45,6 +45,7 @@ private void testNoStopwordsAfter(org.elasticsearch.Version noStopwordVersion, S builder.put(SETTING_VERSION_CREATED, version); } builder.put("index.analysis.analyzer.foo.type", type); + builder.put("path.home", createTempDir().toString()); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(builder.build()); NamedAnalyzer analyzer = analysisService.analyzer("foo"); if (version.onOrAfter(noStopwordVersion)) { diff --git a/src/test/java/org/elasticsearch/index/analysis/CJKFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/CJKFilterFactoryTests.java index b0bdda19be016..bfa4c5ed59614 100644 --- a/src/test/java/org/elasticsearch/index/analysis/CJKFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/CJKFilterFactoryTests.java @@ -33,7 +33,7 @@ public class CJKFilterFactoryTests extends ElasticsearchTokenStreamTestCase { @Test public void testDefault() throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("cjk_bigram"); String source = "多くの学生が試験に落ちた。"; String[] expected = new String[]{"多く", "くの", "の学", "学生", "生が", "が試", "試験", "験に", "に落", "落ち", "ちた" }; @@ -44,7 +44,7 @@ public void testDefault() throws IOException { @Test public void testNoFlags() throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("cjk_no_flags"); String source = "多くの学生が試験に落ちた。"; String[] expected = new String[]{"多く", "くの", "の学", "学生", "生が", "が試", "試験", "験に", "に落", "落ち", "ちた" }; @@ -55,7 +55,7 @@ public void testNoFlags() throws IOException { @Test public void testHanOnly() throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("cjk_han_only"); String source = "多くの学生が試験に落ちた。"; String[] expected = new String[]{"多", "く", "の", "学生", "が", "試験", "に", "落", "ち", "た" }; @@ -66,7 +66,7 @@ public void testHanOnly() throws IOException { @Test public void testHanUnigramOnly() throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("cjk_han_unigram_only"); String source = "多くの学生が試験に落ちた。"; String[] expected = new String[]{"多", "く", "の", "学", "学生", "生", "が", "試", "試験", "験", "に", "落", "ち", "た" }; diff --git a/src/test/java/org/elasticsearch/index/analysis/CharFilterTests.java b/src/test/java/org/elasticsearch/index/analysis/CharFilterTests.java index e2715f690c855..c592579c801c8 100644 --- a/src/test/java/org/elasticsearch/index/analysis/CharFilterTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/CharFilterTests.java @@ -22,6 +22,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.ModulesBuilder; +import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; @@ -49,6 +50,7 @@ public void testMappingCharFilter() throws Exception { .putArray("index.analysis.char_filter.my_mapping.mappings", "ph=>f", "qu=>q") .put("index.analysis.analyzer.custom_with_char_filter.tokenizer", "standard") .putArray("index.analysis.analyzer.custom_with_char_filter.char_filter", "my_mapping") + .put("path.home", createTempDir().toString()) .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector(); Injector injector = new ModulesBuilder().add( @@ -74,6 +76,7 @@ public void testHtmlStripCharFilter() throws Exception { .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .put("index.analysis.analyzer.custom_with_char_filter.tokenizer", "standard") .putArray("index.analysis.analyzer.custom_with_char_filter.char_filter", "html_strip") + .put("path.home", createTempDir().toString()) .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector(); Injector injector = new ModulesBuilder().add( diff --git a/src/test/java/org/elasticsearch/index/analysis/CompoundAnalysisTests.java b/src/test/java/org/elasticsearch/index/analysis/CompoundAnalysisTests.java index a3e7552f50bab..37b3bfc21a717 100644 --- a/src/test/java/org/elasticsearch/index/analysis/CompoundAnalysisTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/CompoundAnalysisTests.java @@ -110,10 +110,18 @@ private List analyze(Settings settings, String analyzerName, String text } private Settings getJsonSettings() { - return settingsBuilder().loadFromClasspath("org/elasticsearch/index/analysis/test1.json").put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); + return settingsBuilder() + .loadFromClasspath("org/elasticsearch/index/analysis/test1.json") + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put("path.home", createTempDir().toString()) + .build(); } private Settings getYamlSettings() { - return settingsBuilder().loadFromClasspath("org/elasticsearch/index/analysis/test1.yml").put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); + return settingsBuilder() + .loadFromClasspath("org/elasticsearch/index/analysis/test1.yml") + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put("path.home", createTempDir().toString()) + .build(); } } diff --git a/src/test/java/org/elasticsearch/index/analysis/HunspellTokenFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/HunspellTokenFilterFactoryTests.java index cb79991b90c1e..298910c92167a 100644 --- a/src/test/java/org/elasticsearch/index/analysis/HunspellTokenFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/HunspellTokenFilterFactoryTests.java @@ -33,6 +33,7 @@ public class HunspellTokenFilterFactoryTests extends ElasticsearchTestCase { @Test public void testDedup() throws IOException { Settings settings = settingsBuilder() + .put("path.home", createTempDir().toString()) .put("path.conf", getDataPath("/indices/analyze/conf_dir")) .put("index.analysis.filter.en_US.type", "hunspell") .put("index.analysis.filter.en_US.locale", "en_US") @@ -45,6 +46,7 @@ public void testDedup() throws IOException { assertThat(hunspellTokenFilter.dedup(), is(true)); settings = settingsBuilder() + .put("path.home", createTempDir().toString()) .put("path.conf", getDataPath("/indices/analyze/conf_dir")) .put("index.analysis.filter.en_US.type", "hunspell") .put("index.analysis.filter.en_US.dedup", false) diff --git a/src/test/java/org/elasticsearch/index/analysis/KeepFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/KeepFilterFactoryTests.java index 78f2bd5077c6e..fb708a40c2613 100644 --- a/src/test/java/org/elasticsearch/index/analysis/KeepFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/KeepFilterFactoryTests.java @@ -40,7 +40,7 @@ public class KeepFilterFactoryTests extends ElasticsearchTokenStreamTestCase { @Test public void testLoadWithoutSettings() { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("keep"); Assert.assertNull(tokenFilter); } @@ -48,6 +48,7 @@ public void testLoadWithoutSettings() { @Test public void testLoadOverConfiguredSettings() { Settings settings = ImmutableSettings.settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.broken_keep_filter.type", "keep") .put("index.analysis.filter.broken_keep_filter.keep_words_path", "does/not/exists.txt") .put("index.analysis.filter.broken_keep_filter.keep_words", "[\"Hello\", \"worlD\"]") @@ -63,6 +64,7 @@ public void testLoadOverConfiguredSettings() { @Test public void testKeepWordsPathSettings() { Settings settings = ImmutableSettings.settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.non_broken_keep_filter.type", "keep") .put("index.analysis.filter.non_broken_keep_filter.keep_words_path", "does/not/exists.txt") .build(); @@ -89,7 +91,7 @@ public void testKeepWordsPathSettings() { @Test public void testCaseInsensitiveMapping() throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("my_keep_filter"); assertThat(tokenFilter, instanceOf(KeepWordFilterFactory.class)); String source = "hello small world"; @@ -101,7 +103,7 @@ public void testCaseInsensitiveMapping() throws IOException { @Test public void testCaseSensitiveMapping() throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("my_case_sensitive_keep_filter"); assertThat(tokenFilter, instanceOf(KeepWordFilterFactory.class)); String source = "Hello small world"; diff --git a/src/test/java/org/elasticsearch/index/analysis/KeepTypesFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/KeepTypesFilterFactoryTests.java index 95c942e19fd05..c296c875987c9 100644 --- a/src/test/java/org/elasticsearch/index/analysis/KeepTypesFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/KeepTypesFilterFactoryTests.java @@ -36,6 +36,7 @@ public class KeepTypesFilterFactoryTests extends ElasticsearchTokenStreamTestCas @Test public void testKeepTypes() throws IOException { Settings settings = ImmutableSettings.settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.keep_numbers.type", "keep_types") .putArray("index.analysis.filter.keep_numbers.types", new String[] {"", ""}) .build(); diff --git a/src/test/java/org/elasticsearch/index/analysis/LimitTokenCountFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/LimitTokenCountFilterFactoryTests.java index 5473c635980cd..0428e66263dc3 100644 --- a/src/test/java/org/elasticsearch/index/analysis/LimitTokenCountFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/LimitTokenCountFilterFactoryTests.java @@ -33,7 +33,10 @@ public class LimitTokenCountFilterFactoryTests extends ElasticsearchTokenStreamT @Test public void testDefault() throws IOException { - Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.limit_default.type", "limit").build(); + Settings settings = ImmutableSettings.settingsBuilder() + .put("index.analysis.filter.limit_default.type", "limit") + .put("path.home", createTempDir().toString()) + .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); { TokenFilterFactory tokenFilter = analysisService.tokenFilter("limit_default"); @@ -56,8 +59,11 @@ public void testDefault() throws IOException { @Test public void testSettings() throws IOException { { - Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.limit_1.type", "limit") - .put("index.analysis.filter.limit_1.max_token_count", 3).put("index.analysis.filter.limit_1.consume_all_tokens", true) + Settings settings = ImmutableSettings.settingsBuilder() + .put("index.analysis.filter.limit_1.type", "limit") + .put("index.analysis.filter.limit_1.max_token_count", 3) + .put("index.analysis.filter.limit_1.consume_all_tokens", true) + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter("limit_1"); @@ -68,8 +74,11 @@ public void testSettings() throws IOException { assertTokenStreamContents(tokenFilter.create(tokenizer), expected); } { - Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.limit_1.type", "limit") - .put("index.analysis.filter.limit_1.max_token_count", 3).put("index.analysis.filter.limit_1.consume_all_tokens", false) + Settings settings = ImmutableSettings.settingsBuilder() + .put("index.analysis.filter.limit_1.type", "limit") + .put("index.analysis.filter.limit_1.max_token_count", 3) + .put("index.analysis.filter.limit_1.consume_all_tokens", false) + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter("limit_1"); @@ -81,8 +90,11 @@ public void testSettings() throws IOException { } { - Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.limit_1.type", "limit") - .put("index.analysis.filter.limit_1.max_token_count", 17).put("index.analysis.filter.limit_1.consume_all_tokens", true) + Settings settings = ImmutableSettings.settingsBuilder() + .put("index.analysis.filter.limit_1.type", "limit") + .put("index.analysis.filter.limit_1.max_token_count", 17) + .put("index.analysis.filter.limit_1.consume_all_tokens", true) + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter("limit_1"); diff --git a/src/test/java/org/elasticsearch/index/analysis/PatternCaptureTokenFilterTests.java b/src/test/java/org/elasticsearch/index/analysis/PatternCaptureTokenFilterTests.java index 996471a205cfe..eaab794e50008 100644 --- a/src/test/java/org/elasticsearch/index/analysis/PatternCaptureTokenFilterTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/PatternCaptureTokenFilterTests.java @@ -42,7 +42,11 @@ public class PatternCaptureTokenFilterTests extends ElasticsearchTokenStreamTest @Test public void testPatternCaptureTokenFilter() throws Exception { Index index = new Index("test"); - Settings settings = settingsBuilder().loadFromClasspath("org/elasticsearch/index/analysis/pattern_capture.json").put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); + Settings settings = settingsBuilder() + .put("path.home", createTempDir()) + .loadFromClasspath("org/elasticsearch/index/analysis/pattern_capture.json") + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector(); Injector injector = new ModulesBuilder().add( new IndexSettingsModule(index, settings), diff --git a/src/test/java/org/elasticsearch/index/analysis/ShingleTokenFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/ShingleTokenFilterFactoryTests.java index a6c193df2ecbc..866aad321f8b0 100644 --- a/src/test/java/org/elasticsearch/index/analysis/ShingleTokenFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/ShingleTokenFilterFactoryTests.java @@ -40,7 +40,7 @@ public class ShingleTokenFilterFactoryTests extends ElasticsearchTokenStreamTest @Test public void testDefault() throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("shingle"); String source = "the quick brown fox"; String[] expected = new String[]{"the", "the quick", "quick", "quick brown", "brown", "brown fox", "fox"}; @@ -51,7 +51,7 @@ public void testDefault() throws IOException { @Test public void testInverseMapping() throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("shingle_inverse"); assertThat(tokenFilter, instanceOf(ShingleTokenFilterFactory.class)); String source = "the quick brown fox"; @@ -63,7 +63,7 @@ public void testInverseMapping() throws IOException { @Test public void testInverseMappingNoShingles() throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("shingle_inverse"); assertThat(tokenFilter, instanceOf(ShingleTokenFilterFactory.class)); String source = "the quick"; @@ -75,7 +75,7 @@ public void testInverseMappingNoShingles() throws IOException { @Test public void testFillerToken() throws IOException { - AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(RESOURCE); + AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromClassPath(createTempDir(), RESOURCE); TokenFilterFactory tokenFilter = analysisService.tokenFilter("shingle_filler"); String source = "simon the sorcerer"; String[] expected = new String[]{"simon FILLER", "simon FILLER sorcerer", "FILLER sorcerer"}; diff --git a/src/test/java/org/elasticsearch/index/analysis/StemmerTokenFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/StemmerTokenFilterFactoryTests.java index ab335129df5e3..727b71f3b2f0d 100644 --- a/src/test/java/org/elasticsearch/index/analysis/StemmerTokenFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/StemmerTokenFilterFactoryTests.java @@ -54,6 +54,7 @@ public void testEnglishBackwardsCompatibility() throws IOException { .put("index.analysis.analyzer.my_english.tokenizer","whitespace") .put("index.analysis.analyzer.my_english.filter","my_english") .put(SETTING_VERSION_CREATED,v) + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); @@ -87,6 +88,7 @@ public void testPorter2BackwardsCompatibility() throws IOException { .put("index.analysis.analyzer.my_porter2.tokenizer","whitespace") .put("index.analysis.analyzer.my_porter2.filter","my_porter2") .put(SETTING_VERSION_CREATED,v) + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); diff --git a/src/test/java/org/elasticsearch/index/analysis/StopAnalyzerTests.java b/src/test/java/org/elasticsearch/index/analysis/StopAnalyzerTests.java index 134b2cd5e3e1a..00e59547a6916 100644 --- a/src/test/java/org/elasticsearch/index/analysis/StopAnalyzerTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/StopAnalyzerTests.java @@ -42,7 +42,11 @@ public class StopAnalyzerTests extends ElasticsearchTokenStreamTestCase { @Test public void testDefaultsCompoundAnalysis() throws Exception { Index index = new Index("test"); - Settings settings = settingsBuilder().loadFromClasspath("org/elasticsearch/index/analysis/stop.json").put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); + Settings settings = settingsBuilder() + .loadFromClasspath("org/elasticsearch/index/analysis/stop.json") + .put("path.home", createTempDir().toString()) + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector(); Injector injector = new ModulesBuilder().add( new IndexSettingsModule(index, settings), diff --git a/src/test/java/org/elasticsearch/index/analysis/StopTokenFilterTests.java b/src/test/java/org/elasticsearch/index/analysis/StopTokenFilterTests.java index 929d4f335d8b3..fa1dbf71362db 100644 --- a/src/test/java/org/elasticsearch/index/analysis/StopTokenFilterTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/StopTokenFilterTests.java @@ -49,6 +49,7 @@ public void testPositionIncrementSetting() throws IOException { if (random().nextBoolean()) { builder.put("index.analysis.filter.my_stop.version", "5.0"); } + builder.put("path.home", createTempDir().toString()); Settings settings = builder.build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); analysisService.tokenFilter("my_stop"); @@ -68,6 +69,7 @@ public void testCorrectPositionIncrementSetting() throws IOException { } else { // don't specify } + builder.put("path.home", createTempDir().toString()); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(builder.build()); TokenFilterFactory tokenFilter = analysisService.tokenFilter("my_stop"); assertThat(tokenFilter, instanceOf(StopTokenFilterFactory.class)); @@ -83,8 +85,11 @@ public void testCorrectPositionIncrementSetting() throws IOException { @Test public void testDeprecatedPositionIncrementSettingWithVersions() throws IOException { - Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.my_stop.type", "stop") - .put("index.analysis.filter.my_stop.enable_position_increments", false).put("index.analysis.filter.my_stop.version", "4.3") + Settings settings = ImmutableSettings.settingsBuilder() + .put("index.analysis.filter.my_stop.type", "stop") + .put("index.analysis.filter.my_stop.enable_position_increments", false) + .put("index.analysis.filter.my_stop.version", "4.3") + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter("my_stop"); @@ -100,6 +105,7 @@ public void testThatSuggestStopFilterWorks() throws Exception { Settings settings = ImmutableSettings.settingsBuilder() .put("index.analysis.filter.my_stop.type", "stop") .put("index.analysis.filter.my_stop.remove_trailing", false) + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter("my_stop"); diff --git a/src/test/java/org/elasticsearch/index/analysis/WordDelimiterTokenFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/WordDelimiterTokenFilterFactoryTests.java index 24aba316d6e64..52dc850c12aba 100644 --- a/src/test/java/org/elasticsearch/index/analysis/WordDelimiterTokenFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/WordDelimiterTokenFilterFactoryTests.java @@ -34,6 +34,7 @@ public class WordDelimiterTokenFilterFactoryTests extends ElasticsearchTokenStre @Test public void testDefault() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_word_delimiter.type", "word_delimiter") .build()); TokenFilterFactory tokenFilter = analysisService.tokenFilter("my_word_delimiter"); @@ -47,6 +48,7 @@ public void testDefault() throws IOException { @Test public void testCatenateWords() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_word_delimiter.type", "word_delimiter") .put("index.analysis.filter.my_word_delimiter.catenate_words", "true") .put("index.analysis.filter.my_word_delimiter.generate_word_parts", "false") @@ -62,6 +64,7 @@ public void testCatenateWords() throws IOException { @Test public void testCatenateNumbers() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_word_delimiter.type", "word_delimiter") .put("index.analysis.filter.my_word_delimiter.generate_number_parts", "false") .put("index.analysis.filter.my_word_delimiter.catenate_numbers", "true") @@ -77,6 +80,7 @@ public void testCatenateNumbers() throws IOException { @Test public void testCatenateAll() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_word_delimiter.type", "word_delimiter") .put("index.analysis.filter.my_word_delimiter.generate_word_parts", "false") .put("index.analysis.filter.my_word_delimiter.generate_number_parts", "false") @@ -93,6 +97,7 @@ public void testCatenateAll() throws IOException { @Test public void testSplitOnCaseChange() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_word_delimiter.type", "word_delimiter") .put("index.analysis.filter.my_word_delimiter.split_on_case_change", "false") .build()); @@ -107,6 +112,7 @@ public void testSplitOnCaseChange() throws IOException { @Test public void testPreserveOriginal() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_word_delimiter.type", "word_delimiter") .put("index.analysis.filter.my_word_delimiter.preserve_original", "true") .build()); @@ -121,6 +127,7 @@ public void testPreserveOriginal() throws IOException { @Test public void testStemEnglishPossessive() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_word_delimiter.type", "word_delimiter") .put("index.analysis.filter.my_word_delimiter.stem_english_possessive", "false") .build()); @@ -136,6 +143,7 @@ public void testStemEnglishPossessive() throws IOException { @Test public void testPartsAndCatenate() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_word_delimiter.type", "word_delimiter") .put("index.analysis.filter.my_word_delimiter.catenate_words", "true") .put("index.analysis.filter.my_word_delimiter.generate_word_parts", "true") @@ -153,6 +161,7 @@ public void testPartsAndCatenate() throws IOException { @Test public void testDeprecatedPartsAndCatenate() throws IOException { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settingsBuilder() + .put("path.home", createTempDir().toString()) .put("index.analysis.filter.my_word_delimiter.type", "word_delimiter") .put("index.analysis.filter.my_word_delimiter.catenate_words", "true") .put("index.analysis.filter.my_word_delimiter.generate_word_parts", "true") diff --git a/src/test/java/org/elasticsearch/index/analysis/commongrams/CommonGramsTokenFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/commongrams/CommonGramsTokenFilterFactoryTests.java index 2792f0c4150cf..164892ff48c9e 100644 --- a/src/test/java/org/elasticsearch/index/analysis/commongrams/CommonGramsTokenFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/commongrams/CommonGramsTokenFilterFactoryTests.java @@ -39,7 +39,10 @@ public class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream @Test public void testDefault() throws IOException { - Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.common_grams_default.type", "common_grams").build(); + Settings settings = ImmutableSettings.settingsBuilder() + .put("index.analysis.filter.common_grams_default.type", "common_grams") + .put("path.home", createTempDir().toString()) + .build(); try { AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); @@ -53,6 +56,7 @@ public void testWithoutCommonWordsMatch() throws IOException { { Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.common_grams_default.type", "common_grams") .putArray("index.analysis.filter.common_grams_default.common_words", "chromosome", "protein") + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); @@ -69,6 +73,7 @@ public void testWithoutCommonWordsMatch() throws IOException { { Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.common_grams_default.type", "common_grams") .put("index.analysis.filter.common_grams_default.query_mode", false) + .put("path.home", createTempDir().toString()) .putArray("index.analysis.filter.common_grams_default.common_words", "chromosome", "protein") .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); @@ -88,6 +93,7 @@ public void testSettings() throws IOException { { Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.common_grams_1.type", "common_grams") .put("index.analysis.filter.common_grams_1.ignore_case", true) + .put("path.home", createTempDir().toString()) .putArray("index.analysis.filter.common_grams_1.common_words", "the", "Or", "Not", "a", "is", "an", "they", "are") .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); @@ -101,6 +107,7 @@ public void testSettings() throws IOException { { Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.common_grams_2.type", "common_grams") .put("index.analysis.filter.common_grams_2.ignore_case", false) + .put("path.home", createTempDir().toString()) .putArray("index.analysis.filter.common_grams_2.common_words", "the", "Or", "noT", "a", "is", "an", "they", "are") .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); @@ -114,6 +121,7 @@ public void testSettings() throws IOException { { Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.common_grams_3.type", "common_grams") .putArray("index.analysis.filter.common_grams_3.common_words", "the", "or", "not", "a", "is", "an", "they", "are") + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter("common_grams_3"); @@ -127,7 +135,10 @@ public void testSettings() throws IOException { @Test public void testCommonGramsAnalysis() throws IOException { - Settings settings = ImmutableSettings.settingsBuilder().loadFromClasspath("org/elasticsearch/index/analysis/commongrams/commongrams.json").build(); + Settings settings = ImmutableSettings.settingsBuilder() + .loadFromClasspath("org/elasticsearch/index/analysis/commongrams/commongrams.json") + .put("path.home", createTempDir().toString()) + .build(); { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); Analyzer analyzer = analysisService.analyzer("commongramsAnalyzer").analyzer(); @@ -151,6 +162,7 @@ public void testQueryModeSettings() throws IOException { .put("index.analysis.filter.common_grams_1.query_mode", true) .putArray("index.analysis.filter.common_grams_1.common_words", "the", "Or", "Not", "a", "is", "an", "they", "are") .put("index.analysis.filter.common_grams_1.ignore_case", true) + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter("common_grams_1"); @@ -165,6 +177,7 @@ public void testQueryModeSettings() throws IOException { .put("index.analysis.filter.common_grams_2.query_mode", true) .putArray("index.analysis.filter.common_grams_2.common_words", "the", "Or", "noT", "a", "is", "an", "they", "are") .put("index.analysis.filter.common_grams_2.ignore_case", false) + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter("common_grams_2"); @@ -178,6 +191,7 @@ public void testQueryModeSettings() throws IOException { Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.common_grams_3.type", "common_grams") .put("index.analysis.filter.common_grams_3.query_mode", true) .putArray("index.analysis.filter.common_grams_3.common_words", "the", "Or", "noT", "a", "is", "an", "they", "are") + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter("common_grams_3"); @@ -191,6 +205,7 @@ public void testQueryModeSettings() throws IOException { Settings settings = ImmutableSettings.settingsBuilder().put("index.analysis.filter.common_grams_4.type", "common_grams") .put("index.analysis.filter.common_grams_4.query_mode", true) .putArray("index.analysis.filter.common_grams_4.common_words", "the", "or", "not", "a", "is", "an", "they", "are") + .put("path.home", createTempDir().toString()) .build(); AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); TokenFilterFactory tokenFilter = analysisService.tokenFilter("common_grams_4"); @@ -204,7 +219,10 @@ public void testQueryModeSettings() throws IOException { @Test public void testQueryModeCommonGramsAnalysis() throws IOException { - Settings settings = ImmutableSettings.settingsBuilder().loadFromClasspath("org/elasticsearch/index/analysis/commongrams/commongrams_query_mode.json").build(); + Settings settings = ImmutableSettings.settingsBuilder() + .loadFromClasspath("org/elasticsearch/index/analysis/commongrams/commongrams_query_mode.json") + .put("path.home", createTempDir().toString()) + .build(); { AnalysisService analysisService = AnalysisTestsHelper.createAnalysisServiceFromSettings(settings); Analyzer analyzer = analysisService.analyzer("commongramsAnalyzer").analyzer(); diff --git a/src/test/java/org/elasticsearch/index/analysis/synonyms/SynonymsAnalysisTest.java b/src/test/java/org/elasticsearch/index/analysis/synonyms/SynonymsAnalysisTest.java index c1d09a90bb100..6df27d10212c5 100644 --- a/src/test/java/org/elasticsearch/index/analysis/synonyms/SynonymsAnalysisTest.java +++ b/src/test/java/org/elasticsearch/index/analysis/synonyms/SynonymsAnalysisTest.java @@ -59,9 +59,9 @@ public class SynonymsAnalysisTest extends ElasticsearchTestCase { @Test public void testSynonymsAnalysis() throws IOException { - Settings settings = settingsBuilder(). loadFromClasspath("org/elasticsearch/index/analysis/synonyms/synonyms.json") + .put("path.home", createTempDir().toString()) .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); Index index = new Index("test"); diff --git a/src/test/java/org/elasticsearch/index/query/TemplateQueryParserTest.java b/src/test/java/org/elasticsearch/index/query/TemplateQueryParserTest.java index 654a377a4f1eb..15872851d454e 100644 --- a/src/test/java/org/elasticsearch/index/query/TemplateQueryParserTest.java +++ b/src/test/java/org/elasticsearch/index/query/TemplateQueryParserTest.java @@ -67,6 +67,7 @@ public class TemplateQueryParserTest extends ElasticsearchTestCase { @Before public void setup() throws IOException { Settings settings = ImmutableSettings.settingsBuilder() + .put("path.home", createTempDir().toString()) .put("path.conf", this.getDataPath("config")) .put("name", getClass().getName()) .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) diff --git a/src/test/java/org/elasticsearch/index/query/plugin/IndexQueryParserPlugin2Tests.java b/src/test/java/org/elasticsearch/index/query/plugin/IndexQueryParserPlugin2Tests.java index 75cccb7000f61..a7d30c465ddf8 100644 --- a/src/test/java/org/elasticsearch/index/query/plugin/IndexQueryParserPlugin2Tests.java +++ b/src/test/java/org/elasticsearch/index/query/plugin/IndexQueryParserPlugin2Tests.java @@ -29,6 +29,8 @@ import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsModule; +import org.elasticsearch.env.Environment; +import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNameModule; import org.elasticsearch.index.analysis.AnalysisModule; @@ -56,7 +58,10 @@ public class IndexQueryParserPlugin2Tests extends ElasticsearchTestCase { @Test public void testCustomInjection() throws InterruptedException { - Settings settings = ImmutableSettings.builder().put("name", "testCustomInjection").put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); + Settings settings = ImmutableSettings.builder() + .put("name", "testCustomInjection") + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put("path.home", createTempDir()).build(); IndexQueryParserModule queryParserModule = new IndexQueryParserModule(settings); queryParserModule.addQueryParser("my", PluginJsonQueryParser.class); @@ -64,6 +69,7 @@ public void testCustomInjection() throws InterruptedException { Index index = new Index("test"); Injector injector = new ModulesBuilder().add( + new EnvironmentModule(new Environment(settings)), new SettingsModule(settings), new ThreadPoolModule(settings), new IndicesQueriesModule(), diff --git a/src/test/java/org/elasticsearch/index/query/plugin/IndexQueryParserPluginTests.java b/src/test/java/org/elasticsearch/index/query/plugin/IndexQueryParserPluginTests.java index 92ce6bcde203f..bbbee45228443 100644 --- a/src/test/java/org/elasticsearch/index/query/plugin/IndexQueryParserPluginTests.java +++ b/src/test/java/org/elasticsearch/index/query/plugin/IndexQueryParserPluginTests.java @@ -29,6 +29,8 @@ import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsModule; +import org.elasticsearch.env.Environment; +import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNameModule; import org.elasticsearch.index.analysis.AnalysisModule; @@ -56,7 +58,10 @@ public class IndexQueryParserPluginTests extends ElasticsearchTestCase { @Test public void testCustomInjection() throws InterruptedException { - Settings settings = ImmutableSettings.builder().put("name", "testCustomInjection").put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); + Settings settings = ImmutableSettings.builder() + .put("name", "testCustomInjection") + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put("path.home", createTempDir()).build(); IndexQueryParserModule queryParserModule = new IndexQueryParserModule(settings); queryParserModule.addProcessor(new IndexQueryParserModule.QueryParsersProcessor() { @@ -73,6 +78,7 @@ public void processXContentFilterParsers(XContentFilterParsersBindings bindings) Index index = new Index("test"); Injector injector = new ModulesBuilder().add( + new EnvironmentModule(new Environment(settings)), new SettingsModule(settings), new ThreadPoolModule(settings), new IndicesQueriesModule(), diff --git a/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java b/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java index 304940e814114..742f5d1615e89 100644 --- a/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java +++ b/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java @@ -79,17 +79,6 @@ public void testLocaleDirectoryWithLocaleSpecificConfig() throws Exception { assertIgnoreCase(true, dictionary); } - @Test - public void testCustomizeLocaleDirectory() throws Exception { - Settings settings = ImmutableSettings.settingsBuilder() - .put(HUNSPELL_LOCATION, getDataPath("/indices/analyze/conf_dir/hunspell")) - .build(); - - internalCluster().startNode(settings); - Dictionary dictionary = internalCluster().getInstance(HunspellService.class).getDictionary("en_US"); - assertThat(dictionary, notNullValue()); - } - @Test public void testDicWithNoAff() throws Exception { Settings settings = ImmutableSettings.settingsBuilder() diff --git a/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java b/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java index 8db6fd4e5c05b..25cc99820b6a5 100644 --- a/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java +++ b/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java @@ -44,11 +44,20 @@ public void cleanupSystemProperties() { @Test public void testIgnoreSystemProperties() { - Tuple tuple = InternalSettingsPreparer.prepareSettings(settingsBuilder().put("node.zone", "bar").build(), true); + Settings settings = settingsBuilder() + .put("node.zone", "bar") + .put("path.home", createTempDir().toString()) + .build(); + Tuple tuple = InternalSettingsPreparer.prepareSettings(settings, true); // Should use setting from the system property assertThat(tuple.v1().get("node.zone"), equalTo("foo")); - tuple = InternalSettingsPreparer.prepareSettings(settingsBuilder().put("config.ignore_system_properties", true).put("node.zone", "bar").build(), true); + settings = settingsBuilder() + .put("config.ignore_system_properties", true) + .put("node.zone", "bar") + .put("path.home", createTempDir().toString()) + .build(); + tuple = InternalSettingsPreparer.prepareSettings(settings, true); // Should use setting from the system property assertThat(tuple.v1().get("node.zone"), equalTo("bar")); } diff --git a/src/test/java/org/elasticsearch/script/NativeScriptTests.java b/src/test/java/org/elasticsearch/script/NativeScriptTests.java index 951f605801ed7..04c2e63e0207f 100644 --- a/src/test/java/org/elasticsearch/script/NativeScriptTests.java +++ b/src/test/java/org/elasticsearch/script/NativeScriptTests.java @@ -28,6 +28,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; +import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.script.ScriptService.ScriptType; import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.threadpool.ThreadPool; @@ -50,8 +51,10 @@ public void testNativeScript() throws InterruptedException { Settings settings = ImmutableSettings.settingsBuilder() .put("script.native.my.type", MyNativeScriptFactory.class.getName()) .put("name", "testNativeScript") + .put("path.home", createTempDir()) .build(); Injector injector = new ModulesBuilder().add( + new EnvironmentModule(new Environment(settings)), new ThreadPoolModule(settings), new SettingsModule(settings), new ScriptModule(settings)).createInjector(); @@ -73,7 +76,7 @@ public void testFineGrainedSettingsDontAffectNativeScripts() throws IOException String scriptContext = randomFrom(ScriptContext.Standard.values()).getKey(); builder.put(ScriptModes.SCRIPT_SETTINGS_PREFIX + scriptContext, randomFrom(ScriptMode.values())); } - Settings settings = builder.build(); + Settings settings = builder.put("path.home", createTempDir()).build(); Environment environment = new Environment(settings); ResourceWatcherService resourceWatcherService = new ResourceWatcherService(settings, null); Map nativeScriptFactoryMap = new HashMap<>(); diff --git a/src/test/java/org/elasticsearch/script/ScriptServiceTests.java b/src/test/java/org/elasticsearch/script/ScriptServiceTests.java index 69aa868583552..c3f164ab25f1f 100644 --- a/src/test/java/org/elasticsearch/script/ScriptServiceTests.java +++ b/src/test/java/org/elasticsearch/script/ScriptServiceTests.java @@ -69,6 +69,7 @@ public class ScriptServiceTests extends ElasticsearchTestCase { public void setup() throws IOException { Path genericConfigFolder = createTempDir(); baseSettings = settingsBuilder() + .put("path.home", createTempDir().toString()) .put("path.conf", genericConfigFolder) .build(); resourceWatcherService = new ResourceWatcherService(baseSettings, null); diff --git a/src/test/java/org/elasticsearch/stresstest/client/ClientFailover.java b/src/test/java/org/elasticsearch/stresstest/client/ClientFailover.java index 86ae03992e276..c00ceec27b3c3 100644 --- a/src/test/java/org/elasticsearch/stresstest/client/ClientFailover.java +++ b/src/test/java/org/elasticsearch/stresstest/client/ClientFailover.java @@ -21,6 +21,7 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.client.transport.TransportClient; +import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.node.Node; import org.elasticsearch.node.NodeBuilder; @@ -38,8 +39,10 @@ public static void main(String[] args) throws Exception { for (int i = 0; i < nodes.length; i++) { nodes[i] = NodeBuilder.nodeBuilder().node(); } + + // TODO: what is this? a public static void main test?!?! - final TransportClient client = new TransportClient() + final TransportClient client = new TransportClient(ImmutableSettings.EMPTY) .addTransportAddress(new InetSocketTransportAddress("localhost", 9300)) .addTransportAddress(new InetSocketTransportAddress("localhost", 9301)) .addTransportAddress(new InetSocketTransportAddress("localhost", 9302)); diff --git a/src/test/java/org/elasticsearch/stresstest/manyindices/ManyIndicesRemoteStressTest.java b/src/test/java/org/elasticsearch/stresstest/manyindices/ManyIndicesRemoteStressTest.java index 66239f3434731..fb113a604b76e 100644 --- a/src/test/java/org/elasticsearch/stresstest/manyindices/ManyIndicesRemoteStressTest.java +++ b/src/test/java/org/elasticsearch/stresstest/manyindices/ManyIndicesRemoteStressTest.java @@ -47,8 +47,9 @@ public static void main(String[] args) throws Exception { Client client; Node node = null; + // TODO: what is this? a public static void main test?!?!?! if (true) { - client = new TransportClient().addTransportAddress(new InetSocketTransportAddress("localhost", 9300)); + client = new TransportClient(ImmutableSettings.EMPTY).addTransportAddress(new InetSocketTransportAddress("localhost", 9300)); } else { node = NodeBuilder.nodeBuilder().client(true).node(); client = node.client(); diff --git a/src/test/java/org/elasticsearch/test/InternalTestCluster.java b/src/test/java/org/elasticsearch/test/InternalTestCluster.java index 4c857c2402794..194d54968b220 100644 --- a/src/test/java/org/elasticsearch/test/InternalTestCluster.java +++ b/src/test/java/org/elasticsearch/test/InternalTestCluster.java @@ -802,7 +802,7 @@ private Client getOrBuildTransportClient() { /* no sniff client for now - doesn't work will all tests since it might throw NoNodeAvailableException if nodes are shut down. * we first need support of transportClientRatio as annotations or so */ - return transportClient = TransportClientFactory.noSniff(settingsSource.transportClient()).client(node, clusterName); + return transportClient = new TransportClientFactory(false, settingsSource.transportClient(), baseDir).client(node, clusterName); } void resetClient() throws IOException { @@ -856,29 +856,14 @@ public void close() throws IOException { public static final String TRANSPORT_CLIENT_PREFIX = "transport_client_"; static class TransportClientFactory { - private static TransportClientFactory NO_SNIFF_CLIENT_FACTORY = new TransportClientFactory(false, ImmutableSettings.EMPTY); - private static TransportClientFactory SNIFF_CLIENT_FACTORY = new TransportClientFactory(true, ImmutableSettings.EMPTY); - private final boolean sniff; private final Settings settings; + private final Path baseDir; - public static TransportClientFactory noSniff(Settings settings) { - if (settings == null || settings.names().isEmpty()) { - return NO_SNIFF_CLIENT_FACTORY; - } - return new TransportClientFactory(false, settings); - } - - public static TransportClientFactory sniff(Settings settings) { - if (settings == null || settings.names().isEmpty()) { - return SNIFF_CLIENT_FACTORY; - } - return new TransportClientFactory(true, settings); - } - - TransportClientFactory(boolean sniff, Settings settings) { + TransportClientFactory(boolean sniff, Settings settings, Path baseDir) { this.sniff = sniff; this.settings = settings != null ? settings : ImmutableSettings.EMPTY; + this.baseDir = baseDir; } public Client client(Node node, String clusterName) { @@ -886,6 +871,7 @@ public Client client(Node node, String clusterName) { Settings nodeSettings = node.settings(); Builder builder = settingsBuilder() .put("client.transport.nodes_sampler_interval", "1s") + .put("path.home", baseDir) .put("name", TRANSPORT_CLIENT_PREFIX + node.settings().get("name")) .put("plugins." + PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false) .put(ClusterName.SETTING, clusterName).put("client.transport.sniff", sniff) diff --git a/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationTests.java b/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationTests.java index 10b7fa91ac071..53919f8a718e2 100644 --- a/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationTests.java +++ b/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationTests.java @@ -66,6 +66,7 @@ public void testThatTransportClientCanConnect() throws Exception { Settings settings = settingsBuilder() .put("cluster.name", internalCluster().getClusterName()) .put(TransportModule.TRANSPORT_TYPE_KEY, NettyTransport.class.getName()) + .put("path.home", createTempDir().toString()) .build(); try (TransportClient transportClient = new TransportClient(settings, false)) { transportClient.addTransportAddress(new InetSocketTransportAddress("127.0.0.1", randomPort)); diff --git a/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java b/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java index 2089404165c59..2f1e81eead721 100644 --- a/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java +++ b/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java @@ -95,7 +95,8 @@ private static void assertTribeNodeSuccesfullyCreated(Settings extraSettings) th //tribe node doesn't need the node.mode setting, as it's forced local internally anyways. The tribe clients do need it to make sure //they can find their corresponding tribes using the proper transport Settings settings = ImmutableSettings.builder().put("http.enabled", false).put("node.name", "tribe_node") - .put("tribe.t1.node.mode", NODE_MODE).put("tribe.t2.node.mode", NODE_MODE).put(extraSettings).build(); + .put("tribe.t1.node.mode", NODE_MODE).put("tribe.t2.node.mode", NODE_MODE) + .put("path.home", createTempDir()).put(extraSettings).build(); try (Node node = NodeBuilder.nodeBuilder().settings(settings).node()) { try (Client client = node.client()) {