Merge pull request #10923 from elastic/die_cwd_die
Remove CWD access in tests and don't implicitly use CWD/user.dir for configuration.
This commit is contained in:
commit
02da246b10
|
@ -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 `<path.conf>/hunspell`). Each dictionary is expected to
|
||||
(`<path.conf>/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.
|
||||
|
|
|
@ -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 `<path.conf>/hunspell` is always used.
|
||||
|
|
|
@ -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
|
||||
* <tt>elasticsearch.(yml|json)</tt> files optionally prefixed with <tt>config/</tt>).
|
||||
*/
|
||||
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 <tt>elasticsearch.(yml|json)</tt> files optionally prefixed with <tt>config/</tt>).
|
||||
|
|
|
@ -32,7 +32,6 @@ import java.nio.file.Path;
|
|||
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 class Environment {
|
|||
}
|
||||
|
||||
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)) {
|
||||
// first, try it as a path in the config directory
|
||||
Path f = configFile.resolve(path);
|
||||
if (Files.exists(f)) {
|
||||
try {
|
||||
return f1.toUri().toURL();
|
||||
return f.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)) {
|
||||
try {
|
||||
return f2.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 class Environment {
|
|||
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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String, Dictionary> dictionaries;
|
||||
private final Map<String, Dictionary> knownDictionaries;
|
||||
|
||||
|
@ -116,9 +116,9 @@ public class HunspellService extends AbstractComponent {
|
|||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
|
|
@ -127,6 +127,7 @@ public class TribeService extends AbstractLifecycleComponent<TribeService> {
|
|||
for (Map.Entry<String, Settings> 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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.elasticsearch.client.Client;
|
|||
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 class BulkProcessorTests extends ElasticsearchIntegrationTest {
|
|||
//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);
|
||||
|
|
|
@ -23,6 +23,8 @@ import org.elasticsearch.action.support.QuerySourceBuilder;
|
|||
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
|
||||
|
|
|
@ -21,6 +21,8 @@ package org.elasticsearch.action.search;
|
|||
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -59,7 +59,7 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTests {
|
|||
.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 class TransportClientHeadersTests extends AbstractClientHeadersTests {
|
|||
.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);
|
||||
|
|
|
@ -62,7 +62,8 @@ public class TransportClientRetryTests extends ElasticsearchIntegrationTest {
|
|||
.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);
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.elasticsearch.cluster.node.DiscoveryNode;
|
|||
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 org.junit.Test;
|
|||
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 class TransportClientTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@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"));
|
||||
}
|
||||
|
|
|
@ -54,73 +54,73 @@ public class CheckFileCommandTests extends ElasticsearchTestCase {
|
|||
|
||||
@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 class CheckFileCommandTests extends ElasticsearchTestCase {
|
|||
|
||||
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 class CheckFileCommandTests extends ElasticsearchTestCase {
|
|||
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 @@ public class CheckFileCommandTests extends ElasticsearchTestCase {
|
|||
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 @@ public class CheckFileCommandTests extends ElasticsearchTestCase {
|
|||
*/
|
||||
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 class CheckFileCommandTests extends ElasticsearchTestCase {
|
|||
*/
|
||||
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 class CheckFileCommandTests extends ElasticsearchTestCase {
|
|||
*/
|
||||
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
|
||||
|
|
|
@ -22,6 +22,8 @@ package org.elasticsearch.common.cli;
|
|||
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 @@ import java.util.Locale;
|
|||
@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;
|
||||
|
|
|
@ -56,6 +56,7 @@ public class Log4jESLoggerTests extends ElasticsearchTestCase {
|
|||
// 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);
|
||||
|
||||
|
|
|
@ -59,6 +59,7 @@ public class LoggingConfigurationTests extends ElasticsearchTestCase {
|
|||
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 class LoggingConfigurationTests extends ElasticsearchTestCase {
|
|||
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 class LoggingConfigurationTests extends ElasticsearchTestCase {
|
|||
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 class LoggingConfigurationTests extends ElasticsearchTestCase {
|
|||
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 class LoggingConfigurationTests extends ElasticsearchTestCase {
|
|||
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);
|
||||
|
|
|
@ -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 class ASCIIFoldingTokenFilterFactoryTests extends ElasticsearchTokenStrea
|
|||
@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());
|
||||
|
|
|
@ -77,8 +77,11 @@ public class AnalysisModuleTests extends ElasticsearchTestCase {
|
|||
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 class AnalysisModuleTests extends ElasticsearchTestCase {
|
|||
|
||||
@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 class AnalysisModuleTests extends ElasticsearchTestCase {
|
|||
}
|
||||
|
||||
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 @@ public class AnalysisModuleTests extends ElasticsearchTestCase {
|
|||
|
||||
@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));
|
||||
|
|
|
@ -34,11 +34,15 @@ import org.elasticsearch.index.settings.IndexSettingsModule;
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ public class AnalyzerBackwardsCompatTests extends ElasticsearchTokenStreamTestCa
|
|||
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)) {
|
||||
|
|
|
@ -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 class CJKFilterFactoryTests extends ElasticsearchTokenStreamTestCase {
|
|||
|
||||
@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 class CJKFilterFactoryTests extends ElasticsearchTokenStreamTestCase {
|
|||
|
||||
@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 class CJKFilterFactoryTests extends ElasticsearchTokenStreamTestCase {
|
|||
|
||||
@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[]{"多", "く", "の", "学", "学生", "生", "が", "試", "試験", "験", "に", "落", "ち", "た" };
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.elasticsearch.Version;
|
|||
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 class CharFilterTests extends ElasticsearchTokenStreamTestCase {
|
|||
.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 class CharFilterTests extends ElasticsearchTokenStreamTestCase {
|
|||
.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(
|
||||
|
|
|
@ -110,10 +110,18 @@ public class CompoundAnalysisTests extends ElasticsearchTestCase {
|
|||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 class HunspellTokenFilterFactoryTests extends ElasticsearchTestCase {
|
|||
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)
|
||||
|
|
|
@ -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 class KeepFilterFactoryTests extends ElasticsearchTokenStreamTestCase {
|
|||
@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 class KeepFilterFactoryTests extends ElasticsearchTokenStreamTestCase {
|
|||
@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 class KeepFilterFactoryTests extends ElasticsearchTokenStreamTestCase {
|
|||
|
||||
@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 class KeepFilterFactoryTests extends ElasticsearchTokenStreamTestCase {
|
|||
|
||||
@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";
|
||||
|
|
|
@ -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[] {"<NUM>", "<SOMETHINGELSE>"})
|
||||
.build();
|
||||
|
|
|
@ -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 class LimitTokenCountFilterFactoryTests extends ElasticsearchTokenStreamT
|
|||
@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 class LimitTokenCountFilterFactoryTests extends ElasticsearchTokenStreamT
|
|||
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 class LimitTokenCountFilterFactoryTests extends ElasticsearchTokenStreamT
|
|||
}
|
||||
|
||||
{
|
||||
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");
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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 class ShingleTokenFilterFactoryTests extends ElasticsearchTokenStreamTest
|
|||
|
||||
@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 class ShingleTokenFilterFactoryTests extends ElasticsearchTokenStreamTest
|
|||
|
||||
@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 class ShingleTokenFilterFactoryTests extends ElasticsearchTokenStreamTest
|
|||
|
||||
@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"};
|
||||
|
|
|
@ -54,6 +54,7 @@ public class StemmerTokenFilterFactoryTests extends ElasticsearchTokenStreamTest
|
|||
.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 class StemmerTokenFilterFactoryTests extends ElasticsearchTokenStreamTest
|
|||
.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);
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -49,6 +49,7 @@ public class StopTokenFilterTests extends ElasticsearchTokenStreamTestCase {
|
|||
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 class StopTokenFilterTests extends ElasticsearchTokenStreamTestCase {
|
|||
} 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 class StopTokenFilterTests extends ElasticsearchTokenStreamTestCase {
|
|||
|
||||
@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 class StopTokenFilterTests extends ElasticsearchTokenStreamTestCase {
|
|||
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");
|
||||
|
|
|
@ -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 class WordDelimiterTokenFilterFactoryTests extends ElasticsearchTokenStre
|
|||
@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 class WordDelimiterTokenFilterFactoryTests extends ElasticsearchTokenStre
|
|||
@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 class WordDelimiterTokenFilterFactoryTests extends ElasticsearchTokenStre
|
|||
@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 class WordDelimiterTokenFilterFactoryTests extends ElasticsearchTokenStre
|
|||
@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 class WordDelimiterTokenFilterFactoryTests extends ElasticsearchTokenStre
|
|||
@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 class WordDelimiterTokenFilterFactoryTests extends ElasticsearchTokenStre
|
|||
@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 class WordDelimiterTokenFilterFactoryTests extends ElasticsearchTokenStre
|
|||
@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 class WordDelimiterTokenFilterFactoryTests extends ElasticsearchTokenStre
|
|||
@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")
|
||||
|
|
|
@ -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 class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream
|
|||
{
|
||||
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 class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream
|
|||
{
|
||||
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 class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream
|
|||
{
|
||||
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 class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream
|
|||
{
|
||||
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 class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream
|
|||
{
|
||||
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 class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream
|
|||
|
||||
@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 class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream
|
|||
.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 class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream
|
|||
.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 class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream
|
|||
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 class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream
|
|||
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 class CommonGramsTokenFilterFactoryTests extends ElasticsearchTokenStream
|
|||
|
||||
@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();
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -29,6 +29,8 @@ import org.elasticsearch.common.inject.util.Providers;
|
|||
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 class IndexQueryParserPlugin2Tests extends ElasticsearchTestCase {
|
|||
|
||||
Index index = new Index("test");
|
||||
Injector injector = new ModulesBuilder().add(
|
||||
new EnvironmentModule(new Environment(settings)),
|
||||
new SettingsModule(settings),
|
||||
new ThreadPoolModule(settings),
|
||||
new IndicesQueriesModule(),
|
||||
|
|
|
@ -29,6 +29,8 @@ import org.elasticsearch.common.inject.util.Providers;
|
|||
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 class IndexQueryParserPluginTests extends ElasticsearchTestCase {
|
|||
|
||||
Index index = new Index("test");
|
||||
Injector injector = new ModulesBuilder().add(
|
||||
new EnvironmentModule(new Environment(settings)),
|
||||
new SettingsModule(settings),
|
||||
new ThreadPoolModule(settings),
|
||||
new IndicesQueriesModule(),
|
||||
|
|
|
@ -79,17 +79,6 @@ public class HunspellServiceTests extends ElasticsearchIntegrationTest {
|
|||
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()
|
||||
|
|
|
@ -44,11 +44,20 @@ public class InternalSettingsPreparerTests extends ElasticsearchTestCase {
|
|||
|
||||
@Test
|
||||
public void testIgnoreSystemProperties() {
|
||||
Tuple<Settings, Environment> tuple = InternalSettingsPreparer.prepareSettings(settingsBuilder().put("node.zone", "bar").build(), true);
|
||||
Settings settings = settingsBuilder()
|
||||
.put("node.zone", "bar")
|
||||
.put("path.home", createTempDir().toString())
|
||||
.build();
|
||||
Tuple<Settings, Environment> 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"));
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ 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.script.ScriptService.ScriptType;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
|
@ -50,8 +51,10 @@ public class NativeScriptTests extends ElasticsearchTestCase {
|
|||
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 class NativeScriptTests extends ElasticsearchTestCase {
|
|||
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<String, NativeScriptFactory> nativeScriptFactoryMap = new HashMap<>();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.stresstest.client;
|
|||
|
||||
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 class ClientFailover {
|
|||
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));
|
||||
|
|
|
@ -47,8 +47,9 @@ public class ManyIndicesRemoteStressTest {
|
|||
|
||||
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();
|
||||
|
|
|
@ -802,7 +802,7 @@ public final class InternalTestCluster extends TestCluster {
|
|||
/* 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 final class InternalTestCluster extends TestCluster {
|
|||
|
||||
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 final class InternalTestCluster extends TestCluster {
|
|||
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)
|
||||
|
|
|
@ -66,6 +66,7 @@ public class NettyTransportMultiPortIntegrationTests extends ElasticsearchIntegr
|
|||
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));
|
||||
|
|
|
@ -95,7 +95,8 @@ public class TribeUnitTests extends ElasticsearchTestCase {
|
|||
//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()) {
|
||||
|
|
Loading…
Reference in New Issue