diff --git a/TESTING.asciidoc b/TESTING.asciidoc index 3acf5a5f77e..1bcbce4ca47 100644 --- a/TESTING.asciidoc +++ b/TESTING.asciidoc @@ -260,7 +260,7 @@ The REST tests are run automatically when executing the maven test command. To r REST tests use the following command: --------------------------------------------------------------------------- -mvn test -Dtests.class=org.elasticsearch.test.rest.ElasticsearchRestTests +mvn test -Dtests.filter="@Rest" --------------------------------------------------------------------------- `ElasticsearchRestTests` is the executable test class that runs all the diff --git a/dev-tools/forbidden/all-signatures.txt b/dev-tools/forbidden/all-signatures.txt index e8494c2721e..5e893e537f3 100644 --- a/dev-tools/forbidden/all-signatures.txt +++ b/dev-tools/forbidden/all-signatures.txt @@ -33,3 +33,6 @@ java.nio.file.Path#toFile() @defaultMessage Don't use deprecated lucene apis org.apache.lucene.index.DocsEnum org.apache.lucene.index.DocsAndPositionsEnum + +java.nio.file.Paths @ Use PathUtils.get instead. +java.nio.file.FileSystems#getDefault() @ use PathUtils.getDefault instead. diff --git a/dev-tools/forbidden/test-signatures.txt b/dev-tools/forbidden/test-signatures.txt index 7471aa685bc..7ea2c6a45f1 100644 --- a/dev-tools/forbidden/test-signatures.txt +++ b/dev-tools/forbidden/test-signatures.txt @@ -16,3 +16,5 @@ com.carrotsearch.randomizedtesting.RandomizedTest#globalTempDir() @ Use newTempDirPath() instead com.carrotsearch.randomizedtesting.annotations.Seed @ Don't commit hardcoded seeds + +org.apache.lucene.codecs.Codec#setDefault(org.apache.lucene.codecs.Codec) @ Use the SuppressCodecs("*") annotation instead diff --git a/pom.xml b/pom.xml index dcd343d2055..1418049897d 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,8 @@ 5.2.0 - 5.2.0-snapshot-1674183 + 5.2.0-snapshot-1674576 + 2.1.14 auto true onerror @@ -40,7 +41,8 @@ ${project.basedir}/backwards random random - INFO + false + ERROR 512m ${basedir}/logs/ 5 @@ -66,7 +68,7 @@ lucene-snapshots Lucene Snapshots - https://download.elastic.co/lucenesnapshots/1674183 + https://download.elastic.co/lucenesnapshots/1674576 @@ -80,7 +82,7 @@ com.carrotsearch.randomizedtesting randomizedtesting-runner - 2.1.13 + ${testframework.version} test @@ -501,7 +503,7 @@ com.carrotsearch.randomizedtesting junit4-maven-plugin - 2.1.13 + ${testframework.version} tests @@ -510,9 +512,10 @@ junit4 - 20 + 10 pipe,warn true + fail @@ -525,7 +528,19 @@ showStatusFailure="true" showStatusIgnored="true" showSuiteSummary="true" - timestamps="false"/> + timestamps="false"> + + + + + + + + + + + + @@ -561,7 +576,8 @@ ${tests.verbose} ${tests.seed} ${tests.failfast} - false + + true ./temp @@ -570,7 +586,6 @@ ${tests.bwc.path} ${tests.bwc.version} ${tests.jvm.argline} - ${tests.processors} ${tests.appendseed} ${tests.iters} ${tests.maxfailures} @@ -1626,6 +1641,7 @@ 2.9 eclipse-build + true diff --git a/rest-api-spec/test/README.asciidoc b/rest-api-spec/test/README.asciidoc index 38a3be23841..2f2d50b9fe5 100644 --- a/rest-api-spec/test/README.asciidoc +++ b/rest-api-spec/test/README.asciidoc @@ -65,7 +65,7 @@ skipped, and the reason why the tests are skipped. For instance: .... "Parent": - skip: - version: "0 - 0.90.2" + version: "0.20.1 - 0.90.2" reason: Delete ignores the parent param - do: @@ -75,14 +75,17 @@ skipped, and the reason why the tests are skipped. For instance: All tests in the file following the skip statement should be skipped if: `min <= current <= max`. -The `version` range should always have an upper bound. Versions should -either have each version part compared numerically, or should be converted -to a string with sufficient digits to allow string comparison, eg +The `version` range can leave either bound empty, which means "open ended". +For instance: +.... + "Parent": + - skip: + version: "1.0.0.Beta1 - " + reason: Delete ignores the parent param - 0.90.2 -> 000-090-002 - -Snapshot versions and versions of the form `1.0.0.Beta1` can be treated -as the rounded down version, eg `1.0.0`. + - do: + ... test definitions ... +.... The skip section can also be used to list new features that need to be supported in order to run a test. This way the up-to-date runners will diff --git a/rest-api-spec/test/cluster.put_settings/10_basic.yaml b/rest-api-spec/test/cluster.put_settings/10_basic.yaml index 37396dac822..bb1256efecd 100644 --- a/rest-api-spec/test/cluster.put_settings/10_basic.yaml +++ b/rest-api-spec/test/cluster.put_settings/10_basic.yaml @@ -1,7 +1,7 @@ --- setup: - skip: - version: 0 - 999 + version: " - " reason: leaves transient metadata behind, need to fix it --- "Test put settings": diff --git a/rest-api-spec/test/indices.get/10_basic.yaml b/rest-api-spec/test/indices.get/10_basic.yaml index 68e0e200fab..fd860745b52 100644 --- a/rest-api-spec/test/indices.get/10_basic.yaml +++ b/rest-api-spec/test/indices.get/10_basic.yaml @@ -166,7 +166,7 @@ setup: "Should return test_index_3 if expand_wildcards=closed": - skip: - version: "0 - 2.0.0" + version: " - 2.0.0" reason: Requires fix for issue 7258 - do: diff --git a/rest-api-spec/test/indices.get_aliases/10_basic.yaml b/rest-api-spec/test/indices.get_aliases/10_basic.yaml index 73e136ad15d..f83a164d912 100644 --- a/rest-api-spec/test/indices.get_aliases/10_basic.yaml +++ b/rest-api-spec/test/indices.get_aliases/10_basic.yaml @@ -202,7 +202,7 @@ setup: "Getting alias on an non-existent index should return 404": - skip: - version: 1 - 999 + version: "1.0.0.Beta1 - " reason: not implemented yet - do: catch: missing diff --git a/rest-api-spec/test/indices.put_settings/all_path_options.yaml b/rest-api-spec/test/indices.put_settings/all_path_options.yaml index b9ae7122216..bd64d57ff17 100644 --- a/rest-api-spec/test/indices.put_settings/all_path_options.yaml +++ b/rest-api-spec/test/indices.put_settings/all_path_options.yaml @@ -81,7 +81,7 @@ setup: --- "put settings in list of indices": - skip: - version: 1 - 999 + version: " - " reason: list of indices not implemented yet - do: indices.put_settings: diff --git a/rest-api-spec/test/update/85_fields_meta.yaml b/rest-api-spec/test/update/85_fields_meta.yaml index dd265cfb5fa..ab38d5c1315 100644 --- a/rest-api-spec/test/update/85_fields_meta.yaml +++ b/rest-api-spec/test/update/85_fields_meta.yaml @@ -2,7 +2,7 @@ "Metadata Fields": - skip: - version: "0 - 999" + version: " - " reason: "Update doesn't return metadata fields, waiting for #3259" - do: diff --git a/src/main/java/org/elasticsearch/Version.java b/src/main/java/org/elasticsearch/Version.java index 9a150cc7296..d34f1fb2f97 100644 --- a/src/main/java/org/elasticsearch/Version.java +++ b/src/main/java/org/elasticsearch/Version.java @@ -485,7 +485,7 @@ public class Version { } String[] parts = version.split("\\."); if (parts.length < 3 || parts.length > 4) { - throw new IllegalArgumentException("the version needs to contain major, minor and revision, and optionally the build"); + throw new IllegalArgumentException("the version needs to contain major, minor and revision, and optionally the build: " + version); } try { diff --git a/src/main/java/org/elasticsearch/action/termvectors/TermVectorsWriter.java b/src/main/java/org/elasticsearch/action/termvectors/TermVectorsWriter.java index 21b990ed2fd..53cdd35bc09 100644 --- a/src/main/java/org/elasticsearch/action/termvectors/TermVectorsWriter.java +++ b/src/main/java/org/elasticsearch/action/termvectors/TermVectorsWriter.java @@ -104,9 +104,14 @@ final class TermVectorsWriter { if (flags.contains(Flag.TermStatistics)) { // get the doc frequency if (dfs != null) { - writeTermStatistics(dfs.termStatistics().get(term)); + final TermStatistics statistics = dfs.termStatistics().get(term); + writeTermStatistics(statistics == null ? new TermStatistics(termBytesRef, 0, 0) : statistics); } else { - writeTermStatistics(topLevelIterator); + if (foundTerm) { + writeTermStatistics(topLevelIterator); + } else { + writeTermStatistics(new TermStatistics(termBytesRef, 0, 0)); + } } } if (useDocsAndPos) { diff --git a/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java b/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java index 47288a667b0..9020d115a8b 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java +++ b/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java @@ -26,6 +26,8 @@ import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.inject.CreationException; import org.elasticsearch.common.inject.spi.Message; +import org.elasticsearch.common.io.FileSystemUtils; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.jna.Natives; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; @@ -153,7 +155,7 @@ public class Bootstrap { if (pidFile != null) { try { - PidFile.create(Paths.get(pidFile), true); + PidFile.create(PathUtils.get(pidFile), true); } catch (Exception e) { String errorMessage = buildErrorMessage("pid", e); sysError(errorMessage, true); diff --git a/src/main/java/org/elasticsearch/common/io/FileSystemUtils.java b/src/main/java/org/elasticsearch/common/io/FileSystemUtils.java index 12440352be8..50f845f754a 100644 --- a/src/main/java/org/elasticsearch/common/io/FileSystemUtils.java +++ b/src/main/java/org/elasticsearch/common/io/FileSystemUtils.java @@ -208,7 +208,7 @@ public final class FileSystemUtils { } else if (suffix != null) { if (!isSameFile(file, path)) { // If it already exists we try to copy this new version appending suffix to its name - path = Paths.get(path.toString().concat(suffix)); + path = path.resolveSibling(path.getFileName().toString().concat(suffix)); // We just move the file to new dir but with a new name (appended with suffix) Files.move(file, path, StandardCopyOption.REPLACE_EXISTING); } @@ -258,6 +258,8 @@ public final class FileSystemUtils { Files.walkFileTree(source, new TreeCopier(source, destination, true)); } } + + // TODO: note that this will fail if source and target are on different NIO.2 filesystems. static class TreeCopier extends SimpleFileVisitor { private final Path source; diff --git a/src/main/java/org/elasticsearch/common/io/PathUtils.java b/src/main/java/org/elasticsearch/common/io/PathUtils.java new file mode 100644 index 00000000000..c70286a19b4 --- /dev/null +++ b/src/main/java/org/elasticsearch/common/io/PathUtils.java @@ -0,0 +1,84 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.common.io; + +import org.elasticsearch.common.SuppressForbidden; + +import java.net.URI; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * Utilities for creating a Path from names, + * or accessing the default FileSystem. + *

+ * This class allows the default filesystem to + * be changed during tests. + */ +@SuppressForbidden(reason = "accesses the default filesystem by design") +public final class PathUtils { + /** no instantiation */ + private PathUtils() {} + + /** the actual JDK default */ + static final FileSystem ACTUAL_DEFAULT = FileSystems.getDefault(); + + /** can be changed by tests (via reflection) */ + private static volatile FileSystem DEFAULT = ACTUAL_DEFAULT; + + /** + * Returns a {@code Path} from name components. + *

+ * This works just like {@code Paths.get()}. + * Remember: just like {@code Paths.get()} this is NOT A STRING CONCATENATION + * UTILITY FUNCTION. + *

+ * Remember: this should almost never be used. Usually resolve + * a path against an existing one! + */ + public static Path get(String first, String... more) { + return DEFAULT.getPath(first, more); + } + + /** + * Returns a {@code Path} from a URI + *

+ * This works just like {@code Paths.get()}. + *

+ * Remember: this should almost never be used. Usually resolve + * a path against an existing one! + */ + public static Path get(URI uri) { + if (uri.getScheme().equalsIgnoreCase("file")) { + return DEFAULT.provider().getPath(uri); + } else { + return Paths.get(uri); + } + } + + /** + * Returns the default FileSystem. + */ + public static FileSystem getDefaultFileSystem() { + return DEFAULT; + } +} diff --git a/src/main/java/org/elasticsearch/common/util/concurrent/EsExecutors.java b/src/main/java/org/elasticsearch/common/util/concurrent/EsExecutors.java index 22f0e807cc6..92e8d7d095f 100644 --- a/src/main/java/org/elasticsearch/common/util/concurrent/EsExecutors.java +++ b/src/main/java/org/elasticsearch/common/util/concurrent/EsExecutors.java @@ -36,6 +36,9 @@ public class EsExecutors { */ public static final String PROCESSORS = "processors"; + /** Useful for testing */ + public static final String DEFAULT_SYSPROP = "es.processors.override"; + /** * Returns the number of processors available but at most 32. */ @@ -44,7 +47,11 @@ public class EsExecutors { * ie. >= 48 create too many threads and run into OOM see #3478 * We just use an 32 core upper-bound here to not stress the system * too much with too many created threads */ - return settings.getAsInt(PROCESSORS, Math.min(32, Runtime.getRuntime().availableProcessors())); + int defaultValue = Math.min(32, Runtime.getRuntime().availableProcessors()); + try { + defaultValue = Integer.parseInt(System.getProperty(DEFAULT_SYSPROP)); + } catch (Throwable ignored) {} + return settings.getAsInt(PROCESSORS, defaultValue); } public static PrioritizedEsThreadPoolExecutor newSinglePrioritizing(ThreadFactory threadFactory) { diff --git a/src/main/java/org/elasticsearch/env/Environment.java b/src/main/java/org/elasticsearch/env/Environment.java index 62f09d72d04..87a356774f1 100644 --- a/src/main/java/org/elasticsearch/env/Environment.java +++ b/src/main/java/org/elasticsearch/env/Environment.java @@ -20,6 +20,8 @@ package org.elasticsearch.env; import org.elasticsearch.cluster.ClusterName; +import org.elasticsearch.common.io.FileSystemUtils; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.settings.Settings; @@ -68,25 +70,25 @@ public class Environment { public Environment(Settings settings) { this.settings = settings; if (settings.get("path.home") != null) { - homeFile = Paths.get(cleanPath(settings.get("path.home"))); + homeFile = PathUtils.get(cleanPath(settings.get("path.home"))); } else { - homeFile = Paths.get(System.getProperty("user.dir")); + homeFile = PathUtils.get(System.getProperty("user.dir")); } if (settings.get("path.conf") != null) { - configFile = Paths.get(cleanPath(settings.get("path.conf"))); + configFile = PathUtils.get(cleanPath(settings.get("path.conf"))); } else { configFile = homeFile.resolve("config"); } if (settings.get("path.plugins") != null) { - pluginsFile = Paths.get(cleanPath(settings.get("path.plugins"))); + pluginsFile = PathUtils.get(cleanPath(settings.get("path.plugins"))); } else { pluginsFile = homeFile.resolve("plugins"); } if (settings.get("path.work") != null) { - workFile = Paths.get(cleanPath(settings.get("path.work"))); + workFile = PathUtils.get(cleanPath(settings.get("path.work"))); } else { workFile = homeFile.resolve("work"); } @@ -97,7 +99,7 @@ public class Environment { dataFiles = new Path[dataPaths.length]; dataWithClusterFiles = new Path[dataPaths.length]; for (int i = 0; i < dataPaths.length; i++) { - dataFiles[i] = Paths.get(dataPaths[i]); + dataFiles[i] = PathUtils.get(dataPaths[i]); dataWithClusterFiles[i] = dataFiles[i].resolve(ClusterName.clusterNameFromSettings(settings).value()); } } else { @@ -106,7 +108,7 @@ public class Environment { } if (settings.get("path.logs") != null) { - logsFile = Paths.get(cleanPath(settings.get("path.logs"))); + logsFile = PathUtils.get(cleanPath(settings.get("path.logs"))); } else { logsFile = homeFile.resolve("logs"); } @@ -178,7 +180,7 @@ 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 = Paths.get(path); + Path f1 = PathUtils.get(path); if (Files.exists(f1)) { try { return f1.toUri().toURL(); diff --git a/src/main/java/org/elasticsearch/env/NodeEnvironment.java b/src/main/java/org/elasticsearch/env/NodeEnvironment.java index 201fe226af6..458acf5e935 100644 --- a/src/main/java/org/elasticsearch/env/NodeEnvironment.java +++ b/src/main/java/org/elasticsearch/env/NodeEnvironment.java @@ -22,6 +22,7 @@ package org.elasticsearch.env; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import com.google.common.primitives.Ints; + import org.apache.lucene.store.*; import org.apache.lucene.util.Constants; import org.apache.lucene.util.IOUtils; @@ -33,6 +34,7 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.FileSystemUtils; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; @@ -128,7 +130,8 @@ public class NodeEnvironment extends AbstractComponent implements Closeable { int maxLocalStorageNodes = settings.getAsInt("node.max_local_storage_nodes", 50); for (int possibleLockId = 0; possibleLockId < maxLocalStorageNodes; possibleLockId++) { for (int dirIndex = 0; dirIndex < environment.dataWithClusterFiles().length; dirIndex++) { - Path dir = environment.dataWithClusterFiles()[dirIndex].resolve(Paths.get(NODES_FOLDER, Integer.toString(possibleLockId))); + // TODO: wtf with resolve(get()) + Path dir = environment.dataWithClusterFiles()[dirIndex].resolve(PathUtils.get(NODES_FOLDER, Integer.toString(possibleLockId))); Files.createDirectories(dir); try (Directory luceneDir = FSDirectory.open(dir, NativeFSLockFactory.INSTANCE)) { @@ -616,7 +619,8 @@ public class NodeEnvironment extends AbstractComponent implements Closeable { final NodePath[] nodePaths = nodePaths(); final Path[] shardLocations = new Path[nodePaths.length]; for (int i = 0; i < nodePaths.length; i++) { - shardLocations[i] = nodePaths[i].path.resolve(Paths.get(INDICES_FOLDER, + // TODO: wtf with resolve(get()) + shardLocations[i] = nodePaths[i].path.resolve(PathUtils.get(INDICES_FOLDER, shardId.index().name(), Integer.toString(shardId.id()))); } @@ -730,9 +734,9 @@ public class NodeEnvironment extends AbstractComponent implements Closeable { // This assert is because this should be caught by MetaDataCreateIndexService assert customPathsEnabled; if (addNodeId) { - return Paths.get(customDataDir, Integer.toString(this.localNodeId)); + return PathUtils.get(customDataDir, Integer.toString(this.localNodeId)); } else { - return Paths.get(customDataDir); + return PathUtils.get(customDataDir); } } else { throw new ElasticsearchIllegalArgumentException("no custom " + IndexMetaData.SETTING_DATA_PATH + " setting available"); diff --git a/src/main/java/org/elasticsearch/http/HttpServer.java b/src/main/java/org/elasticsearch/http/HttpServer.java index b4a26ba8c57..6d43053e408 100644 --- a/src/main/java/org/elasticsearch/http/HttpServer.java +++ b/src/main/java/org/elasticsearch/http/HttpServer.java @@ -25,6 +25,7 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.FileSystemUtils; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.node.service.NodeService; @@ -175,7 +176,7 @@ public class HttpServer extends AbstractLifecycleComponent { // Convert file separators. sitePath = sitePath.replace("/", separator); // this is a plugin provided site, serve it as static files from the plugin location - Path file = FileSystemUtils.append(siteFile, Paths.get(sitePath), 0); + Path file = FileSystemUtils.append(siteFile, PathUtils.get(sitePath), 0); if (!Files.exists(file) || Files.isHidden(file)) { channel.sendResponse(new BytesRestResponse(NOT_FOUND)); return; diff --git a/src/main/java/org/elasticsearch/index/codec/CodecService.java b/src/main/java/org/elasticsearch/index/codec/CodecService.java index 248e153a706..cd1940eb8da 100644 --- a/src/main/java/org/elasticsearch/index/codec/CodecService.java +++ b/src/main/java/org/elasticsearch/index/codec/CodecService.java @@ -50,6 +50,8 @@ public class CodecService extends AbstractIndexComponent { public final static String DEFAULT_CODEC = "default"; public final static String BEST_COMPRESSION_CODEC = "best_compression"; + /** the raw unfiltered lucene default. useful for testing */ + public final static String LUCENE_DEFAULT_CODEC = "lucene_default"; public CodecService(Index index) { this(index, ImmutableSettings.Builder.EMPTY_SETTINGS); @@ -73,6 +75,7 @@ public class CodecService extends AbstractIndexComponent { codecs.put(BEST_COMPRESSION_CODEC, new PerFieldMappingPostingFormatCodec(Mode.BEST_COMPRESSION, mapperService, logger)); } + codecs.put(LUCENE_DEFAULT_CODEC, Codec.getDefault()); for (String codec : Codec.availableCodecs()) { codecs.put(codec, Codec.forName(codec)); } diff --git a/src/main/java/org/elasticsearch/index/engine/InternalEngine.java b/src/main/java/org/elasticsearch/index/engine/InternalEngine.java index b4db6b93f17..018a4fb6c40 100644 --- a/src/main/java/org/elasticsearch/index/engine/InternalEngine.java +++ b/src/main/java/org/elasticsearch/index/engine/InternalEngine.java @@ -20,6 +20,7 @@ package org.elasticsearch.index.engine; import com.google.common.collect.Lists; + import org.apache.lucene.index.*; import org.apache.lucene.index.IndexWriter.IndexReaderWarmer; import org.apache.lucene.search.*; @@ -27,6 +28,7 @@ import org.apache.lucene.store.AlreadyClosedException; import org.apache.lucene.store.LockObtainFailedException; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.IOUtils; +import org.apache.lucene.util.InfoStream; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.cluster.routing.DjbHashFunction; import org.elasticsearch.common.Nullable; @@ -999,7 +1001,12 @@ public class InternalEngine extends Engine { iwc.setCommitOnClose(false); // we by default don't commit on close iwc.setOpenMode(create ? IndexWriterConfig.OpenMode.CREATE : IndexWriterConfig.OpenMode.APPEND); iwc.setIndexDeletionPolicy(deletionPolicy); - iwc.setInfoStream(new LoggerInfoStream(logger)); + // with tests.verbose, lucene sets this up: plumb to align with filesystem stream + boolean verbose = false; + try { + verbose = Boolean.parseBoolean(System.getProperty("tests.verbose")); + } catch (Throwable ignore) {} + iwc.setInfoStream(verbose ? InfoStream.getDefault() : new LoggerInfoStream(logger)); iwc.setMergeScheduler(mergeScheduler.newMergeScheduler()); MergePolicy mergePolicy = mergePolicyProvider.getMergePolicy(); // Give us the opportunity to upgrade old segments while performing diff --git a/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/src/main/java/org/elasticsearch/index/mapper/MapperService.java index 697d2488bd3..e7629f51035 100755 --- a/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -45,6 +45,7 @@ import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.compress.CompressedString; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.FileSystemUtils; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.lucene.search.AndFilter; import org.elasticsearch.common.lucene.search.NotFilter; @@ -180,7 +181,7 @@ public class MapperService extends AbstractIndexComponent { } catch (FailedToResolveConfigException e) { // not there, default to the built in one try { - percolatorMappingUrl = Paths.get(percolatorMappingLocation).toUri().toURL(); + percolatorMappingUrl = PathUtils.get(percolatorMappingLocation).toUri().toURL(); } catch (MalformedURLException e1) { throw new FailedToResolveConfigException("Failed to resolve default percolator mapping location [" + percolatorMappingLocation + "]"); } @@ -231,7 +232,7 @@ public class MapperService extends AbstractIndexComponent { } catch (FailedToResolveConfigException e) { // not there, default to the built in one try { - mappingUrl = Paths.get(mappingLocation).toUri().toURL(); + mappingUrl = PathUtils.get(mappingLocation).toUri().toURL(); } catch (MalformedURLException e1) { throw new FailedToResolveConfigException("Failed to resolve dynamic mapping location [" + mappingLocation + "]"); } diff --git a/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java b/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java index b5628fcf370..ccb49a6fd2a 100644 --- a/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java +++ b/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java @@ -22,11 +22,13 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.util.concurrent.UncheckedExecutionException; + import org.apache.lucene.analysis.hunspell.Dictionary; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.FileSystemUtils; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; @@ -116,7 +118,7 @@ public class HunspellService extends AbstractComponent { private Path resolveHunspellDirectory(Settings settings, Environment env) { String location = settings.get(HUNSPELL_LOCATION, null); if (location != null) { - return Paths.get(location); + return PathUtils.get(location); } return env.configFile().resolve("hunspell"); } diff --git a/src/main/java/org/elasticsearch/plugins/PluginsService.java b/src/main/java/org/elasticsearch/plugins/PluginsService.java index 87420fc7184..7a7c569acbe 100644 --- a/src/main/java/org/elasticsearch/plugins/PluginsService.java +++ b/src/main/java/org/elasticsearch/plugins/PluginsService.java @@ -21,6 +21,7 @@ package org.elasticsearch.plugins; import com.google.common.base.Charsets; import com.google.common.collect.*; + import org.apache.lucene.util.Constants; import org.apache.lucene.util.IOUtils; import org.elasticsearch.ElasticsearchException; @@ -35,6 +36,7 @@ import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.io.FileSystemUtils; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.settings.ImmutableSettings; @@ -61,7 +63,7 @@ public class PluginsService extends AbstractComponent { public static final String ES_PLUGIN_PROPERTIES = "es-plugin.properties"; public static final String LOAD_PLUGIN_FROM_CLASSPATH = "plugins.load_classpath_plugins"; - private static final PathMatcher PLUGIN_LIB_MATCHER = FileSystems.getDefault().getPathMatcher("glob:**.{jar,zip}"); + static final String PLUGIN_LIB_PATTERN = "glob:**.{jar,zip}"; public static final String PLUGINS_CHECK_LUCENE_KEY = "plugins.check_lucene"; public static final String PLUGINS_INFO_REFRESH_INTERVAL_KEY = "plugins.info_refresh_interval"; @@ -393,9 +395,11 @@ public class PluginsService extends AbstractComponent { libFiles.addAll(Arrays.asList(files(libLocation))); } + PathMatcher matcher = PathUtils.getDefaultFileSystem().getPathMatcher(PLUGIN_LIB_PATTERN); + // if there are jars in it, add it as well for (Path libFile : libFiles) { - if (!hasLibExtension(libFile)) { + if (!matcher.matches(libFile)) { continue; } addURL.invoke(classLoader, libFile.toUri().toURL()); @@ -407,10 +411,6 @@ public class PluginsService extends AbstractComponent { } } - protected static boolean hasLibExtension(Path lib) { - return PLUGIN_LIB_MATCHER.matches(lib); - } - private Path[] files(Path from) throws IOException { try (DirectoryStream stream = Files.newDirectoryStream(from)) { return Iterators.toArray(stream.iterator(), Path.class); diff --git a/src/main/java/org/elasticsearch/repositories/fs/FsRepository.java b/src/main/java/org/elasticsearch/repositories/fs/FsRepository.java index aa65f6983da..49c783b56ae 100644 --- a/src/main/java/org/elasticsearch/repositories/fs/FsRepository.java +++ b/src/main/java/org/elasticsearch/repositories/fs/FsRepository.java @@ -23,6 +23,8 @@ import org.elasticsearch.common.blobstore.BlobPath; import org.elasticsearch.common.blobstore.BlobStore; import org.elasticsearch.common.blobstore.fs.FsBlobStore; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.io.FileSystemUtils; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.index.snapshots.IndexShardRepository; import org.elasticsearch.repositories.RepositoryException; @@ -74,7 +76,7 @@ public class FsRepository extends BlobStoreRepository { logger.warn("using local fs location for gateway, should be changed to be a shared location across nodes"); throw new RepositoryException(name.name(), "missing location"); } else { - locationFile = Paths.get(location); + locationFile = PathUtils.get(location); } blobStore = new FsBlobStore(settings, locationFile); this.chunkSize = repositorySettings.settings().getAsBytesSize("chunk_size", settings.getAsBytesSize("repositories.fs.chunk_size", null)); diff --git a/src/test/java/org/apache/lucene/queries/BlendedTermQueryTest.java b/src/test/java/org/apache/lucene/queries/BlendedTermQueryTest.java index a127e5d8dde..634026a5df7 100644 --- a/src/test/java/org/apache/lucene/queries/BlendedTermQueryTest.java +++ b/src/test/java/org/apache/lucene/queries/BlendedTermQueryTest.java @@ -41,7 +41,7 @@ import org.apache.lucene.search.similarities.DefaultSimilarity; import org.apache.lucene.search.similarities.Similarity; import org.apache.lucene.store.Directory; import org.apache.lucene.util.TestUtil; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; +import org.elasticsearch.test.ElasticsearchTestCase; import org.junit.Test; import java.io.IOException; @@ -56,7 +56,7 @@ import static org.hamcrest.Matchers.equalTo; /** */ -public class BlendedTermQueryTest extends ElasticsearchLuceneTestCase { +public class BlendedTermQueryTest extends ElasticsearchTestCase { @Test public void testBooleanQuery() throws IOException { diff --git a/src/test/java/org/apache/lucene/search/postingshighlight/CustomPostingsHighlighterTests.java b/src/test/java/org/apache/lucene/search/postingshighlight/CustomPostingsHighlighterTests.java index cf981b90339..01abea2b4f4 100644 --- a/src/test/java/org/apache/lucene/search/postingshighlight/CustomPostingsHighlighterTests.java +++ b/src/test/java/org/apache/lucene/search/postingshighlight/CustomPostingsHighlighterTests.java @@ -28,10 +28,9 @@ import org.apache.lucene.search.*; import org.apache.lucene.search.highlight.DefaultEncoder; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; -import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.UnicodeUtil; import org.elasticsearch.search.highlight.HighlightUtils; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; +import org.elasticsearch.test.ElasticsearchTestCase; import org.junit.Test; import java.io.IOException; @@ -40,8 +39,7 @@ import java.util.*; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.notNullValue; -@LuceneTestCase.SuppressCodecs({"MockFixedIntBlock", "MockVariableIntBlock", "MockSep", "MockRandom", "Lucene3x"}) -public class CustomPostingsHighlighterTests extends ElasticsearchLuceneTestCase { +public class CustomPostingsHighlighterTests extends ElasticsearchTestCase { @Test public void testDiscreteHighlightingPerValue() throws Exception { diff --git a/src/test/java/org/apache/lucene/search/postingshighlight/XPostingsHighlighterTests.java b/src/test/java/org/apache/lucene/search/postingshighlight/XPostingsHighlighterTests.java index 6f70595d005..b20e544866d 100644 --- a/src/test/java/org/apache/lucene/search/postingshighlight/XPostingsHighlighterTests.java +++ b/src/test/java/org/apache/lucene/search/postingshighlight/XPostingsHighlighterTests.java @@ -27,7 +27,8 @@ import org.apache.lucene.search.*; import org.apache.lucene.search.highlight.DefaultEncoder; import org.apache.lucene.store.Directory; import org.apache.lucene.util.LuceneTestCase; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; +import org.apache.lucene.util.TestUtil; +import org.elasticsearch.test.ElasticsearchTestCase; import org.junit.Test; import java.io.BufferedReader; @@ -40,8 +41,7 @@ import java.util.Map; import static org.hamcrest.CoreMatchers.*; -@LuceneTestCase.SuppressCodecs({"MockFixedIntBlock", "MockVariableIntBlock", "MockSep", "MockRandom", "Lucene3x"}) -public class XPostingsHighlighterTests extends ElasticsearchLuceneTestCase { +public class XPostingsHighlighterTests extends ElasticsearchTestCase { /* Tests changes needed to make possible to perform discrete highlighting. diff --git a/src/test/java/org/apache/lucene/util/AbstractRandomizedTest.java b/src/test/java/org/apache/lucene/util/AbstractRandomizedTest.java deleted file mode 100644 index d5cbdf8b076..00000000000 --- a/src/test/java/org/apache/lucene/util/AbstractRandomizedTest.java +++ /dev/null @@ -1,448 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.lucene.util; - -import com.carrotsearch.randomizedtesting.*; -import com.carrotsearch.randomizedtesting.annotations.Listeners; -import com.carrotsearch.randomizedtesting.annotations.TestGroup; -import com.carrotsearch.randomizedtesting.annotations.TestMethodProviders; -import com.carrotsearch.randomizedtesting.rules.NoClassHooksShadowingRule; -import com.carrotsearch.randomizedtesting.rules.NoInstanceHooksOverridesRule; -import com.carrotsearch.randomizedtesting.rules.StaticFieldsInvariantRule; -import com.carrotsearch.randomizedtesting.rules.SystemPropertiesInvariantRule; -import org.apache.lucene.util.LuceneTestCase.SuppressCodecs; -import org.elasticsearch.common.lucene.Lucene; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.common.util.concurrent.EsExecutors; -import org.elasticsearch.test.AfterTestRule; -import org.elasticsearch.test.ElasticsearchIntegrationTest; -import org.elasticsearch.test.ElasticsearchTestCase; -import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.rules.RuleChain; -import org.junit.rules.TestRule; -import org.junit.runner.RunWith; - -import java.io.Closeable; -import java.io.IOException; -import java.lang.annotation.*; -import java.lang.reflect.Method; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.*; -import java.util.concurrent.atomic.AtomicReference; -import java.util.logging.Logger; - -@TestMethodProviders({ - LuceneJUnit3MethodProvider.class, - JUnit4MethodProvider.class -}) -@Listeners({ - ReproduceInfoPrinter.class, - FailureMarker.class -}) -@RunWith(value = com.carrotsearch.randomizedtesting.RandomizedRunner.class) -@SuppressCodecs(value = "Lucene3x") - -// NOTE: this class is in o.a.lucene.util since it uses some classes that are related -// to the test framework that didn't make sense to copy but are package private access -public abstract class AbstractRandomizedTest extends RandomizedTest { - - - /** - * The number of concurrent JVMs used to run the tests, Default is 1 - */ - public static final int CHILD_JVM_COUNT = Integer.parseInt(System.getProperty(SysGlobals.CHILDVM_SYSPROP_JVM_COUNT, "1")); - /** - * The child JVM ordinal of this JVM. Default is 0 - */ - public static final int CHILD_JVM_ID = Integer.parseInt(System.getProperty(SysGlobals.CHILDVM_SYSPROP_JVM_ID, "0")); - - /** - * Annotation for backwards compat tests - */ - @Inherited - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.TYPE) - @TestGroup(enabled = false, sysProperty = TESTS_BACKWARDS_COMPATIBILITY) - public @interface Backwards { - } - - /** - * Key used to set the path for the elasticsearch executable used to run backwards compatibility tests from - * via the commandline -D{@value #TESTS_BACKWARDS_COMPATIBILITY} - */ - public static final String TESTS_BACKWARDS_COMPATIBILITY = "tests.bwc"; - - public static final String TESTS_BACKWARDS_COMPATIBILITY_VERSION = "tests.bwc.version"; - - /** - * Key used to set the path for the elasticsearch executable used to run backwards compatibility tests from - * via the commandline -D{@value #TESTS_BACKWARDS_COMPATIBILITY_PATH} - */ - public static final String TESTS_BACKWARDS_COMPATIBILITY_PATH = "tests.bwc.path"; - - /** - * Annotation for REST tests - */ - @Inherited - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.TYPE) - @TestGroup(enabled = true, sysProperty = TESTS_REST) - public @interface Rest { - } - - /** - * Property that allows to control whether the REST tests are run (default) or not - */ - public static final String TESTS_REST = "tests.rest"; - - /** - * Annotation for integration tests - */ - @Inherited - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.TYPE) - @TestGroup(enabled = true, sysProperty = SYSPROP_INTEGRATION) - public @interface Integration { - } - - // -------------------------------------------------------------------- - // Test groups, system properties and other annotations modifying tests - // -------------------------------------------------------------------- - - /** - * @see #ignoreAfterMaxFailures - */ - public static final String SYSPROP_MAXFAILURES = "tests.maxfailures"; - - /** - * @see #ignoreAfterMaxFailures - */ - public static final String SYSPROP_FAILFAST = "tests.failfast"; - - public static final String SYSPROP_INTEGRATION = "tests.integration"; - - public static final String SYSPROP_PROCESSORS = "tests.processors"; - - // ----------------------------------------------------------------- - // Truly immutable fields and constants, initialized once and valid - // for all suites ever since. - // ----------------------------------------------------------------- - - /** - * Use this constant when creating Analyzers and any other version-dependent stuff. - *

NOTE: Change this when development starts for new Lucene version: - */ - public static final Version TEST_VERSION_CURRENT = Lucene.VERSION; - - /** - * True if and only if tests are run in verbose mode. If this flag is false - * tests are not expected to print any messages. - */ - public static final boolean VERBOSE = systemPropertyAsBoolean("tests.verbose", false); - - /** - * A random multiplier which you should use when writing random tests: - * multiply it by the number of iterations to scale your tests (for nightly builds). - */ - public static final int RANDOM_MULTIPLIER = systemPropertyAsInt("tests.multiplier", 1); - - /** - * TODO: javadoc? - */ - public static final String DEFAULT_LINE_DOCS_FILE = "europarl.lines.txt.gz"; - - /** - * the line file used by LineFileDocs - */ - public static final String TEST_LINE_DOCS_FILE = System.getProperty("tests.linedocsfile", DEFAULT_LINE_DOCS_FILE); - - /** - * Create indexes in this directory, optimally use a subdir, named after the test - */ - public static final Path TEMP_DIR; - - public static final int TESTS_PROCESSORS; - - static { - String s = System.getProperty("tempDir", System.getProperty("java.io.tmpdir")); - if (s == null) - throw new RuntimeException("To run tests, you need to define system property 'tempDir' or 'java.io.tmpdir'."); - TEMP_DIR = Paths.get(s); - try { - Files.createDirectories(TEMP_DIR); - } catch (IOException e) { - throw new RuntimeException(e); - } - - String processors = System.getProperty(SYSPROP_PROCESSORS, ""); // mvn sets "" as default - if (processors == null || processors.isEmpty()) { - processors = Integer.toString(EsExecutors.boundedNumberOfProcessors(ImmutableSettings.EMPTY)); - } - TESTS_PROCESSORS = Integer.parseInt(processors); - } - - /** - * These property keys will be ignored in verification of altered properties. - * - * @see SystemPropertiesInvariantRule - * @see #ruleChain - * @see #classRules - */ - private static final String[] IGNORED_INVARIANT_PROPERTIES = { - "user.timezone", "java.rmi.server.randomIDs", "sun.nio.ch.bugLevel", - "solr.directoryFactory", "solr.solr.home", "solr.data.dir" // these might be set by the LuceneTestCase -- ignore - }; - - // ----------------------------------------------------------------- - // Fields initialized in class or instance rules. - // ----------------------------------------------------------------- - - - // ----------------------------------------------------------------- - // Class level (suite) rules. - // ----------------------------------------------------------------- - - /** - * Stores the currently class under test. - */ - private static final TestRuleStoreClassName classNameRule; - - /** - * Class environment setup rule. - */ - static final TestRuleSetupAndRestoreClassEnv classEnvRule; - - /** - * Suite failure marker (any error in the test or suite scope). - */ - public final static TestRuleMarkFailure suiteFailureMarker = - new TestRuleMarkFailure(); - - /** - * Ignore tests after hitting a designated number of initial failures. This - * is truly a "static" global singleton since it needs to span the lifetime of all - * test classes running inside this JVM (it cannot be part of a class rule). - *

- *

This poses some problems for the test framework's tests because these sometimes - * trigger intentional failures which add up to the global count. This field contains - * a (possibly) changing reference to {@link TestRuleIgnoreAfterMaxFailures} and we - * dispatch to its current value from the {@link #classRules} chain using {@link TestRuleDelegate}. - */ - private static final AtomicReference ignoreAfterMaxFailuresDelegate; - private static final TestRule ignoreAfterMaxFailures; - - private static final AfterTestRule.Task noOpAfterRuleTask = new AfterTestRule.Task(); - - static { - int maxFailures = systemPropertyAsInt(SYSPROP_MAXFAILURES, Integer.MAX_VALUE); - boolean failFast = systemPropertyAsBoolean(SYSPROP_FAILFAST, false); - - if (failFast) { - if (maxFailures == Integer.MAX_VALUE) { - maxFailures = 1; - } else { - Logger.getLogger(LuceneTestCase.class.getSimpleName()).warning( - "Property '" + SYSPROP_MAXFAILURES + "'=" + maxFailures + ", 'failfast' is" + - " ignored."); - } - } - - ignoreAfterMaxFailuresDelegate = - new AtomicReference<>( - new TestRuleIgnoreAfterMaxFailures(maxFailures)); - ignoreAfterMaxFailures = TestRuleDelegate.of(ignoreAfterMaxFailuresDelegate); - } - - /** - * Temporarily substitute the global {@link TestRuleIgnoreAfterMaxFailures}. See - * {@link #ignoreAfterMaxFailuresDelegate} for some explanation why this method - * is needed. - */ - public static TestRuleIgnoreAfterMaxFailures replaceMaxFailureRule(TestRuleIgnoreAfterMaxFailures newValue) { - return ignoreAfterMaxFailuresDelegate.getAndSet(newValue); - } - - /** - * Max 10mb of static data stored in a test suite class after the suite is complete. - * Prevents static data structures leaking and causing OOMs in subsequent tests. - */ - private final static long STATIC_LEAK_THRESHOLD = 10 * 1024 * 1024; - - /** - * By-name list of ignored types like loggers etc. - */ - private final static Set STATIC_LEAK_IGNORED_TYPES = - Collections.unmodifiableSet(new HashSet<>(Arrays.asList( - EnumSet.class.getName()))); - - private final static Set> TOP_LEVEL_CLASSES = - Collections.unmodifiableSet(new HashSet>(Arrays.asList( - AbstractRandomizedTest.class, LuceneTestCase.class, - ElasticsearchIntegrationTest.class, ElasticsearchTestCase.class))); - - /** - * This controls how suite-level rules are nested. It is important that _all_ rules declared - * in {@link LuceneTestCase} are executed in proper order if they depend on each - * other. - */ - @ClassRule - public static TestRule classRules = RuleChain - .outerRule(new TestRuleIgnoreTestSuites()) - .around(ignoreAfterMaxFailures) - .around(suiteFailureMarker) - .around(new TestRuleAssertionsRequired()) - .around(new StaticFieldsInvariantRule(STATIC_LEAK_THRESHOLD, true) { - @Override - protected boolean accept(java.lang.reflect.Field field) { - // Don't count known classes that consume memory once. - if (STATIC_LEAK_IGNORED_TYPES.contains(field.getType().getName())) { - return false; - } - // Don't count references from ourselves, we're top-level. - if (TOP_LEVEL_CLASSES.contains(field.getDeclaringClass())) { - return false; - } - return super.accept(field); - } - }) - .around(new NoClassHooksShadowingRule()) - .around(new NoInstanceHooksOverridesRule() { - @Override - protected boolean verify(Method key) { - String name = key.getName(); - return !(name.equals("setUp") || name.equals("tearDown")); - } - }) - .around(new SystemPropertiesInvariantRule(IGNORED_INVARIANT_PROPERTIES)) - .around(classNameRule = new TestRuleStoreClassName()) - .around(classEnvRule = new TestRuleSetupAndRestoreClassEnv()); - - - // ----------------------------------------------------------------- - // Test level rules. - // ----------------------------------------------------------------- - - /** - * Enforces {@link #setUp()} and {@link #tearDown()} calls are chained. - */ - private TestRuleSetupTeardownChained parentChainCallRule = new TestRuleSetupTeardownChained(); - - /** - * Save test thread and name. - */ - private TestRuleThreadAndTestName threadAndTestNameRule = new TestRuleThreadAndTestName(); - - /** - * Taint suite result with individual test failures. - */ - private TestRuleMarkFailure testFailureMarker = new TestRuleMarkFailure(suiteFailureMarker); - - protected AfterTestRule afterTestRule = new AfterTestRule(afterTestTask()); - - /** - * This controls how individual test rules are nested. It is important that - * _all_ rules declared in {@link LuceneTestCase} are executed in proper order - * if they depend on each other. - */ - @Rule - public final TestRule ruleChain = RuleChain - .outerRule(testFailureMarker) - .around(ignoreAfterMaxFailures) - .around(threadAndTestNameRule) - .around(new SystemPropertiesInvariantRule(IGNORED_INVARIANT_PROPERTIES)) - .around(new TestRuleSetupAndRestoreInstanceEnv()) - .around(parentChainCallRule) - .around(afterTestRule); - - // ----------------------------------------------------------------- - // Suite and test case setup/ cleanup. - // ----------------------------------------------------------------- - - /** MockFSDirectoryService sets this: */ - public static boolean checkIndexFailed; - - /** - * For subclasses to override. Overrides must call {@code super.setUp()}. - */ - @Before - public void setUp() throws Exception { - parentChainCallRule.setupCalled = true; - checkIndexFailed = false; - } - - /** - * For subclasses to override. Overrides must call {@code super.tearDown()}. - */ - @After - public void tearDown() throws Exception { - parentChainCallRule.teardownCalled = true; - assertFalse("at least one shard failed CheckIndex", checkIndexFailed); - } - - - // ----------------------------------------------------------------- - // Test facilities and facades for subclasses. - // ----------------------------------------------------------------- - - /** - * Registers a {@link Closeable} resource that should be closed after the test - * completes. - * - * @return resource (for call chaining). - */ - @Override - public T closeAfterTest(T resource) { - return RandomizedContext.current().closeAtEnd(resource, LifecycleScope.TEST); - } - - /** - * Registers a {@link Closeable} resource that should be closed after the suite - * completes. - * - * @return resource (for call chaining). - */ - public static T closeAfterSuite(T resource) { - return RandomizedContext.current().closeAtEnd(resource, LifecycleScope.SUITE); - } - - /** - * Return the current class being tested. - */ - public static Class getTestClass() { - return classNameRule.getTestClass(); - } - - /** - * Return the name of the currently executing test case. - */ - public String getTestName() { - return threadAndTestNameRule.testMethodName; - } - - protected AfterTestRule.Task afterTestTask() { - return noOpAfterRuleTask; - } -} diff --git a/src/test/java/org/apache/lucene/util/SloppyMathTests.java b/src/test/java/org/apache/lucene/util/SloppyMathTests.java index 2bcd9ed34e1..61a74b49e02 100644 --- a/src/test/java/org/apache/lucene/util/SloppyMathTests.java +++ b/src/test/java/org/apache/lucene/util/SloppyMathTests.java @@ -63,8 +63,8 @@ public class SloppyMathTests extends ElasticsearchTestCase { for (int i = 0; i < 100; i++) { // crop pole areas, sine we now there the function // is not accurate around lat(89°, 90°) and lat(-90°, -89°) - final double lat2 = Math.max(-89.0, Math.min(+89.0, lat1 + (randomDouble() - 0.5) * 2 * deltaDeg[test])); - final double lon2 = lon1 + (randomDouble() - 0.5) * 2 * deltaDeg[test]; + final double lat2 = Math.max(-89.0, Math.min(+89.0, lat1 + (random().nextDouble() - 0.5) * 2 * deltaDeg[test])); + final double lon2 = lon1 + (random().nextDouble() - 0.5) * 2 * deltaDeg[test]; final double accurate = GeoDistance.ARC.calculate(lat1, lon1, lat2, lon2, unit); final double dist = GeoDistance.SLOPPY_ARC.calculate(lat1, lon1, lat2, lon2, unit); @@ -83,10 +83,10 @@ public class SloppyMathTests extends ElasticsearchTestCase { private static final double randomLatitude() { // crop pole areas, sine we now there the function // is not accurate around lat(89°, 90°) and lat(-90°, -89°) - return (getRandom().nextDouble() - 0.5) * 178.0; + return (random().nextDouble() - 0.5) * 178.0; } private static final double randomLongitude() { - return (getRandom().nextDouble() - 0.5) * 360.0; + return (random().nextDouble() - 0.5) * 360.0; } } diff --git a/src/test/java/org/elasticsearch/NamingConventionTests.java b/src/test/java/org/elasticsearch/NamingConventionTests.java index 3a792c35e41..db39c66f30b 100644 --- a/src/test/java/org/elasticsearch/NamingConventionTests.java +++ b/src/test/java/org/elasticsearch/NamingConventionTests.java @@ -20,9 +20,12 @@ package org.elasticsearch; import com.google.common.base.Joiner; import com.google.common.collect.Sets; + import junit.framework.TestCase; + import org.apache.lucene.util.LuceneTestCase; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; +import org.elasticsearch.common.io.PathUtils; +import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.test.ElasticsearchTokenStreamTestCase; import org.junit.Ignore; @@ -51,10 +54,10 @@ public class NamingConventionTests extends ElasticsearchTestCase { String[] packages = {"org.elasticsearch", "org.apache.lucene"}; for (final String packageName : packages) { final String path = "/" + packageName.replace('.', '/'); - final Path startPath = Paths.get(NamingConventionTests.class.getResource(path).toURI()); - final Set ignore = Sets.newHashSet(Paths.get("/org/elasticsearch/stresstest"), Paths.get("/org/elasticsearch/benchmark/stress")); + final Path startPath = getDataPath(path); + final Set ignore = Sets.newHashSet(PathUtils.get("/org/elasticsearch/stresstest"), PathUtils.get("/org/elasticsearch/benchmark/stress")); Files.walkFileTree(startPath, new FileVisitor() { - private Path pkgPrefix = Paths.get(path).getParent(); + private Path pkgPrefix = PathUtils.get(path).getParent(); @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { Path next = pkgPrefix.resolve(dir.getFileName()); @@ -101,7 +104,7 @@ public class NamingConventionTests extends ElasticsearchTestCase { } private boolean isTestCase(Class clazz) { - return ElasticsearchTestCase.class.isAssignableFrom(clazz) || ElasticsearchLuceneTestCase.class.isAssignableFrom(clazz) || ElasticsearchTokenStreamTestCase.class.isAssignableFrom(clazz) || LuceneTestCase.class.isAssignableFrom(clazz); + return ElasticsearchTestCase.class.isAssignableFrom(clazz) || ElasticsearchTestCase.class.isAssignableFrom(clazz) || ElasticsearchTokenStreamTestCase.class.isAssignableFrom(clazz) || LuceneTestCase.class.isAssignableFrom(clazz); } private Class loadClass(String filename) throws ClassNotFoundException { @@ -135,7 +138,7 @@ public class NamingConventionTests extends ElasticsearchTestCase { String classesToSubclass = Joiner.on(',').join( ElasticsearchTestCase.class.getSimpleName(), - ElasticsearchLuceneTestCase.class.getSimpleName(), + ElasticsearchTestCase.class.getSimpleName(), ElasticsearchTokenStreamTestCase.class.getSimpleName(), LuceneTestCase.class.getSimpleName()); assertTrue("Not all subclasses of " + ElasticsearchTestCase.class.getSimpleName() + @@ -158,7 +161,7 @@ public class NamingConventionTests extends ElasticsearchTestCase { public static final class WrongName extends ElasticsearchTestCase {} - public static final class WrongNameTheSecond extends ElasticsearchLuceneTestCase {} + public static final class WrongNameTheSecond extends ElasticsearchTestCase {} public static final class PlainUnit extends TestCase {} diff --git a/src/test/java/org/elasticsearch/VersionTests.java b/src/test/java/org/elasticsearch/VersionTests.java index af19ae032bc..c78c3118e57 100644 --- a/src/test/java/org/elasticsearch/VersionTests.java +++ b/src/test/java/org/elasticsearch/VersionTests.java @@ -23,6 +23,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.test.ElasticsearchTestCase; +import org.elasticsearch.test.VersionUtils; import org.hamcrest.Matchers; import org.junit.Test; @@ -33,6 +34,7 @@ import java.util.Map; import static org.elasticsearch.Version.V_0_20_0; import static org.elasticsearch.Version.V_0_90_0; +import static org.elasticsearch.test.VersionUtils.randomVersion; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.sameInstance; @@ -44,7 +46,7 @@ public class VersionTests extends ElasticsearchTestCase { // we use here is the version that is actually set to the project.version // in maven String property = System.getProperty("tests.version", null); - assumeNotNull(property); + assumeTrue("tests.version is set", property != null); assertEquals(property, Version.CURRENT.toString()); } @@ -71,7 +73,7 @@ public class VersionTests extends ElasticsearchTestCase { assertThat(Version.CURRENT.luceneVersion, equalTo(org.apache.lucene.util.Version.LATEST)); final int iters = scaledRandomIntBetween(20, 100); for (int i = 0; i < iters; i++) { - Version version = randomVersion(); + Version version = randomVersion(random()); assertThat(version, sameInstance(Version.fromId(version.id))); assertThat(version.luceneVersion, sameInstance(Version.fromId(version.id).luceneVersion)); } @@ -80,7 +82,7 @@ public class VersionTests extends ElasticsearchTestCase { public void testCURRENTIsLatest() { final int iters = scaledRandomIntBetween(100, 1000); for (int i = 0; i < iters; i++) { - Version version = randomVersion(); + Version version = randomVersion(random()); if (version != Version.CURRENT) { assertThat("Version: " + version + " should be before: " + Version.CURRENT + " but wasn't", version.before(Version.CURRENT), is(true)); } @@ -90,7 +92,7 @@ public class VersionTests extends ElasticsearchTestCase { public void testVersionFromString() { final int iters = scaledRandomIntBetween(100, 1000); for (int i = 0; i < iters; i++) { - Version version = randomVersion(); + Version version = randomVersion(random()); if (version.snapshot()) { // number doesn't include SNAPSHOT but the parser checks for that assertEquals(Version.fromString(version.number()), version); } else { @@ -137,9 +139,9 @@ public class VersionTests extends ElasticsearchTestCase { public void testParseVersion() { final int iters = scaledRandomIntBetween(100, 1000); for (int i = 0; i < iters; i++) { - Version version = randomVersion(); + Version version = randomVersion(random()); String stringVersion = version.toString(); - if (version.snapshot() == false && randomBoolean()) { + if (version.snapshot() == false && random().nextBoolean()) { version = new Version(version.id, true, version.luceneVersion); } Version parsedVersion = Version.fromString(version.toString()); @@ -150,7 +152,7 @@ public class VersionTests extends ElasticsearchTestCase { public void testParseLenient() { // note this is just a silly sanity check, we test it in lucene - for (Version version : allVersions()) { + for (Version version : VersionUtils.allVersions()) { org.apache.lucene.util.Version luceneVersion = version.luceneVersion; String string = luceneVersion.toString().toUpperCase(Locale.ROOT) .replaceFirst("^LUCENE_(\\d+)_(\\d+)$", "$1.$2"); diff --git a/src/test/java/org/elasticsearch/action/IndicesRequestTests.java b/src/test/java/org/elasticsearch/action/IndicesRequestTests.java index e7a0f9d2e62..dcb076212ef 100644 --- a/src/test/java/org/elasticsearch/action/IndicesRequestTests.java +++ b/src/test/java/org/elasticsearch/action/IndicesRequestTests.java @@ -104,6 +104,7 @@ import org.elasticsearch.search.action.SearchServiceTransportAction; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.*; +import org.apache.lucene.util.LuceneTestCase.Slow; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -117,6 +118,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFa import static org.hamcrest.Matchers.*; @ClusterScope(scope = Scope.SUITE, numClientNodes = 1) +@Slow public class IndicesRequestTests extends ElasticsearchIntegrationTest { private final List indices = new ArrayList<>(); diff --git a/src/test/java/org/elasticsearch/action/OriginalIndicesTests.java b/src/test/java/org/elasticsearch/action/OriginalIndicesTests.java index 0253a0a691c..6ff8bb5a118 100644 --- a/src/test/java/org/elasticsearch/action/OriginalIndicesTests.java +++ b/src/test/java/org/elasticsearch/action/OriginalIndicesTests.java @@ -27,6 +27,7 @@ import org.junit.Test; import java.io.IOException; +import static org.elasticsearch.test.VersionUtils.randomVersion; import static org.hamcrest.CoreMatchers.equalTo; public class OriginalIndicesTests extends ElasticsearchTestCase { @@ -42,7 +43,7 @@ public class OriginalIndicesTests extends ElasticsearchTestCase { OriginalIndices originalIndices = randomOriginalIndices(); BytesStreamOutput out = new BytesStreamOutput(); - out.setVersion(randomVersion()); + out.setVersion(randomVersion(random())); OriginalIndices.writeOriginalIndices(originalIndices, out); BytesStreamInput in = new BytesStreamInput(out.bytes()); diff --git a/src/test/java/org/elasticsearch/action/admin/HotThreadsTest.java b/src/test/java/org/elasticsearch/action/admin/HotThreadsTest.java index 65dbcc852a9..afada410b1d 100644 --- a/src/test/java/org/elasticsearch/action/admin/HotThreadsTest.java +++ b/src/test/java/org/elasticsearch/action/admin/HotThreadsTest.java @@ -18,6 +18,7 @@ */ package org.elasticsearch.action.admin; +import org.apache.lucene.util.LuceneTestCase.Slow; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.node.hotthreads.NodeHotThreads; import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsRequestBuilder; @@ -44,6 +45,7 @@ import static org.hamcrest.Matchers.lessThan; /** */ +@Slow public class HotThreadsTest extends ElasticsearchIntegrationTest { @Test diff --git a/src/test/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequestTest.java b/src/test/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequestTest.java index d0d1e2e2452..fca09aa861d 100644 --- a/src/test/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequestTest.java +++ b/src/test/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequestTest.java @@ -24,6 +24,7 @@ import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.common.io.stream.BytesStreamInput; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.test.ElasticsearchTestCase; +import org.elasticsearch.test.VersionUtils; import org.junit.Test; import static org.hamcrest.CoreMatchers.equalTo; @@ -42,7 +43,7 @@ public class ClusterStateRequestTest extends ElasticsearchTestCase { ClusterStateRequest clusterStateRequest = new ClusterStateRequest().routingTable(randomBoolean()).metaData(randomBoolean()) .nodes(randomBoolean()).blocks(randomBoolean()).indices("testindex", "testindex2").indicesOptions(indicesOptions); - Version testVersion = randomVersionBetween(Version.CURRENT.minimumCompatibilityVersion(), Version.CURRENT); + Version testVersion = VersionUtils.randomVersionBetween(random(), Version.CURRENT.minimumCompatibilityVersion(), Version.CURRENT); BytesStreamOutput output = new BytesStreamOutput(); output.setVersion(testVersion); clusterStateRequest.writeTo(output); diff --git a/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationTests.java b/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationTests.java index 12dc753b315..bace2472a3c 100644 --- a/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationTests.java +++ b/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.action.bulk; import com.google.common.base.Charsets; + import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.junit.Test; diff --git a/src/test/java/org/elasticsearch/action/bulk/BulkProcessorTests.java b/src/test/java/org/elasticsearch/action/bulk/BulkProcessorTests.java index 0726655ca00..e357206bc38 100644 --- a/src/test/java/org/elasticsearch/action/bulk/BulkProcessorTests.java +++ b/src/test/java/org/elasticsearch/action/bulk/BulkProcessorTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.action.bulk; import com.carrotsearch.ant.tasks.junit4.dependencies.com.carrotsearch.randomizedtesting.generators.RandomPicks; + import org.elasticsearch.action.get.MultiGetItemResponse; import org.elasticsearch.action.get.MultiGetRequestBuilder; import org.elasticsearch.action.get.MultiGetResponse; diff --git a/src/test/java/org/elasticsearch/action/get/MultiGetShardRequestTests.java b/src/test/java/org/elasticsearch/action/get/MultiGetShardRequestTests.java index aafa5e076ca..24d7ac410ab 100644 --- a/src/test/java/org/elasticsearch/action/get/MultiGetShardRequestTests.java +++ b/src/test/java/org/elasticsearch/action/get/MultiGetShardRequestTests.java @@ -19,7 +19,6 @@ package org.elasticsearch.action.get; -import org.elasticsearch.Version; import org.elasticsearch.common.io.stream.BytesStreamInput; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.index.VersionType; @@ -29,6 +28,7 @@ import org.junit.Test; import java.io.IOException; +import static org.elasticsearch.test.VersionUtils.randomVersion; import static org.hamcrest.CoreMatchers.equalTo; public class MultiGetShardRequestTests extends ElasticsearchTestCase { @@ -70,7 +70,7 @@ public class MultiGetShardRequestTests extends ElasticsearchTestCase { } BytesStreamOutput out = new BytesStreamOutput(); - out.setVersion(randomVersion()); + out.setVersion(randomVersion(random())); multiGetShardRequest.writeTo(out); BytesStreamInput in = new BytesStreamInput(out.bytes()); diff --git a/src/test/java/org/elasticsearch/action/indexedscripts/get/GetIndexedScriptRequestTests.java b/src/test/java/org/elasticsearch/action/indexedscripts/get/GetIndexedScriptRequestTests.java index 153d14298a0..f940e055550 100644 --- a/src/test/java/org/elasticsearch/action/indexedscripts/get/GetIndexedScriptRequestTests.java +++ b/src/test/java/org/elasticsearch/action/indexedscripts/get/GetIndexedScriptRequestTests.java @@ -27,6 +27,7 @@ import org.junit.Test; import java.io.IOException; +import static org.elasticsearch.test.VersionUtils.randomVersion; import static org.hamcrest.CoreMatchers.equalTo; public class GetIndexedScriptRequestTests extends ElasticsearchTestCase { @@ -40,7 +41,7 @@ public class GetIndexedScriptRequestTests extends ElasticsearchTestCase { } BytesStreamOutput out = new BytesStreamOutput(); - out.setVersion(randomVersion()); + out.setVersion(randomVersion(random())); request.writeTo(out); BytesStreamInput in = new BytesStreamInput(out.bytes()); diff --git a/src/test/java/org/elasticsearch/action/mlt/MoreLikeThisRequestTests.java b/src/test/java/org/elasticsearch/action/mlt/MoreLikeThisRequestTests.java index 99a01de5047..77400ff0817 100644 --- a/src/test/java/org/elasticsearch/action/mlt/MoreLikeThisRequestTests.java +++ b/src/test/java/org/elasticsearch/action/mlt/MoreLikeThisRequestTests.java @@ -19,7 +19,6 @@ package org.elasticsearch.action.mlt; -import org.elasticsearch.Version; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.BytesStreamInput; @@ -33,6 +32,7 @@ import org.junit.Test; import java.io.IOException; +import static org.elasticsearch.test.VersionUtils.randomVersion; import static org.hamcrest.CoreMatchers.*; public class MoreLikeThisRequestTests extends ElasticsearchTestCase { @@ -99,7 +99,7 @@ public class MoreLikeThisRequestTests extends ElasticsearchTestCase { } BytesStreamOutput out = new BytesStreamOutput(); - out.setVersion(randomVersion()); + out.setVersion(randomVersion(random())); mltRequest.writeTo(out); BytesStreamInput in = new BytesStreamInput(out.bytes()); diff --git a/src/test/java/org/elasticsearch/action/support/IndicesOptionsTests.java b/src/test/java/org/elasticsearch/action/support/IndicesOptionsTests.java index 96d56848fe5..e757f9ca4ac 100644 --- a/src/test/java/org/elasticsearch/action/support/IndicesOptionsTests.java +++ b/src/test/java/org/elasticsearch/action/support/IndicesOptionsTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.test.ElasticsearchTestCase; import org.junit.Test; +import static org.elasticsearch.test.VersionUtils.randomVersion; import static org.hamcrest.CoreMatchers.equalTo; public class IndicesOptionsTests extends ElasticsearchTestCase { @@ -36,12 +37,12 @@ public class IndicesOptionsTests extends ElasticsearchTestCase { IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()); BytesStreamOutput output = new BytesStreamOutput(); - Version outputVersion = randomVersion(); + Version outputVersion = randomVersion(random()); output.setVersion(outputVersion); indicesOptions.writeIndicesOptions(output); BytesStreamInput bytesStreamInput = new BytesStreamInput(output.bytes()); - bytesStreamInput.setVersion(randomVersion()); + bytesStreamInput.setVersion(randomVersion(random())); IndicesOptions indicesOptions2 = IndicesOptions.readIndicesOptions(bytesStreamInput); assertThat(indicesOptions2.ignoreUnavailable(), equalTo(indicesOptions.ignoreUnavailable())); diff --git a/src/test/java/org/elasticsearch/action/termvectors/GetTermVectorsTests.java b/src/test/java/org/elasticsearch/action/termvectors/GetTermVectorsTests.java index f07500cc7a4..d99d03ec0b4 100644 --- a/src/test/java/org/elasticsearch/action/termvectors/GetTermVectorsTests.java +++ b/src/test/java/org/elasticsearch/action/termvectors/GetTermVectorsTests.java @@ -20,10 +20,12 @@ package org.elasticsearch.action.termvectors; import com.carrotsearch.hppc.ObjectIntOpenHashMap; + import org.apache.lucene.analysis.payloads.PayloadHelper; import org.apache.lucene.document.FieldType; import org.apache.lucene.index.*; import org.apache.lucene.util.BytesRef; +import org.apache.lucene.util.LuceneTestCase.Slow; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionFuture; import org.elasticsearch.action.admin.indices.alias.Alias; @@ -49,6 +51,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcke import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows; import static org.hamcrest.Matchers.*; +@Slow public class GetTermVectorsTests extends AbstractTermVectorsTests { @Test diff --git a/src/test/java/org/elasticsearch/action/termvectors/TermVectorsUnitTests.java b/src/test/java/org/elasticsearch/action/termvectors/TermVectorsUnitTests.java index c799c9b8522..dab38d997fa 100644 --- a/src/test/java/org/elasticsearch/action/termvectors/TermVectorsUnitTests.java +++ b/src/test/java/org/elasticsearch/action/termvectors/TermVectorsUnitTests.java @@ -42,7 +42,7 @@ import org.elasticsearch.index.mapper.core.AbstractFieldMapper; import org.elasticsearch.index.mapper.core.TypeParsers; import org.elasticsearch.index.mapper.internal.AllFieldMapper; import org.elasticsearch.rest.action.termvectors.RestTermVectorsAction; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; +import org.elasticsearch.test.ElasticsearchTestCase; import org.hamcrest.Matchers; import org.junit.Test; @@ -55,7 +55,7 @@ import java.util.Set; import static org.hamcrest.Matchers.equalTo; -public class TermVectorsUnitTests extends ElasticsearchLuceneTestCase { +public class TermVectorsUnitTests extends ElasticsearchTestCase { @Test public void streamResponse() throws Exception { diff --git a/src/test/java/org/elasticsearch/aliases/IndexAliasesTests.java b/src/test/java/org/elasticsearch/aliases/IndexAliasesTests.java index 3b7f7c55643..3a23269d055 100644 --- a/src/test/java/org/elasticsearch/aliases/IndexAliasesTests.java +++ b/src/test/java/org/elasticsearch/aliases/IndexAliasesTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.aliases; +import org.apache.lucene.util.LuceneTestCase.Slow; import org.elasticsearch.ElasticsearchIllegalArgumentException; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.admin.indices.alias.Alias; @@ -69,6 +70,7 @@ import static org.hamcrest.Matchers.*; /** * */ +@Slow public class IndexAliasesTests extends ElasticsearchIntegrationTest { @Test diff --git a/src/test/java/org/elasticsearch/benchmark/common/lucene/uidscan/LuceneUidScanBenchmark.java b/src/test/java/org/elasticsearch/benchmark/common/lucene/uidscan/LuceneUidScanBenchmark.java index 41ddbc20c59..fe548b9ee4c 100644 --- a/src/test/java/org/elasticsearch/benchmark/common/lucene/uidscan/LuceneUidScanBenchmark.java +++ b/src/test/java/org/elasticsearch/benchmark/common/lucene/uidscan/LuceneUidScanBenchmark.java @@ -25,6 +25,7 @@ import org.apache.lucene.document.StringField; import org.apache.lucene.index.*; import org.apache.lucene.store.FSDirectory; import org.elasticsearch.common.StopWatch; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.uid.Versions; import org.elasticsearch.common.unit.SizeValue; @@ -40,7 +41,7 @@ public class LuceneUidScanBenchmark { public static void main(String[] args) throws Exception { - FSDirectory dir = FSDirectory.open(Paths.get("work/test")); + FSDirectory dir = FSDirectory.open(PathUtils.get("work/test")); IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(Lucene.STANDARD_ANALYZER)); final int NUMBER_OF_THREADS = 2; diff --git a/src/test/java/org/elasticsearch/benchmark/fs/FsAppendBenchmark.java b/src/test/java/org/elasticsearch/benchmark/fs/FsAppendBenchmark.java index 99bb5375c55..7dd6481a0c9 100644 --- a/src/test/java/org/elasticsearch/benchmark/fs/FsAppendBenchmark.java +++ b/src/test/java/org/elasticsearch/benchmark/fs/FsAppendBenchmark.java @@ -20,6 +20,7 @@ package org.elasticsearch.benchmark.fs; import org.apache.lucene.util.IOUtils; import org.elasticsearch.common.StopWatch; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.unit.ByteSizeValue; import java.nio.ByteBuffer; @@ -35,7 +36,7 @@ import java.util.Random; public class FsAppendBenchmark { public static void main(String[] args) throws Exception { - Path path = Paths.get("work/test.log"); + Path path = PathUtils.get("work/test.log"); IOUtils.deleteFilesIgnoringExceptions(path); int CHUNK = (int) ByteSizeValue.parseBytesSizeValue("1k").bytes(); diff --git a/src/test/java/org/elasticsearch/benchmark/scripts/score/BasicScriptBenchmark.java b/src/test/java/org/elasticsearch/benchmark/scripts/score/BasicScriptBenchmark.java index 59683666aa4..79b009e2010 100644 --- a/src/test/java/org/elasticsearch/benchmark/scripts/score/BasicScriptBenchmark.java +++ b/src/test/java/org/elasticsearch/benchmark/scripts/score/BasicScriptBenchmark.java @@ -25,6 +25,7 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.client.Client; import org.elasticsearch.common.StopWatch; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.lucene.search.function.CombineFunction; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -150,7 +151,7 @@ public class BasicScriptBenchmark { } public static void writeHelperFunction() throws IOException { - try (BufferedWriter out = Files.newBufferedWriter(Paths.get("addToPlot.m"), StandardCharsets.UTF_8)) { + try (BufferedWriter out = Files.newBufferedWriter(PathUtils.get("addToPlot.m"), StandardCharsets.UTF_8)) { out.write("function handle = addToPlot(numTerms, perDoc, color, linestyle, linewidth)\n" + "handle = line(numTerms, perDoc);\n" + "set(handle, 'color', color);\n" + "set(handle, 'linestyle',linestyle);\n" + "set(handle, 'LineWidth',linewidth);\n" + "end\n"); @@ -161,7 +162,7 @@ public class BasicScriptBenchmark { if (args.length == 0) { return; } - try (BufferedWriter out = Files.newBufferedWriter(Paths.get(args[0]), StandardCharsets.UTF_8)) { + try (BufferedWriter out = Files.newBufferedWriter(PathUtils.get(args[0]), StandardCharsets.UTF_8)) { out.write("#! /usr/local/bin/octave -qf"); out.write("\n\n\n\n"); out.write("######################################\n"); diff --git a/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java b/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java index 497d497847d..37885a8706e 100644 --- a/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java +++ b/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java @@ -19,8 +19,8 @@ package org.elasticsearch.bwcompat; -import com.carrotsearch.randomizedtesting.LifecycleScope; import com.google.common.util.concurrent.ListenableFuture; + import org.apache.lucene.index.IndexWriter; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TestUtil; @@ -48,24 +48,20 @@ import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.test.ElasticsearchIntegrationTest; +import org.elasticsearch.test.VersionUtils; import org.elasticsearch.test.hamcrest.ElasticsearchAssertions; import org.elasticsearch.test.index.merge.NoMergePolicyProvider; -import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.test.rest.client.http.HttpRequestBuilder; import org.hamcrest.Matchers; import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.Before; import java.io.IOException; import java.io.InputStream; -import java.lang.reflect.Modifier; -import java.net.URL; import java.nio.file.DirectoryStream; import java.nio.file.FileVisitResult; -import java.nio.file.FileVisitor; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.*; @@ -74,21 +70,21 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcke import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo; -@LuceneTestCase.SuppressCodecs({"Lucene3x", "MockFixedIntBlock", "MockVariableIntBlock", "MockSep", "MockRandom", "Lucene40", "Lucene41", "Appending", "Lucene42", "Lucene45", "Lucene46", "Lucene49"}) @ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.TEST, numDataNodes = 0) +@LuceneTestCase.SuppressFileSystems("ExtrasFS") +@LuceneTestCase.Slow public class OldIndexBackwardsCompatibilityTests extends ElasticsearchIntegrationTest { // TODO: test for proper exception on unsupported indexes (maybe via separate test?) // We have a 0.20.6.zip etc for this. - static List indexes; + List indexes; static Path singleDataPath; static Path[] multiDataPath; - @BeforeClass - public static void initIndexesList() throws Exception { + @Before + public void initIndexesList() throws Exception { indexes = new ArrayList<>(); - URL dirUrl = OldIndexBackwardsCompatibilityTests.class.getResource("."); - Path dir = Paths.get(dirUrl.toURI()); + Path dir = getDataPath("."); try (DirectoryStream stream = Files.newDirectoryStream(dir, "index-*.zip")) { for (Path path : stream) { indexes.add(path.getFileName().toString()); @@ -99,7 +95,6 @@ public class OldIndexBackwardsCompatibilityTests extends ElasticsearchIntegratio @AfterClass public static void tearDownStatics() { - indexes = null; singleDataPath = null; multiDataPath = null; } @@ -116,7 +111,7 @@ public class OldIndexBackwardsCompatibilityTests extends ElasticsearchIntegratio void setupCluster() throws Exception { ListenableFuture> replicas = internalCluster().startNodesAsync(1); // for replicas - Path baseTempDir = newTempDirPath(LifecycleScope.SUITE); + Path baseTempDir = createTempDir(); // start single data path node ImmutableSettings.Builder nodeSettings = ImmutableSettings.builder() .put("path.data", baseTempDir.resolve("single-path").toAbsolutePath()) @@ -152,12 +147,12 @@ public class OldIndexBackwardsCompatibilityTests extends ElasticsearchIntegratio } String loadIndex(String indexFile) throws Exception { - Path unzipDir = newTempDirPath(); + Path unzipDir = createTempDir(); Path unzipDataDir = unzipDir.resolve("data"); String indexName = indexFile.replace(".zip", "").toLowerCase(Locale.ROOT); // decompress the index - Path backwardsIndex = Paths.get(getClass().getResource(indexFile).toURI()); + Path backwardsIndex = getDataPath(indexFile); try (InputStream stream = Files.newInputStream(backwardsIndex)) { TestUtil.unzip(stream, unzipDir); } @@ -230,21 +225,11 @@ public class OldIndexBackwardsCompatibilityTests extends ElasticsearchIntegratio public void testAllVersionsTested() throws Exception { SortedSet expectedVersions = new TreeSet<>(); - for (java.lang.reflect.Field field : Version.class.getDeclaredFields()) { - if (Modifier.isStatic(field.getModifiers()) && field.getType() == Version.class) { - Version v = (Version) field.get(Version.class); - if (v.snapshot()) { - continue; // snapshots are unreleased, so there is no backcompat yet - } - if (v.onOrBefore(Version.V_0_20_6)) { - continue; // we can only test back one major lucene version - } - if (v.equals(Version.CURRENT)) { - continue; // the current version is always compatible with itself - } - - expectedVersions.add("index-" + v.toString() + ".zip"); - } + for (Version v : VersionUtils.allVersions()) { + if (v.snapshot()) continue; // snapshots are unreleased, so there is no backcompat yet + if (v.onOrBefore(Version.V_0_20_6)) continue; // we can only test back one major lucene version + if (v.equals(Version.CURRENT)) continue; // the current version is always compatible with itself + expectedVersions.add("index-" + v.toString() + ".zip"); } for (String index : indexes) { diff --git a/src/test/java/org/elasticsearch/bwcompat/RestoreBackwardsCompatTests.java b/src/test/java/org/elasticsearch/bwcompat/RestoreBackwardsCompatTests.java index fce98bb7c22..70288427a96 100644 --- a/src/test/java/org/elasticsearch/bwcompat/RestoreBackwardsCompatTests.java +++ b/src/test/java/org/elasticsearch/bwcompat/RestoreBackwardsCompatTests.java @@ -26,6 +26,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexTemplateMetaData; import org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.snapshots.AbstractSnapshotTests; @@ -92,9 +93,9 @@ public class RestoreBackwardsCompatTests extends AbstractSnapshotTests { } } - public static List repoVersions() throws Exception { + private List repoVersions() throws Exception { List repoVersions = newArrayList(); - Path repoFiles = Paths.get(RestoreBackwardsCompatTests.class.getResource(".").toURI()); + Path repoFiles = getDataPath("."); try (DirectoryStream stream = Files.newDirectoryStream(repoFiles, "repo-*.zip")) { for (Path entry : stream) { String fileName = entry.getFileName().toString(); diff --git a/src/test/java/org/elasticsearch/bwcompat/StaticIndexBackwardCompatibilityTest.java b/src/test/java/org/elasticsearch/bwcompat/StaticIndexBackwardCompatibilityTest.java index 1b0718038bf..c8c64c848a9 100644 --- a/src/test/java/org/elasticsearch/bwcompat/StaticIndexBackwardCompatibilityTest.java +++ b/src/test/java/org/elasticsearch/bwcompat/StaticIndexBackwardCompatibilityTest.java @@ -33,13 +33,13 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; * These tests are against static indexes, built from versions of ES that cannot be upgraded without * a full cluster restart (ie no wire format compatibility). */ -@LuceneTestCase.SuppressCodecs({"Lucene3x", "MockFixedIntBlock", "MockVariableIntBlock", "MockSep", "MockRandom", "Lucene40", "Lucene41", "Appending", "Lucene42", "Lucene45", "Lucene46", "Lucene49"}) +@LuceneTestCase.SuppressCodecs("*") @ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.TEST, numDataNodes = 0, minNumDataNodes = 0, maxNumDataNodes = 0) public class StaticIndexBackwardCompatibilityTest extends ElasticsearchIntegrationTest { public void loadIndex(String index, Object... settings) throws Exception { logger.info("Checking static index " + index); - Settings nodeSettings = prepareBackwardsDataDir(Paths.get(getClass().getResource(index + ".zip").toURI()), settings); + Settings nodeSettings = prepareBackwardsDataDir(getDataPath(index + ".zip"), settings); internalCluster().startNode(nodeSettings); ensureGreen(index); assertIndexSanity(index); diff --git a/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java b/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java index d94d351d34b..dcf35d2dff6 100644 --- a/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java +++ b/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java @@ -54,7 +54,7 @@ public class TransportClientTests extends ElasticsearchIntegrationTest { TransportClientNodesService nodeService = client.nodeService(); Node node = nodeBuilder().data(false).settings(ImmutableSettings.builder() .put(internalCluster().getDefaultSettings()) - .put("path.home", newTempDirPath()) + .put("path.home", createTempDir()) .put("node.name", "testNodeVersionIsUpdated") .put("http.enabled", false) .put("index.store.type", "ram") diff --git a/src/test/java/org/elasticsearch/cluster/ClusterServiceTests.java b/src/test/java/org/elasticsearch/cluster/ClusterServiceTests.java index e1d1daa7aae..cd393ff88cd 100644 --- a/src/test/java/org/elasticsearch/cluster/ClusterServiceTests.java +++ b/src/test/java/org/elasticsearch/cluster/ClusterServiceTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.cluster; import com.google.common.base.Predicate; import com.google.common.util.concurrent.ListenableFuture; + import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse; @@ -602,7 +603,7 @@ public class ClusterServiceTests extends ElasticsearchIntegrationTest { block2.countDown(); } - @Test + @Test @Slow public void testLocalNodeMasterListenerCallbacks() throws Exception { Settings settings = settingsBuilder() .put("discovery.type", "zen") diff --git a/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesTests.java b/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesTests.java index 4d01f1daa4b..fedd3aca276 100644 --- a/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesTests.java +++ b/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.cluster; import com.google.common.base.Predicate; + import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; import org.elasticsearch.client.Client; @@ -169,7 +170,7 @@ public class MinimumMasterNodesTests extends ElasticsearchIntegrationTest { } } - @Test + @Test @Slow public void multipleNodesShutdownNonMasterNodes() throws Exception { Settings settings = settingsBuilder() .put("discovery.type", "zen") diff --git a/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesTests.java b/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesTests.java index 3544ff0ef32..6defc2c3ebf 100644 --- a/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesTests.java +++ b/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesTests.java @@ -37,6 +37,7 @@ import static org.hamcrest.Matchers.*; * */ @ClusterScope(scope = Scope.TEST, numDataNodes = 0) +@Slow public class SpecificMasterNodesTests extends ElasticsearchIntegrationTest { protected final ImmutableSettings.Builder settingsBuilder() { diff --git a/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeTests.java b/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeTests.java index ace51a3587e..1db6a4b894b 100644 --- a/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeTests.java +++ b/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeTests.java @@ -33,6 +33,8 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; +import static org.elasticsearch.test.VersionUtils.randomVersion; + public class DiscoveryNodeTests extends ElasticsearchTestCase { @@ -49,7 +51,7 @@ public class DiscoveryNodeTests extends ElasticsearchTestCase { for (int a = randomInt(10); a > 0; a--) { attributes.put(randomUnicodeOfLengthBetween(3, 20), randomUnicodeOfLengthBetween(3, 20)); } - final Version version = randomVersion(); + final Version version = randomVersion(random()); DiscoveryNode discoveryNode = new DiscoveryNode(nodeName, id, hostName, hostAddress, transportAddress, attributes, version); BytesStreamOutput bytesOutput = new BytesStreamOutput(); ThrowableObjectOutputStream too = new ThrowableObjectOutputStream(bytesOutput); diff --git a/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityTests.java b/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityTests.java index fb1ac5922eb..9fa24cb79e3 100644 --- a/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityTests.java +++ b/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityTests.java @@ -29,6 +29,7 @@ import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.node.Node; import org.elasticsearch.test.ElasticsearchTestCase; +import org.elasticsearch.test.VersionUtils; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -38,7 +39,7 @@ import java.util.Arrays; public class RoutingBackwardCompatibilityTests extends ElasticsearchTestCase { public void testBackwardCompatibility() throws Exception { - Path baseDir = newTempDirPath(); + Path baseDir = createTempDir(); Node node = new Node(ImmutableSettings.builder().put("path.home", baseDir.toString()).build(), false); try { try (BufferedReader reader = new BufferedReader(new InputStreamReader(RoutingBackwardCompatibilityTests.class.getResourceAsStream("/org/elasticsearch/cluster/routing/shard_routes.txt"), "UTF-8"))) { @@ -57,7 +58,7 @@ public class RoutingBackwardCompatibilityTests extends ElasticsearchTestCase { final int currentExpectedShard = Integer.parseInt(parts[6]); OperationRouting operationRouting = node.injector().getInstance(OperationRouting.class); - for (Version version : allVersions()) { + for (Version version : VersionUtils.allVersions()) { final Settings settings = settings(version).build(); IndexMetaData indexMetaData = IndexMetaData.builder(index).settings(settings).numberOfShards(numberOfShards).numberOfReplicas(randomInt(3)).build(); MetaData.Builder metaData = MetaData.builder().put(indexMetaData, false); diff --git a/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityUponUpgradeTests.java b/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityUponUpgradeTests.java index 145fe5ca2c0..b0ec52e3bbd 100644 --- a/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityUponUpgradeTests.java +++ b/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityUponUpgradeTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.cluster.routing; +import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.action.admin.indices.get.GetIndexResponse; import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse; import org.elasticsearch.action.get.GetResponse; @@ -31,12 +32,12 @@ import org.elasticsearch.search.SearchHit; import org.elasticsearch.test.ElasticsearchIntegrationTest; import java.nio.file.Path; -import java.nio.file.Paths; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse; @ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.TEST, numDataNodes = 0, minNumDataNodes = 0, maxNumDataNodes = 0) +@LuceneTestCase.SuppressFileSystems("*") // extra files break the single data cluster expectation when unzipping the static index public class RoutingBackwardCompatibilityUponUpgradeTests extends ElasticsearchIntegrationTest { public void testDefaultRouting() throws Exception { @@ -48,7 +49,7 @@ public class RoutingBackwardCompatibilityUponUpgradeTests extends ElasticsearchI } private void test(String name, Class expectedHashFunction, boolean expectedUseType) throws Exception { - Path zippedIndexDir = Paths.get(getClass().getResource("/org/elasticsearch/cluster/routing/" + name + ".zip").toURI()); + Path zippedIndexDir = getDataPath("/org/elasticsearch/cluster/routing/" + name + ".zip"); Settings baseSettings = prepareBackwardsDataDir(zippedIndexDir); internalCluster().startNode(ImmutableSettings.builder() .put(baseSettings) diff --git a/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceUnbalancedClusterTest.java b/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceUnbalancedClusterTest.java index fc3fb6af17d..658256adf29 100644 --- a/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceUnbalancedClusterTest.java +++ b/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceUnbalancedClusterTest.java @@ -19,6 +19,7 @@ package org.elasticsearch.cluster.routing.allocation; import org.apache.lucene.util.TestUtil; +import org.apache.lucene.util.LuceneTestCase.Slow; import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetaData; @@ -40,12 +41,13 @@ import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilde /** * see issue #9023 */ +@Slow public class BalanceUnbalancedClusterTest extends CatAllocationTestBase { @Override protected Path getCatPath() throws IOException { - Path tmp = newTempDirPath(); - try (InputStream stream = Files.newInputStream(getResourcePath("/org/elasticsearch/cluster/routing/issue_9023.zip"))) { + Path tmp = createTempDir(); + try (InputStream stream = Files.newInputStream(getDataPath("/org/elasticsearch/cluster/routing/issue_9023.zip"))) { TestUtil.unzip(stream, tmp); } return tmp.resolve("issue_9023"); diff --git a/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java b/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java index c78bd1a3075..371bdc3bc1f 100644 --- a/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java +++ b/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java @@ -33,6 +33,7 @@ import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllo import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.test.ElasticsearchAllocationTestCase; +import org.elasticsearch.test.VersionUtils; import org.junit.Test; import java.util.ArrayList; @@ -41,6 +42,7 @@ import java.util.List; import static org.elasticsearch.cluster.routing.ShardRoutingState.*; import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; +import static org.elasticsearch.test.VersionUtils.randomVersion; import static org.hamcrest.Matchers.*; /** @@ -122,7 +124,7 @@ public class NodeVersionAllocationDeciderTests extends ElasticsearchAllocationTe } clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()) - .put(newNode("node3", getPreviousVersion()))) + .put(newNode("node3", VersionUtils.getPreviousVersion()))) .build(); prevRoutingTable = routingTable; routingTable = strategy.reroute(clusterState).routingTable(); @@ -202,9 +204,9 @@ public class NodeVersionAllocationDeciderTests extends ElasticsearchAllocationTe } else { for (int j = nodes.size(); j < numNodes; j++) { if (frequently()) { - nodes.add(newNode("node" + (nodeIdx++), randomBoolean() ? getPreviousVersion() : Version.CURRENT)); + nodes.add(newNode("node" + (nodeIdx++), randomBoolean() ? VersionUtils.getPreviousVersion() : Version.CURRENT)); } else { - nodes.add(newNode("node" + (nodeIdx++), randomVersion())); + nodes.add(newNode("node" + (nodeIdx++), randomVersion(random()))); } } } @@ -247,20 +249,20 @@ public class NodeVersionAllocationDeciderTests extends ElasticsearchAllocationTe assertThat(routingTable.index("test").shard(i).shards().get(2).currentNodeId(), nullValue()); } clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() - .put(newNode("old0", getPreviousVersion())) - .put(newNode("old1", getPreviousVersion())) - .put(newNode("old2", getPreviousVersion()))).build(); + .put(newNode("old0", VersionUtils.getPreviousVersion())) + .put(newNode("old1", VersionUtils.getPreviousVersion())) + .put(newNode("old2", VersionUtils.getPreviousVersion()))).build(); clusterState = stabilize(clusterState, service); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() - .put(newNode("old0", getPreviousVersion())) - .put(newNode("old1", getPreviousVersion())) + .put(newNode("old0", VersionUtils.getPreviousVersion())) + .put(newNode("old1", VersionUtils.getPreviousVersion())) .put(newNode("new0"))).build(); clusterState = stabilize(clusterState, service); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() - .put(newNode("node0", getPreviousVersion())) + .put(newNode("node0", VersionUtils.getPreviousVersion())) .put(newNode("new1")) .put(newNode("new0"))).build(); diff --git a/src/test/java/org/elasticsearch/codecs/CodecTests.java b/src/test/java/org/elasticsearch/codecs/CodecTests.java index db0fbd17153..0af133670b7 100644 --- a/src/test/java/org/elasticsearch/codecs/CodecTests.java +++ b/src/test/java/org/elasticsearch/codecs/CodecTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.codecs; import org.apache.lucene.codecs.Codec; +import org.apache.lucene.util.LuceneTestCase.Slow; import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.settings.ImmutableSettings; @@ -28,6 +29,7 @@ import org.elasticsearch.index.IndexService; import org.elasticsearch.index.mapper.DocumentMapperParser; import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.test.ElasticsearchSingleNodeTest; +import org.elasticsearch.test.VersionUtils; import org.junit.Assert; import java.io.IOException; @@ -36,6 +38,7 @@ import static org.hamcrest.Matchers.containsString; /** */ +@Slow public class CodecTests extends ElasticsearchSingleNodeTest { public void testAcceptPostingsFormat() throws IOException { @@ -43,7 +46,7 @@ public class CodecTests extends ElasticsearchSingleNodeTest { .startObject("properties").startObject("field").field("type", "string").field("postings_format", Codec.getDefault().postingsFormat().getName()).endObject().endObject() .endObject().endObject().string(); int i = 0; - for (Version v : allVersions()) { + for (Version v : VersionUtils.allVersions()) { IndexService indexService = createIndex("test-" + i++, ImmutableSettings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, v).build()); DocumentMapperParser parser = indexService.mapperService().documentMapperParser(); try { @@ -66,7 +69,7 @@ public class CodecTests extends ElasticsearchSingleNodeTest { .startObject("properties").startObject("field").field("type", "string").field("doc_values_format", Codec.getDefault().docValuesFormat().getName()).endObject().endObject() .endObject().endObject().string(); int i = 0; - for (Version v : allVersions()) { + for (Version v : VersionUtils.allVersions()) { IndexService indexService = createIndex("test-" + i++, ImmutableSettings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, v).build()); DocumentMapperParser parser = indexService.mapperService().documentMapperParser(); try { diff --git a/src/test/java/org/elasticsearch/common/ChannelsTests.java b/src/test/java/org/elasticsearch/common/ChannelsTests.java index e1061ea3073..2fae109a6aa 100644 --- a/src/test/java/org/elasticsearch/common/ChannelsTests.java +++ b/src/test/java/org/elasticsearch/common/ChannelsTests.java @@ -53,7 +53,7 @@ public class ChannelsTests extends ElasticsearchTestCase { @Before public void setUp() throws Exception { super.setUp(); - Path tmpFile = newTempFilePath(); + Path tmpFile = createTempFile(); FileChannel randomAccessFile = FileChannel.open(tmpFile, StandardOpenOption.READ, StandardOpenOption.WRITE); fileChannel = new MockFileChannel(randomAccessFile); randomBytes = randomUnicodeOfLength(scaledRandomIntBetween(10, 100000)).getBytes("UTF-8"); diff --git a/src/test/java/org/elasticsearch/common/PidFileTests.java b/src/test/java/org/elasticsearch/common/PidFileTests.java index d022ab2177a..0c66b411c60 100644 --- a/src/test/java/org/elasticsearch/common/PidFileTests.java +++ b/src/test/java/org/elasticsearch/common/PidFileTests.java @@ -37,7 +37,7 @@ public class PidFileTests extends ElasticsearchTestCase { @Test(expected = ElasticsearchIllegalArgumentException.class) public void testParentIsFile() throws IOException { - Path dir = newTempDirPath(); + Path dir = createTempDir(); Path parent = dir.resolve("foo"); try(BufferedWriter stream = Files.newBufferedWriter(parent, Charsets.UTF_8, StandardOpenOption.CREATE_NEW)) { stream.write("foo"); @@ -48,7 +48,7 @@ public class PidFileTests extends ElasticsearchTestCase { @Test public void testPidFile() throws IOException { - Path dir = newTempDirPath(); + Path dir = createTempDir(); Path parent = dir.resolve("foo"); if (randomBoolean()) { Files.createDirectories(parent); diff --git a/src/test/java/org/elasticsearch/common/blobstore/BlobStoreTest.java b/src/test/java/org/elasticsearch/common/blobstore/BlobStoreTest.java index d6bbd3e432a..10fd9ef1405 100644 --- a/src/test/java/org/elasticsearch/common/blobstore/BlobStoreTest.java +++ b/src/test/java/org/elasticsearch/common/blobstore/BlobStoreTest.java @@ -18,10 +18,10 @@ */ package org.elasticsearch.common.blobstore; -import com.carrotsearch.randomizedtesting.LifecycleScope; import com.google.common.collect.ImmutableMap; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; +import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.common.blobstore.fs.FsBlobStore; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; @@ -41,6 +41,7 @@ import static com.google.common.collect.Maps.newHashMap; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.notNullValue; +@LuceneTestCase.SuppressFileSystems("ExtrasFS") public class BlobStoreTest extends ElasticsearchTestCase { @Test @@ -140,7 +141,7 @@ public class BlobStoreTest extends ElasticsearchTestCase { } protected BlobStore newBlobStore() throws IOException { - Path tempDir = newTempDirPath(LifecycleScope.TEST); + Path tempDir = createTempDir(); Settings settings = randomBoolean() ? ImmutableSettings.EMPTY : ImmutableSettings.builder().put("buffer_size", new ByteSizeValue(randomIntBetween(1, 100), ByteSizeUnit.KB)).build(); FsBlobStore store = new FsBlobStore(settings, tempDir); return store; diff --git a/src/test/java/org/elasticsearch/common/bytes/PagedBytesReferenceTest.java b/src/test/java/org/elasticsearch/common/bytes/PagedBytesReferenceTest.java index 6ae5696f804..586d78ce538 100644 --- a/src/test/java/org/elasticsearch/common/bytes/PagedBytesReferenceTest.java +++ b/src/test/java/org/elasticsearch/common/bytes/PagedBytesReferenceTest.java @@ -263,7 +263,7 @@ public class PagedBytesReferenceTest extends ElasticsearchTestCase { public void testWriteToChannel() throws IOException { int length = randomIntBetween(10, PAGE_SIZE * 4); BytesReference pbr = getRandomizedPagedBytesReference(length); - Path tFile = newTempFilePath(); + Path tFile = createTempFile(); try (FileChannel channel = FileChannel.open(tFile, StandardOpenOption.WRITE)) { pbr.writeTo(channel); assertEquals(pbr.length(), channel.position()); @@ -290,7 +290,7 @@ public class PagedBytesReferenceTest extends ElasticsearchTestCase { int sliceOffset = randomIntBetween(1, length / 2); int sliceLength = length - sliceOffset; BytesReference slice = pbr.slice(sliceOffset, sliceLength); - Path tFile = newTempFilePath(); + Path tFile = createTempFile(); try (FileChannel channel = FileChannel.open(tFile, StandardOpenOption.WRITE)) { slice.writeTo(channel); assertEquals(slice.length(), channel.position()); diff --git a/src/test/java/org/elasticsearch/common/hppc/HppcMapsTests.java b/src/test/java/org/elasticsearch/common/hppc/HppcMapsTests.java index 53677349d32..68b894a45fd 100644 --- a/src/test/java/org/elasticsearch/common/hppc/HppcMapsTests.java +++ b/src/test/java/org/elasticsearch/common/hppc/HppcMapsTests.java @@ -32,7 +32,9 @@ public class HppcMapsTests extends ElasticsearchTestCase { @Test public void testIntersection() throws Exception { - assumeTrue(ASSERTIONS_ENABLED); + boolean enabled = false; + assert enabled = true; + assumeTrue("assertions enabled", enabled); ObjectOpenHashSet set1 = ObjectOpenHashSet.from("1", "2", "3"); ObjectOpenHashSet set2 = ObjectOpenHashSet.from("1", "2", "3"); List values = toList(HppcMaps.intersection(set1, set2)); diff --git a/src/test/java/org/elasticsearch/common/io/FileSystemUtilsTests.java b/src/test/java/org/elasticsearch/common/io/FileSystemUtilsTests.java index 6f75150f1ed..aa8c56cc97a 100644 --- a/src/test/java/org/elasticsearch/common/io/FileSystemUtilsTests.java +++ b/src/test/java/org/elasticsearch/common/io/FileSystemUtilsTests.java @@ -20,16 +20,18 @@ package org.elasticsearch.common.io; import com.google.common.base.Charsets; + import org.elasticsearch.test.ElasticsearchTestCase; +import org.apache.lucene.util.LuceneTestCase.SuppressFileSystems; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import java.io.IOException; import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFileExists; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFileNotExists; @@ -39,6 +41,7 @@ import static org.hamcrest.CoreMatchers.is; /** * Unit tests for {@link org.elasticsearch.common.io.FileSystemUtils}. */ +@SuppressFileSystems("WindowsFS") // tries to move away open file handles public class FileSystemUtilsTests extends ElasticsearchTestCase { private Path src; @@ -46,14 +49,14 @@ public class FileSystemUtilsTests extends ElasticsearchTestCase { @Before public void copySourceFilesToTarget() throws IOException, URISyntaxException { - src = newTempDirPath(); - dst = newTempDirPath(); + src = createTempDir(); + dst = createTempDir(); Files.createDirectories(src); Files.createDirectories(dst); // We first copy sources test files from src/test/resources // Because after when the test runs, src files are moved to their destination - final Path path = Paths.get(FileSystemUtilsTests.class.getResource("/org/elasticsearch/common/io/copyappend").toURI()); + final Path path = getDataPath("/org/elasticsearch/common/io/copyappend"); FileSystemUtils.copyDirectoryRecursively(path, src); } @@ -86,7 +89,7 @@ public class FileSystemUtilsTests extends ElasticsearchTestCase { @Test public void testMoveOverExistingFileAndIgnore() throws IOException { - Path dest = newTempDirPath(); + Path dest = createTempDir(); FileSystemUtils.moveFilesWithoutOverwriting(src.resolve("v1"), dest, null); assertFileContent(dest, "file1.txt", "version1"); @@ -114,7 +117,7 @@ public class FileSystemUtilsTests extends ElasticsearchTestCase { @Test public void testMoveFilesDoesNotCreateSameFileWithSuffix() throws Exception { - Path[] dirs = new Path[] { newTempDirPath(), newTempDirPath(), newTempDirPath()}; + Path[] dirs = new Path[] { createTempDir(), createTempDir(), createTempDir()}; for (Path dir : dirs) { Files.write(dir.resolve("file1.txt"), "file1".getBytes(Charsets.UTF_8)); Files.createDirectory(dir.resolve("dir")); @@ -153,7 +156,7 @@ public class FileSystemUtilsTests extends ElasticsearchTestCase { Assert.assertThat("file [" + file + "] should not exist.", Files.exists(file), is(false)); } else { assertFileExists(file); - String fileContent = new String(Files.readAllBytes(file), UTF8); + String fileContent = new String(Files.readAllBytes(file), StandardCharsets.UTF_8); // trim the string content to prevent different handling on windows vs. unix and CR chars... Assert.assertThat(fileContent.trim(), equalTo(expected.trim())); } @@ -161,13 +164,13 @@ public class FileSystemUtilsTests extends ElasticsearchTestCase { @Test public void testAppend() { - assertEquals(FileSystemUtils.append(Paths.get("/foo/bar"), Paths.get("/hello/world/this_is/awesome"), 0), - Paths.get("/foo/bar/hello/world/this_is/awesome")); + assertEquals(FileSystemUtils.append(PathUtils.get("/foo/bar"), PathUtils.get("/hello/world/this_is/awesome"), 0), + PathUtils.get("/foo/bar/hello/world/this_is/awesome")); - assertEquals(FileSystemUtils.append(Paths.get("/foo/bar"), Paths.get("/hello/world/this_is/awesome"), 2), - Paths.get("/foo/bar/this_is/awesome")); + assertEquals(FileSystemUtils.append(PathUtils.get("/foo/bar"), PathUtils.get("/hello/world/this_is/awesome"), 2), + PathUtils.get("/foo/bar/this_is/awesome")); - assertEquals(FileSystemUtils.append(Paths.get("/foo/bar"), Paths.get("/hello/world/this_is/awesome"), 1), - Paths.get("/foo/bar/world/this_is/awesome")); + assertEquals(FileSystemUtils.append(PathUtils.get("/foo/bar"), PathUtils.get("/hello/world/this_is/awesome"), 1), + PathUtils.get("/foo/bar/world/this_is/awesome")); } } diff --git a/src/test/java/org/elasticsearch/common/io/streams/BytesStreamsTests.java b/src/test/java/org/elasticsearch/common/io/streams/BytesStreamsTests.java index a0905276947..9ee4c272580 100644 --- a/src/test/java/org/elasticsearch/common/io/streams/BytesStreamsTests.java +++ b/src/test/java/org/elasticsearch/common/io/streams/BytesStreamsTests.java @@ -260,7 +260,7 @@ public class BytesStreamsTests extends ElasticsearchTestCase { @Test public void testSimpleStreams() throws Exception { - assumeTrue(Constants.JRE_IS_64BIT); + assumeTrue("requires a 64-bit JRE ... ?!", Constants.JRE_IS_64BIT); BytesStreamOutput out = new BytesStreamOutput(); out.writeBoolean(false); out.writeByte((byte)1); 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 cb55da1be98..c39c8a5b90f 100644 --- a/src/test/java/org/elasticsearch/common/logging/log4j/Log4jESLoggerTests.java +++ b/src/test/java/org/elasticsearch/common/logging/log4j/Log4jESLoggerTests.java @@ -24,6 +24,7 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.spi.LocationInfo; import org.apache.log4j.spi.LoggingEvent; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; @@ -51,7 +52,7 @@ public class Log4jESLoggerTests extends ElasticsearchTestCase { super.setUp(); this.testLevel = Log4jESLoggerFactory.getLogger("test").getLevel(); LogConfigurator.reset(); - Path configDir = resolveConfigDir(); + Path configDir = getDataPath("config"); // 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()) @@ -127,11 +128,6 @@ public class Log4jESLoggerTests extends ElasticsearchTestCase { } - private static Path resolveConfigDir() throws Exception { - URL url = Log4jESLoggerTests.class.getResource("config"); - return Paths.get(url.toURI()); - } - private static class TestAppender extends AppenderSkeleton { private List events = new ArrayList<>(); 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 264b82a287d..b53b434a492 100644 --- a/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java +++ b/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.common.logging.log4j; import org.apache.log4j.Appender; import org.apache.log4j.Logger; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.ImmutableSettings; @@ -55,7 +56,7 @@ public class LoggingConfigurationTests extends ElasticsearchTestCase { public void testResolveMultipleConfigs() throws Exception { String level = Log4jESLoggerFactory.getLogger("test").getLevel(); try { - Path configDir = resolveConfigDir(); + Path configDir = getDataPath("config"); Settings settings = ImmutableSettings.builder() .put("path.conf", configDir.toAbsolutePath()) .build(); @@ -82,7 +83,7 @@ public class LoggingConfigurationTests extends ElasticsearchTestCase { @Test public void testResolveJsonLoggingConfig() throws Exception { - Path tmpDir = newTempDirPath(); + Path tmpDir = createTempDir(); Path loggingConf = tmpDir.resolve(loggingConfiguration("json")); Files.write(loggingConf, "{\"json\": \"foo\"}".getBytes(StandardCharsets.UTF_8)); Environment environment = new Environment( @@ -97,7 +98,7 @@ public class LoggingConfigurationTests extends ElasticsearchTestCase { @Test public void testResolvePropertiesLoggingConfig() throws Exception { - Path tmpDir = newTempDirPath(); + Path tmpDir = createTempDir(); Path loggingConf = tmpDir.resolve(loggingConfiguration("properties")); Files.write(loggingConf, "key: value".getBytes(StandardCharsets.UTF_8)); Environment environment = new Environment( @@ -112,7 +113,7 @@ public class LoggingConfigurationTests extends ElasticsearchTestCase { @Test public void testResolveYamlLoggingConfig() throws Exception { - Path tmpDir = newTempDirPath(); + Path tmpDir = createTempDir(); Path loggingConf1 = tmpDir.resolve(loggingConfiguration("yml")); Path loggingConf2 = tmpDir.resolve(loggingConfiguration("yaml")); Files.write(loggingConf1, "yml: bar".getBytes(StandardCharsets.UTF_8)); @@ -130,7 +131,7 @@ public class LoggingConfigurationTests extends ElasticsearchTestCase { @Test public void testResolveConfigInvalidFilename() throws Exception { - Path tmpDir = newTempDirPath(); + Path tmpDir = createTempDir(); Path invalidSuffix = tmpDir.resolve(loggingConfiguration(randomFrom(LogConfigurator.ALLOWED_SUFFIXES)) + randomInvalidSuffix()); Files.write(invalidSuffix, "yml: bar".getBytes(StandardCharsets.UTF_8)); Environment environment = new Environment( @@ -143,11 +144,6 @@ public class LoggingConfigurationTests extends ElasticsearchTestCase { assertThat(logSettings.get("yml"), Matchers.nullValue()); } - private static Path resolveConfigDir() throws Exception { - URL url = LoggingConfigurationTests.class.getResource("config"); - return Paths.get(url.toURI()); - } - private static String loggingConfiguration(String suffix) { return "logging." + randomAsciiOfLength(randomIntBetween(0, 10)) + "." + suffix; } diff --git a/src/test/java/org/elasticsearch/common/lucene/LuceneTest.java b/src/test/java/org/elasticsearch/common/lucene/LuceneTest.java index 1f96a83692d..e74f22cb6d8 100644 --- a/src/test/java/org/elasticsearch/common/lucene/LuceneTest.java +++ b/src/test/java/org/elasticsearch/common/lucene/LuceneTest.java @@ -26,7 +26,7 @@ import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.TermQuery; import org.apache.lucene.store.MockDirectoryWrapper; import org.apache.lucene.util.Version; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; +import org.elasticsearch.test.ElasticsearchTestCase; import org.junit.Test; import java.io.IOException; @@ -36,7 +36,7 @@ import java.util.Set; /** * */ -public class LuceneTest extends ElasticsearchLuceneTestCase { +public class LuceneTest extends ElasticsearchTestCase { /* diff --git a/src/test/java/org/elasticsearch/common/lucene/index/ElasticsearchDirectoryReaderTests.java b/src/test/java/org/elasticsearch/common/lucene/index/ElasticsearchDirectoryReaderTests.java index 5f56b461ac3..934dd8d6c44 100644 --- a/src/test/java/org/elasticsearch/common/lucene/index/ElasticsearchDirectoryReaderTests.java +++ b/src/test/java/org/elasticsearch/common/lucene/index/ElasticsearchDirectoryReaderTests.java @@ -31,10 +31,10 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.util.IOUtils; import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; +import org.elasticsearch.test.ElasticsearchTestCase; /** Simple tests for this filterreader */ -public class ElasticsearchDirectoryReaderTests extends ElasticsearchLuceneTestCase { +public class ElasticsearchDirectoryReaderTests extends ElasticsearchTestCase { /** Test that core cache key (needed for NRT) is working */ public void testCoreCacheKey() throws Exception { diff --git a/src/test/java/org/elasticsearch/common/lucene/index/FreqTermsEnumTests.java b/src/test/java/org/elasticsearch/common/lucene/index/FreqTermsEnumTests.java index f7167fc17e0..28fdf7c6ae0 100644 --- a/src/test/java/org/elasticsearch/common/lucene/index/FreqTermsEnumTests.java +++ b/src/test/java/org/elasticsearch/common/lucene/index/FreqTermsEnumTests.java @@ -22,6 +22,7 @@ package org.elasticsearch.common.lucene.index; import com.carrotsearch.ant.tasks.junit4.dependencies.com.google.common.collect.Lists; import com.carrotsearch.ant.tasks.junit4.dependencies.com.google.common.collect.Maps; import com.google.common.collect.Sets; + import org.apache.lucene.analysis.core.KeywordAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; @@ -35,7 +36,7 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.IOUtils; import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.util.BigArrays; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; +import org.elasticsearch.test.ElasticsearchTestCase; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -48,7 +49,7 @@ import static org.hamcrest.Matchers.is; /** */ -public class FreqTermsEnumTests extends ElasticsearchLuceneTestCase { +public class FreqTermsEnumTests extends ElasticsearchTestCase { private String[] terms; private IndexWriter iw; diff --git a/src/test/java/org/elasticsearch/common/lucene/search/AndDocIdSetTests.java b/src/test/java/org/elasticsearch/common/lucene/search/AndDocIdSetTests.java index 61cd83e5abb..e1650c03aeb 100644 --- a/src/test/java/org/elasticsearch/common/lucene/search/AndDocIdSetTests.java +++ b/src/test/java/org/elasticsearch/common/lucene/search/AndDocIdSetTests.java @@ -28,9 +28,9 @@ import org.apache.lucene.util.BitDocIdSet; import org.apache.lucene.util.Bits; import org.apache.lucene.util.FixedBitSet; import org.elasticsearch.common.lucene.docset.AndDocIdSet; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; +import org.elasticsearch.test.ElasticsearchTestCase; -public class AndDocIdSetTests extends ElasticsearchLuceneTestCase { +public class AndDocIdSetTests extends ElasticsearchTestCase { private static FixedBitSet randomBitSet(int numDocs) { FixedBitSet b = new FixedBitSet(numDocs); diff --git a/src/test/java/org/elasticsearch/common/lucene/search/XBooleanFilterTests.java b/src/test/java/org/elasticsearch/common/lucene/search/XBooleanFilterTests.java index aa742cf9115..ea1539d867c 100644 --- a/src/test/java/org/elasticsearch/common/lucene/search/XBooleanFilterTests.java +++ b/src/test/java/org/elasticsearch/common/lucene/search/XBooleanFilterTests.java @@ -32,8 +32,9 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.FixedBitSet; +import org.apache.lucene.util.TestUtil; import org.elasticsearch.common.lucene.Lucene; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; +import org.elasticsearch.test.ElasticsearchTestCase; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -48,7 +49,7 @@ import static org.hamcrest.core.IsEqual.equalTo; /** */ -public class XBooleanFilterTests extends ElasticsearchLuceneTestCase { +public class XBooleanFilterTests extends ElasticsearchTestCase { private Directory directory; private LeafReader reader; diff --git a/src/test/java/org/elasticsearch/common/lucene/uid/VersionsTests.java b/src/test/java/org/elasticsearch/common/lucene/uid/VersionsTests.java index d9dcd408523..fc055d243c3 100644 --- a/src/test/java/org/elasticsearch/common/lucene/uid/VersionsTests.java +++ b/src/test/java/org/elasticsearch/common/lucene/uid/VersionsTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.common.lucene.uid; import com.google.common.collect.ImmutableMap; + import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.core.KeywordAnalyzer; @@ -27,7 +28,6 @@ import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; import org.apache.lucene.document.*; import org.apache.lucene.document.Field.Store; import org.apache.lucene.index.*; -import org.apache.lucene.index.IndexOptions; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.Numbers; @@ -35,7 +35,7 @@ import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.index.mapper.internal.UidFieldMapper; import org.elasticsearch.index.mapper.internal.VersionFieldMapper; import org.elasticsearch.index.merge.policy.ElasticsearchMergePolicy; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; +import org.elasticsearch.test.ElasticsearchTestCase; import org.hamcrest.MatcherAssert; import org.junit.Test; @@ -46,7 +46,7 @@ import java.util.Map; import static org.hamcrest.Matchers.*; -public class VersionsTests extends ElasticsearchLuceneTestCase { +public class VersionsTests extends ElasticsearchTestCase { public static DirectoryReader reopen(DirectoryReader reader) throws IOException { return reopen(reader, true); diff --git a/src/test/java/org/elasticsearch/deleteByQuery/DeleteByQueryTests.java b/src/test/java/org/elasticsearch/deleteByQuery/DeleteByQueryTests.java index d1beb07f0d7..ffc8db1d36b 100644 --- a/src/test/java/org/elasticsearch/deleteByQuery/DeleteByQueryTests.java +++ b/src/test/java/org/elasticsearch/deleteByQuery/DeleteByQueryTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.deleteByQuery; +import org.apache.lucene.util.LuceneTestCase.Slow; import org.elasticsearch.action.ActionWriteResponse; import org.elasticsearch.action.admin.indices.alias.Alias; import org.elasticsearch.action.deletebyquery.DeleteByQueryRequestBuilder; @@ -38,6 +39,7 @@ import java.util.concurrent.ExecutionException; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*; import static org.hamcrest.Matchers.*; +@Slow public class DeleteByQueryTests extends ElasticsearchIntegrationTest { @Test diff --git a/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryTests.java b/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryTests.java index f37f138c9e5..430690ae146 100644 --- a/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryTests.java +++ b/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.discovery; +import org.apache.lucene.util.LuceneTestCase.Slow; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.settings.ImmutableSettings; @@ -36,6 +37,7 @@ import java.util.concurrent.ExecutionException; import static org.hamcrest.Matchers.equalTo; @ClusterScope(scope = Scope.TEST, numDataNodes = 0) +@Slow public class ZenUnicastDiscoveryTests extends ElasticsearchIntegrationTest { private ClusterDiscoveryConfiguration discoveryConfig; diff --git a/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryTests.java b/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryTests.java index 469da2078e0..58e177b1115 100644 --- a/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryTests.java +++ b/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.discovery.zen; +import org.apache.lucene.util.LuceneTestCase.Slow; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.Version; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; @@ -59,6 +60,7 @@ import static org.hamcrest.Matchers.*; /** */ @ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.TEST, numDataNodes = 0, numClientNodes = 0) +@Slow public class ZenDiscoveryTests extends ElasticsearchIntegrationTest { @Test diff --git a/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingTests.java b/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingTests.java index f5b8de4130c..25a8eccd0cf 100644 --- a/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingTests.java +++ b/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingTests.java @@ -37,6 +37,7 @@ import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.netty.NettyTransport; +import org.apache.lucene.util.LuceneTestCase.Slow; import org.junit.Test; import static org.hamcrest.Matchers.equalTo; @@ -44,6 +45,7 @@ import static org.hamcrest.Matchers.equalTo; /** * */ +@Slow public class UnicastZenPingTests extends ElasticsearchTestCase { @Test diff --git a/src/test/java/org/elasticsearch/env/EnvironmentTests.java b/src/test/java/org/elasticsearch/env/EnvironmentTests.java index ebbaeab3dac..31785e6f7ea 100644 --- a/src/test/java/org/elasticsearch/env/EnvironmentTests.java +++ b/src/test/java/org/elasticsearch/env/EnvironmentTests.java @@ -42,7 +42,7 @@ public class EnvironmentTests extends ElasticsearchTestCase { public Environment newEnvironment(Settings settings) throws IOException { Settings build = ImmutableSettings.builder() .put(settings) - .put("path.home", newTempDirPath().toAbsolutePath()) + .put("path.home", createTempDir().toAbsolutePath()) .putArray("path.data", tmpPaths()).build(); return new Environment(build); } diff --git a/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java b/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java index 5e63bcdac9d..cee1f2e9fd6 100644 --- a/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java +++ b/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java @@ -20,8 +20,10 @@ package org.elasticsearch.env; import org.apache.lucene.store.LockObtainFailedException; import org.apache.lucene.util.IOUtils; +import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.ElasticsearchIllegalStateException; import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.AbstractRunnable; @@ -45,6 +47,7 @@ import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; import static org.hamcrest.CoreMatchers.equalTo; +@LuceneTestCase.SuppressFileSystems("ExtrasFS") // TODO: fix test to allow extras public class NodeEnvironmentTests extends ElasticsearchTestCase { private final Settings idxSettings = ImmutableSettings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).build(); @@ -69,7 +72,7 @@ public class NodeEnvironmentTests extends ElasticsearchTestCase { assertEquals(env.nodeDataPaths().length, dataPaths.length); for (int i = 0; i < dataPaths.length; i++) { - assertTrue(env.nodeDataPaths()[i].startsWith(Paths.get(dataPaths[i]))); + assertTrue(env.nodeDataPaths()[i].startsWith(PathUtils.get(dataPaths[i]))); } env.close(); assertTrue("LockedShards: " + env.lockedShards(), env.lockedShards().isEmpty()); @@ -312,7 +315,7 @@ public class NodeEnvironmentTests extends ElasticsearchTestCase { assertTrue("settings with path_data should have a custom data path", NodeEnvironment.hasCustomDataPath(s2)); assertThat(env.shardDataPaths(sid, s1), equalTo(env.shardPaths(sid))); - assertThat(env.shardDataPaths(sid, s2), equalTo(new Path[] {Paths.get("/tmp/foo/0/myindex/0")})); + assertThat(env.shardDataPaths(sid, s2), equalTo(new Path[] {PathUtils.get("/tmp/foo/0/myindex/0")})); assertThat("shard paths with a custom data_path should contain only regular paths", env.shardPaths(sid), @@ -326,7 +329,7 @@ public class NodeEnvironmentTests extends ElasticsearchTestCase { ImmutableSettings.builder().put(NodeEnvironment.ADD_NODE_ID_TO_CUSTOM_PATH, false).build()); assertThat(env2.shardDataPaths(sid, s1), equalTo(env2.shardPaths(sid))); - assertThat(env2.shardDataPaths(sid, s2), equalTo(new Path[] {Paths.get("/tmp/foo/myindex/0")})); + assertThat(env2.shardDataPaths(sid, s2), equalTo(new Path[] {PathUtils.get("/tmp/foo/myindex/0")})); assertThat("shard paths with a custom data_path should contain only regular paths", env2.shardPaths(sid), @@ -342,7 +345,7 @@ public class NodeEnvironmentTests extends ElasticsearchTestCase { private Path[] stringsToPaths(String[] strings, String additional) { Path[] locations = new Path[strings.length]; for (int i = 0; i < strings.length; i++) { - locations[i] = Paths.get(strings[i], additional); + locations[i] = PathUtils.get(strings[i], additional); } return locations; } @@ -352,7 +355,7 @@ public class NodeEnvironmentTests extends ElasticsearchTestCase { final int numPaths = randomIntBetween(1, 3); final String[] absPaths = new String[numPaths]; for (int i = 0; i < numPaths; i++) { - absPaths[i] = newTempDirPath().toAbsolutePath().toString(); + absPaths[i] = createTempDir().toAbsolutePath().toString(); } return absPaths; } @@ -366,7 +369,7 @@ public class NodeEnvironmentTests extends ElasticsearchTestCase { public NodeEnvironment newNodeEnvironment(Settings settings) throws IOException { Settings build = ImmutableSettings.builder() .put(settings) - .put("path.home", newTempDirPath().toAbsolutePath().toString()) + .put("path.home", createTempDir().toAbsolutePath().toString()) .put(NodeEnvironment.SETTING_CUSTOM_DATA_PATH_ENABLED, true) .putArray("path.data", tmpPaths()).build(); return new NodeEnvironment(build, new Environment(build)); @@ -375,7 +378,7 @@ public class NodeEnvironmentTests extends ElasticsearchTestCase { public NodeEnvironment newNodeEnvironment(String[] dataPaths, Settings settings) throws IOException { Settings build = ImmutableSettings.builder() .put(settings) - .put("path.home", newTempDirPath().toAbsolutePath().toString()) + .put("path.home", createTempDir().toAbsolutePath().toString()) .put(NodeEnvironment.SETTING_CUSTOM_DATA_PATH_ENABLED, true) .putArray("path.data", dataPaths).build(); return new NodeEnvironment(build, new Environment(build)); diff --git a/src/test/java/org/elasticsearch/gateway/GatewayIndexStateTests.java b/src/test/java/org/elasticsearch/gateway/GatewayIndexStateTests.java index 0cee6e9588c..7039fe130ae 100644 --- a/src/test/java/org/elasticsearch/gateway/GatewayIndexStateTests.java +++ b/src/test/java/org/elasticsearch/gateway/GatewayIndexStateTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.gateway; +import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase.Slow; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; diff --git a/src/test/java/org/elasticsearch/gateway/MetaDataStateFormatTest.java b/src/test/java/org/elasticsearch/gateway/MetaDataStateFormatTest.java index fa8a473fff2..5581290d0e5 100644 --- a/src/test/java/org/elasticsearch/gateway/MetaDataStateFormatTest.java +++ b/src/test/java/org/elasticsearch/gateway/MetaDataStateFormatTest.java @@ -18,7 +18,6 @@ */ package org.elasticsearch.gateway; -import com.carrotsearch.randomizedtesting.LifecycleScope; import com.google.common.collect.Iterators; import org.apache.lucene.codecs.CodecUtil; @@ -29,6 +28,7 @@ import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.store.MockDirectoryWrapper; import org.apache.lucene.store.SimpleFSDirectory; +import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TestRuleMarkFailure; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchIllegalStateException; @@ -72,6 +72,7 @@ import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.startsWith; +@LuceneTestCase.SuppressFileSystems("ExtrasFS") // TODO: fix test to work with ExtrasFS public class MetaDataStateFormatTest extends ElasticsearchTestCase { @@ -91,7 +92,7 @@ public class MetaDataStateFormatTest extends ElasticsearchTestCase { return MetaData.Builder.fromXContent(parser); } }; - Path tmp = newTempDirPath(); + Path tmp = createTempDir(); final InputStream resource = this.getClass().getResourceAsStream("global-3.st"); assertThat(resource, notNullValue()); Path dst = tmp.resolve("global-3.st"); @@ -105,7 +106,7 @@ public class MetaDataStateFormatTest extends ElasticsearchTestCase { public void testReadWriteState() throws IOException { Path[] dirs = new Path[randomIntBetween(1, 5)]; for (int i = 0; i < dirs.length; i++) { - dirs[i] = newTempDirPath(LifecycleScope.TEST); + dirs[i] = createTempDir(); } final long id = addDummyFiles("foo-", dirs); Format format = new Format(randomFrom(XContentType.values()), "foo-"); @@ -147,7 +148,7 @@ public class MetaDataStateFormatTest extends ElasticsearchTestCase { public void testVersionMismatch() throws IOException { Path[] dirs = new Path[randomIntBetween(1, 5)]; for (int i = 0; i < dirs.length; i++) { - dirs[i] = newTempDirPath(LifecycleScope.TEST); + dirs[i] = createTempDir(); } final long id = addDummyFiles("foo-", dirs); @@ -172,7 +173,7 @@ public class MetaDataStateFormatTest extends ElasticsearchTestCase { public void testCorruption() throws IOException { Path[] dirs = new Path[randomIntBetween(1, 5)]; for (int i = 0; i < dirs.length; i++) { - dirs[i] = newTempDirPath(LifecycleScope.TEST); + dirs[i] = createTempDir(); } final long id = addDummyFiles("foo-", dirs); Format format = new Format(randomFrom(XContentType.values()), "foo-"); @@ -246,8 +247,8 @@ public class MetaDataStateFormatTest extends ElasticsearchTestCase { final ToXContent.Params params = ToXContent.EMPTY_PARAMS; MetaDataStateFormat format = MetaStateService.globalStateFormat(randomFrom(XContentType.values()), params); final Path[] dirs = new Path[2]; - dirs[0] = newTempDirPath(LifecycleScope.TEST); - dirs[1] = newTempDirPath(LifecycleScope.TEST); + dirs[0] = createTempDir(); + dirs[1] = createTempDir(); for (Path dir : dirs) { Files.createDirectories(dir.resolve(MetaDataStateFormat.STATE_DIR_NAME)); } @@ -291,8 +292,8 @@ public class MetaDataStateFormatTest extends ElasticsearchTestCase { final ToXContent.Params params = ToXContent.EMPTY_PARAMS; MetaDataStateFormat format = MetaStateService.globalStateFormat(randomFrom(XContentType.values()), params); final Path[] dirs = new Path[2]; - dirs[0] = newTempDirPath(LifecycleScope.TEST); - dirs[1] = newTempDirPath(LifecycleScope.TEST); + dirs[0] = createTempDir(); + dirs[1] = createTempDir(); for (Path dir : dirs) { Files.createDirectories(dir.resolve(MetaDataStateFormat.STATE_DIR_NAME)); } @@ -333,7 +334,7 @@ public class MetaDataStateFormatTest extends ElasticsearchTestCase { Set corruptedFiles = new HashSet<>(); MetaDataStateFormat format = MetaStateService.globalStateFormat(randomFrom(XContentType.values()), params); for (int i = 0; i < dirs.length; i++) { - dirs[i] = newTempDirPath(LifecycleScope.TEST); + dirs[i] = createTempDir(); Files.createDirectories(dirs[i].resolve(MetaDataStateFormat.STATE_DIR_NAME)); for (int j = 0; j < numLegacy; j++) { XContentType type = format.format(); @@ -428,7 +429,7 @@ public class MetaDataStateFormatTest extends ElasticsearchTestCase { @Override protected Directory newDirectory(Path dir) throws IOException { MockDirectoryWrapper mock = new MockDirectoryWrapper(getRandom(), super.newDirectory(dir)); - closeAfterSuite(new CloseableDirectory(mock, suiteFailureMarker)); + closeAfterSuite(mock); return mock; } } diff --git a/src/test/java/org/elasticsearch/gateway/MetaStateServiceTests.java b/src/test/java/org/elasticsearch/gateway/MetaStateServiceTests.java index 86296541f12..486e6c267cd 100644 --- a/src/test/java/org/elasticsearch/gateway/MetaStateServiceTests.java +++ b/src/test/java/org/elasticsearch/gateway/MetaStateServiceTests.java @@ -23,6 +23,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.test.ElasticsearchTestCase; import org.junit.Test; @@ -113,7 +114,7 @@ public class MetaStateServiceTests extends ElasticsearchTestCase { private Settings randomSettings() { ImmutableSettings.Builder builder = ImmutableSettings.builder(); if (randomBoolean()) { - builder.put(MetaStateService.FORMAT_SETTING, randomXContentType().shortName()); + builder.put(MetaStateService.FORMAT_SETTING, randomFrom(XContentType.values()).shortName()); } return builder.build(); } diff --git a/src/test/java/org/elasticsearch/gateway/RecoverAfterNodesTests.java b/src/test/java/org/elasticsearch/gateway/RecoverAfterNodesTests.java index 92e9a6a4bf3..00e6fcdf4f1 100644 --- a/src/test/java/org/elasticsearch/gateway/RecoverAfterNodesTests.java +++ b/src/test/java/org/elasticsearch/gateway/RecoverAfterNodesTests.java @@ -20,6 +20,8 @@ package org.elasticsearch.gateway; import com.google.common.collect.ImmutableSet; + +import org.apache.lucene.util.LuceneTestCase.Slow; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.block.ClusterBlock; import org.elasticsearch.cluster.block.ClusterBlockLevel; @@ -39,6 +41,7 @@ import static org.hamcrest.Matchers.hasItem; * */ @ClusterScope(scope = Scope.TEST, numDataNodes = 0) +@Slow public class RecoverAfterNodesTests extends ElasticsearchIntegrationTest { private final static TimeValue BLOCK_WAIT_TIMEOUT = TimeValue.timeValueSeconds(10); diff --git a/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayTests.java b/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayTests.java index 9efd4c8b8e8..42b8822a980 100644 --- a/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayTests.java +++ b/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayTests.java @@ -438,11 +438,11 @@ public class RecoveryFromGatewayTests extends ElasticsearchIntegrationTest { public void testRecoveryDifferentNodeOrderStartup() throws Exception { // we need different data paths so we make sure we start the second node fresh - final String node_1 = internalCluster().startNode(settingsBuilder().put("path.data", newTempDirPath()).build()); + final String node_1 = internalCluster().startNode(settingsBuilder().put("path.data", createTempDir()).build()); client().prepareIndex("test", "type1", "1").setSource("field", "value").execute().actionGet(); - internalCluster().startNode(settingsBuilder().put("path.data", newTempDirPath()).build()); + internalCluster().startNode(settingsBuilder().put("path.data", createTempDir()).build()); ensureGreen(); diff --git a/src/test/java/org/elasticsearch/http/netty/NettyHttpServerPipeliningTest.java b/src/test/java/org/elasticsearch/http/netty/NettyHttpServerPipeliningTest.java index eb6098e94cb..623ce887619 100644 --- a/src/test/java/org/elasticsearch/http/netty/NettyHttpServerPipeliningTest.java +++ b/src/test/java/org/elasticsearch/http/netty/NettyHttpServerPipeliningTest.java @@ -20,6 +20,7 @@ package org.elasticsearch.http.netty; import com.google.common.base.Charsets; import com.google.common.collect.Lists; + import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.network.NetworkService; import org.elasticsearch.common.settings.ImmutableSettings; @@ -210,7 +211,12 @@ public class NettyHttpServerPipeliningTest extends ElasticsearchTestCase { final int timeout = request.getUri().startsWith("/slow") && decoder.getParameters().containsKey("sleep") ? Integer.valueOf(decoder.getParameters().get("sleep").get(0)) : 0; if (timeout > 0) { - sleep(timeout); + try { + Thread.sleep(timeout); + } catch (InterruptedException e1) { + Thread.currentThread().interrupt(); + throw new RuntimeException(); + } } if (oue != null) { diff --git a/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasTests.java b/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasTests.java index 438f461b31b..c0a63d22922 100644 --- a/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasTests.java +++ b/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasTests.java @@ -66,7 +66,7 @@ public class IndexWithShadowReplicasTests extends ElasticsearchIntegrationTest { .build(); internalCluster().startNodesAsync(3, nodeSettings).get(); - final Path dataPath = newTempDirPath(); + final Path dataPath = createTempDir(); Settings idxSettings = ImmutableSettings.builder() .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0).build(); @@ -80,7 +80,7 @@ public class IndexWithShadowReplicasTests extends ElasticsearchIntegrationTest { assertAcked(client().admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()))); + .put("location", createTempDir()))); CreateSnapshotResponse createSnapshotResponse = client().admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("foo").get(); assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards())); @@ -126,7 +126,7 @@ public class IndexWithShadowReplicasTests extends ElasticsearchIntegrationTest { internalCluster().startNodesAsync(3, nodeSettings).get(); final String IDX = "test"; - final Path dataPath = newTempDirPath(); + final Path dataPath = createTempDir(); Settings idxSettings = ImmutableSettings.builder() .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) @@ -191,7 +191,7 @@ public class IndexWithShadowReplicasTests extends ElasticsearchIntegrationTest { .build(); String node1 = internalCluster().startNode(nodeSettings); - Path dataPath = newTempDirPath(); + Path dataPath = createTempDir(); String IDX = "test"; Settings idxSettings = ImmutableSettings.builder() @@ -253,7 +253,7 @@ public class IndexWithShadowReplicasTests extends ElasticsearchIntegrationTest { .build(); String node1 = internalCluster().startNode(nodeSettings); - Path dataPath = newTempDirPath(); + Path dataPath = createTempDir(); String IDX = "test"; Settings idxSettings = ImmutableSettings.builder() @@ -318,7 +318,7 @@ public class IndexWithShadowReplicasTests extends ElasticsearchIntegrationTest { int nodeCount = randomIntBetween(2, 5); internalCluster().startNodesAsync(nodeCount, nodeSettings).get(); - Path dataPath = newTempDirPath(); + Path dataPath = createTempDir(); String IDX = "test"; Settings idxSettings = ImmutableSettings.builder() @@ -362,7 +362,7 @@ public class IndexWithShadowReplicasTests extends ElasticsearchIntegrationTest { .build(); internalCluster().startNodesAsync(2, nodeSettings).get(); - Path dataPath = newTempDirPath(); + Path dataPath = createTempDir(); String IDX = "test"; Settings idxSettings = ImmutableSettings.builder() @@ -419,7 +419,7 @@ public class IndexWithShadowReplicasTests extends ElasticsearchIntegrationTest { .build(); internalCluster().startNodesAsync(3, nodeSettings).get(); - Path dataPath = newTempDirPath(); + Path dataPath = createTempDir(); String IDX = "test"; Settings idxSettings = ImmutableSettings.builder() diff --git a/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java b/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java index 01c65c38a45..81f06ad79d7 100644 --- a/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java @@ -212,7 +212,7 @@ public class AnalysisModuleTests extends ElasticsearchTestCase { } private Path generateWordList(String[] words) throws Exception { - Path wordListFile = newTempDirPath().resolve("wordlist.txt"); + Path wordListFile = createTempDir().resolve("wordlist.txt"); try (BufferedWriter writer = Files.newBufferedWriter(wordListFile, StandardCharsets.UTF_8)) { for (String word : words) { writer.write(word); diff --git a/src/test/java/org/elasticsearch/index/analysis/HunspellTokenFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/HunspellTokenFilterFactoryTests.java index a547fb88805..cb79991b90c 100644 --- a/src/test/java/org/elasticsearch/index/analysis/HunspellTokenFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/HunspellTokenFilterFactoryTests.java @@ -33,7 +33,7 @@ public class HunspellTokenFilterFactoryTests extends ElasticsearchTestCase { @Test public void testDedup() throws IOException { Settings settings = settingsBuilder() - .put("path.conf", getResourcePath("/indices/analyze/conf_dir")) + .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") .build(); @@ -45,7 +45,7 @@ public class HunspellTokenFilterFactoryTests extends ElasticsearchTestCase { assertThat(hunspellTokenFilter.dedup(), is(true)); settings = settingsBuilder() - .put("path.conf", getResourcePath("/indices/analyze/conf_dir")) + .put("path.conf", getDataPath("/indices/analyze/conf_dir")) .put("index.analysis.filter.en_US.type", "hunspell") .put("index.analysis.filter.en_US.dedup", false) .put("index.analysis.filter.en_US.locale", "en_US") diff --git a/src/test/java/org/elasticsearch/index/analysis/PreBuiltAnalyzerTests.java b/src/test/java/org/elasticsearch/index/analysis/PreBuiltAnalyzerTests.java index 241ac52d4cc..69e227f9604 100644 --- a/src/test/java/org/elasticsearch/index/analysis/PreBuiltAnalyzerTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/PreBuiltAnalyzerTests.java @@ -37,6 +37,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; +import static org.elasticsearch.test.VersionUtils.randomVersion; import static org.hamcrest.Matchers.*; /** @@ -86,7 +87,7 @@ public class PreBuiltAnalyzerTests extends ElasticsearchSingleNodeTest { assertThat(list, contains("dude")); } ts.close(); - version = randomVersion(); + version = randomVersion(random()); } } @@ -121,7 +122,7 @@ public class PreBuiltAnalyzerTests extends ElasticsearchSingleNodeTest { assertThat(list, contains("dude")); } ts.close(); - version = randomVersion(); + version = randomVersion(random()); } } @@ -152,7 +153,7 @@ public class PreBuiltAnalyzerTests extends ElasticsearchSingleNodeTest { PreBuiltAnalyzers randomPreBuiltAnalyzer = PreBuiltAnalyzers.values()[randomInt]; String analyzerName = randomPreBuiltAnalyzer.name().toLowerCase(Locale.ROOT); - Version randomVersion = randomVersion(); + Version randomVersion = randomVersion(random()); Settings indexSettings = ImmutableSettings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, randomVersion).build(); NamedAnalyzer namedAnalyzer = new PreBuiltAnalyzerProvider(analyzerName, AnalyzerScope.INDEX, randomPreBuiltAnalyzer.getAnalyzer(randomVersion)).get(); diff --git a/src/test/java/org/elasticsearch/index/analysis/StemmerTokenFilterFactoryTests.java b/src/test/java/org/elasticsearch/index/analysis/StemmerTokenFilterFactoryTests.java index 15f18f016ec..ab335129df5 100644 --- a/src/test/java/org/elasticsearch/index/analysis/StemmerTokenFilterFactoryTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/StemmerTokenFilterFactoryTests.java @@ -26,8 +26,8 @@ import org.apache.lucene.analysis.snowball.SnowballFilter; import org.elasticsearch.Version; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.test.ElasticsearchTokenStreamTestCase; +import org.elasticsearch.test.VersionUtils; import org.junit.Test; import java.io.IOException; @@ -47,7 +47,7 @@ public class StemmerTokenFilterFactoryTests extends ElasticsearchTokenStreamTest int iters = scaledRandomIntBetween(20, 100); for (int i = 0; i < iters; i++) { - Version v = ElasticsearchTestCase.randomVersion(random()); + Version v = VersionUtils.randomVersion(random()); Settings settings = ImmutableSettings.settingsBuilder() .put("index.analysis.filter.my_english.type", "stemmer") .put("index.analysis.filter.my_english.language", "english") @@ -80,7 +80,7 @@ public class StemmerTokenFilterFactoryTests extends ElasticsearchTokenStreamTest int iters = scaledRandomIntBetween(20, 100); for (int i = 0; i < iters; i++) { - Version v = ElasticsearchTestCase.randomVersion(random()); + Version v = VersionUtils.randomVersion(random()); Settings settings = ImmutableSettings.settingsBuilder() .put("index.analysis.filter.my_porter2.type", "stemmer") .put("index.analysis.filter.my_porter2.language", "porter2") diff --git a/src/test/java/org/elasticsearch/index/codec/CodecTests.java b/src/test/java/org/elasticsearch/index/codec/CodecTests.java index 5e714281e56..1014fdfba74 100644 --- a/src/test/java/org/elasticsearch/index/codec/CodecTests.java +++ b/src/test/java/org/elasticsearch/index/codec/CodecTests.java @@ -36,23 +36,17 @@ import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.SegmentReader; import org.apache.lucene.store.Directory; +import org.apache.lucene.util.LuceneTestCase.SuppressCodecs; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexService; -import org.elasticsearch.test.ElasticsearchSingleNodeLuceneTestCase; -import org.junit.Before; +import org.elasticsearch.test.ElasticsearchSingleNodeTest; import org.junit.Test; import static org.hamcrest.Matchers.instanceOf; -public class CodecTests extends ElasticsearchSingleNodeLuceneTestCase { - - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - forceDefaultCodec(); // we test against default codec so never get a random one here! - } +@SuppressCodecs("*") // we test against default codec so never get a random one here! +public class CodecTests extends ElasticsearchSingleNodeTest { @Test public void testResolveDefaultCodecs() throws Exception { diff --git a/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index ad9d9c57cec..a7f93723849 100644 --- a/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -41,7 +41,7 @@ import org.apache.lucene.store.AlreadyClosedException; import org.apache.lucene.store.Directory; import org.apache.lucene.store.MockDirectoryWrapper; import org.apache.lucene.util.IOUtils; -import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util.LuceneTestCase.SuppressFileSystems; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; @@ -89,7 +89,7 @@ import org.elasticsearch.index.translog.Translog; import org.elasticsearch.index.translog.TranslogSizeMatcher; import org.elasticsearch.index.translog.fs.FsTranslog; import org.elasticsearch.test.DummyShardLock; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; +import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.hamcrest.MatcherAssert; import org.junit.After; @@ -102,21 +102,17 @@ import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; -import static com.carrotsearch.randomizedtesting.RandomizedTest.randomBoolean; -import static com.carrotsearch.randomizedtesting.RandomizedTest.randomDouble; -import static com.carrotsearch.randomizedtesting.RandomizedTest.randomIntBetween; import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS; import static org.elasticsearch.index.engine.Engine.Operation.Origin.PRIMARY; import static org.elasticsearch.index.engine.Engine.Operation.Origin.REPLICA; -import static org.elasticsearch.test.ElasticsearchTestCase.assertBusy; -import static org.elasticsearch.test.ElasticsearchTestCase.terminate; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; -@LuceneTestCase.SuppressFileSystems("*") // mock FS causes translog issues recovering sometimes because of their use of globs, see LUCENE-6424 -public class InternalEngineTests extends ElasticsearchLuceneTestCase { +// TODO: this guy isn't ready for mock filesystems yet +@SuppressFileSystems("*") +public class InternalEngineTests extends ElasticsearchTestCase { protected final ShardId shardId = new ShardId(new Index("index"), 1); @@ -1409,6 +1405,7 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase { @Test public void testIndexWriterInfoStream() { + assumeFalse("who tests the tester?", VERBOSE); MockAppender mockAppender = new MockAppender(); Logger rootLogger = Logger.getRootLogger(); @@ -1437,6 +1434,7 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase { // #8603: make sure we can separately log IFD's messages public void testIndexWriterIFDInfoStream() { + assumeFalse("who tests the tester?", VERBOSE); MockAppender mockAppender = new MockAppender(); // Works when running this test inside Intellij: diff --git a/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java b/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java index 4d209a626ad..210cc44dada 100644 --- a/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java +++ b/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.engine; -import com.carrotsearch.randomizedtesting.LifecycleScope; import org.apache.lucene.codecs.Codec; import org.apache.lucene.document.Field; import org.apache.lucene.document.NumericDocValuesField; @@ -31,6 +30,7 @@ import org.apache.lucene.index.Term; import org.apache.lucene.search.TermQuery; import org.apache.lucene.store.Directory; import org.apache.lucene.store.MockDirectoryWrapper; +import org.apache.lucene.util.TestUtil; import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.Nullable; @@ -63,7 +63,7 @@ import org.elasticsearch.index.store.distributor.LeastUsedDistributor; import org.elasticsearch.index.translog.Translog; import org.elasticsearch.index.translog.fs.FsTranslog; import org.elasticsearch.test.DummyShardLock; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; +import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.hamcrest.MatcherAssert; import org.junit.After; @@ -75,12 +75,7 @@ import java.nio.file.Path; import java.util.Arrays; import java.util.List; -import static com.carrotsearch.randomizedtesting.RandomizedTest.getRandom; -import static com.carrotsearch.randomizedtesting.RandomizedTest.randomBoolean; -import static com.carrotsearch.randomizedtesting.RandomizedTest.randomDouble; -import static com.carrotsearch.randomizedtesting.RandomizedTest.randomIntBetween; import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS; -import static org.elasticsearch.test.ElasticsearchTestCase.newTempDirPath; import static org.elasticsearch.test.ElasticsearchTestCase.terminate; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; @@ -90,7 +85,7 @@ import static org.hamcrest.Matchers.nullValue; /** * TODO: document me! */ -public class ShadowEngineTests extends ElasticsearchLuceneTestCase { +public class ShadowEngineTests extends ElasticsearchTestCase { protected final ShardId shardId = new ShardId(new Index("index"), 1); diff --git a/src/test/java/org/elasticsearch/index/fielddata/AbstractFieldDataTests.java b/src/test/java/org/elasticsearch/index/fielddata/AbstractFieldDataTests.java index 599101f9dec..6765dd3bd73 100644 --- a/src/test/java/org/elasticsearch/index/fielddata/AbstractFieldDataTests.java +++ b/src/test/java/org/elasticsearch/index/fielddata/AbstractFieldDataTests.java @@ -25,7 +25,6 @@ import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.index.*; import org.apache.lucene.search.Filter; import org.apache.lucene.store.RAMDirectory; -import org.apache.lucene.util.LuceneTestCase.SuppressCodecs; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.mapper.ContentPath; @@ -41,9 +40,6 @@ import org.junit.Before; import static org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested; -// we might wanna cut this over to LuceneTestCase -@SuppressCodecs({"Lucene3x", "Lucene40", "Lucene41", "Lucene42", "Lucene45", "Lucene46"}) -// avoid codecs that do not support SortedNumerics, SortedSet, etc public abstract class AbstractFieldDataTests extends ElasticsearchSingleNodeTest { protected IndexService indexService; diff --git a/src/test/java/org/elasticsearch/index/fielddata/fieldcomparator/ReplaceMissingTests.java b/src/test/java/org/elasticsearch/index/fielddata/fieldcomparator/ReplaceMissingTests.java index 06d1db982a5..08a960e7699 100644 --- a/src/test/java/org/elasticsearch/index/fielddata/fieldcomparator/ReplaceMissingTests.java +++ b/src/test/java/org/elasticsearch/index/fielddata/fieldcomparator/ReplaceMissingTests.java @@ -24,11 +24,9 @@ import org.apache.lucene.document.SortedDocValuesField; import org.apache.lucene.index.*; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; -import org.apache.lucene.util.LuceneTestCase.SuppressCodecs; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; +import org.elasticsearch.test.ElasticsearchTestCase; -@SuppressCodecs({ "Lucene3x", "Lucene40", "Lucene41", "Lucene42" }) // these codecs dont support missing values -public class ReplaceMissingTests extends ElasticsearchLuceneTestCase { +public class ReplaceMissingTests extends ElasticsearchTestCase { public void test() throws Exception { Directory dir = newDirectory(); diff --git a/src/test/java/org/elasticsearch/index/fielddata/plain/ParentChildFilteredTermsEnumTests.java b/src/test/java/org/elasticsearch/index/fielddata/plain/ParentChildFilteredTermsEnumTests.java index 9eac5db386f..48c95aa3f65 100644 --- a/src/test/java/org/elasticsearch/index/fielddata/plain/ParentChildFilteredTermsEnumTests.java +++ b/src/test/java/org/elasticsearch/index/fielddata/plain/ParentChildFilteredTermsEnumTests.java @@ -26,8 +26,7 @@ import org.apache.lucene.index.*; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; -import org.junit.BeforeClass; +import org.elasticsearch.test.ElasticsearchTestCase; import org.junit.Test; import java.util.Locale; @@ -38,12 +37,7 @@ import static org.hamcrest.core.IsNull.notNullValue; /** */ -public class ParentChildFilteredTermsEnumTests extends ElasticsearchLuceneTestCase { - - @BeforeClass - public static void before() { - forceDefaultCodec(); - } +public class ParentChildFilteredTermsEnumTests extends ElasticsearchTestCase { @Test public void testSimple_twoFieldEachUniqueValue() throws Exception { diff --git a/src/test/java/org/elasticsearch/index/mapper/FileBasedMappingsTests.java b/src/test/java/org/elasticsearch/index/mapper/FileBasedMappingsTests.java index 6c28e50d3ad..6772a5dfcd4 100644 --- a/src/test/java/org/elasticsearch/index/mapper/FileBasedMappingsTests.java +++ b/src/test/java/org/elasticsearch/index/mapper/FileBasedMappingsTests.java @@ -45,7 +45,7 @@ public class FileBasedMappingsTests extends ElasticsearchTestCase { private static final String NAME = FileBasedMappingsTests.class.getSimpleName(); public void testFileBasedMappings() throws Exception { - Path configDir = newTempDirPath(); + Path configDir = createTempDir(); Path mappingsDir = configDir.resolve("mappings"); Path indexMappings = mappingsDir.resolve("index").resolve("type.json"); Path defaultMappings = mappingsDir.resolve("_default").resolve("type.json"); @@ -82,7 +82,7 @@ public class FileBasedMappingsTests extends ElasticsearchTestCase { Settings settings = ImmutableSettings.builder() .put(ClusterName.SETTING, NAME) .put("node.name", NAME) - .put("path.home", newTempDirPath()) + .put("path.home", createTempDir()) .put("path.conf", configDir.toAbsolutePath()) .put("http.enabled", false) .build(); diff --git a/src/test/java/org/elasticsearch/index/mapper/TransformOnIndexMapperIntegrationTest.java b/src/test/java/org/elasticsearch/index/mapper/TransformOnIndexMapperIntegrationTest.java index e82be52f061..6b2180c840e 100644 --- a/src/test/java/org/elasticsearch/index/mapper/TransformOnIndexMapperIntegrationTest.java +++ b/src/test/java/org/elasticsearch/index/mapper/TransformOnIndexMapperIntegrationTest.java @@ -21,6 +21,7 @@ package org.elasticsearch.index.mapper; import com.google.common.collect.ImmutableMap; +import org.apache.lucene.util.LuceneTestCase.SuppressCodecs; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.suggest.SuggestResponse; @@ -51,6 +52,7 @@ import static org.hamcrest.Matchers.not; /** * Tests for transforming the source document before indexing. */ +@SuppressCodecs("*") // requires custom completion format public class TransformOnIndexMapperIntegrationTest extends ElasticsearchIntegrationTest { @Test public void searchOnTransformed() throws Exception { diff --git a/src/test/java/org/elasticsearch/index/mapper/externalvalues/SimpleExternalMappingTests.java b/src/test/java/org/elasticsearch/index/mapper/externalvalues/SimpleExternalMappingTests.java index f48dd286e0c..b95fda8d7b4 100644 --- a/src/test/java/org/elasticsearch/index/mapper/externalvalues/SimpleExternalMappingTests.java +++ b/src/test/java/org/elasticsearch/index/mapper/externalvalues/SimpleExternalMappingTests.java @@ -23,7 +23,7 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.ParsedDocument; -import org.elasticsearch.test.ElasticsearchSingleNodeLuceneTestCase; +import org.elasticsearch.test.ElasticsearchSingleNodeTest; import org.junit.Test; import static org.hamcrest.Matchers.is; @@ -31,7 +31,7 @@ import static org.hamcrest.Matchers.notNullValue; /** */ -public class SimpleExternalMappingTests extends ElasticsearchSingleNodeLuceneTestCase { +public class SimpleExternalMappingTests extends ElasticsearchSingleNodeTest { @Test public void testExternalValues() throws Exception { diff --git a/src/test/java/org/elasticsearch/index/mapper/lucene/DoubleIndexingDocTest.java b/src/test/java/org/elasticsearch/index/mapper/lucene/DoubleIndexingDocTest.java index 303ce09bfea..8bb02a0c3ae 100644 --- a/src/test/java/org/elasticsearch/index/mapper/lucene/DoubleIndexingDocTest.java +++ b/src/test/java/org/elasticsearch/index/mapper/lucene/DoubleIndexingDocTest.java @@ -28,7 +28,7 @@ import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.ParsedDocument; -import org.elasticsearch.test.ElasticsearchSingleNodeLuceneTestCase; +import org.elasticsearch.test.ElasticsearchSingleNodeTest; import org.junit.Test; import static org.hamcrest.Matchers.equalTo; @@ -36,7 +36,7 @@ import static org.hamcrest.Matchers.equalTo; /** * */ -public class DoubleIndexingDocTest extends ElasticsearchSingleNodeLuceneTestCase { +public class DoubleIndexingDocTest extends ElasticsearchSingleNodeTest { @Test public void testDoubleIndexingSameDoc() throws Exception { diff --git a/src/test/java/org/elasticsearch/index/mapper/timestamp/TimestampMappingTests.java b/src/test/java/org/elasticsearch/index/mapper/timestamp/TimestampMappingTests.java index d81168de38b..7ebd994dd2a 100644 --- a/src/test/java/org/elasticsearch/index/mapper/timestamp/TimestampMappingTests.java +++ b/src/test/java/org/elasticsearch/index/mapper/timestamp/TimestampMappingTests.java @@ -31,7 +31,6 @@ import org.elasticsearch.common.compress.CompressedString; import org.elasticsearch.common.io.stream.BytesStreamInput; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.joda.Joda; -import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContent; @@ -41,15 +40,18 @@ import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.index.mapper.*; import org.elasticsearch.index.mapper.internal.TimestampFieldMapper; import org.elasticsearch.test.ElasticsearchSingleNodeTest; -import org.elasticsearch.test.ElasticsearchTestCase; import org.junit.Test; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; +import static org.elasticsearch.Version.V_1_5_0; +import static org.elasticsearch.Version.V_2_0_0; +import static org.elasticsearch.test.VersionUtils.randomVersion; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.*; @@ -91,7 +93,7 @@ public class TimestampMappingTests extends ElasticsearchSingleNodeTest { @Test public void testDefaultValues() throws Exception { - for (Version version : Arrays.asList(Version.V_1_5_0, Version.V_2_0_0, ElasticsearchTestCase.randomVersion())) { + for (Version version : Arrays.asList(V_1_5_0, V_2_0_0, randomVersion(random()))) { for (String mapping : Arrays.asList( XContentFactory.jsonBuilder().startObject().startObject("type").endObject().string(), XContentFactory.jsonBuilder().startObject().startObject("type").startObject("_timestamp").endObject().endObject().string())) { @@ -437,7 +439,7 @@ public class TimestampMappingTests extends ElasticsearchSingleNodeTest { { MappingMetaData.Timestamp timestamp = new MappingMetaData.Timestamp(true, null, TimestampFieldMapper.DEFAULT_DATE_TIME_FORMAT, null, null); - MappingMetaData expected = new MappingMetaData("type", new CompressedString("{}".getBytes(UTF8)), + MappingMetaData expected = new MappingMetaData("type", new CompressedString("{}".getBytes(StandardCharsets.UTF_8)), new MappingMetaData.Id(null), new MappingMetaData.Routing(false, null), timestamp, false); BytesStreamOutput out = new BytesStreamOutput(); @@ -454,7 +456,7 @@ public class TimestampMappingTests extends ElasticsearchSingleNodeTest { { MappingMetaData.Timestamp timestamp = new MappingMetaData.Timestamp(true, null, TimestampFieldMapper.DEFAULT_DATE_TIME_FORMAT, "now", null); - MappingMetaData expected = new MappingMetaData("type", new CompressedString("{}".getBytes(UTF8)), + MappingMetaData expected = new MappingMetaData("type", new CompressedString("{}".getBytes(StandardCharsets.UTF_8)), new MappingMetaData.Id(null), new MappingMetaData.Routing(false, null), timestamp, false); BytesStreamOutput out = new BytesStreamOutput(); @@ -471,7 +473,7 @@ public class TimestampMappingTests extends ElasticsearchSingleNodeTest { { MappingMetaData.Timestamp timestamp = new MappingMetaData.Timestamp(true, null, TimestampFieldMapper.DEFAULT_DATE_TIME_FORMAT, "now", false); - MappingMetaData expected = new MappingMetaData("type", new CompressedString("{}".getBytes(UTF8)), + MappingMetaData expected = new MappingMetaData("type", new CompressedString("{}".getBytes(StandardCharsets.UTF_8)), new MappingMetaData.Id(null), new MappingMetaData.Routing(false, null), timestamp, false); BytesStreamOutput out = new BytesStreamOutput(); diff --git a/src/test/java/org/elasticsearch/index/mapper/update/UpdateMappingOnClusterTests.java b/src/test/java/org/elasticsearch/index/mapper/update/UpdateMappingOnClusterTests.java index 496cb58a692..890db5e3fdb 100644 --- a/src/test/java/org/elasticsearch/index/mapper/update/UpdateMappingOnClusterTests.java +++ b/src/test/java/org/elasticsearch/index/mapper/update/UpdateMappingOnClusterTests.java @@ -40,7 +40,6 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcke import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; - public class UpdateMappingOnClusterTests extends ElasticsearchIntegrationTest { private static final String INDEX = "index"; diff --git a/src/test/java/org/elasticsearch/index/merge/policy/VersionFieldUpgraderTest.java b/src/test/java/org/elasticsearch/index/merge/policy/VersionFieldUpgraderTest.java index ea51eb76509..3c66cbc3aa9 100644 --- a/src/test/java/org/elasticsearch/index/merge/policy/VersionFieldUpgraderTest.java +++ b/src/test/java/org/elasticsearch/index/merge/policy/VersionFieldUpgraderTest.java @@ -36,10 +36,10 @@ import org.apache.lucene.util.TestUtil; import org.elasticsearch.common.Numbers; import org.elasticsearch.index.mapper.internal.UidFieldMapper; import org.elasticsearch.index.mapper.internal.VersionFieldMapper; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; +import org.elasticsearch.test.ElasticsearchTestCase; /** Tests upgrading old document versions from _uid payloads to _version docvalues */ -public class VersionFieldUpgraderTest extends ElasticsearchLuceneTestCase { +public class VersionFieldUpgraderTest extends ElasticsearchTestCase { /** Simple test: one doc in the old format, check that it looks correct */ public void testUpgradeOneDocument() throws Exception { diff --git a/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java b/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java index 40969dc4ddc..aedfec5fa58 100644 --- a/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java +++ b/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.index.query; import com.google.common.collect.Lists; import com.google.common.collect.Sets; + import org.apache.lucene.analysis.core.WhitespaceAnalyzer; import org.apache.lucene.index.*; import org.apache.lucene.index.memory.MemoryIndex; diff --git a/src/test/java/org/elasticsearch/index/query/TemplateQueryParserTest.java b/src/test/java/org/elasticsearch/index/query/TemplateQueryParserTest.java index ddaecec2fa8..36611e1b43c 100644 --- a/src/test/java/org/elasticsearch/index/query/TemplateQueryParserTest.java +++ b/src/test/java/org/elasticsearch/index/query/TemplateQueryParserTest.java @@ -66,7 +66,7 @@ public class TemplateQueryParserTest extends ElasticsearchTestCase { @Before public void setup() throws IOException { Settings settings = ImmutableSettings.settingsBuilder() - .put("path.conf", this.getResourcePath("config")) + .put("path.conf", this.getDataPath("config")) .put("name", getClass().getName()) .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .build(); diff --git a/src/test/java/org/elasticsearch/index/query/TemplateQueryTest.java b/src/test/java/org/elasticsearch/index/query/TemplateQueryTest.java index 0d8b8909d21..dbc3f300b32 100644 --- a/src/test/java/org/elasticsearch/index/query/TemplateQueryTest.java +++ b/src/test/java/org/elasticsearch/index/query/TemplateQueryTest.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.query; import com.google.common.collect.Maps; + import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.indexedscripts.delete.DeleteIndexedScriptResponse; import org.elasticsearch.action.indexedscripts.get.GetIndexedScriptResponse; @@ -66,7 +67,7 @@ public class TemplateQueryTest extends ElasticsearchIntegrationTest { @Override public Settings nodeSettings(int nodeOrdinal) { return settingsBuilder().put(super.nodeSettings(nodeOrdinal)) - .put("path.conf", this.getResourcePath("config")).build(); + .put("path.conf", this.getDataPath("config")).build(); } @Test diff --git a/src/test/java/org/elasticsearch/index/search/child/AbstractChildTests.java b/src/test/java/org/elasticsearch/index/search/child/AbstractChildTests.java index d08762e481a..21bae1d20ba 100644 --- a/src/test/java/org/elasticsearch/index/search/child/AbstractChildTests.java +++ b/src/test/java/org/elasticsearch/index/search/child/AbstractChildTests.java @@ -41,7 +41,7 @@ import org.elasticsearch.index.mapper.internal.UidFieldMapper; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.search.internal.SearchContext; -import org.elasticsearch.test.ElasticsearchSingleNodeLuceneTestCase; +import org.elasticsearch.test.ElasticsearchSingleNodeTest; import org.hamcrest.Description; import org.hamcrest.StringDescription; import org.junit.After; @@ -53,21 +53,7 @@ import java.io.IOException; import static org.hamcrest.Matchers.equalTo; @Ignore -@LuceneTestCase.SuppressCodecs(value = {"Lucene40", "Lucene3x"}) -public abstract class AbstractChildTests extends ElasticsearchSingleNodeLuceneTestCase { - - // TODO: Parent/child does not work with the query cache - private static final QueryCache DEFAULT_QUERY_CACHE = IndexSearcher.getDefaultQueryCache(); - - @Before - public void disableQueryCache() { - IndexSearcher.setDefaultQueryCache(null); - } - - @After - public void restoreQueryCache() { - IndexSearcher.setDefaultQueryCache(DEFAULT_QUERY_CACHE); - } +public abstract class AbstractChildTests extends ElasticsearchSingleNodeTest { /** * The name of the field within the child type that stores a score to use in test queries. diff --git a/src/test/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQueryTests.java b/src/test/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQueryTests.java index f4ec4b7a041..259ed60ae4e 100644 --- a/src/test/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQueryTests.java +++ b/src/test/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQueryTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.index.search.child; import com.carrotsearch.hppc.IntOpenHashSet; import com.carrotsearch.hppc.ObjectObjectOpenHashMap; + import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; @@ -34,6 +35,7 @@ import org.apache.lucene.search.join.BitDocIdSetFilter; import org.apache.lucene.store.Directory; import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util.TestUtil; import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.fielddata.plain.ParentChildIndexFieldData; @@ -63,7 +65,6 @@ public class ChildrenConstantScoreQueryTests extends AbstractChildTests { @BeforeClass public static void before() throws IOException { - forceDefaultCodec(); SearchContext.setCurrent(createSearchContext("test", "parent", "child")); } diff --git a/src/test/java/org/elasticsearch/index/search/child/ChildrenQueryTests.java b/src/test/java/org/elasticsearch/index/search/child/ChildrenQueryTests.java index 0c788b6842e..d5c91ad862d 100644 --- a/src/test/java/org/elasticsearch/index/search/child/ChildrenQueryTests.java +++ b/src/test/java/org/elasticsearch/index/search/child/ChildrenQueryTests.java @@ -65,7 +65,6 @@ public class ChildrenQueryTests extends AbstractChildTests { @BeforeClass public static void before() throws IOException { - forceDefaultCodec(); SearchContext.setCurrent(createSearchContext("test", "parent", "child")); } diff --git a/src/test/java/org/elasticsearch/index/search/child/ParentConstantScoreQueryTests.java b/src/test/java/org/elasticsearch/index/search/child/ParentConstantScoreQueryTests.java index b22d9af0c20..48451930579 100644 --- a/src/test/java/org/elasticsearch/index/search/child/ParentConstantScoreQueryTests.java +++ b/src/test/java/org/elasticsearch/index/search/child/ParentConstantScoreQueryTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.index.search.child; import com.carrotsearch.hppc.IntIntOpenHashMap; import com.carrotsearch.hppc.ObjectObjectOpenHashMap; + import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; @@ -63,7 +64,6 @@ public class ParentConstantScoreQueryTests extends AbstractChildTests { @BeforeClass public static void before() throws IOException { - forceDefaultCodec(); SearchContext.setCurrent(createSearchContext("test", "parent", "child")); } diff --git a/src/test/java/org/elasticsearch/index/search/child/ParentQueryTests.java b/src/test/java/org/elasticsearch/index/search/child/ParentQueryTests.java index 1ed19f3982c..218b2a514db 100644 --- a/src/test/java/org/elasticsearch/index/search/child/ParentQueryTests.java +++ b/src/test/java/org/elasticsearch/index/search/child/ParentQueryTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.index.search.child; import com.carrotsearch.hppc.FloatArrayList; import com.carrotsearch.hppc.IntIntOpenHashMap; import com.carrotsearch.hppc.ObjectObjectOpenHashMap; + import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; @@ -61,7 +62,6 @@ public class ParentQueryTests extends AbstractChildTests { @BeforeClass public static void before() throws IOException { - forceDefaultCodec(); SearchContext.setCurrent(createSearchContext("test", "parent", "child")); } diff --git a/src/test/java/org/elasticsearch/index/search/child/TopChildrenQueryTests.java b/src/test/java/org/elasticsearch/index/search/child/TopChildrenQueryTests.java index 9c3f605c9c6..6def1d5a752 100644 --- a/src/test/java/org/elasticsearch/index/search/child/TopChildrenQueryTests.java +++ b/src/test/java/org/elasticsearch/index/search/child/TopChildrenQueryTests.java @@ -40,7 +40,6 @@ public class TopChildrenQueryTests extends AbstractChildTests { @BeforeClass public static void before() throws IOException { - forceDefaultCodec(); SearchContext.setCurrent(ChildrenConstantScoreQueryTests.createSearchContext("test", "parent", "child")); } diff --git a/src/test/java/org/elasticsearch/index/shard/ShardUtilsTests.java b/src/test/java/org/elasticsearch/index/shard/ShardUtilsTests.java index ba3459a8f9b..e2163fa89b6 100644 --- a/src/test/java/org/elasticsearch/index/shard/ShardUtilsTests.java +++ b/src/test/java/org/elasticsearch/index/shard/ShardUtilsTests.java @@ -25,11 +25,11 @@ import org.apache.lucene.index.*; import org.apache.lucene.store.BaseDirectoryWrapper; import org.apache.lucene.util.IOUtils; import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; +import org.elasticsearch.test.ElasticsearchTestCase; import java.io.IOException; -public class ShardUtilsTests extends ElasticsearchLuceneTestCase { +public class ShardUtilsTests extends ElasticsearchTestCase { public void testExtractShardId() throws IOException { BaseDirectoryWrapper dir = newDirectory(); diff --git a/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTest.java b/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTest.java index d16a9db3fda..c8d127667d3 100644 --- a/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTest.java +++ b/src/test/java/org/elasticsearch/index/snapshots/blobstore/FileInfoTest.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.snapshots.blobstore; import org.apache.lucene.util.BytesRef; +import org.apache.lucene.util.Version; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.xcontent.*; import org.elasticsearch.index.store.StoreFileMetaData; @@ -43,7 +44,7 @@ public class FileInfoTest extends ElasticsearchTestCase { for (int i = 0; i < hash.length; i++) { hash.bytes[i] = randomByte(); } - StoreFileMetaData meta = new StoreFileMetaData("foobar", randomInt(), randomAsciiOfLengthBetween(1, 10), TEST_VERSION_CURRENT, hash); + StoreFileMetaData meta = new StoreFileMetaData("foobar", randomInt(), randomAsciiOfLengthBetween(1, 10), Version.LATEST, hash); ByteSizeValue size = new ByteSizeValue(Math.max(0,Math.abs(randomLong()))); BlobStoreIndexShardSnapshot.FileInfo info = new BlobStoreIndexShardSnapshot.FileInfo("_foobar", meta, size); XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint(); @@ -62,7 +63,7 @@ public class FileInfoTest extends ElasticsearchTestCase { assertThat(info.partBytes(), equalTo(parsedInfo.partBytes())); assertThat(parsedInfo.metadata().hash().length, equalTo(hash.length)); assertThat(parsedInfo.metadata().hash(), equalTo(hash)); - assertThat(parsedInfo.metadata().writtenBy(), equalTo(TEST_VERSION_CURRENT)); + assertThat(parsedInfo.metadata().writtenBy(), equalTo(Version.LATEST)); assertThat(parsedInfo.isSame(info.metadata()), is(true)); } } diff --git a/src/test/java/org/elasticsearch/index/store/CorruptedFileTest.java b/src/test/java/org/elasticsearch/index/store/CorruptedFileTest.java index 0c793981395..429ee7ac775 100644 --- a/src/test/java/org/elasticsearch/index/store/CorruptedFileTest.java +++ b/src/test/java/org/elasticsearch/index/store/CorruptedFileTest.java @@ -23,10 +23,12 @@ import com.carrotsearch.randomizedtesting.LifecycleScope; import com.carrotsearch.randomizedtesting.generators.RandomPicks; import com.google.common.base.Charsets; import com.google.common.base.Predicate; + import org.apache.lucene.codecs.CodecUtil; import org.apache.lucene.index.CheckIndex; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.store.*; +import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; @@ -45,6 +47,7 @@ import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDeci import org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.settings.ImmutableSettings; @@ -484,7 +487,7 @@ public class CorruptedFileTest extends ElasticsearchIntegrationTest { logger.info("--> creating repository"); assertAcked(client().admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(settingsBuilder() - .put("location", newTempDirPath(LifecycleScope.SUITE).toAbsolutePath()) + .put("location", createTempDir().toAbsolutePath()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)))); logger.info("--> snapshot"); @@ -528,7 +531,7 @@ public class CorruptedFileTest extends ElasticsearchIntegrationTest { for (FsStats.Info info : nodeStatses.getNodes()[0].getFs()) { String path = info.getPath(); final String relativeDataLocationPath = "indices/test/" + Integer.toString(shardRouting.getId()) + "/index"; - Path file = Paths.get(path).resolve(relativeDataLocationPath); + Path file = PathUtils.get(path).resolve(relativeDataLocationPath); try (DirectoryStream stream = Files.newDirectoryStream(file)) { for (Path item : stream) { if (Files.isRegularFile(item) && "write.lock".equals(item.getFileName().toString()) == false) { @@ -637,7 +640,7 @@ public class CorruptedFileTest extends ElasticsearchIntegrationTest { List files = new ArrayList<>(); for (FsStats.Info info : nodeStatses.getNodes()[0].getFs()) { String path = info.getPath(); - Path file = Paths.get(path).resolve("indices/test/" + Integer.toString(routing.getId()) + "/index"); + Path file = PathUtils.get(path).resolve("indices/test/" + Integer.toString(routing.getId()) + "/index"); try (DirectoryStream stream = Files.newDirectoryStream(file)) { for (Path item : stream) { files.add(item); diff --git a/src/test/java/org/elasticsearch/index/store/CorruptedTranslogTests.java b/src/test/java/org/elasticsearch/index/store/CorruptedTranslogTests.java index 992359fbf0d..70c4bd75538 100644 --- a/src/test/java/org/elasticsearch/index/store/CorruptedTranslogTests.java +++ b/src/test/java/org/elasticsearch/index/store/CorruptedTranslogTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.index.store; import com.carrotsearch.ant.tasks.junit4.dependencies.com.google.common.collect.Lists; import com.carrotsearch.randomizedtesting.generators.RandomPicks; + import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchPhaseExecutionException; @@ -28,6 +29,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardIterator; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.shard.IndexShard; @@ -97,7 +99,7 @@ public class CorruptedTranslogTests extends ElasticsearchIntegrationTest { // Restart the single node internalCluster().fullRestart(); // node needs time to start recovery and discover the translog corruption - sleep(1000); + Thread.sleep(1000); enableTranslogFlush("test"); try { @@ -125,7 +127,7 @@ public class CorruptedTranslogTests extends ElasticsearchIntegrationTest { for (FsStats.Info info : nodeStatses.getNodes()[0].getFs()) { String path = info.getPath(); final String relativeDataLocationPath = "indices/test/" + Integer.toString(shardRouting.getId()) + "/translog"; - Path file = Paths.get(path).resolve(relativeDataLocationPath); + Path file = PathUtils.get(path).resolve(relativeDataLocationPath); logger.info("--> path: {}", file); try (DirectoryStream stream = Files.newDirectoryStream(file)) { for (Path item : stream) { diff --git a/src/test/java/org/elasticsearch/index/store/DirectoryUtilsTest.java b/src/test/java/org/elasticsearch/index/store/DirectoryUtilsTest.java index 7a9ee113a15..950de0e27a3 100644 --- a/src/test/java/org/elasticsearch/index/store/DirectoryUtilsTest.java +++ b/src/test/java/org/elasticsearch/index/store/DirectoryUtilsTest.java @@ -18,10 +18,7 @@ */ package org.elasticsearch.index.store; -import com.carrotsearch.randomizedtesting.LifecycleScope; - import org.apache.lucene.store.*; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; import org.elasticsearch.test.ElasticsearchTestCase; import org.junit.Test; @@ -32,11 +29,11 @@ import java.util.Set; import static org.hamcrest.CoreMatchers.*; -public class DirectoryUtilsTest extends ElasticsearchLuceneTestCase { +public class DirectoryUtilsTest extends ElasticsearchTestCase { @Test public void testGetLeave() throws IOException { - Path file = ElasticsearchTestCase.newTempDirPath(LifecycleScope.TEST); + Path file = createTempDir(); final int iters = scaledRandomIntBetween(10, 100); for (int i = 0; i < iters; i++) { { diff --git a/src/test/java/org/elasticsearch/index/store/DistributorInTheWildTest.java b/src/test/java/org/elasticsearch/index/store/DistributorInTheWildTest.java index 6ccc3cd8696..3f6a9242728 100644 --- a/src/test/java/org/elasticsearch/index/store/DistributorInTheWildTest.java +++ b/src/test/java/org/elasticsearch/index/store/DistributorInTheWildTest.java @@ -32,6 +32,8 @@ import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.index.store.distributor.Distributor; import org.elasticsearch.test.junit.listeners.LoggingListener; +import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter; + import org.junit.Before; import java.io.IOException; @@ -47,8 +49,13 @@ import java.util.concurrent.ExecutorService; @LuceneTestCase.SuppressCodecs({ "SimpleText", "Memory", "Direct" }) @ThreadLeakScope(ThreadLeakScope.Scope.SUITE) @ThreadLeakLingering(linger = 5000) // 5 sec lingering -@Listeners(LoggingListener.class) +@Listeners({ + ReproduceInfoPrinter.class, + LoggingListener.class +}) +@LuceneTestCase.SuppressReproduceLine @LuceneTestCase.SuppressSysoutChecks(bugUrl = "we log a lot on purpose") +@LuceneTestCase.SuppressFileSystems("ExtrasFS") // can easily create the same extra file in two subdirs public class DistributorInTheWildTest extends ThreadedIndexingAndSearchingTestCase { protected final ESLogger logger = Loggers.getLogger(getClass()); diff --git a/src/test/java/org/elasticsearch/index/store/LegacyVerificationTests.java b/src/test/java/org/elasticsearch/index/store/LegacyVerificationTests.java index 00ae1bd3c9f..f870cfa1236 100644 --- a/src/test/java/org/elasticsearch/index/store/LegacyVerificationTests.java +++ b/src/test/java/org/elasticsearch/index/store/LegacyVerificationTests.java @@ -23,13 +23,10 @@ import java.nio.charset.StandardCharsets; import java.util.zip.Adler32; import org.apache.lucene.index.CorruptIndexException; - import org.apache.lucene.store.IndexOutput; - import org.apache.lucene.store.IOContext; - import org.apache.lucene.store.Directory; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; +import org.elasticsearch.test.ElasticsearchTestCase; /** * Simple tests for LegacyVerification (old segments) @@ -37,7 +34,7 @@ import org.elasticsearch.test.ElasticsearchLuceneTestCase; * segments is not longer needed. */ @Deprecated -public class LegacyVerificationTests extends ElasticsearchLuceneTestCase { +public class LegacyVerificationTests extends ElasticsearchTestCase { public void testAdler32() throws Exception { Adler32 expected = new Adler32(); diff --git a/src/test/java/org/elasticsearch/index/store/StoreTest.java b/src/test/java/org/elasticsearch/index/store/StoreTest.java index 01dc0a098fd..bf350fa8439 100644 --- a/src/test/java/org/elasticsearch/index/store/StoreTest.java +++ b/src/test/java/org/elasticsearch/index/store/StoreTest.java @@ -42,7 +42,7 @@ import org.elasticsearch.index.store.distributor.Distributor; import org.elasticsearch.index.store.distributor.LeastUsedDistributor; import org.elasticsearch.index.store.distributor.RandomWeightedDistributor; import org.elasticsearch.test.DummyShardLock; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; +import org.elasticsearch.test.ElasticsearchTestCase; import org.hamcrest.Matchers; import org.junit.Test; @@ -57,7 +57,7 @@ import java.util.zip.Adler32; import static com.carrotsearch.randomizedtesting.RandomizedTest.*; import static org.hamcrest.Matchers.*; -public class StoreTest extends ElasticsearchLuceneTestCase { +public class StoreTest extends ElasticsearchTestCase { @Test public void testRefCount() throws IOException { @@ -237,7 +237,7 @@ public class StoreTest extends ElasticsearchLuceneTestCase { Store store = new Store(shardId, ImmutableSettings.EMPTY, directoryService, randomDistributor(directoryService), new DummyShardLock(shardId)); // set default codec - all segments need checksums final boolean usesOldCodec = randomBoolean(); - IndexWriter writer = new IndexWriter(store.directory(), newIndexWriterConfig(random(), new MockAnalyzer(random())).setCodec(usesOldCodec ? new OldSIMockingCodec() : actualDefaultCodec())); + IndexWriter writer = new IndexWriter(store.directory(), newIndexWriterConfig(random(), new MockAnalyzer(random())).setCodec(usesOldCodec ? new OldSIMockingCodec() : TestUtil.getDefaultCodec())); int docs = 1 + random().nextInt(100); for (int i = 0; i < docs; i++) { @@ -321,7 +321,7 @@ public class StoreTest extends ElasticsearchLuceneTestCase { DirectoryService directoryService = new LuceneManagedDirectoryService(random()); Store store = new Store(shardId, ImmutableSettings.EMPTY, directoryService, randomDistributor(directoryService), new DummyShardLock(shardId)); // set default codec - all segments need checksums - IndexWriter writer = new IndexWriter(store.directory(), newIndexWriterConfig(random(), new MockAnalyzer(random())).setCodec(actualDefaultCodec())); + IndexWriter writer = new IndexWriter(store.directory(), newIndexWriterConfig(random(), new MockAnalyzer(random())).setCodec(TestUtil.getDefaultCodec())); int docs = 1 + random().nextInt(100); for (int i = 0; i < docs; i++) { @@ -381,7 +381,7 @@ public class StoreTest extends ElasticsearchLuceneTestCase { DirectoryService directoryService = new LuceneManagedDirectoryService(random()); Store store = new Store(shardId, ImmutableSettings.EMPTY, directoryService, randomDistributor(directoryService), new DummyShardLock(shardId)); // this time random codec.... - IndexWriter writer = new IndexWriter(store.directory(), newIndexWriterConfig(random(), new MockAnalyzer(random())).setCodec(actualDefaultCodec())); + IndexWriter writer = new IndexWriter(store.directory(), newIndexWriterConfig(random(), new MockAnalyzer(random())).setCodec(TestUtil.getDefaultCodec())); int docs = 1 + random().nextInt(100); for (int i = 0; i < docs; i++) { @@ -769,7 +769,7 @@ public class StoreTest extends ElasticsearchLuceneTestCase { Store.MetadataSnapshot first; { Random random = new Random(seed); - IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random)).setCodec(actualDefaultCodec()); + IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random)).setCodec(TestUtil.getDefaultCodec()); iwc.setMergePolicy(NoMergePolicy.INSTANCE); iwc.setUseCompoundFile(random.nextBoolean()); iwc.setMaxThreadStates(1); @@ -800,7 +800,7 @@ public class StoreTest extends ElasticsearchLuceneTestCase { Store store; { Random random = new Random(seed); - IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random)).setCodec(actualDefaultCodec()); + IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random)).setCodec(TestUtil.getDefaultCodec()); iwc.setMergePolicy(NoMergePolicy.INSTANCE); iwc.setUseCompoundFile(random.nextBoolean()); iwc.setMaxThreadStates(1); @@ -841,7 +841,7 @@ public class StoreTest extends ElasticsearchLuceneTestCase { // lets add some deletes Random random = new Random(seed); - IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random)).setCodec(actualDefaultCodec()); + IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random)).setCodec(TestUtil.getDefaultCodec()); iwc.setMergePolicy(NoMergePolicy.INSTANCE); iwc.setUseCompoundFile(random.nextBoolean()); iwc.setMaxThreadStates(1); @@ -877,7 +877,7 @@ public class StoreTest extends ElasticsearchLuceneTestCase { assertThat(selfDiff.missing, empty()); // add a new commit - iwc = new IndexWriterConfig(new MockAnalyzer(random)).setCodec(actualDefaultCodec()); + iwc = new IndexWriterConfig(new MockAnalyzer(random)).setCodec(TestUtil.getDefaultCodec()); iwc.setMergePolicy(NoMergePolicy.INSTANCE); iwc.setUseCompoundFile(true); // force CFS - easier to test here since we know it will add 3 files iwc.setMaxThreadStates(1); @@ -909,7 +909,7 @@ public class StoreTest extends ElasticsearchLuceneTestCase { DirectoryService directoryService = new LuceneManagedDirectoryService(random()); Store store = new Store(shardId, ImmutableSettings.EMPTY, directoryService, randomDistributor(directoryService), new DummyShardLock(shardId)); // this time random codec.... - IndexWriterConfig indexWriterConfig = newIndexWriterConfig(random(), new MockAnalyzer(random())).setCodec(actualDefaultCodec()); + IndexWriterConfig indexWriterConfig = newIndexWriterConfig(random(), new MockAnalyzer(random())).setCodec(TestUtil.getDefaultCodec()); // we keep all commits and that allows us clean based on multiple snapshots indexWriterConfig.setIndexDeletionPolicy(NoDeletionPolicy.INSTANCE); IndexWriter writer = new IndexWriter(store.directory(), indexWriterConfig); diff --git a/src/test/java/org/elasticsearch/index/store/distributor/DistributorTests.java b/src/test/java/org/elasticsearch/index/store/distributor/DistributorTests.java index 028ead0b178..61cd41fe7e7 100644 --- a/src/test/java/org/elasticsearch/index/store/distributor/DistributorTests.java +++ b/src/test/java/org/elasticsearch/index/store/distributor/DistributorTests.java @@ -165,7 +165,7 @@ public class DistributorTests extends ElasticsearchTestCase { public FakeFsDirectory(String path, long usableSpace) throws IOException { - super(newTempDirPath().resolve(path), NoLockFactory.INSTANCE); + super(createTempDir().resolve(path), NoLockFactory.INSTANCE); allocationCount = 0; this.useableSpace = usableSpace; } diff --git a/src/test/java/org/elasticsearch/index/translog/AbstractSimpleTranslogTests.java b/src/test/java/org/elasticsearch/index/translog/AbstractSimpleTranslogTests.java index c1df57afdc7..8913d7a9527 100644 --- a/src/test/java/org/elasticsearch/index/translog/AbstractSimpleTranslogTests.java +++ b/src/test/java/org/elasticsearch/index/translog/AbstractSimpleTranslogTests.java @@ -55,6 +55,7 @@ import static org.hamcrest.Matchers.*; /** * */ +@LuceneTestCase.SuppressFileSystems("ExtrasFS") public abstract class AbstractSimpleTranslogTests extends ElasticsearchTestCase { protected final ShardId shardId = new ShardId(new Index("index"), 1); @@ -66,7 +67,7 @@ public abstract class AbstractSimpleTranslogTests extends ElasticsearchTestCase @Before public void setUp() throws Exception { super.setUp(); - translogDir = newTempDirPath(); + translogDir = createTempDir(); translog = create(translogDir); translog.newTranslog(1); } diff --git a/src/test/java/org/elasticsearch/index/translog/TranslogVersionTests.java b/src/test/java/org/elasticsearch/index/translog/TranslogVersionTests.java index c2c5036ecf8..ea2989ccbb2 100644 --- a/src/test/java/org/elasticsearch/index/translog/TranslogVersionTests.java +++ b/src/test/java/org/elasticsearch/index/translog/TranslogVersionTests.java @@ -37,7 +37,7 @@ public class TranslogVersionTests extends ElasticsearchTestCase { @Test public void testV0LegacyTranslogVersion() throws Exception { - Path translogFile = getResourcePath("/org/elasticsearch/index/translog/translog-v0.binary"); + Path translogFile = getDataPath("/org/elasticsearch/index/translog/translog-v0.binary"); assertThat("test file should exist", Files.exists(translogFile), equalTo(true)); TranslogStream stream = TranslogStreams.translogStreamFor(translogFile); assertThat("a version0 stream is returned", stream instanceof LegacyTranslogStream, equalTo(true)); @@ -66,11 +66,12 @@ public class TranslogVersionTests extends ElasticsearchTestCase { } catch (EOFException e) { // success } + in.close(); } @Test public void testV1ChecksummedTranslogVersion() throws Exception { - Path translogFile = getResourcePath("/org/elasticsearch/index/translog/translog-v1.binary"); + Path translogFile = getDataPath("/org/elasticsearch/index/translog/translog-v1.binary"); assertThat("test file should exist", Files.exists(translogFile), equalTo(true)); TranslogStream stream = TranslogStreams.translogStreamFor(translogFile); assertThat("a version1 stream is returned", stream instanceof ChecksummedTranslogStream, equalTo(true)); @@ -101,12 +102,13 @@ public class TranslogVersionTests extends ElasticsearchTestCase { } } assertThat("there should be 5 translog operations", opNum, equalTo(5)); + in.close(); } @Test public void testCorruptedTranslogs() throws Exception { try { - Path translogFile = getResourcePath("/org/elasticsearch/index/translog/translog-v1-corrupted-magic.binary"); + Path translogFile = getDataPath("/org/elasticsearch/index/translog/translog-v1-corrupted-magic.binary"); assertThat("test file should exist", Files.exists(translogFile), equalTo(true)); TranslogStream stream = TranslogStreams.translogStreamFor(translogFile); fail("should have thrown an exception about the header being corrupt"); @@ -116,7 +118,7 @@ public class TranslogVersionTests extends ElasticsearchTestCase { } try { - Path translogFile = getResourcePath("/org/elasticsearch/index/translog/translog-invalid-first-byte.binary"); + Path translogFile = getDataPath("/org/elasticsearch/index/translog/translog-invalid-first-byte.binary"); assertThat("test file should exist", Files.exists(translogFile), equalTo(true)); TranslogStream stream = TranslogStreams.translogStreamFor(translogFile); fail("should have thrown an exception about the header being corrupt"); @@ -126,7 +128,7 @@ public class TranslogVersionTests extends ElasticsearchTestCase { } try { - Path translogFile = getResourcePath("/org/elasticsearch/index/translog/translog-v1-corrupted-body.binary"); + Path translogFile = getDataPath("/org/elasticsearch/index/translog/translog-v1-corrupted-body.binary"); assertThat("test file should exist", Files.exists(translogFile), equalTo(true)); TranslogStream stream = TranslogStreams.translogStreamFor(translogFile); try (StreamInput in = stream.openInput(translogFile)) { @@ -149,7 +151,7 @@ public class TranslogVersionTests extends ElasticsearchTestCase { @Test public void testTruncatedTranslog() throws Exception { try { - Path translogFile = getResourcePath("/org/elasticsearch/index/translog/translog-v1-truncated.binary"); + Path translogFile = getDataPath("/org/elasticsearch/index/translog/translog-v1-truncated.binary"); assertThat("test file should exist", Files.exists(translogFile), equalTo(true)); TranslogStream stream = TranslogStreams.translogStreamFor(translogFile); try (StreamInput in = stream.openInput(translogFile)) { diff --git a/src/test/java/org/elasticsearch/indexing/IndexActionTests.java b/src/test/java/org/elasticsearch/indexing/IndexActionTests.java index be3f0c22d10..9201e1c381d 100644 --- a/src/test/java/org/elasticsearch/indexing/IndexActionTests.java +++ b/src/test/java/org/elasticsearch/indexing/IndexActionTests.java @@ -49,7 +49,7 @@ public class IndexActionTests extends ElasticsearchIntegrationTest { * This test tries to simulate load while creating an index and indexing documents * while the index is being created. */ - @Test + @Test @Slow public void testAutoGenerateIdNoDuplicates() throws Exception { int numberOfIterations = scaledRandomIntBetween(10, 50); for (int i = 0; i < numberOfIterations; i++) { diff --git a/src/test/java/org/elasticsearch/indices/IndicesCustomDataPathTests.java b/src/test/java/org/elasticsearch/indices/IndicesCustomDataPathTests.java index 1f235bb38b0..628913dcefa 100644 --- a/src/test/java/org/elasticsearch/indices/IndicesCustomDataPathTests.java +++ b/src/test/java/org/elasticsearch/indices/IndicesCustomDataPathTests.java @@ -20,9 +20,11 @@ package org.elasticsearch.indices; import org.apache.lucene.util.IOUtils; +import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.junit.annotations.TestLogging; @@ -48,19 +50,19 @@ public class IndicesCustomDataPathTests extends ElasticsearchIntegrationTest { @Before public void setup() { - path = newTempDirPath().toAbsolutePath().toString(); + path = createTempDir().toAbsolutePath().toString(); } @After public void teardown() throws Exception { - IOUtils.deleteFilesIgnoringExceptions(Paths.get(path)); + IOUtils.deleteFilesIgnoringExceptions(PathUtils.get(path)); } @Test @TestLogging("_root:DEBUG,index:TRACE") public void testDataPathCanBeChanged() throws Exception { final String INDEX = "idx"; - Path root = newTempDirPath(); + Path root = createTempDir(); Path startDir = root.resolve("start"); Path endDir = root.resolve("end"); logger.info("--> start dir: [{}]", startDir.toAbsolutePath().toString()); diff --git a/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationTests.java b/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationTests.java index e036b933334..d5798aa94f1 100644 --- a/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationTests.java +++ b/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationTests.java @@ -329,7 +329,7 @@ public class IndicesOptionsIntegrationTests extends ElasticsearchIntegrationTest waitForRelocation(); PutRepositoryResponse putRepositoryResponse = client().admin().cluster().preparePutRepository("dummy-repo") - .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", newTempDir())).get(); + .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", createTempDir())).get(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); client().admin().cluster().prepareCreateSnapshot("dummy-repo", "snap1").setWaitForCompletion(true).get(); @@ -486,7 +486,7 @@ public class IndicesOptionsIntegrationTests extends ElasticsearchIntegrationTest waitForRelocation(); PutRepositoryResponse putRepositoryResponse = client().admin().cluster().preparePutRepository("dummy-repo") - .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", newTempDir())).get(); + .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", createTempDir())).get(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); client().admin().cluster().prepareCreateSnapshot("dummy-repo", "snap1").setWaitForCompletion(true).get(); diff --git a/src/test/java/org/elasticsearch/indices/analysis/PreBuiltAnalyzerIntegrationTests.java b/src/test/java/org/elasticsearch/indices/analysis/PreBuiltAnalyzerIntegrationTests.java index c3360dcd2b6..72e91a75556 100644 --- a/src/test/java/org/elasticsearch/indices/analysis/PreBuiltAnalyzerIntegrationTests.java +++ b/src/test/java/org/elasticsearch/indices/analysis/PreBuiltAnalyzerIntegrationTests.java @@ -26,8 +26,8 @@ import org.elasticsearch.Version; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.test.ElasticsearchBackwardsCompatIntegrationTest; import org.elasticsearch.test.ElasticsearchIntegrationTest; -import org.elasticsearch.test.ElasticsearchTestCase; import org.junit.Test; import java.lang.reflect.Field; @@ -36,11 +36,12 @@ import java.util.Locale; import java.util.Map; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.elasticsearch.test.VersionUtils.randomVersion; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; @ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.SUITE) -@ElasticsearchTestCase.CompatibilityVersion(version = Version.V_1_2_0_ID) // we throw an exception if we create an index with _field_names that is 1.3 +@ElasticsearchBackwardsCompatIntegrationTest.CompatibilityVersion(version = Version.V_1_2_0_ID) // we throw an exception if we create an index with _field_names that is 1.3 public class PreBuiltAnalyzerIntegrationTests extends ElasticsearchIntegrationTest { @Override @@ -64,7 +65,7 @@ public class PreBuiltAnalyzerIntegrationTests extends ElasticsearchIntegrationTe PreBuiltAnalyzers preBuiltAnalyzer = PreBuiltAnalyzers.values()[randomInt]; String name = preBuiltAnalyzer.name().toLowerCase(Locale.ROOT); - Version randomVersion = randomVersion(); + Version randomVersion = randomVersion(random()); if (!loadedAnalyzers.containsKey(preBuiltAnalyzer)) { loadedAnalyzers.put(preBuiltAnalyzer, Lists.newArrayList()); } @@ -138,7 +139,7 @@ public class PreBuiltAnalyzerIntegrationTests extends ElasticsearchIntegrationTe .endObject() .endObject(); - Settings versionSettings = settings(randomVersion()) + Settings versionSettings = settings(randomVersion(random())) .put("index.analysis.analyzer.my_dummy.type", "custom") .put("index.analysis.analyzer.my_dummy.filter", "my_dummy_token_filter") .put("index.analysis.analyzer.my_dummy.char_filter", "my_dummy_char_filter") diff --git a/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java b/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java index cbaef97c5d0..304940e8141 100644 --- a/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java +++ b/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java @@ -45,7 +45,7 @@ public class HunspellServiceTests extends ElasticsearchIntegrationTest { @Test public void testLocaleDirectoryWithNodeLevelConfig() throws Exception { Settings settings = ImmutableSettings.settingsBuilder() - .put("path.conf", getResourcePath("/indices/analyze/conf_dir")) + .put("path.conf", getDataPath("/indices/analyze/conf_dir")) .put(HUNSPELL_LAZY_LOAD, randomBoolean()) .put(HUNSPELL_IGNORE_CASE, true) .build(); @@ -59,7 +59,7 @@ public class HunspellServiceTests extends ElasticsearchIntegrationTest { @Test public void testLocaleDirectoryWithLocaleSpecificConfig() throws Exception { Settings settings = ImmutableSettings.settingsBuilder() - .put("path.conf", getResourcePath("/indices/analyze/conf_dir")) + .put("path.conf", getDataPath("/indices/analyze/conf_dir")) .put(HUNSPELL_LAZY_LOAD, randomBoolean()) .put(HUNSPELL_IGNORE_CASE, true) .put("indices.analysis.hunspell.dictionary.en_US.strict_affix_parsing", false) @@ -82,7 +82,7 @@ public class HunspellServiceTests extends ElasticsearchIntegrationTest { @Test public void testCustomizeLocaleDirectory() throws Exception { Settings settings = ImmutableSettings.settingsBuilder() - .put(HUNSPELL_LOCATION, getResourcePath("/indices/analyze/conf_dir/hunspell")) + .put(HUNSPELL_LOCATION, getDataPath("/indices/analyze/conf_dir/hunspell")) .build(); internalCluster().startNode(settings); @@ -93,7 +93,7 @@ public class HunspellServiceTests extends ElasticsearchIntegrationTest { @Test public void testDicWithNoAff() throws Exception { Settings settings = ImmutableSettings.settingsBuilder() - .put("path.conf", getResourcePath("/indices/analyze/no_aff_conf_dir")) + .put("path.conf", getDataPath("/indices/analyze/no_aff_conf_dir")) .put(HUNSPELL_LAZY_LOAD, randomBoolean()) .build(); @@ -112,7 +112,7 @@ public class HunspellServiceTests extends ElasticsearchIntegrationTest { @Test public void testDicWithTwoAffs() throws Exception { Settings settings = ImmutableSettings.settingsBuilder() - .put("path.conf", getResourcePath("/indices/analyze/two_aff_conf_dir")) + .put("path.conf", getDataPath("/indices/analyze/two_aff_conf_dir")) .put(HUNSPELL_LAZY_LOAD, randomBoolean()) .build(); diff --git a/src/test/java/org/elasticsearch/indices/mapping/ConcurrentDynamicTemplateTests.java b/src/test/java/org/elasticsearch/indices/mapping/ConcurrentDynamicTemplateTests.java index 118aa9478e6..70ac71c132b 100644 --- a/src/test/java/org/elasticsearch/indices/mapping/ConcurrentDynamicTemplateTests.java +++ b/src/test/java/org/elasticsearch/indices/mapping/ConcurrentDynamicTemplateTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.indices.mapping; import com.google.common.collect.Sets; + import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.index.IndexResponse; diff --git a/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingTests.java b/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingTests.java index 20be0605c02..d225c936121 100644 --- a/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingTests.java +++ b/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.indices.mapping; import com.google.common.collect.Lists; + import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; diff --git a/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryTests.java b/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryTests.java index c7b0245fce1..113ac6d80b7 100644 --- a/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryTests.java +++ b/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryTests.java @@ -427,7 +427,7 @@ public class IndexRecoveryTests extends ElasticsearchIntegrationTest { logger.info("--> create repository"); assertAcked(client().admin().cluster().preparePutRepository(REPO_NAME) .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDir(LifecycleScope.SUITE)) + .put("location", createTempDir()) .put("compress", false) ).get()); diff --git a/src/test/java/org/elasticsearch/indices/recovery/RecoveryStateTest.java b/src/test/java/org/elasticsearch/indices/recovery/RecoveryStateTest.java index bd8b51b276d..e1b5c04368b 100644 --- a/src/test/java/org/elasticsearch/indices/recovery/RecoveryStateTest.java +++ b/src/test/java/org/elasticsearch/indices/recovery/RecoveryStateTest.java @@ -39,6 +39,7 @@ import java.util.Collections; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import static org.elasticsearch.test.VersionUtils.randomVersion; import static org.hamcrest.Matchers.*; public class RecoveryStateTest extends ElasticsearchTestCase { @@ -52,7 +53,7 @@ public class RecoveryStateTest extends ElasticsearchTestCase { final Version streamVersion; Streamer(AtomicBoolean shouldStop, T source) { - this(shouldStop, source, randomVersion()); + this(shouldStop, source, randomVersion(random())); } Streamer(AtomicBoolean shouldStop, T source, Version streamVersion) { diff --git a/src/test/java/org/elasticsearch/indices/recovery/StartRecoveryRequestTest.java b/src/test/java/org/elasticsearch/indices/recovery/StartRecoveryRequestTest.java index 9b5ec3d863f..c15d1d8b552 100644 --- a/src/test/java/org/elasticsearch/indices/recovery/StartRecoveryRequestTest.java +++ b/src/test/java/org/elasticsearch/indices/recovery/StartRecoveryRequestTest.java @@ -33,6 +33,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.Collections; +import static org.elasticsearch.test.VersionUtils.randomVersion; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.nullValue; @@ -42,7 +43,7 @@ public class StartRecoveryRequestTest extends ElasticsearchTestCase { @Test public void testSerialization() throws Exception { - Version targetNodeVersion = randomVersion(); + Version targetNodeVersion = randomVersion(random()); StartRecoveryRequest outRequest = new StartRecoveryRequest( new ShardId("test", 0), new DiscoveryNode("a", new LocalTransportAddress("1"), targetNodeVersion), diff --git a/src/test/java/org/elasticsearch/indices/stats/IndexStatsTests.java b/src/test/java/org/elasticsearch/indices/stats/IndexStatsTests.java index 9dd277cdd27..cd43c297dc6 100644 --- a/src/test/java/org/elasticsearch/indices/stats/IndexStatsTests.java +++ b/src/test/java/org/elasticsearch/indices/stats/IndexStatsTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.indices.stats; import org.apache.lucene.util.Version; +import org.apache.lucene.util.LuceneTestCase.SuppressCodecs; import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; import org.elasticsearch.action.admin.indices.stats.*; import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags.Flag; @@ -60,6 +61,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcke import static org.hamcrest.Matchers.*; @ClusterScope(scope = Scope.SUITE, numDataNodes = 2, numClientNodes = 0, randomDynamicTemplates = false) +@SuppressCodecs("*") // requires custom completion format public class IndexStatsTests extends ElasticsearchIntegrationTest { @Override @@ -540,7 +542,7 @@ public class IndexStatsTests extends ElasticsearchIntegrationTest { assertThat(stats.getTotal().getSegments(), notNullValue()); assertThat(stats.getTotal().getSegments().getCount(), equalTo((long) test1.totalNumShards)); - assumeTrue(org.elasticsearch.Version.CURRENT.luceneVersion != Version.LUCENE_4_6_0); + assumeTrue("test doesn't work with 4.6.0", org.elasticsearch.Version.CURRENT.luceneVersion != Version.LUCENE_4_6_0); assertThat(stats.getTotal().getSegments().getMemoryInBytes(), greaterThan(0l)); } diff --git a/src/test/java/org/elasticsearch/indices/store/IndicesStoreIntegrationTests.java b/src/test/java/org/elasticsearch/indices/store/IndicesStoreIntegrationTests.java index 978f85f4a0a..b74eaf59d01 100644 --- a/src/test/java/org/elasticsearch/indices/store/IndicesStoreIntegrationTests.java +++ b/src/test/java/org/elasticsearch/indices/store/IndicesStoreIntegrationTests.java @@ -20,7 +20,6 @@ package org.elasticsearch.indices.store; import com.google.common.base.Predicate; -import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; import org.elasticsearch.cluster.ClusterService; @@ -176,7 +175,7 @@ public class IndicesStoreIntegrationTests extends ElasticsearchIntegrationTest { assertThat(waitForShardDeletion(node_4, "test", 0), equalTo(false)); } - @Test + @Test @Slow public void testShardActiveElseWhere() throws Exception { boolean node1IsMasterEligible = randomBoolean(); boolean node2IsMasterEligible = !node1IsMasterEligible || randomBoolean(); diff --git a/src/test/java/org/elasticsearch/indices/store/IndicesStoreTests.java b/src/test/java/org/elasticsearch/indices/store/IndicesStoreTests.java index 0949033df1a..eadee06e2e2 100644 --- a/src/test/java/org/elasticsearch/indices/store/IndicesStoreTests.java +++ b/src/test/java/org/elasticsearch/indices/store/IndicesStoreTests.java @@ -39,6 +39,8 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Set; +import static org.elasticsearch.Version.CURRENT; +import static org.elasticsearch.test.VersionUtils.randomVersion; import static org.hamcrest.Matchers.is; /** @@ -149,7 +151,7 @@ public class IndicesStoreTests extends ElasticsearchTestCase { int numReplicas = randomInt(2); // Most of the times don't test bwc and use current version - final Version nodeVersion = randomBoolean() ? Version.CURRENT : randomVersion(); + final Version nodeVersion = randomBoolean() ? CURRENT : randomVersion(random()); ClusterState.Builder clusterState = ClusterState.builder(new ClusterName("test")); clusterState.metaData(MetaData.builder().put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(numShards).numberOfReplicas(numReplicas))); clusterState.nodes(DiscoveryNodes.builder().localNodeId(localNode.id()).put(localNode).put(new DiscoveryNode("xyz", new LocalTransportAddress("xyz"), nodeVersion))); @@ -172,7 +174,7 @@ public class IndicesStoreTests extends ElasticsearchTestCase { ClusterState.Builder clusterState = ClusterState.builder(new ClusterName("test")); clusterState.metaData(MetaData.builder().put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(numShards).numberOfReplicas(numReplicas))); - final Version nodeVersion = randomBoolean() ? Version.CURRENT : randomVersion(); + final Version nodeVersion = randomBoolean() ? CURRENT : randomVersion(random()); clusterState.nodes(DiscoveryNodes.builder().localNodeId(localNode.id()) .put(localNode) diff --git a/src/test/java/org/elasticsearch/indices/template/IndexTemplateFileLoadingTests.java b/src/test/java/org/elasticsearch/indices/template/IndexTemplateFileLoadingTests.java index baceb45b401..86b8c3e8d1e 100644 --- a/src/test/java/org/elasticsearch/indices/template/IndexTemplateFileLoadingTests.java +++ b/src/test/java/org/elasticsearch/indices/template/IndexTemplateFileLoadingTests.java @@ -49,7 +49,7 @@ public class IndexTemplateFileLoadingTests extends ElasticsearchIntegrationTest settingsBuilder.put(super.nodeSettings(nodeOrdinal)); try { - Path directory = newTempDirPath(LifecycleScope.SUITE); + Path directory = createTempDir(); settingsBuilder.put("path.conf", directory.toAbsolutePath()); Path templatesDir = directory.resolve("templates"); diff --git a/src/test/java/org/elasticsearch/mlt/MoreLikeThisActionTests.java b/src/test/java/org/elasticsearch/mlt/MoreLikeThisActionTests.java index 312ba8c9d93..1530a35f713 100644 --- a/src/test/java/org/elasticsearch/mlt/MoreLikeThisActionTests.java +++ b/src/test/java/org/elasticsearch/mlt/MoreLikeThisActionTests.java @@ -213,10 +213,11 @@ public class MoreLikeThisActionTests extends ElasticsearchIntegrationTest { @Test // See issue https://github.com/elasticsearch/elasticsearch/issues/3252 public void testNumericField() throws Exception { + final String[] numericTypes = new String[]{"byte", "short", "integer", "long"}; prepareCreate("test").addMapping("type", jsonBuilder() .startObject().startObject("type") .startObject("properties") - .startObject("int_value").field("type", randomNumericType(getRandom())).endObject() + .startObject("int_value").field("type", randomFrom(numericTypes)).endObject() .startObject("string_value").field("type", "string").endObject() .endObject() .endObject().endObject()).execute().actionGet(); @@ -578,7 +579,7 @@ public class MoreLikeThisActionTests extends ElasticsearchIntegrationTest { logger.info("Indexing a single document ..."); XContentBuilder doc = jsonBuilder().startObject(); for (int i = 0; i < numFields; i++) { - doc.field("field"+i, generateRandomStringArray(5, 10)); + doc.field("field"+i, generateRandomStringArray(5, 10, false)); } doc.endObject(); indexRandom(true, client().prepareIndex("test", "type1", "0").setSource(doc)); diff --git a/src/test/java/org/elasticsearch/mlt/XMoreLikeThisTests.java b/src/test/java/org/elasticsearch/mlt/XMoreLikeThisTests.java index f7d2bfa381a..aaf2105b494 100644 --- a/src/test/java/org/elasticsearch/mlt/XMoreLikeThisTests.java +++ b/src/test/java/org/elasticsearch/mlt/XMoreLikeThisTests.java @@ -31,7 +31,7 @@ import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.TermQuery; import org.apache.lucene.store.Directory; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; +import org.elasticsearch.test.ElasticsearchTestCase; import org.junit.Test; import java.io.IOException; @@ -39,7 +39,7 @@ import java.io.StringReader; import java.util.Arrays; import java.util.List; -public class XMoreLikeThisTests extends ElasticsearchLuceneTestCase { +public class XMoreLikeThisTests extends ElasticsearchTestCase { private void addDoc(RandomIndexWriter writer, String[] texts) throws IOException { Document doc = new Document(); diff --git a/src/test/java/org/elasticsearch/nested/SimpleNestedTests.java b/src/test/java/org/elasticsearch/nested/SimpleNestedTests.java index 5eab6aad5e5..f7a254389e8 100644 --- a/src/test/java/org/elasticsearch/nested/SimpleNestedTests.java +++ b/src/test/java/org/elasticsearch/nested/SimpleNestedTests.java @@ -164,7 +164,7 @@ public class SimpleNestedTests extends ElasticsearchIntegrationTest { assertThat(searchResponse.getHits().totalHits(), equalTo(1l)); } - @Test + @Test @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/10661") public void simpleNestedMatchQueries() throws Exception { XContentBuilder builder = jsonBuilder().startObject() .startObject("type1") diff --git a/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoTests.java b/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoTests.java index bc4433b299a..9e29ef957bb 100644 --- a/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoTests.java +++ b/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoTests.java @@ -25,10 +25,12 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.action.admin.cluster.node.info.PluginInfo; import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.nodesinfo.plugin.dummy1.TestPlugin; import org.elasticsearch.nodesinfo.plugin.dummy2.TestNoVersionPlugin; +import org.elasticsearch.plugins.PluginTestCase; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope; import org.elasticsearch.test.hamcrest.ElasticsearchAssertions; @@ -50,7 +52,7 @@ import static org.hamcrest.Matchers.*; * */ @ClusterScope(scope= Scope.TEST, numDataNodes =0) -public class SimpleNodesInfoTests extends ElasticsearchIntegrationTest { +public class SimpleNodesInfoTests extends PluginTestCase { static final class Fields { static final String SITE_PLUGIN = "dummy"; @@ -153,29 +155,11 @@ public class SimpleNodesInfoTests extends ElasticsearchIntegrationTest { Lists.newArrayList(PluginInfo.VERSION_NOT_AVAILABLE)); } - public static String startNodeWithPlugins(int nodeId, String ... pluginClassNames) throws URISyntaxException { + public String startNodeWithPlugins(int nodeId, String ... pluginClassNames) throws URISyntaxException { return startNodeWithPlugins(ImmutableSettings.EMPTY, "/org/elasticsearch/nodesinfo/node" + Integer.toString(nodeId) + "/", pluginClassNames); } - public static String startNodeWithPlugins(Settings nodeSettings, String pluginDir, String ... pluginClassNames) throws URISyntaxException { - URL resource = SimpleNodesInfoTests.class.getResource(pluginDir); - ImmutableSettings.Builder settings = settingsBuilder(); - settings.put(nodeSettings); - if (resource != null) { - settings.put("path.plugins", Paths.get(resource.toURI()).toAbsolutePath()); - } - if (pluginClassNames.length > 0) { - settings.putArray("plugin.types", pluginClassNames); - } - - String nodeName = internalCluster().startNode(settings); - - // We wait for a Green status - client().admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet(); - - return internalCluster().getInstance(ClusterService.class, nodeName).state().nodes().localNodeId(); - } } diff --git a/src/test/java/org/elasticsearch/percolator/PercolatorTests.java b/src/test/java/org/elasticsearch/percolator/PercolatorTests.java index 19a0b8a98e2..01c0eab4dee 100644 --- a/src/test/java/org/elasticsearch/percolator/PercolatorTests.java +++ b/src/test/java/org/elasticsearch/percolator/PercolatorTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.percolator; import com.google.common.base.Predicate; + import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; diff --git a/src/test/java/org/elasticsearch/percolator/TTLPercolatorTests.java b/src/test/java/org/elasticsearch/percolator/TTLPercolatorTests.java index b142dc7ba31..2cfd711787f 100644 --- a/src/test/java/org/elasticsearch/percolator/TTLPercolatorTests.java +++ b/src/test/java/org/elasticsearch/percolator/TTLPercolatorTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.percolator; import com.google.common.base.Predicate; + import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.percolate.PercolateResponse; diff --git a/src/test/java/org/elasticsearch/plugins/PluginLuceneCheckerTests.java b/src/test/java/org/elasticsearch/plugins/PluginLuceneCheckerTests.java index ac138953f68..b7c37f1c83a 100644 --- a/src/test/java/org/elasticsearch/plugins/PluginLuceneCheckerTests.java +++ b/src/test/java/org/elasticsearch/plugins/PluginLuceneCheckerTests.java @@ -36,7 +36,7 @@ import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilde * */ @ClusterScope(scope= ElasticsearchIntegrationTest.Scope.TEST, numDataNodes=0, transportClientRatio = 0) -public class PluginLuceneCheckerTests extends ElasticsearchIntegrationTest { +public class PluginLuceneCheckerTests extends PluginTestCase { /** * We check that no Lucene version checking is done @@ -44,7 +44,7 @@ public class PluginLuceneCheckerTests extends ElasticsearchIntegrationTest { */ @Test public void testDisableLuceneVersionCheckingPlugin() throws URISyntaxException { - String serverNodeId = SimpleNodesInfoTests.startNodeWithPlugins( + String serverNodeId = startNodeWithPlugins( settingsBuilder().put(PluginsService.PLUGINS_CHECK_LUCENE_KEY, false) .put(PluginsService.ES_PLUGIN_PROPERTIES_FILE_KEY, "es-plugin-test.properties") .put(PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, true).build(), @@ -69,7 +69,7 @@ public class PluginLuceneCheckerTests extends ElasticsearchIntegrationTest { */ @Test public void testEnableLuceneVersionCheckingPlugin() throws URISyntaxException { - String serverNodeId = SimpleNodesInfoTests.startNodeWithPlugins( + String serverNodeId = startNodeWithPlugins( settingsBuilder().put(PluginsService.PLUGINS_CHECK_LUCENE_KEY, true) .put(PluginsService.ES_PLUGIN_PROPERTIES_FILE_KEY, "es-plugin-test.properties") .put(PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, true).build(), diff --git a/src/test/java/org/elasticsearch/plugins/PluginManagerTests.java b/src/test/java/org/elasticsearch/plugins/PluginManagerTests.java index 7638bd4530a..2489fec6b3a 100644 --- a/src/test/java/org/elasticsearch/plugins/PluginManagerTests.java +++ b/src/test/java/org/elasticsearch/plugins/PluginManagerTests.java @@ -21,12 +21,14 @@ package org.elasticsearch.plugins; import com.google.common.base.Predicate; import org.apache.http.impl.client.HttpClients; import org.apache.lucene.util.IOUtils; +import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchIllegalArgumentException; import org.elasticsearch.ElasticsearchTimeoutException; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.action.admin.cluster.node.info.PluginInfo; import org.elasticsearch.common.collect.Tuple; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -61,6 +63,9 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; @ClusterScope(scope = Scope.TEST, numDataNodes = 0, transportClientRatio = 0.0) +@LuceneTestCase.SuppressFileSystems("*") // TODO: clean up this test to allow extra files +// TODO: jimfs is really broken here (throws wrong exception from detection method). +// if its in your classpath, then do not use plugins!!!!!! public class PluginManagerTests extends ElasticsearchIntegrationTest { @Test(expected = ElasticsearchIllegalArgumentException.class) @@ -282,7 +287,7 @@ public class PluginManagerTests extends ElasticsearchIntegrationTest { Settings settings = ImmutableSettings.settingsBuilder() .put("discovery.zen.ping.multicast.enabled", false) .put("http.enabled", true) - .put("path.home", newTempDirPath()).build(); + .put("path.home", createTempDir()).build(); return InternalSettingsPreparer.prepareSettings(settings, false); } @@ -417,7 +422,7 @@ public class PluginManagerTests extends ElasticsearchIntegrationTest { @Test @Network public void testInstallPluginWithElasticsearchDownloadService() throws IOException { - assumeTrue(isDownloadServiceWorking("download.elasticsearch.org", 80, "/elasticsearch/ci-test.txt")); + assumeTrue("download.elasticsearch.org is accessible", isDownloadServiceWorking("download.elasticsearch.org", 80, "/elasticsearch/ci-test.txt")); singlePluginInstallAndRemove("elasticsearch/elasticsearch-transport-thrift/2.4.0", null); } @@ -430,8 +435,8 @@ public class PluginManagerTests extends ElasticsearchIntegrationTest { @Test @Network public void testInstallPluginWithMavenCentral() throws IOException { - assumeTrue(isDownloadServiceWorking("search.maven.org", 80, "/")); - assumeTrue(isDownloadServiceWorking("repo1.maven.org", 443, "/maven2/org/elasticsearch/elasticsearch-transport-thrift/2.4.0/elasticsearch-transport-thrift-2.4.0.pom")); + assumeTrue("search.maven.org is accessible", isDownloadServiceWorking("search.maven.org", 80, "/")); + assumeTrue("repo1.maven.org is accessible", isDownloadServiceWorking("repo1.maven.org", 443, "/maven2/org/elasticsearch/elasticsearch-transport-thrift/2.4.0/elasticsearch-transport-thrift-2.4.0.pom")); singlePluginInstallAndRemove("org.elasticsearch/elasticsearch-transport-thrift/2.4.0", null); } @@ -444,7 +449,7 @@ public class PluginManagerTests extends ElasticsearchIntegrationTest { @Test @Network public void testInstallPluginWithGithub() throws IOException { - assumeTrue(isDownloadServiceWorking("github.com", 443, "/")); + assumeTrue("github.com is accessible", isDownloadServiceWorking("github.com", 443, "/")); singlePluginInstallAndRemove("elasticsearch/kibana", null); } diff --git a/src/test/java/org/elasticsearch/plugins/PluginManagerUnitTests.java b/src/test/java/org/elasticsearch/plugins/PluginManagerUnitTests.java index 97024b48913..4208075ccf7 100644 --- a/src/test/java/org/elasticsearch/plugins/PluginManagerUnitTests.java +++ b/src/test/java/org/elasticsearch/plugins/PluginManagerUnitTests.java @@ -40,8 +40,8 @@ public class PluginManagerUnitTests extends ElasticsearchTestCase { @Test public void testThatConfigDirectoryCanBeOutsideOfElasticsearchHomeDirectory() throws IOException { String pluginName = randomAsciiOfLength(10); - Path homeFolder = newTempDirPath(); - Path genericConfigFolder = newTempDirPath(); + Path homeFolder = createTempDir(); + Path genericConfigFolder = createTempDir(); Settings settings = settingsBuilder() .put("path.conf", genericConfigFolder) diff --git a/src/test/java/org/elasticsearch/plugins/PluginServiceTests.java b/src/test/java/org/elasticsearch/plugins/PluginServiceTests.java index 00ffaf73c2c..5527f2d4698 100644 --- a/src/test/java/org/elasticsearch/plugins/PluginServiceTests.java +++ b/src/test/java/org/elasticsearch/plugins/PluginServiceTests.java @@ -20,8 +20,10 @@ package org.elasticsearch.plugins; import com.google.common.collect.ImmutableList; + import org.elasticsearch.action.admin.cluster.node.info.PluginInfo; import org.elasticsearch.common.collect.Tuple; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.nodesinfo.SimpleNodesInfoTests; import org.elasticsearch.plugins.loading.classpath.InClassPathPlugin; @@ -31,6 +33,7 @@ import org.junit.Test; import java.net.URISyntaxException; import java.nio.file.Path; +import java.nio.file.PathMatcher; import java.nio.file.Paths; import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; @@ -38,7 +41,7 @@ import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.instanceOf; @ClusterScope(scope= ElasticsearchIntegrationTest.Scope.TEST, numDataNodes=0, numClientNodes = 1, transportClientRatio = 0) -public class PluginServiceTests extends ElasticsearchIntegrationTest { +public class PluginServiceTests extends PluginTestCase { @Test public void testPluginLoadingFromClassName() throws URISyntaxException { @@ -50,7 +53,7 @@ public class PluginServiceTests extends ElasticsearchIntegrationTest { .put("plugin.types", InSettingsPlugin.class.getName()) .build(); - SimpleNodesInfoTests.startNodeWithPlugins(settings, "/org/elasticsearch/plugins/loading/"); + startNodeWithPlugins(settings, "/org/elasticsearch/plugins/loading/"); Plugin plugin = getPlugin("in-settings-plugin"); assertNotNull("InSettingsPlugin (defined below in this class) must be loaded", plugin); @@ -71,17 +74,19 @@ public class PluginServiceTests extends ElasticsearchIntegrationTest { @Test public void testHasLibExtension() { - Path p = Paths.get("path", "to", "plugin.jar"); - assertTrue(PluginsService.hasLibExtension(p)); + PathMatcher matcher = PathUtils.getDefaultFileSystem().getPathMatcher(PluginsService.PLUGIN_LIB_PATTERN); - p = Paths.get("path", "to", "plugin.zip"); - assertTrue(PluginsService.hasLibExtension(p)); + Path p = PathUtils.get("path", "to", "plugin.jar"); + assertTrue(matcher.matches(p)); - p = Paths.get("path", "to", "plugin.tar.gz"); - assertFalse(PluginsService.hasLibExtension(p)); + p = PathUtils.get("path", "to", "plugin.zip"); + assertTrue(matcher.matches(p)); - p = Paths.get("path", "to", "plugin"); - assertFalse(PluginsService.hasLibExtension(p)); + p = PathUtils.get("path", "to", "plugin.tar.gz"); + assertFalse(matcher.matches(p)); + + p = PathUtils.get("path", "to", "plugin"); + assertFalse(matcher.matches(p)); } private Plugin getPlugin(String pluginName) { diff --git a/src/test/java/org/elasticsearch/plugins/PluginTestCase.java b/src/test/java/org/elasticsearch/plugins/PluginTestCase.java new file mode 100644 index 00000000000..1b0668120da --- /dev/null +++ b/src/test/java/org/elasticsearch/plugins/PluginTestCase.java @@ -0,0 +1,59 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.plugins; + +import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.test.ElasticsearchIntegrationTest; +import org.junit.Ignore; + +import java.net.URISyntaxException; +import java.net.URL; + +import static org.elasticsearch.client.Requests.clusterHealthRequest; +import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; + +/** + * Base class that lets you start a node with plugins. + */ +@Ignore +public abstract class PluginTestCase extends ElasticsearchIntegrationTest { + + public String startNodeWithPlugins(Settings nodeSettings, String pluginDir, String ... pluginClassNames) throws URISyntaxException { + URL resource = getClass().getResource(pluginDir); + ImmutableSettings.Builder settings = settingsBuilder(); + settings.put(nodeSettings); + if (resource != null) { + settings.put("path.plugins", getDataPath(pluginDir).toAbsolutePath()); + } + + if (pluginClassNames.length > 0) { + settings.putArray("plugin.types", pluginClassNames); + } + + String nodeName = internalCluster().startNode(settings); + + // We wait for a Green status + client().admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet(); + + return internalCluster().getInstance(ClusterService.class, nodeName).state().nodes().localNodeId(); + } +} diff --git a/src/test/java/org/elasticsearch/plugins/SitePluginTests.java b/src/test/java/org/elasticsearch/plugins/SitePluginTests.java index 83e0e46695d..7889ec9ead9 100644 --- a/src/test/java/org/elasticsearch/plugins/SitePluginTests.java +++ b/src/test/java/org/elasticsearch/plugins/SitePluginTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.plugins; import org.apache.http.client.config.RequestConfig; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.http.HttpServerTransport; import org.elasticsearch.rest.RestStatus; @@ -48,16 +49,12 @@ public class SitePluginTests extends ElasticsearchIntegrationTest { @Override protected Settings nodeSettings(int nodeOrdinal) { - try { - Path pluginDir = Paths.get(SitePluginTests.class.getResource("/org/elasticsearch/plugins").toURI()); - return settingsBuilder() - .put(super.nodeSettings(nodeOrdinal)) - .put("path.plugins", pluginDir.toAbsolutePath()) - .put("force.http.enabled", true) - .build(); - } catch (URISyntaxException ex) { - throw new RuntimeException(ex); - } + Path pluginDir = getDataPath("/org/elasticsearch/plugins"); + return settingsBuilder() + .put(super.nodeSettings(nodeOrdinal)) + .put("path.plugins", pluginDir.toAbsolutePath()) + .put("force.http.enabled", true) + .build(); } public HttpRequestBuilder httpClient() { diff --git a/src/test/java/org/elasticsearch/recovery/RelocationTests.java b/src/test/java/org/elasticsearch/recovery/RelocationTests.java index 299c61108b7..7ccd1387d93 100644 --- a/src/test/java/org/elasticsearch/recovery/RelocationTests.java +++ b/src/test/java/org/elasticsearch/recovery/RelocationTests.java @@ -446,6 +446,7 @@ public class RelocationTests extends ElasticsearchIntegrationTest { } @Test + @Slow @TestLogging("cluster.service:TRACE,indices.recovery:TRACE") public void testRelocationWithBusyClusterUpdateThread() throws Exception { final String indexName = "test"; diff --git a/src/test/java/org/elasticsearch/recovery/TruncatedRecoveryTests.java b/src/test/java/org/elasticsearch/recovery/TruncatedRecoveryTests.java index 2dda962e2f3..6a22599b634 100644 --- a/src/test/java/org/elasticsearch/recovery/TruncatedRecoveryTests.java +++ b/src/test/java/org/elasticsearch/recovery/TruncatedRecoveryTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.recovery; import org.apache.lucene.util.English; +import org.apache.lucene.util.LuceneTestCase.SuppressCodecs; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; import org.elasticsearch.action.index.IndexRequestBuilder; @@ -52,6 +53,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitC import static org.hamcrest.Matchers.greaterThanOrEqualTo; @ElasticsearchIntegrationTest.ClusterScope(numDataNodes = 2, numClientNodes = 0, scope = ElasticsearchIntegrationTest.Scope.TEST) +@SuppressCodecs("*") // test relies on exact file extensions public class TruncatedRecoveryTests extends ElasticsearchIntegrationTest { protected Settings nodeSettings(int nodeOrdinal) { diff --git a/src/test/java/org/elasticsearch/script/CustomScriptContextTests.java b/src/test/java/org/elasticsearch/script/CustomScriptContextTests.java index 6c193dfefed..76a9ff03e15 100644 --- a/src/test/java/org/elasticsearch/script/CustomScriptContextTests.java +++ b/src/test/java/org/elasticsearch/script/CustomScriptContextTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.script; import com.google.common.collect.ImmutableSet; + import org.elasticsearch.ElasticsearchIllegalArgumentException; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.settings.ImmutableSettings; diff --git a/src/test/java/org/elasticsearch/script/OnDiskScriptTests.java b/src/test/java/org/elasticsearch/script/OnDiskScriptTests.java index 7a73ab7d470..78a28520d4a 100644 --- a/src/test/java/org/elasticsearch/script/OnDiskScriptTests.java +++ b/src/test/java/org/elasticsearch/script/OnDiskScriptTests.java @@ -44,7 +44,7 @@ public class OnDiskScriptTests extends ElasticsearchIntegrationTest { public Settings nodeSettings(int nodeOrdinal) { //Set path so ScriptService will pick up the test scripts return settingsBuilder().put(super.nodeSettings(nodeOrdinal)) - .put("path.conf", this.getResourcePath("config")) + .put("path.conf", this.getDataPath("config")) .put("script.engine.expression.file.aggs", "off") .put("script.engine.mustache.file.aggs", "off") .put("script.engine.mustache.file.search", "off") diff --git a/src/test/java/org/elasticsearch/script/ScriptServiceTests.java b/src/test/java/org/elasticsearch/script/ScriptServiceTests.java index f435e53f092..0187d22c5d4 100644 --- a/src/test/java/org/elasticsearch/script/ScriptServiceTests.java +++ b/src/test/java/org/elasticsearch/script/ScriptServiceTests.java @@ -69,7 +69,7 @@ public class ScriptServiceTests extends ElasticsearchTestCase { @Before public void setup() throws IOException { - Path genericConfigFolder = newTempDirPath(); + Path genericConfigFolder = createTempDir(); baseSettings = settingsBuilder() .put("path.conf", genericConfigFolder) .build(); diff --git a/src/test/java/org/elasticsearch/search/aggregations/bucket/DedicatedAggregationTests.java b/src/test/java/org/elasticsearch/search/aggregations/bucket/DedicatedAggregationTests.java index 9e3fed6b49b..aeba973a7da 100644 --- a/src/test/java/org/elasticsearch/search/aggregations/bucket/DedicatedAggregationTests.java +++ b/src/test/java/org/elasticsearch/search/aggregations/bucket/DedicatedAggregationTests.java @@ -32,7 +32,6 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSear import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.instanceOf; - public class DedicatedAggregationTests extends ElasticsearchIntegrationTest { // https://github.com/elasticsearch/elasticsearch/issues/7240 diff --git a/src/test/java/org/elasticsearch/search/aggregations/bucket/ParentIdAggTests.java b/src/test/java/org/elasticsearch/search/aggregations/bucket/ParentIdAggTests.java index e91d61e6cf8..b3ae0733dd1 100644 --- a/src/test/java/org/elasticsearch/search/aggregations/bucket/ParentIdAggTests.java +++ b/src/test/java/org/elasticsearch/search/aggregations/bucket/ParentIdAggTests.java @@ -34,7 +34,6 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSear import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.instanceOf; - public class ParentIdAggTests extends ElasticsearchIntegrationTest { @Test diff --git a/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreTests.java b/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreTests.java index ab08c6765c4..14330a1f900 100644 --- a/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreTests.java +++ b/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreTests.java @@ -58,9 +58,6 @@ import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse; -import static org.hamcrest.Matchers.closeTo; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.*; /** @@ -79,7 +76,7 @@ public class SignificantTermsSignificanceScoreTests extends ElasticsearchIntegra return settingsBuilder() .put(super.nodeSettings(nodeOrdinal)) .put("plugin.types", CustomSignificanceHeuristicPlugin.class.getName()) - .put("path.conf", this.getResourcePath("config")) + .put("path.conf", this.getDataPath("config")) .build(); } diff --git a/src/test/java/org/elasticsearch/search/aggregations/bucket/TopHitsTests.java b/src/test/java/org/elasticsearch/search/aggregations/bucket/TopHitsTests.java index 0b8b2ba810f..54ae5418613 100644 --- a/src/test/java/org/elasticsearch/search/aggregations/bucket/TopHitsTests.java +++ b/src/test/java/org/elasticsearch/search/aggregations/bucket/TopHitsTests.java @@ -776,7 +776,7 @@ public class TopHitsTests extends ElasticsearchIntegrationTest { assertThat(topReviewers.getHits().getAt(0).getNestedIdentity().getChild().getOffset(), equalTo(0)); } - @Test + @Test @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/10661") public void testNestedFetchFeatures() { String hlType = randomFrom("plain", "fvh", "postings"); HighlightBuilder.Field hlField = new HighlightBuilder.Field("comments.message") diff --git a/src/test/java/org/elasticsearch/search/aggregations/bucket/nested/NestedAggregatorTest.java b/src/test/java/org/elasticsearch/search/aggregations/bucket/nested/NestedAggregatorTest.java index cea6efd8747..9a9060c9ed0 100644 --- a/src/test/java/org/elasticsearch/search/aggregations/bucket/nested/NestedAggregatorTest.java +++ b/src/test/java/org/elasticsearch/search/aggregations/bucket/nested/NestedAggregatorTest.java @@ -42,7 +42,7 @@ import org.elasticsearch.search.aggregations.BucketCollector; import org.elasticsearch.search.aggregations.SearchContextAggregations; import org.elasticsearch.search.aggregations.support.AggregationContext; import org.elasticsearch.search.internal.SearchContext; -import org.elasticsearch.test.ElasticsearchSingleNodeLuceneTestCase; +import org.elasticsearch.test.ElasticsearchSingleNodeTest; import org.junit.Test; import java.util.ArrayList; @@ -53,7 +53,7 @@ import static org.hamcrest.Matchers.equalTo; /** */ -public class NestedAggregatorTest extends ElasticsearchSingleNodeLuceneTestCase { +public class NestedAggregatorTest extends ElasticsearchSingleNodeTest { @Test public void testResetRootDocId() throws Exception { diff --git a/src/test/java/org/elasticsearch/search/aggregations/bucket/significant/SignificanceHeuristicTests.java b/src/test/java/org/elasticsearch/search/aggregations/bucket/significant/SignificanceHeuristicTests.java index e84a785f5ad..a5b38728a0f 100644 --- a/src/test/java/org/elasticsearch/search/aggregations/bucket/significant/SignificanceHeuristicTests.java +++ b/src/test/java/org/elasticsearch/search/aggregations/bucket/significant/SignificanceHeuristicTests.java @@ -32,7 +32,6 @@ import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.search.aggregations.InternalAggregations; import org.elasticsearch.search.aggregations.bucket.significant.heuristics.*; import org.elasticsearch.search.internal.SearchContext; -import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.test.TestSearchContext; import org.junit.Test; @@ -45,6 +44,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import static org.elasticsearch.test.VersionUtils.randomVersion; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThanOrEqualTo; @@ -76,7 +76,7 @@ public class SignificanceHeuristicTests extends ElasticsearchTestCase { SignificanceHeuristicStreams.registerStream(GND.STREAM, GND.STREAM.getName()); SignificanceHeuristicStreams.registerStream(ChiSquare.STREAM, ChiSquare.STREAM.getName()); SignificanceHeuristicStreams.registerStream(ScriptHeuristic.STREAM, ScriptHeuristic.STREAM.getName()); - Version version = ElasticsearchIntegrationTest.randomVersion(); + Version version = randomVersion(random()); InternalSignificantTerms[] sigTerms = getRandomSignificantTerms(getRandomSignificanceheuristic()); // write diff --git a/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricTests.java b/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricTests.java index 7dfd0e050ce..10a8df25b98 100644 --- a/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricTests.java +++ b/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricTests.java @@ -115,7 +115,7 @@ public class ScriptedMetricTests extends ElasticsearchIntegrationTest { protected Settings nodeSettings(int nodeOrdinal) { Settings settings = ImmutableSettings.settingsBuilder() .put(super.nodeSettings(nodeOrdinal)) - .put("path.conf", getResourcePath("/org/elasticsearch/search/aggregations/metrics/scripted/conf")) + .put("path.conf", getDataPath("/org/elasticsearch/search/aggregations/metrics/scripted/conf")) .build(); return settings; } diff --git a/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsTests.java b/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsTests.java index 15b5c6440c6..22095325fa7 100644 --- a/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsTests.java +++ b/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsTests.java @@ -54,6 +54,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*; public class SearchWithRandomExceptionsTests extends ElasticsearchIntegrationTest { @Test + @Slow // maybe due to all the logging? @TestLogging("action.search.type:TRACE,index.shard:TRACE") public void testRandomDirectoryIOExceptions() throws IOException, InterruptedException, ExecutionException { String mapping = XContentFactory.jsonBuilder(). diff --git a/src/test/java/org/elasticsearch/search/basic/TransportTwoNodesSearchTests.java b/src/test/java/org/elasticsearch/search/basic/TransportTwoNodesSearchTests.java index aa242bd8128..2381cd2eea0 100644 --- a/src/test/java/org/elasticsearch/search/basic/TransportTwoNodesSearchTests.java +++ b/src/test/java/org/elasticsearch/search/basic/TransportTwoNodesSearchTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.unit.TimeValue; import com.google.common.base.Charsets; import com.google.common.collect.Sets; + import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.search.MultiSearchResponse; import org.elasticsearch.action.search.SearchPhaseExecutionException; diff --git a/src/test/java/org/elasticsearch/search/child/SimpleChildQuerySearchTests.java b/src/test/java/org/elasticsearch/search/child/SimpleChildQuerySearchTests.java index e0ab41e6e86..deaf6e4d94f 100644 --- a/src/test/java/org/elasticsearch/search/child/SimpleChildQuerySearchTests.java +++ b/src/test/java/org/elasticsearch/search/child/SimpleChildQuerySearchTests.java @@ -1649,7 +1649,7 @@ public class SimpleChildQuerySearchTests extends ElasticsearchIntegrationTest { } } - @Test + @Test @Slow // The SimpleIdReaderTypeCache#docById method used lget, which can't be used if a map is shared. public void testTopChildrenBug_concurrencyIssue() throws Exception { assertAcked(prepareCreate("test") diff --git a/src/test/java/org/elasticsearch/search/fetch/innerhits/NestedChildrenFilterTest.java b/src/test/java/org/elasticsearch/search/fetch/innerhits/NestedChildrenFilterTest.java index a5b7992781b..0edc47a0123 100644 --- a/src/test/java/org/elasticsearch/search/fetch/innerhits/NestedChildrenFilterTest.java +++ b/src/test/java/org/elasticsearch/search/fetch/innerhits/NestedChildrenFilterTest.java @@ -34,7 +34,7 @@ import org.apache.lucene.search.join.BitDocIdSetFilter; import org.apache.lucene.store.Directory; import org.elasticsearch.search.fetch.FetchSubPhase; import org.elasticsearch.search.fetch.innerhits.InnerHitsContext.NestedInnerHits.NestedChildrenFilter; -import org.elasticsearch.test.ElasticsearchLuceneTestCase; +import org.elasticsearch.test.ElasticsearchTestCase; import org.junit.Test; import java.util.ArrayList; @@ -44,7 +44,7 @@ import static org.hamcrest.Matchers.equalTo; /** */ -public class NestedChildrenFilterTest extends ElasticsearchLuceneTestCase { +public class NestedChildrenFilterTest extends ElasticsearchTestCase { @Test public void testNestedChildrenFilter() throws Exception { diff --git a/src/test/java/org/elasticsearch/search/functionscore/FunctionScoreTests.java b/src/test/java/org/elasticsearch/search/functionscore/FunctionScoreTests.java index 83bb1d923c5..cf0468732b5 100644 --- a/src/test/java/org/elasticsearch/search/functionscore/FunctionScoreTests.java +++ b/src/test/java/org/elasticsearch/search/functionscore/FunctionScoreTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.search.functionscore; +import org.apache.lucene.util.LuceneTestCase.Slow; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchResponse; @@ -60,6 +61,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.is; +@Slow public class FunctionScoreTests extends ElasticsearchIntegrationTest { static final String TYPE = "type"; diff --git a/src/test/java/org/elasticsearch/search/functionscore/RandomScoreFunctionTests.java b/src/test/java/org/elasticsearch/search/functionscore/RandomScoreFunctionTests.java index eee8504b24c..4ad41d9f44e 100644 --- a/src/test/java/org/elasticsearch/search/functionscore/RandomScoreFunctionTests.java +++ b/src/test/java/org/elasticsearch/search/functionscore/RandomScoreFunctionTests.java @@ -37,9 +37,9 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcke import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; import static org.hamcrest.Matchers.*; - public class RandomScoreFunctionTests extends ElasticsearchIntegrationTest { + @Slow public void testConsistentHitsWithSameSeed() throws Exception { createIndex("test"); ensureGreen(); // make sure we are done otherwise preference could change? diff --git a/src/test/java/org/elasticsearch/search/highlight/HighlighterSearchTests.java b/src/test/java/org/elasticsearch/search/highlight/HighlighterSearchTests.java index c728062570e..1834d9d63df 100644 --- a/src/test/java/org/elasticsearch/search/highlight/HighlighterSearchTests.java +++ b/src/test/java/org/elasticsearch/search/highlight/HighlighterSearchTests.java @@ -60,6 +60,7 @@ import static org.hamcrest.Matchers.*; /** * */ +@Slow public class HighlighterSearchTests extends ElasticsearchIntegrationTest { @Test diff --git a/src/test/java/org/elasticsearch/search/query/ExistsMissingTests.java b/src/test/java/org/elasticsearch/search/query/ExistsMissingTests.java index 25dfd8051f8..b420521eaaa 100644 --- a/src/test/java/org/elasticsearch/search/query/ExistsMissingTests.java +++ b/src/test/java/org/elasticsearch/search/query/ExistsMissingTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.search.query; import com.google.common.collect.ImmutableMap; + import org.elasticsearch.action.explain.ExplainResponse; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchResponse; @@ -36,7 +37,6 @@ import java.util.*; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*; - public class ExistsMissingTests extends ElasticsearchIntegrationTest { public void testExistsMissing() throws Exception { diff --git a/src/test/java/org/elasticsearch/search/query/MultiMatchQueryTests.java b/src/test/java/org/elasticsearch/search/query/MultiMatchQueryTests.java index 59359619cdb..66205a1b032 100644 --- a/src/test/java/org/elasticsearch/search/query/MultiMatchQueryTests.java +++ b/src/test/java/org/elasticsearch/search/query/MultiMatchQueryTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.search.query; import com.carrotsearch.randomizedtesting.generators.RandomPicks; import com.google.common.collect.Sets; + import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchResponse; diff --git a/src/test/java/org/elasticsearch/search/query/SearchQueryTests.java b/src/test/java/org/elasticsearch/search/query/SearchQueryTests.java index 7471866c5c1..d0a5a6b357b 100644 --- a/src/test/java/org/elasticsearch/search/query/SearchQueryTests.java +++ b/src/test/java/org/elasticsearch/search/query/SearchQueryTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.search.query; import org.apache.lucene.util.English; +import org.apache.lucene.util.LuceneTestCase.Slow; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; @@ -52,17 +53,17 @@ import java.util.Random; import java.util.Set; import java.util.concurrent.ExecutionException; -import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS; import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS; import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.query.FilterBuilders.*; import static org.elasticsearch.index.query.QueryBuilders.*; import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.scriptFunction; +import static org.elasticsearch.test.VersionUtils.randomVersion; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*; import static org.hamcrest.Matchers.*; - +@Slow public class SearchQueryTests extends ElasticsearchIntegrationTest { @Override @@ -489,7 +490,7 @@ public class SearchQueryTests extends ElasticsearchIntegrationTest { assertThat(version.toString(), version.onOrAfter(Version.V_1_0_0_RC2), equalTo(true)); assertThat(ex.getCause().getMessage(), equalTo("'omit_term_freq_and_positions' is not supported anymore - use ['index_options' : 'docs'] instead")); } - version = randomVersion(); + version = randomVersion(random()); } } diff --git a/src/test/java/org/elasticsearch/search/query/SimpleQueryStringTests.java b/src/test/java/org/elasticsearch/search/query/SimpleQueryStringTests.java index 34813a2dc40..fc14abf27da 100644 --- a/src/test/java/org/elasticsearch/search/query/SimpleQueryStringTests.java +++ b/src/test/java/org/elasticsearch/search/query/SimpleQueryStringTests.java @@ -37,7 +37,6 @@ import static org.elasticsearch.index.query.QueryBuilders.boolQuery; import static org.elasticsearch.index.query.QueryBuilders.queryStringQuery; import static org.elasticsearch.index.query.QueryBuilders.simpleQueryStringQuery; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits; import static org.hamcrest.Matchers.equalTo; /** diff --git a/src/test/java/org/elasticsearch/search/rescore/QueryRescorerTests.java b/src/test/java/org/elasticsearch/search/rescore/QueryRescorerTests.java index 9c60b1ac612..81b10faed93 100644 --- a/src/test/java/org/elasticsearch/search/rescore/QueryRescorerTests.java +++ b/src/test/java/org/elasticsearch/search/rescore/QueryRescorerTests.java @@ -569,7 +569,7 @@ public class QueryRescorerTests extends ElasticsearchIntegrationTest { } } - @Test + @Test @Slow public void testScoring() throws Exception { int numDocs = indexRandomNumbers("keyword"); diff --git a/src/test/java/org/elasticsearch/search/scroll/DuelScrollTests.java b/src/test/java/org/elasticsearch/search/scroll/DuelScrollTests.java index 116a03bfe02..3e77aa4b4f1 100644 --- a/src/test/java/org/elasticsearch/search/scroll/DuelScrollTests.java +++ b/src/test/java/org/elasticsearch/search/scroll/DuelScrollTests.java @@ -158,7 +158,7 @@ public class DuelScrollTests extends ElasticsearchIntegrationTest { int scrollRequestSize = randomIntBetween(1, rarely() ? numDocs : numDocs / 2); boolean unevenRouting = randomBoolean(); - int numMissingDocs = atMost(numDocs / 100); + int numMissingDocs = scaledRandomIntBetween(0, numDocs / 100); IntOpenHashSet missingDocs = new IntOpenHashSet(numMissingDocs); for (int i = 0; i < numMissingDocs; i++) { while (!missingDocs.add(randomInt(numDocs))) {} diff --git a/src/test/java/org/elasticsearch/search/sort/SimpleSortTests.java b/src/test/java/org/elasticsearch/search/sort/SimpleSortTests.java index e35fcedc2a7..b40e5547b1a 100644 --- a/src/test/java/org/elasticsearch/search/sort/SimpleSortTests.java +++ b/src/test/java/org/elasticsearch/search/sort/SimpleSortTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.search.sort; import com.carrotsearch.randomizedtesting.annotations.Repeat; + import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TestUtil; @@ -457,14 +458,14 @@ public class SimpleSortTests extends ElasticsearchIntegrationTest { Random random = getRandom(); assertAcked(prepareCreate("test") .addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties") - .startObject("str_value").field("type", "string").field("index", "not_analyzed").startObject("fielddata").field("format", maybeDocValues() ? "doc_values" : null).endObject().endObject() + .startObject("str_value").field("type", "string").field("index", "not_analyzed").startObject("fielddata").field("format", random().nextBoolean() ? "doc_values" : null).endObject().endObject() .startObject("boolean_value").field("type", "boolean").endObject() - .startObject("byte_value").field("type", "byte").startObject("fielddata").field("format", maybeDocValues() ? "doc_values" : null).endObject().endObject() - .startObject("short_value").field("type", "short").startObject("fielddata").field("format", maybeDocValues() ? "doc_values" : null).endObject().endObject() - .startObject("integer_value").field("type", "integer").startObject("fielddata").field("format", maybeDocValues() ? "doc_values" : null).endObject().endObject() - .startObject("long_value").field("type", "long").startObject("fielddata").field("format", maybeDocValues() ? "doc_values" : null).endObject().endObject() - .startObject("float_value").field("type", "float").startObject("fielddata").field("format", maybeDocValues() ? "doc_values" : null).endObject().endObject() - .startObject("double_value").field("type", "double").startObject("fielddata").field("format", maybeDocValues() ? "doc_values" : null).endObject().endObject() + .startObject("byte_value").field("type", "byte").startObject("fielddata").field("format", random().nextBoolean() ? "doc_values" : null).endObject().endObject() + .startObject("short_value").field("type", "short").startObject("fielddata").field("format", random().nextBoolean() ? "doc_values" : null).endObject().endObject() + .startObject("integer_value").field("type", "integer").startObject("fielddata").field("format", random().nextBoolean() ? "doc_values" : null).endObject().endObject() + .startObject("long_value").field("type", "long").startObject("fielddata").field("format", random().nextBoolean() ? "doc_values" : null).endObject().endObject() + .startObject("float_value").field("type", "float").startObject("fielddata").field("format", random().nextBoolean() ? "doc_values" : null).endObject().endObject() + .startObject("double_value").field("type", "double").startObject("fielddata").field("format", random().nextBoolean() ? "doc_values" : null).endObject().endObject() .endObject().endObject().endObject())); ensureGreen(); List builders = new ArrayList<>(); @@ -858,7 +859,7 @@ public class SimpleSortTests extends ElasticsearchIntegrationTest { // We have to specify mapping explicitly because by the time search is performed dynamic mapping might not // be propagated to all nodes yet and sort operation fail when the sort field is not defined String mapping = jsonBuilder().startObject().startObject("type1").startObject("properties") - .startObject("svalue").field("type", "string").field("index", "not_analyzed").startObject("fielddata").field("format", maybeDocValues() ? "doc_values" : null).endObject().endObject() + .startObject("svalue").field("type", "string").field("index", "not_analyzed").startObject("fielddata").field("format", random().nextBoolean() ? "doc_values" : null).endObject().endObject() .endObject().endObject().endObject().string(); assertAcked(prepareCreate("test").addMapping("type1", mapping)); ensureGreen(); @@ -955,11 +956,11 @@ public class SimpleSortTests extends ElasticsearchIntegrationTest { .startObject("properties") .startObject("i_value") .field("type", "integer") - .startObject("fielddata").field("format", maybeDocValues() ? "doc_values" : null).endObject() + .startObject("fielddata").field("format", random().nextBoolean() ? "doc_values" : null).endObject() .endObject() .startObject("d_value") .field("type", "float") - .startObject("fielddata").field("format", maybeDocValues() ? "doc_values" : null).endObject() + .startObject("fielddata").field("format", random().nextBoolean() ? "doc_values" : null).endObject() .endObject() .endObject() .endObject() @@ -1021,7 +1022,7 @@ public class SimpleSortTests extends ElasticsearchIntegrationTest { assertThat(searchResponse.getHits().getAt(2).id(), equalTo("3")); } - @Test + @Test @Slow public void testSortMissingStrings() throws ElasticsearchException, IOException { assertAcked(prepareCreate("test").addMapping("type1", XContentFactory.jsonBuilder() @@ -1053,6 +1054,7 @@ public class SimpleSortTests extends ElasticsearchIntegrationTest { flush(); refresh(); + // TODO: WTF? try { Thread.sleep(2000); } catch (InterruptedException e) { @@ -1144,13 +1146,13 @@ public class SimpleSortTests extends ElasticsearchIntegrationTest { public void testSortMVField() throws Exception { assertAcked(prepareCreate("test") .addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties") - .startObject("long_values").field("type", "long").startObject("fielddata").field("format", maybeDocValues() ? "doc_values" : null).endObject().endObject() - .startObject("int_values").field("type", "integer").startObject("fielddata").field("format", maybeDocValues() ? "doc_values" : null).endObject().endObject() - .startObject("short_values").field("type", "short").startObject("fielddata").field("format", maybeDocValues() ? "doc_values" : null).endObject().endObject() - .startObject("byte_values").field("type", "byte").startObject("fielddata").field("format", maybeDocValues() ? "doc_values" : null).endObject().endObject() - .startObject("float_values").field("type", "float").startObject("fielddata").field("format", maybeDocValues() ? "doc_values" : null).endObject().endObject() - .startObject("double_values").field("type", "double").startObject("fielddata").field("format", maybeDocValues() ? "doc_values" : null).endObject().endObject() - .startObject("string_values").field("type", "string").field("index", "not_analyzed").startObject("fielddata").field("format", maybeDocValues() ? "doc_values" : null).endObject().endObject() + .startObject("long_values").field("type", "long").startObject("fielddata").field("format", random().nextBoolean() ? "doc_values" : null).endObject().endObject() + .startObject("int_values").field("type", "integer").startObject("fielddata").field("format", random().nextBoolean() ? "doc_values" : null).endObject().endObject() + .startObject("short_values").field("type", "short").startObject("fielddata").field("format", random().nextBoolean() ? "doc_values" : null).endObject().endObject() + .startObject("byte_values").field("type", "byte").startObject("fielddata").field("format", random().nextBoolean() ? "doc_values" : null).endObject().endObject() + .startObject("float_values").field("type", "float").startObject("fielddata").field("format", random().nextBoolean() ? "doc_values" : null).endObject().endObject() + .startObject("double_values").field("type", "double").startObject("fielddata").field("format", random().nextBoolean() ? "doc_values" : null).endObject().endObject() + .startObject("string_values").field("type", "string").field("index", "not_analyzed").startObject("fielddata").field("format", random().nextBoolean() ? "doc_values" : null).endObject().endObject() .endObject().endObject().endObject())); ensureGreen(); @@ -1459,7 +1461,7 @@ public class SimpleSortTests extends ElasticsearchIntegrationTest { public void testSortOnRareField() throws ElasticsearchException, IOException { assertAcked(prepareCreate("test") .addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties") - .startObject("string_values").field("type", "string").field("index", "not_analyzed").startObject("fielddata").field("format", maybeDocValues() ? "doc_values" : null).endObject().endObject() + .startObject("string_values").field("type", "string").field("index", "not_analyzed").startObject("fielddata").field("format", random().nextBoolean() ? "doc_values" : null).endObject().endObject() .endObject().endObject().endObject())); ensureGreen(); client().prepareIndex("test", "type1", Integer.toString(1)).setSource(jsonBuilder().startObject() @@ -1558,8 +1560,8 @@ public class SimpleSortTests extends ElasticsearchIntegrationTest { } public void testSortMetaField() throws Exception { - final boolean idDocValues = maybeDocValues(); - final boolean timestampDocValues = maybeDocValues(); + final boolean idDocValues = random().nextBoolean(); + final boolean timestampDocValues = random().nextBoolean(); XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("_timestamp").field("enabled", true).field("store", true).field("index", !timestampDocValues || randomBoolean() ? "not_analyzed" : "no").field("doc_values", timestampDocValues).endObject() .endObject().endObject(); diff --git a/src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchTests.java b/src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchTests.java index 5f39c9da200..b2528428297 100644 --- a/src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchTests.java +++ b/src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchTests.java @@ -21,6 +21,8 @@ package org.elasticsearch.search.suggest; import com.carrotsearch.hppc.ObjectLongOpenHashMap; import com.carrotsearch.randomizedtesting.generators.RandomStrings; import com.google.common.collect.Lists; + +import org.apache.lucene.util.LuceneTestCase.SuppressCodecs; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; import org.elasticsearch.action.admin.indices.optimize.OptimizeResponse; @@ -67,6 +69,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcke import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAllSuccessful; import static org.hamcrest.Matchers.*; +@SuppressCodecs("*") // requires custom completion format public class CompletionSuggestSearchTests extends ElasticsearchIntegrationTest { private final String INDEX = RandomStrings.randomAsciiOfLength(getRandom(), 10).toLowerCase(Locale.ROOT); diff --git a/src/test/java/org/elasticsearch/search/suggest/ContextSuggestSearchTests.java b/src/test/java/org/elasticsearch/search/suggest/ContextSuggestSearchTests.java index cec79710804..b3d8eeeb9bc 100644 --- a/src/test/java/org/elasticsearch/search/suggest/ContextSuggestSearchTests.java +++ b/src/test/java/org/elasticsearch/search/suggest/ContextSuggestSearchTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.search.suggest; import com.google.common.collect.Sets; + import org.elasticsearch.ElasticsearchIllegalArgumentException; import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; import org.elasticsearch.action.suggest.SuggestRequest; @@ -40,6 +41,7 @@ import org.elasticsearch.search.suggest.completion.CompletionSuggestionFuzzyBuil import org.elasticsearch.search.suggest.context.ContextBuilder; import org.elasticsearch.search.suggest.context.ContextMapping; import org.elasticsearch.test.ElasticsearchIntegrationTest; +import org.apache.lucene.util.LuceneTestCase.SuppressCodecs; import org.hamcrest.Matchers; import org.junit.Test; @@ -51,6 +53,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*; import static org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions.assertDistance; import static org.hamcrest.Matchers.containsString; +@SuppressCodecs("*") // requires custom completion format public class ContextSuggestSearchTests extends ElasticsearchIntegrationTest { private static final String INDEX = "test"; diff --git a/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreTests.java b/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreTests.java index 55b61aad7d9..e87fa1821af 100644 --- a/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreTests.java +++ b/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreTests.java @@ -25,6 +25,7 @@ import com.carrotsearch.randomizedtesting.LifecycleScope; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.ListenableFuture; +import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.ListenableActionFuture; import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse; @@ -112,7 +113,7 @@ public class DedicatedClusterSnapshotRestoreTests extends AbstractSnapshotTests logger.info("--> create repository"); PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", newTempDir())).execute().actionGet(); + .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", createTempDir())).execute().actionGet(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); logger.info("--> start snapshot"); @@ -145,7 +146,7 @@ public class DedicatedClusterSnapshotRestoreTests extends AbstractSnapshotTests @Test public void restoreCustomMetadata() throws Exception { - Path tempDir = newTempDirPath(); + Path tempDir = createTempDir(); logger.info("--> start node"); internalCluster().startNode(); @@ -292,7 +293,7 @@ public class DedicatedClusterSnapshotRestoreTests extends AbstractSnapshotTests PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo") .setType(MockRepositoryModule.class.getCanonicalName()).setSettings( ImmutableSettings.settingsBuilder() - .put("location", newTempDir(LifecycleScope.TEST)) + .put("location", createTempDir()) .put("random", randomAsciiOfLength(10)) .put("wait_after_unblock", 200) ).get(); @@ -337,7 +338,7 @@ public class DedicatedClusterSnapshotRestoreTests extends AbstractSnapshotTests assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(100L)); logger.info("--> creating repository"); - Path repo = newTempDirPath(LifecycleScope.TEST); + Path repo = createTempDir(); PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo") .setType(MockRepositoryModule.class.getCanonicalName()).setSettings( ImmutableSettings.settingsBuilder() @@ -426,7 +427,7 @@ public class DedicatedClusterSnapshotRestoreTests extends AbstractSnapshotTests logger.info("--> create repository"); logger.info("--> creating repository"); PutRepositoryResponse putRepositoryResponse = client().admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", newTempDir())).execute().actionGet(); + .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", createTempDir())).execute().actionGet(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); logger.info("--> start snapshot with default settings - should fail"); @@ -529,7 +530,7 @@ public class DedicatedClusterSnapshotRestoreTests extends AbstractSnapshotTests logger.info("--> create repository"); PutRepositoryResponse putRepositoryResponse = client().admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", newTempDir())).execute().actionGet(); + .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", createTempDir())).execute().actionGet(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); int numberOfShards = 6; logger.info("--> create an index that will have some unallocated shards"); @@ -588,12 +589,12 @@ public class DedicatedClusterSnapshotRestoreTests extends AbstractSnapshotTests for (int i = 0; i < 5; i++) { client().admin().cluster().preparePutRepository("test-repo" + i) .setType("mock").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDir(LifecycleScope.SUITE))).setVerify(false).get(); + .put("location", createTempDir())).setVerify(false).get(); } logger.info("--> make sure that properly setup repository can be registered on all nodes"); client().admin().cluster().preparePutRepository("test-repo-0") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDir(LifecycleScope.SUITE))).get(); + .put("location", createTempDir())).get(); } @@ -611,7 +612,7 @@ public class DedicatedClusterSnapshotRestoreTests extends AbstractSnapshotTests logger.info("--> creating repository"); assertAcked(client().admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDir(LifecycleScope.SUITE)) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)))); diff --git a/src/test/java/org/elasticsearch/snapshots/RepositoriesTests.java b/src/test/java/org/elasticsearch/snapshots/RepositoriesTests.java index fcae6d44a29..8f86ec572a0 100644 --- a/src/test/java/org/elasticsearch/snapshots/RepositoriesTests.java +++ b/src/test/java/org/elasticsearch/snapshots/RepositoriesTests.java @@ -54,7 +54,7 @@ public class RepositoriesTests extends AbstractSnapshotTests { public void testRepositoryCreation() throws Exception { Client client = client(); - Path location = newTempDirPath(LifecycleScope.SUITE); + Path location = createTempDir(); logger.info("--> creating repository"); PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo-1") @@ -82,7 +82,7 @@ public class RepositoriesTests extends AbstractSnapshotTests { logger.info("--> creating another repository"); putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo-2") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDir(LifecycleScope.SUITE)) + .put("location", createTempDir()) ).get(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); @@ -142,7 +142,7 @@ public class RepositoriesTests extends AbstractSnapshotTests { logger.info("--> creating repository test-repo-1 with 0s timeout - shouldn't ack"); PutRepositoryResponse putRepositoryResponse = client().admin().cluster().preparePutRepository("test-repo-1") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDir(LifecycleScope.SUITE)) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(5, 100)) ) @@ -152,7 +152,7 @@ public class RepositoriesTests extends AbstractSnapshotTests { logger.info("--> creating repository test-repo-2 with standard timeout - should ack"); putRepositoryResponse = client().admin().cluster().preparePutRepository("test-repo-2") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDir(LifecycleScope.SUITE)) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(5, 100)) ).get(); @@ -173,7 +173,7 @@ public class RepositoriesTests extends AbstractSnapshotTests { Client client = client(); Settings settings = ImmutableSettings.settingsBuilder() - .put("location", newTempDir(LifecycleScope.SUITE)) + .put("location", createTempDir()) .put("random_control_io_exception_rate", 1.0).build(); logger.info("--> creating repository that cannot write any files - should fail"); assertThrows(client.admin().cluster().preparePutRepository("test-repo-1") @@ -187,7 +187,7 @@ public class RepositoriesTests extends AbstractSnapshotTests { logger.info("--> verifying repository"); assertThrows(client.admin().cluster().prepareVerifyRepository("test-repo-1"), RepositoryVerificationException.class); - Path location = newTempDirPath(LifecycleScope.SUITE); + Path location = createTempDir(); logger.info("--> creating repository"); try { @@ -208,7 +208,7 @@ public class RepositoriesTests extends AbstractSnapshotTests { Client client = client(); Settings settings = ImmutableSettings.settingsBuilder() - .put("location", newTempDir(LifecycleScope.SUITE)) + .put("location", createTempDir()) .put("random_control_io_exception_rate", 1.0).build(); logger.info("--> creating repository that cannot write any files - should fail"); assertThrows(client.admin().cluster().preparePutRepository("test-repo-1") @@ -222,7 +222,7 @@ public class RepositoriesTests extends AbstractSnapshotTests { logger.info("--> verifying repository"); assertThrows(client.admin().cluster().prepareVerifyRepository("test-repo-1"), RepositoryVerificationException.class); - Path location = newTempDirPath(LifecycleScope.SUITE); + Path location = createTempDir(); logger.info("--> creating repository"); try { diff --git a/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreTests.java b/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreTests.java index c7687478aeb..f6a730c5491 100644 --- a/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreTests.java +++ b/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreTests.java @@ -87,7 +87,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)))); @@ -182,7 +182,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { String indexName = "testindex"; String repoName = "test-restore-snapshot-repo"; String snapshotName = "test-restore-snapshot"; - String absolutePath = newTempDirPath().toAbsolutePath().toString(); + String absolutePath = createTempDir().toAbsolutePath().toString(); logger.info("Path [{}]", absolutePath); String restoredIndexName = indexName + "-restored"; String typeName = "actions"; @@ -228,7 +228,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)))); @@ -277,7 +277,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)))); @@ -325,7 +325,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", newTempDirPath())).get(); + .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", createTempDir())).get(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); logger.info("--> snapshot"); @@ -342,7 +342,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", newTempDirPath()))); + .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", createTempDir()))); logger.info("--> create test indices"); createIndex("test-idx-1", "test-idx-2", "test-idx-3"); @@ -398,7 +398,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") - .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", newTempDirPath()))); + .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", createTempDir()))); logger.info("--> creating test template"); assertThat(client.admin().indices().preparePutTemplate("test-template").setTemplate("te*").addMapping("test-mapping", "{}").get().isAcknowledged(), equalTo(true)); @@ -430,7 +430,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { Client client = client(); logger.info("--> creating repository"); - Path location = newTempDirPath(); + Path location = createTempDir(); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder().put("location", location))); @@ -512,7 +512,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType(MockRepositoryModule.class.getCanonicalName()).setSettings( ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("random", randomAsciiOfLength(10)) .put("random_control_io_exception_rate", 0.2)) .setVerify(false)); @@ -562,7 +562,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType(MockRepositoryModule.class.getCanonicalName()).setSettings( ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("random", randomAsciiOfLength(10)) .put("random_data_file_io_exception_rate", 0.3))); @@ -624,7 +624,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { @Test public void dataFileFailureDuringRestoreTest() throws Exception { - Path repositoryLocation = newTempDirPath(); + Path repositoryLocation = createTempDir(); Client client = client(); logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") @@ -666,7 +666,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { @Test public void deletionOfFailingToRecoverIndexShouldStopRestore() throws Exception { - Path repositoryLocation = newTempDirPath(); + Path repositoryLocation = createTempDir(); Client client = client(); logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") @@ -735,7 +735,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()))); + .put("location", createTempDir()))); logger.info("--> creating index that cannot be allocated"); prepareCreate("test-idx", 2, ImmutableSettings.builder().put(FilterAllocationDecider.INDEX_ROUTING_INCLUDE_GROUP + ".tag", "nowhere").put("index.number_of_shards", 3)).get(); @@ -753,7 +753,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { final int numberOfSnapshots = between(5, 15); Client client = client(); - Path repo = newTempDirPath(); + Path repo = createTempDir(); logger.info("--> creating repository at " + repo.toAbsolutePath()); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() @@ -810,7 +810,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { public void deleteSnapshotWithMissingIndexAndShardMetadataTest() throws Exception { Client client = client(); - Path repo = newTempDirPath(); + Path repo = createTempDir(); logger.info("--> creating repository at " + repo.toAbsolutePath()); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() @@ -849,7 +849,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { public void deleteSnapshotWithMissingMetadataTest() throws Exception { Client client = client(); - Path repo = newTempDirPath(); + Path repo = createTempDir(); logger.info("--> creating repository at " + repo.toAbsolutePath()); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() @@ -884,7 +884,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { public void deleteSnapshotWithCorruptedSnapshotFileTest() throws Exception { Client client = client(); - Path repo = newTempDirPath(); + Path repo = createTempDir(); logger.info("--> creating repository at " + repo.toAbsolutePath()); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() @@ -929,7 +929,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()))); + .put("location", createTempDir()))); createIndex("test-idx", "test-idx-closed"); ensureGreen(); @@ -955,7 +955,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()))); + .put("location", createTempDir()))); createIndex("test-idx"); ensureGreen(); @@ -976,7 +976,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()))); + .put("location", createTempDir()))); createIndex("test-idx-1", "test-idx-2", "test-idx-3"); ensureGreen(); @@ -1092,7 +1092,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { @Test public void moveShardWhileSnapshottingTest() throws Exception { Client client = client(); - Path repositoryLocation = newTempDirPath(); + Path repositoryLocation = createTempDir(); logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType(MockRepositoryModule.class.getCanonicalName()).setSettings( @@ -1154,7 +1154,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { @Test public void deleteRepositoryWhileSnapshottingTest() throws Exception { Client client = client(); - Path repositoryLocation = newTempDirPath(); + Path repositoryLocation = createTempDir(); logger.info("--> creating repository"); PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo") .setType(MockRepositoryModule.class.getCanonicalName()).setSettings( @@ -1239,7 +1239,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { Client client = client(); logger.info("--> creating repository"); - Path repositoryLocation = newTempDirPath(); + Path repositoryLocation = createTempDir(); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() .put("location", repositoryLocation) @@ -1297,7 +1297,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { Client client = client(); logger.info("--> creating repository"); - Path repositoryLocation = newTempDirPath(); + Path repositoryLocation = createTempDir(); boolean throttleSnapshot = randomBoolean(); boolean throttleRestore = randomBoolean(); assertAcked(client.admin().cluster().preparePutRepository("test-repo") @@ -1355,7 +1355,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { @Test public void snapshotStatusTest() throws Exception { Client client = client(); - Path repositoryLocation = newTempDirPath(); + Path repositoryLocation = createTempDir(); logger.info("--> creating repository"); PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo") .setType(MockRepositoryModule.class.getCanonicalName()).setSettings( @@ -1458,7 +1458,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)))); @@ -1506,7 +1506,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)))); @@ -1569,7 +1569,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)))); @@ -1675,7 +1675,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType(MockRepositoryModule.class.getCanonicalName()).setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)) .put("block_on_init", true) @@ -1727,7 +1727,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests { logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType(MockRepositoryModule.class.getCanonicalName()).setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath()) + .put("location", createTempDir()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)) )); diff --git a/src/test/java/org/elasticsearch/snapshots/SnapshotBackwardsCompatibilityTest.java b/src/test/java/org/elasticsearch/snapshots/SnapshotBackwardsCompatibilityTest.java index 10ca2e091d9..5d79fc8a6f8 100644 --- a/src/test/java/org/elasticsearch/snapshots/SnapshotBackwardsCompatibilityTest.java +++ b/src/test/java/org/elasticsearch/snapshots/SnapshotBackwardsCompatibilityTest.java @@ -59,7 +59,7 @@ public class SnapshotBackwardsCompatibilityTest extends ElasticsearchBackwardsCo logger.info("--> creating repository"); assertAcked(client().admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() - .put("location", newTempDirPath(LifecycleScope.SUITE).toAbsolutePath()) + .put("location", createTempDir().toAbsolutePath()) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000)))); String[] indicesBefore = new String[randomIntBetween(2,5)]; @@ -165,7 +165,7 @@ public class SnapshotBackwardsCompatibilityTest extends ElasticsearchBackwardsCo public void testSnapshotMoreThanOnce() throws ExecutionException, InterruptedException, IOException { Client client = client(); - final Path tempDir = newTempDirPath(LifecycleScope.SUITE).toAbsolutePath(); + final Path tempDir = createTempDir().toAbsolutePath(); logger.info("--> creating repository"); assertAcked(client.admin().cluster().preparePutRepository("test-repo") .setType("fs").setSettings(ImmutableSettings.settingsBuilder() diff --git a/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java b/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java index b44b69f5e4e..fe2eb17f654 100644 --- a/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java +++ b/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java @@ -21,6 +21,7 @@ package org.elasticsearch.snapshots.mockstore; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; + import org.elasticsearch.ElasticsearchException; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.metadata.MetaData; @@ -30,6 +31,7 @@ import org.elasticsearch.common.blobstore.BlobMetaData; import org.elasticsearch.common.blobstore.BlobPath; import org.elasticsearch.common.blobstore.BlobStore; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.snapshots.IndexShardRepository; import org.elasticsearch.repositories.RepositoryName; @@ -111,7 +113,7 @@ public class MockRepository extends FsRepository { } private static Settings localizeLocation(Settings settings, ClusterService clusterService) { - Path location = Paths.get(settings.get("location")); + Path location = PathUtils.get(settings.get("location")); location = location.resolve(clusterService.localNode().getId()); return settingsBuilder().put(settings).put("location", location.toAbsolutePath()).build(); } diff --git a/src/test/java/org/elasticsearch/test/AfterTestRule.java b/src/test/java/org/elasticsearch/test/AfterTestRule.java deleted file mode 100644 index e1a25690c58..00000000000 --- a/src/test/java/org/elasticsearch/test/AfterTestRule.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.test; - -import org.junit.rules.TestWatcher; -import org.junit.runner.Description; - -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * A {@link org.junit.rules.TestRule} that detects test failures and allows to run an arbitrary task after a test failed. - * Allows also to run an arbitrary task in any case, regardless of the test result. - * It is possible to force running the first arbitrary task from the outside, as if the test was failed, when e.g. it needs - * to be performed based on external events. - * - * We need it to be able to reset the suite level cluster after each failure, or if there is a problem - * during the after test operations. - */ -public class AfterTestRule extends TestWatcher { - - private final AtomicBoolean failed = new AtomicBoolean(false); - - private final Task task; - - public AfterTestRule(Task task) { - this.task = task; - } - - void forceFailure() { - failed.set(true); - } - - @Override - protected void failed(Throwable e, Description description) { - failed.set(true); - } - - @Override - protected void finished(Description description) { - if (failed.compareAndSet(true, false)) { - task.onTestFailed(); - } - task.onTestFinished(); - } - - /** - * Task to be executed after each test if required, no-op by default - */ - public static class Task { - /** - * The task that needs to be executed after a test fails - */ - void onTestFailed() { - - } - - /** - * The task that needs to be executed when a test is completed, regardless of its result - */ - void onTestFinished() { - - } - } -} diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchBackwardsCompatIntegrationTest.java b/src/test/java/org/elasticsearch/test/ElasticsearchBackwardsCompatIntegrationTest.java index efc629facf8..cba934593a0 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchBackwardsCompatIntegrationTest.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchBackwardsCompatIntegrationTest.java @@ -18,12 +18,14 @@ */ package org.elasticsearch.test; -import org.apache.lucene.util.AbstractRandomizedTest; +import com.carrotsearch.randomizedtesting.annotations.TestGroup; import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.Strings; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; @@ -34,14 +36,18 @@ import org.elasticsearch.transport.Transport; import org.elasticsearch.transport.TransportModule; import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.netty.NettyTransport; -import org.junit.Before; import org.junit.Ignore; import java.io.IOException; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Map; +import java.util.Random; import static org.hamcrest.Matchers.is; @@ -58,12 +64,12 @@ import static org.hamcrest.Matchers.is; *

* Note: this base class is still experimental and might have bugs or leave external processes running behind. *

- * Backwards compatibility tests are disabled by default via {@link org.apache.lucene.util.AbstractRandomizedTest.Backwards} annotation. + * Backwards compatibility tests are disabled by default via {@link Backwards} annotation. * The following system variables control the test execution: *
    *
  • * {@value #TESTS_BACKWARDS_COMPATIBILITY} enables / disables - * tests annotated with {@link org.apache.lucene.util.AbstractRandomizedTest.Backwards} (defaults to + * tests annotated with {@link Backwards} (defaults to * false) *
  • *
  • @@ -81,11 +87,29 @@ import static org.hamcrest.Matchers.is; * */ // the transportClientRatio is tricky here since we don't fully control the cluster nodes -@AbstractRandomizedTest.Backwards +@ElasticsearchBackwardsCompatIntegrationTest.Backwards @ElasticsearchIntegrationTest.ClusterScope(minNumDataNodes = 0, maxNumDataNodes = 2, scope = ElasticsearchIntegrationTest.Scope.SUITE, numClientNodes = 0, transportClientRatio = 0.0) @Ignore public abstract class ElasticsearchBackwardsCompatIntegrationTest extends ElasticsearchIntegrationTest { + /** + * Key used to set the path for the elasticsearch executable used to run backwards compatibility tests from + * via the commandline -D{@value #TESTS_BACKWARDS_COMPATIBILITY} + */ + public static final String TESTS_BACKWARDS_COMPATIBILITY = "tests.bwc"; + public static final String TESTS_BACKWARDS_COMPATIBILITY_VERSION = "tests.bwc.version"; + /** + * Key used to set the path for the elasticsearch executable used to run backwards compatibility tests from + * via the commandline -D{@value #TESTS_BACKWARDS_COMPATIBILITY_PATH} + */ + public static final String TESTS_BACKWARDS_COMPATIBILITY_PATH = "tests.bwc.path"; + /** + * Property that allows to adapt the tests behaviour to older features/bugs based on the input version + */ + private static final String TESTS_COMPATIBILITY = "tests.compatibility"; + + private static final Version GLOABL_COMPATIBILITY_VERSION = Version.fromString(compatibilityVersionProperty()); + private static Path backwardsCompatibilityPath() { String path = System.getProperty(TESTS_BACKWARDS_COMPATIBILITY_PATH); if (path == null || path.isEmpty()) { @@ -99,7 +123,7 @@ public abstract class ElasticsearchBackwardsCompatIntegrationTest extends Elasti throw new IllegalArgumentException("Backcompat elasticsearch version must be same major version as current. " + "backcompat: " + version + ", current: " + Version.CURRENT.toString()); } - Path file = Paths.get(path, "elasticsearch-" + version); + Path file = PathUtils.get(path, "elasticsearch-" + version); if (!Files.exists(file)) { throw new IllegalArgumentException("Backwards tests location is missing: " + file.toAbsolutePath()); } @@ -109,6 +133,53 @@ public abstract class ElasticsearchBackwardsCompatIntegrationTest extends Elasti return file; } + @Override + protected ImmutableSettings.Builder setRandomSettings(Random random, ImmutableSettings.Builder builder) { + if (globalCompatibilityVersion().before(Version.V_1_3_2)) { + // if we test against nodes before 1.3.2 we disable all the compression due to a known bug + // see #7210 + builder.put(RecoverySettings.INDICES_RECOVERY_COMPRESS, false); + } + return builder; + } + + /** + * Retruns the tests compatibility version. + */ + public Version compatibilityVersion() { + return compatibilityVersion(getClass()); + } + + private Version compatibilityVersion(Class clazz) { + if (clazz == Object.class || clazz == ElasticsearchIntegrationTest.class) { + return globalCompatibilityVersion(); + } + CompatibilityVersion annotation = clazz.getAnnotation(CompatibilityVersion.class); + if (annotation != null) { + return Version.smallest(Version.fromId(annotation.version()), compatibilityVersion(clazz.getSuperclass())); + } + return compatibilityVersion(clazz.getSuperclass()); + } + + /** + * Returns a global compatibility version that is set via the + * {@value #TESTS_COMPATIBILITY} or {@value #TESTS_BACKWARDS_COMPATIBILITY_VERSION} system property. + * If both are unset the current version is used as the global compatibility version. This + * compatibility version is used for static randomization. For per-suite compatibility version see + * {@link #compatibilityVersion()} + */ + public static Version globalCompatibilityVersion() { + return GLOABL_COMPATIBILITY_VERSION; + } + + private static String compatibilityVersionProperty() { + final String version = System.getProperty(TESTS_COMPATIBILITY); + if (Strings.hasLength(version)) { + return version; + } + return System.getProperty(TESTS_BACKWARDS_COMPATIBILITY_VERSION); + } + public CompositeTestCluster backwardsCluster() { return (CompositeTestCluster) cluster(); } @@ -193,4 +264,25 @@ public abstract class ElasticsearchBackwardsCompatIntegrationTest extends Elasti protected Settings externalNodeSettings(int nodeOrdinal) { return addLoggerSettings(commonNodeSettings(nodeOrdinal)); } + + /** + * Annotation for backwards compat tests + */ + @Inherited + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.TYPE) + @TestGroup(enabled = false, sysProperty = ElasticsearchBackwardsCompatIntegrationTest.TESTS_BACKWARDS_COMPATIBILITY) + public @interface Backwards { + } + + /** + * If a test is annotated with {@link CompatibilityVersion} + * all randomized settings will only contain settings or mappings which are compatible with the specified version ID. + */ + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE}) + @Ignore + public @interface CompatibilityVersion { + int version(); + } } diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java index 02ad6c76af0..f1f7dd57cec 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java @@ -20,20 +20,23 @@ package org.elasticsearch.test; import com.carrotsearch.randomizedtesting.LifecycleScope; import com.carrotsearch.randomizedtesting.RandomizedContext; +import com.carrotsearch.randomizedtesting.RandomizedTest; import com.carrotsearch.randomizedtesting.Randomness; +import com.carrotsearch.randomizedtesting.annotations.TestGroup; import com.carrotsearch.randomizedtesting.generators.RandomInts; import com.carrotsearch.randomizedtesting.generators.RandomPicks; import com.google.common.base.Joiner; import com.google.common.base.Predicate; import com.google.common.collect.Lists; + +import org.apache.commons.lang3.StringUtils; import org.apache.http.impl.client.HttpClients; import org.apache.lucene.store.StoreRateLimiting; -import org.apache.lucene.util.AbstractRandomizedTest; import org.apache.lucene.util.IOUtils; +import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TestUtil; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ExceptionsHelper; -import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; @@ -75,7 +78,7 @@ import org.elasticsearch.common.Priority; import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.collect.Tuple; -import org.elasticsearch.common.io.FileSystemUtils; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; @@ -93,11 +96,11 @@ import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.discovery.zen.elect.ElectMasterService; import org.elasticsearch.index.IndexService; +import org.elasticsearch.index.codec.CodecService; import org.elasticsearch.index.fielddata.FieldDataType; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.FieldMapper.Loading; -import org.elasticsearch.index.mapper.internal.AllFieldMapper; import org.elasticsearch.index.mapper.internal.SizeFieldMapper; import org.elasticsearch.index.mapper.internal.SourceFieldMapper; import org.elasticsearch.index.mapper.internal.TimestampFieldMapper; @@ -146,7 +149,6 @@ import java.net.InetSocketAddress; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -168,7 +170,6 @@ import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS; import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; -import static org.elasticsearch.test.InternalTestCluster.clusterName; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout; @@ -227,9 +228,25 @@ import static org.hamcrest.Matchers.notNullValue; *

    */ @Ignore -@AbstractRandomizedTest.Integration +@ElasticsearchIntegrationTest.Integration +@LuceneTestCase.SuppressFileSystems("ExtrasFS") // doesn't work with potential multi data path from test cluster yet public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase { + /** + * Property that allows to control whether the Integration tests are run (default) or not + */ + public static final String SYSPROP_INTEGRATION = "tests.integration"; + + /** + * Annotation for integration tests + */ + @Inherited + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.TYPE) + @TestGroup(enabled = true, sysProperty = ElasticsearchIntegrationTest.SYSPROP_INTEGRATION) + public @interface Integration { + } + /** node names of the corresponding clusters will start with these prefixes */ public static final String SUITE_CLUSTER_NODE_PREFIX = "node_s"; public static final String TEST_CLUSTER_NODE_PREFIX = "node_t"; @@ -354,7 +371,14 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase randomSettingsBuilder.put(SETTING_NUMBER_OF_SHARDS, numberOfShards()) .put(SETTING_NUMBER_OF_REPLICAS, numberOfReplicas()); - randomSettingsBuilder.put("index.codec", randomFrom("default", "best_compression")); + // if the test class is annotated with SuppressCodecs("*"), it means don't use lucene's codec randomization + // otherwise, use it, it has assertions and so on that can find bugs. + SuppressCodecs annotation = getClass().getAnnotation(SuppressCodecs.class); + if (annotation != null && annotation.value().length == 1 && "*".equals(annotation.value()[0])) { + randomSettingsBuilder.put("index.codec", randomFrom(CodecService.DEFAULT_CODEC, CodecService.BEST_COMPRESSION_CODEC)); + } else { + randomSettingsBuilder.put("index.codec", CodecService.LUCENE_DEFAULT_CODEC); + } XContentBuilder mappings = null; if (frequently() && randomDynamicTemplates()) { mappings = XContentFactory.jsonBuilder().startObject().startObject("_default_"); @@ -450,7 +474,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase } } - private static ImmutableSettings.Builder setRandomSettings(Random random, ImmutableSettings.Builder builder) { + protected ImmutableSettings.Builder setRandomSettings(Random random, ImmutableSettings.Builder builder) { setRandomMerge(random, builder); setRandomTranslogSettings(random, builder); setRandomNormsLoading(random, builder); @@ -502,11 +526,6 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase builder.put(IndicesFieldDataCache.FIELDDATA_CACHE_CONCURRENCY_LEVEL, RandomInts.randomIntBetween(random, 1, 32)); builder.put(IndicesFilterCache.INDICES_CACHE_FILTER_CONCURRENCY_LEVEL, RandomInts.randomIntBetween(random, 1, 32)); } - if (globalCompatibilityVersion().before(Version.V_1_3_2)) { - // if we test against nodes before 1.3.2 we disable all the compression due to a known bug - // see #7210 - builder.put(RecoverySettings.INDICES_RECOVERY_COMPRESS, false); - } if (random.nextBoolean()) { builder.put(NettyTransport.PING_SCHEDULE, RandomInts.randomIntBetween(random, 100, 2000) + "ms"); } @@ -650,49 +669,12 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase } finally { if (!success) { // if we failed here that means that something broke horribly so we should clear all clusters - afterTestRule.forceFailure(); + // TODO: just let the exception happen, WTF is all this horseshit + // afterTestRule.forceFailure(); } } } - @Override - protected final AfterTestRule.Task afterTestTask() { - return new AfterTestRule.Task() { - @Override - public void onTestFailed () { - //we can't clear clusters after failure when using suite scoped tests, as we would need to call again - //initializeSuiteScope but that is static and can only be called from beforeClass - if (runTestScopeLifecycle()) { - // If there was a problem during the afterTest, we clear all clusters. - // We do the same in case we just had a test failure to make sure subsequent - // tests get a new / clean cluster - try { - clearClusters(); - } catch (IOException e) { - throw new RuntimeException("unable to clear clusters", e); - } - afterTestFailed(); - currentCluster = null; - } - } - - @Override - public void onTestFinished () { - if (runTestScopeLifecycle()) { - if (currentCluster != null) { - // this can be null if the test fails due to static initialization ie. missing parameter on the cmd - try { - currentCluster.afterTest(); - } catch (IOException e) { - throw new RuntimeException("error during afterTest", e); - } - currentCluster = null; - } - } - } - }; - } - /** * Allows to execute some additional task after a test is failed, right after we cleared the clusters */ @@ -801,7 +783,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase } // 30% of the time if (randomInt(9) < 3) { - final Path dataPath = newTempDirPath(LifecycleScope.SUITE); + final Path dataPath = createTempDir(); logger.info("using custom data_path for index: [{}]", dataPath); builder.put(IndexMetaData.SETTING_DATA_PATH, dataPath); } @@ -1481,7 +1463,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase * The scope of a test cluster used together with * {@link org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope} annotations on {@link org.elasticsearch.test.ElasticsearchIntegrationTest} subclasses. */ - public static enum Scope { + public enum Scope { /** * A cluster shared across all method in a single test suite */ @@ -1735,9 +1717,9 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase maxNumDataNodes = getMaxNumDataNodes(); } - return new InternalTestCluster(seed, newTempDirPath(nodeDirScope), minNumDataNodes, maxNumDataNodes, - clusterName(scope.name(), Integer.toString(CHILD_JVM_ID), seed), settingsSource, getNumClientNodes(), - InternalTestCluster.DEFAULT_ENABLE_HTTP_PIPELINING, CHILD_JVM_ID, nodePrefix); + return new InternalTestCluster(seed, createTempDir(), minNumDataNodes, maxNumDataNodes, + scope.name() + "-cluster", settingsSource, getNumClientNodes(), + InternalTestCluster.DEFAULT_ENABLE_HTTP_PIPELINING, nodePrefix); } /** @@ -1793,7 +1775,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase // It sounds like some Java Time Zones are unknown by JODA. For example: Asia/Riyadh88 // We need to fallback in that case to a known time zone try { - timeZone = DateTimeZone.forTimeZone(randomTimeZone()); + timeZone = DateTimeZone.forTimeZone(RandomizedTest.randomTimeZone()); } catch (IllegalArgumentException e) { timeZone = DateTimeZone.forOffsetHours(randomIntBetween(-12, 12)); } @@ -1833,7 +1815,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase * Asserts that there are no files in the specified path */ public void assertPathHasBeenCleared(String path) throws Exception { - assertPathHasBeenCleared(Paths.get(path)); + assertPathHasBeenCleared(PathUtils.get(path)); } /** @@ -1912,10 +1894,11 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase clearClusters(); } SUITE_SEED = null; + currentCluster = null; } private static void initializeSuiteScope() throws Exception { - Class targetClass = getContext().getTargetClass(); + Class targetClass = getTestClass(); /** * Note we create these test class instance via reflection * since JUnit creates a new instance per test and that is also @@ -1953,15 +1936,27 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase * Return settings that could be used to start a node that has the given zipped home directory. */ protected Settings prepareBackwardsDataDir(Path backwardsIndex, Object... settings) throws IOException { - Path indexDir = newTempDirPath(); + Path indexDir = createTempDir(); Path dataDir = indexDir.resolve("data"); try (InputStream stream = Files.newInputStream(backwardsIndex)) { TestUtil.unzip(stream, indexDir); } assertTrue(Files.exists(dataDir)); - Path[] list = FileSystemUtils.files(dataDir); + + // list clusters in the datapath, ignoring anything from extrasfs + final Path[] list; + try (DirectoryStream stream = Files.newDirectoryStream(dataDir)) { + List dirs = new ArrayList<>(); + for (Path p : stream) { + if (!p.getFileName().toString().startsWith("extra")) { + dirs.add(p); + } + } + list = dirs.toArray(new Path[0]); + } + if (list.length != 1) { - throw new IllegalStateException("Backwards index must contain exactly one cluster"); + throw new IllegalStateException("Backwards index must contain exactly one cluster\n" + StringUtils.join(list, "\n")); } Path src = list[0]; Path dest = dataDir.resolve(internalCluster().getClusterName()); diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchLuceneTestCase.java b/src/test/java/org/elasticsearch/test/ElasticsearchLuceneTestCase.java deleted file mode 100644 index 7c86f99aafc..00000000000 --- a/src/test/java/org/elasticsearch/test/ElasticsearchLuceneTestCase.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.test; - -import com.carrotsearch.randomizedtesting.RandomizedTest; -import com.carrotsearch.randomizedtesting.annotations.Listeners; -import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering; -import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; -import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope; -import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite; -import org.apache.lucene.codecs.Codec; -import org.apache.lucene.util.LuceneTestCase; -import org.apache.lucene.util.LuceneTestCase.SuppressFileSystems; -import org.apache.lucene.util.TimeUnits; -import org.elasticsearch.test.junit.listeners.LoggingListener; -import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter; - - -/** - * Base testcase for lucene based testing. This class should be used if low level lucene features are tested. - */ -@Listeners({ - ReproduceInfoPrinter.class, - LoggingListener.class -}) -@ThreadLeakScope(Scope.SUITE) -@ThreadLeakLingering(linger = 5000) // 5 sec lingering -@TimeoutSuite(millis = TimeUnits.HOUR) -@LuceneTestCase.SuppressSysoutChecks(bugUrl = "we log a lot on purpose") -@SuppressFileSystems("*") // we aren't ready for this yet. -public abstract class ElasticsearchLuceneTestCase extends LuceneTestCase { - - private static final Codec DEFAULT_CODEC = Codec.getDefault(); - - /** - * Returns the lucene default codec without any randomization - */ - public static Codec actualDefaultCodec() { - return DEFAULT_CODEC; - } - - /** - * Forcefully reset the default codec - */ - public static void forceDefaultCodec() { - Codec.setDefault(DEFAULT_CODEC); - } - - public static int scaledRandomIntBetween(int min, int max) { - return RandomizedTest.scaledRandomIntBetween(min, max); - } -} diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchSingleNodeLuceneTestCase.java b/src/test/java/org/elasticsearch/test/ElasticsearchSingleNodeLuceneTestCase.java deleted file mode 100644 index c815c56b31d..00000000000 --- a/src/test/java/org/elasticsearch/test/ElasticsearchSingleNodeLuceneTestCase.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.test; - -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.IndexService; -import org.elasticsearch.search.internal.SearchContext; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Ignore; - -/** - * Like {@link ElasticsearchSingleNodeTest} but for tests that need to extend - * {@link ElasticsearchLuceneTestCase}. - */ -@Ignore -public abstract class ElasticsearchSingleNodeLuceneTestCase extends ElasticsearchLuceneTestCase { - - @After - public void cleanup() { - ElasticsearchSingleNodeTest.cleanup(resetNodeAfterTest()); - } - - - @BeforeClass - public static void setUpClass() throws Exception { - ElasticsearchSingleNodeTest.setUpClass(); - } - - @AfterClass - public static void tearDownClass() { - ElasticsearchSingleNodeTest.tearDownClass(); - } - - /** - * This method returns true if the node that is used in the background should be reset - * after each test. This is useful if the test changes the cluster state metadata etc. The default is - * false. - */ - protected boolean resetNodeAfterTest() { - return false; - } - - /** - * Create a new index on the singleton node with empty index settings. - */ - protected static IndexService createIndex(String index) { - return ElasticsearchSingleNodeTest.createIndex(index); - } - - /** - * Create a new index on the singleton node with the provided index settings. - */ - protected static IndexService createIndex(String index, Settings settings) { - return ElasticsearchSingleNodeTest.createIndex(index, settings); - } - - /** - * Create a new search context. - */ - protected static SearchContext createSearchContext(IndexService indexService) { - return ElasticsearchSingleNodeTest.createSearchContext(indexService); - } -} diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchSingleNodeTest.java b/src/test/java/org/elasticsearch/test/ElasticsearchSingleNodeTest.java index af79a55878a..c1c666dde3c 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchSingleNodeTest.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchSingleNodeTest.java @@ -121,7 +121,7 @@ public abstract class ElasticsearchSingleNodeTest extends ElasticsearchTestCase private static Node newNode() { Node build = NodeBuilder.nodeBuilder().local(true).data(true).settings(ImmutableSettings.builder() .put(ClusterName.SETTING, clusterName()) - .put("path.home", newTempDirPath(LifecycleScope.SUITE)) + .put("path.home", createTempDir()) .put("node.name", nodeName()) .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) @@ -154,7 +154,7 @@ public abstract class ElasticsearchSingleNodeTest extends ElasticsearchTestCase * Returns the name of the cluster used for the single test node. */ public static String clusterName() { - return InternalTestCluster.clusterName("single-node", Integer.toString(CHILD_JVM_ID), randomLong()); + return "single-node-cluster"; } /** diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java b/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java index f4009d78d72..90792c78c21 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java @@ -18,28 +18,35 @@ */ package org.elasticsearch.test; -import com.carrotsearch.randomizedtesting.LifecycleScope; +import com.carrotsearch.randomizedtesting.RandomizedContext; import com.carrotsearch.randomizedtesting.RandomizedTest; -import com.carrotsearch.randomizedtesting.annotations.*; +import com.carrotsearch.randomizedtesting.annotations.Listeners; +import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering; +import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope; +import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite; +import com.carrotsearch.randomizedtesting.generators.RandomInts; +import com.carrotsearch.randomizedtesting.generators.RandomPicks; +import com.carrotsearch.randomizedtesting.generators.RandomStrings; import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableList; -import org.apache.lucene.store.MockDirectoryWrapper; -import org.apache.lucene.util.AbstractRandomizedTest; -import org.apache.lucene.util.LuceneTestCase; -import org.apache.lucene.util.TimeUnits; +import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.uninverting.UninvertingReader; +import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util.LuceneTestCase.SuppressCodecs; +import org.apache.lucene.util.TestUtil; +import org.apache.lucene.util.TimeUnits; import org.elasticsearch.Version; import org.elasticsearch.client.Requests; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.routing.DjbHashFunction; -import org.elasticsearch.common.Strings; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.EsAbortPolicy; +import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.env.Environment; @@ -47,23 +54,26 @@ import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.test.cache.recycler.MockBigArrays; import org.elasticsearch.test.cache.recycler.MockPageCacheRecycler; import org.elasticsearch.test.junit.listeners.LoggingListener; +import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter; import org.elasticsearch.test.search.MockSearchService; -import org.elasticsearch.test.store.MockDirectoryHelper; import org.elasticsearch.threadpool.ThreadPool; -import org.junit.*; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; import java.io.Closeable; import java.io.IOException; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.net.URI; +import java.nio.file.FileSystem; import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Formatter; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Random; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -75,46 +85,298 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAllS /** * Base testcase for randomized unit testing with Elasticsearch */ +@Listeners({ + ReproduceInfoPrinter.class, + LoggingListener.class +}) @ThreadLeakScope(Scope.SUITE) @ThreadLeakLingering(linger = 5000) // 5 sec lingering -@TimeoutSuite(millis = 20 * TimeUnits.MINUTE) // timeout the suite after 20min and fail the test. -@Listeners(LoggingListener.class) -@LuceneTestCase.SuppressFileSystems("*") // we aren't ready for this yet. -public abstract class ElasticsearchTestCase extends AbstractRandomizedTest { - - private static Thread.UncaughtExceptionHandler defaultHandler; - +@TimeoutSuite(millis = 20 * TimeUnits.MINUTE) +@LuceneTestCase.SuppressSysoutChecks(bugUrl = "we log a lot on purpose") +// we suppress pretty much all the lucene codecs for now, except asserting +// assertingcodec is the winner for a codec here: it finds bugs and gives clear exceptions. +@SuppressCodecs({ + "SimpleText", "Memory", "CheapBastard", "Direct", "Compressing", "FST50", "FSTOrd50", + "TestBloomFilteredLucenePostings", "MockRandom", "BlockTreeOrds", "LuceneFixedGap", + "LuceneVarGapFixedInterval", "LuceneVarGapDocFreqInterval", "Lucene50" +}) +@LuceneTestCase.SuppressReproduceLine +public abstract class ElasticsearchTestCase extends LuceneTestCase { + + static { + SecurityHack.ensureInitialized(); + } + protected final ESLogger logger = Loggers.getLogger(getClass()); - public static final String TESTS_SECURITY_MANAGER = System.getProperty("tests.security.manager"); - - public static final String JAVA_SECURTY_POLICY = System.getProperty("java.security.policy"); - - /** - * Property that allows to adapt the tests behaviour to older features/bugs based on the input version - */ - private static final String TESTS_COMPATIBILITY = "tests.compatibility"; - - private static final Version GLOABL_COMPATIBILITY_VERSION = Version.fromString(compatibilityVersionProperty()); - - public static final boolean ASSERTIONS_ENABLED; - static { - boolean enabled = false; - assert enabled = true; - ASSERTIONS_ENABLED = enabled; - if (Boolean.parseBoolean(Strings.hasLength(TESTS_SECURITY_MANAGER) ? TESTS_SECURITY_MANAGER : "true") && JAVA_SECURTY_POLICY != null) { - System.setSecurityManager(new SecurityManager()); - } + // ----------------------------------------------------------------- + // Suite and test case setup/cleanup. + // ----------------------------------------------------------------- + // TODO: Parent/child and other things does not work with the query cache + // We must disable query cache for both suite and test to override lucene, but LTC resets it after the suite + + @BeforeClass + public static void disableQueryCacheSuite() { + IndexSearcher.setDefaultQueryCache(null); + } + + @Before + public final void disableQueryCache() { + IndexSearcher.setDefaultQueryCache(null); + } + + // setup mock filesystems for this test run. we change PathUtils + // so that all accesses are plumbed thru any mock wrappers + + @BeforeClass + public static void setFileSystem() throws Exception { + Field field = PathUtils.class.getDeclaredField("DEFAULT"); + field.setAccessible(true); + FileSystem mock = LuceneTestCase.getBaseTempDirForTestClass().getFileSystem(); + field.set(null, mock); + assertEquals(mock, PathUtils.getDefaultFileSystem()); + } + + @AfterClass + public static void restoreFileSystem() throws Exception { + Field field1 = PathUtils.class.getDeclaredField("ACTUAL_DEFAULT"); + field1.setAccessible(true); + Field field2 = PathUtils.class.getDeclaredField("DEFAULT"); + field2.setAccessible(true); + field2.set(null, field1.get(null)); } + // setup a default exception handler which knows when and how to print a stacktrace + private static Thread.UncaughtExceptionHandler defaultHandler; + + @BeforeClass + public static void setDefaultExceptionHandler() throws Exception { + defaultHandler = Thread.getDefaultUncaughtExceptionHandler(); + Thread.setDefaultUncaughtExceptionHandler(new ElasticsearchUncaughtExceptionHandler(defaultHandler)); + } + + @AfterClass + public static void restoreDefaultExceptionHandler() throws Exception { + Thread.setDefaultUncaughtExceptionHandler(defaultHandler); + } + + // randomize content type for request builders + + @BeforeClass + public static void setContentType() throws Exception { + Requests.CONTENT_TYPE = randomFrom(XContentType.values()); + Requests.INDEX_CONTENT_TYPE = randomFrom(XContentType.values()); + } + + @AfterClass + public static void restoreContentType() { + Requests.CONTENT_TYPE = XContentType.SMILE; + Requests.INDEX_CONTENT_TYPE = XContentType.JSON; + } + + // randomize and override the number of cpus so tests reproduce regardless of real number of cpus + + @BeforeClass + public static void setProcessors() { + int numCpu = TestUtil.nextInt(random(), 1, 4); + System.setProperty(EsExecutors.DEFAULT_SYSPROP, Integer.toString(numCpu)); + assertEquals(numCpu, EsExecutors.boundedNumberOfProcessors(ImmutableSettings.EMPTY)); + } + + @AfterClass + public static void restoreProcessors() { + System.clearProperty(EsExecutors.DEFAULT_SYSPROP); + } + + // check some things (like MockDirectoryWrappers) are closed where we currently + // manage them. TODO: can we add these to LuceneTestCase.closeAfterSuite directly? + // or something else simpler instead of the fake closeables? + + @BeforeClass + public static void setAfterSuiteAssertions() throws Exception { + closeAfterSuite(new Closeable() { + @Override + public void close() throws IOException { + assertAllFilesClosed(); + } + }); + closeAfterSuite(new Closeable() { + @Override + public void close() throws IOException { + assertAllSearchersClosed(); + } + }); + } + @After - public void ensureNoFieldCacheUse() { + public final void ensureCleanedUp() throws Exception { + MockPageCacheRecycler.ensureAllPagesAreReleased(); + MockBigArrays.ensureAllArraysAreReleased(); // field cache should NEVER get loaded. String[] entries = UninvertingReader.getUninvertedStats(); assertEquals("fieldcache must never be used, got=" + Arrays.toString(entries), 0, entries.length); } + // this must be a separate method from other ensure checks above so suite scoped integ tests can call...TODO: fix that + @After + public final void ensureAllSearchContextsReleased() throws Exception { + assertBusy(new Runnable() { + @Override + public void run() { + MockSearchService.assertNoInFLightContext(); + } + }); + } + + // mockdirectorywrappers currently set this boolean if checkindex fails + // TODO: can we do this cleaner??? + + /** MockFSDirectoryService sets this: */ + public static boolean checkIndexFailed; + + @Before + public final void resetCheckIndexStatus() throws Exception { + checkIndexFailed = false; + } + + @After + public final void ensureCheckIndexPassed() throws Exception { + assertFalse("at least one shard failed CheckIndex", checkIndexFailed); + } + + // ----------------------------------------------------------------- + // Test facilities and facades for subclasses. + // ----------------------------------------------------------------- + + // TODO: replaces uses of getRandom() with random() + // TODO: decide on one set of naming for between/scaledBetween and remove others + // TODO: replace frequently() with usually() + + /** Shortcut for {@link RandomizedContext#getRandom()}. Use {@link #random()} instead. */ + public static Random getRandom() { + // TODO: replace uses of this function with random() + return random(); + } + + /** + * Returns a "scaled" random number between min and max (inclusive). + * @see RandomizedTest#scaledRandomIntBetween(int, int); + */ + public static int scaledRandomIntBetween(int min, int max) { + return RandomizedTest.scaledRandomIntBetween(min, max); + } + + /** + * A random integer from min to max (inclusive). + * @see #scaledRandomIntBetween(int, int) + */ + public static int randomIntBetween(int min, int max) { + return RandomInts.randomIntBetween(random(), min, max); + } + + /** + * Returns a "scaled" number of iterations for loops which can have a variable + * iteration count. This method is effectively + * an alias to {@link #scaledRandomIntBetween(int, int)}. + */ + public static int iterations(int min, int max) { + return scaledRandomIntBetween(min, max); + } + + /** + * An alias for {@link #randomIntBetween(int, int)}. + * + * @see #scaledRandomIntBetween(int, int) + */ + public static int between(int min, int max) { + return randomIntBetween(min, max); + } + + /** + * The exact opposite of {@link #rarely()}. + */ + public static boolean frequently() { + return !rarely(); + } + + public static boolean randomBoolean() { + return random().nextBoolean(); + } + + public static byte randomByte() { return (byte) random().nextInt(); } + public static short randomShort() { return (short) random().nextInt(); } + public static int randomInt() { return random().nextInt(); } + public static float randomFloat() { return random().nextFloat(); } + public static double randomDouble() { return random().nextDouble(); } + public static long randomLong() { return random().nextLong(); } + + /** A random integer from 0..max (inclusive). */ + public static int randomInt(int max) { + return RandomizedTest.randomInt(max); + } + + /** Pick a random object from the given array. The array must not be empty. */ + public static T randomFrom(T... array) { + return RandomPicks.randomFrom(random(), array); + } + + /** Pick a random object from the given list. */ + public static T randomFrom(List list) { + return RandomPicks.randomFrom(random(), list); + } + + public static String randomAsciiOfLengthBetween(int minCodeUnits, int maxCodeUnits) { + return RandomizedTest.randomAsciiOfLengthBetween(minCodeUnits, maxCodeUnits); + } + + public static String randomAsciiOfLength(int codeUnits) { + return RandomizedTest.randomAsciiOfLength(codeUnits); + } + + public static String randomUnicodeOfLengthBetween(int minCodeUnits, int maxCodeUnits) { + return RandomizedTest.randomUnicodeOfLengthBetween(minCodeUnits, maxCodeUnits); + } + + public static String randomUnicodeOfLength(int codeUnits) { + return RandomizedTest.randomUnicodeOfLength(codeUnits); + } + + public static String randomUnicodeOfCodepointLengthBetween(int minCodePoints, int maxCodePoints) { + return RandomizedTest.randomUnicodeOfCodepointLengthBetween(minCodePoints, maxCodePoints); + } + + public static String randomUnicodeOfCodepointLength(int codePoints) { + return RandomizedTest.randomUnicodeOfCodepointLength(codePoints); + } + + public static String randomRealisticUnicodeOfLengthBetween(int minCodeUnits, int maxCodeUnits) { + return RandomizedTest.randomRealisticUnicodeOfLengthBetween(minCodeUnits, maxCodeUnits); + } + + public static String randomRealisticUnicodeOfLength(int codeUnits) { + return RandomizedTest.randomRealisticUnicodeOfLength(codeUnits); + } + + public static String randomRealisticUnicodeOfCodepointLengthBetween(int minCodePoints, int maxCodePoints) { + return RandomizedTest.randomRealisticUnicodeOfCodepointLengthBetween(minCodePoints, maxCodePoints); + } + + public static String randomRealisticUnicodeOfCodepointLength(int codePoints) { + return RandomizedTest.randomRealisticUnicodeOfCodepointLength(codePoints); + } + + public static String[] generateRandomStringArray(int maxArraySize, int maxStringSize, boolean allowNull) { + if (allowNull && random().nextBoolean()) { + return null; + } + String[] array = new String[random().nextInt(maxArraySize)]; // allow empty arrays + for (int i = 0; i < array.length; i++) { + array[i] = RandomStrings.randomAsciiOfLength(random(), maxStringSize); + } + return array; + } + /** * Runs the code block for 10 seconds waiting for no assertion to trip. */ @@ -163,8 +425,7 @@ public abstract class ElasticsearchTestCase extends AbstractRandomizedTest { throw e; } } - - + public static boolean awaitBusy(Predicate breakPredicate) throws InterruptedException { return awaitBusy(breakPredicate, 10, TimeUnit.SECONDS); } @@ -187,10 +448,18 @@ public abstract class ElasticsearchTestCase extends AbstractRandomizedTest { return breakPredicate.apply(null); } - private static final String[] numericTypes = new String[]{"byte", "short", "integer", "long"}; + public static boolean terminate(ExecutorService... services) throws InterruptedException { + boolean terminated = true; + for (ExecutorService service : services) { + if (service != null) { + terminated &= ThreadPool.terminate(service, 10, TimeUnit.SECONDS); + } + } + return terminated; + } - public static String randomNumericType(Random random) { - return numericTypes[random.nextInt(numericTypes.length)]; + public static boolean terminate(ThreadPool service) throws InterruptedException { + return ThreadPool.terminate(service, 10, TimeUnit.SECONDS); } /** @@ -200,191 +469,41 @@ public abstract class ElasticsearchTestCase extends AbstractRandomizedTest { * return URL encoded paths if the parent path contains spaces or other * non-standard characters. */ - public Path getResourcePath(String relativePath) { - URI uri = URI.create(getClass().getResource(relativePath).toString()); - return Paths.get(uri); - } - - @After - public void ensureAllPagesReleased() throws Exception { - MockPageCacheRecycler.ensureAllPagesAreReleased(); - } - - @After - public void ensureAllArraysReleased() throws Exception { - MockBigArrays.ensureAllArraysAreReleased(); - } - - @After - public void ensureAllSearchContextsReleased() throws Exception { - assertBusy(new Runnable() { - @Override - public void run() { - MockSearchService.assertNoInFLightContext(); - } - }); - } - - public static boolean hasUnclosedWrapper() { - for (MockDirectoryWrapper w : MockDirectoryHelper.wrappers) { - if (w.isOpen()) { - return true; - } - } - return false; - } - - @BeforeClass - public static void setBeforeClass() throws Exception { - closeAfterSuite(new Closeable() { - @Override - public void close() throws IOException { - assertAllFilesClosed(); - } - }); - closeAfterSuite(new Closeable() { - @Override - public void close() throws IOException { - assertAllSearchersClosed(); - } - }); - defaultHandler = Thread.getDefaultUncaughtExceptionHandler(); - Thread.setDefaultUncaughtExceptionHandler(new ElasticsearchUncaughtExceptionHandler(defaultHandler)); - Requests.CONTENT_TYPE = randomXContentType(); - Requests.INDEX_CONTENT_TYPE = randomXContentType(); - } - - public static XContentType randomXContentType() { - return randomFrom(XContentType.values()); - } - - @AfterClass - public static void resetAfterClass() { - Thread.setDefaultUncaughtExceptionHandler(defaultHandler); - Requests.CONTENT_TYPE = XContentType.SMILE; - Requests.INDEX_CONTENT_TYPE = XContentType.JSON; - } - - public static boolean maybeDocValues() { - return randomBoolean(); - } - - private static final List SORTED_VERSIONS; - - static { - Field[] declaredFields = Version.class.getDeclaredFields(); - Set ids = new HashSet<>(); - for (Field field : declaredFields) { - final int mod = field.getModifiers(); - if (Modifier.isStatic(mod) && Modifier.isFinal(mod) && Modifier.isPublic(mod)) { - if (field.getType() == Version.class) { - try { - Version object = (Version) field.get(null); - ids.add(object.id); - } catch (Throwable e) { - throw new RuntimeException(e); - } - } - } - } - List idList = new ArrayList<>(ids); - Collections.sort(idList); - Collections.reverse(idList); - ImmutableList.Builder version = ImmutableList.builder(); - for (Integer integer : idList) { - version.add(Version.fromId(integer)); - } - SORTED_VERSIONS = version.build(); - } - - /** - * @return the {@link Version} before the {@link Version#CURRENT} - */ - public static Version getPreviousVersion() { - Version version = SORTED_VERSIONS.get(1); - assert version.before(Version.CURRENT); - return version; - } - - /** - * A random {@link Version}. - * - * @return a random {@link Version} from all available versions - */ - public static Version randomVersion() { - return randomVersion(getRandom()); - } - - /** - * A random {@link Version}. - * - * @param random - * the {@link Random} to use to generate the random version - * - * @return a random {@link Version} from all available versions - */ - public static Version randomVersion(Random random) { - return SORTED_VERSIONS.get(random.nextInt(SORTED_VERSIONS.size())); - } - - /** - * Returns immutable list of all known versions. - */ - public static List allVersions() { - return Collections.unmodifiableList(SORTED_VERSIONS); - } - - /** - * A random {@link Version} from minVersion to - * maxVersion (inclusive). - * - * @param minVersion - * the minimum version (inclusive) - * @param maxVersion - * the maximum version (inclusive) - * @return a random {@link Version} from minVersion to - * maxVersion (inclusive) - */ - public static Version randomVersionBetween(Version minVersion, Version maxVersion) { - return randomVersionBetween(getRandom(), minVersion, maxVersion); - } - - /** - * A random {@link Version} from minVersion to - * maxVersion (inclusive). - * - * @param random - * the {@link Random} to use to generate the random version - * @param minVersion - * the minimum version (inclusive) - * @param maxVersion - * the maximum version (inclusive) - * @return a random {@link Version} from minVersion to - * maxVersion (inclusive) - */ - public static Version randomVersionBetween(Random random, Version minVersion, Version maxVersion) { - int minVersionIndex = SORTED_VERSIONS.size(); - if (minVersion != null) { - minVersionIndex = SORTED_VERSIONS.indexOf(minVersion); - } - int maxVersionIndex = 0; - if (maxVersion != null) { - maxVersionIndex = SORTED_VERSIONS.indexOf(maxVersion); - } - if (minVersionIndex == -1) { - throw new IllegalArgumentException("minVersion [" + minVersion + "] does not exist."); - } else if (maxVersionIndex == -1) { - throw new IllegalArgumentException("maxVersion [" + maxVersion + "] does not exist."); - } else { - // minVersionIndex is inclusive so need to add 1 to this index - int range = minVersionIndex + 1 - maxVersionIndex; - return SORTED_VERSIONS.get(maxVersionIndex + random.nextInt(range)); + @Override + public Path getDataPath(String relativePath) { + // we override LTC behavior here: wrap even resources with mockfilesystems, + // because some code is buggy when it comes to multiple nio.2 filesystems + // (e.g. FileSystemUtils, and likely some tests) + try { + return PathUtils.get(getClass().getResource(relativePath).toURI()); + } catch (Exception e) { + throw new RuntimeException("resource not found: " + relativePath, e); } } - /** - * Return consistent index settings for the provided index version. - */ + /** Returns a random number of temporary paths. */ + public String[] tmpPaths() { + final int numPaths = TestUtil.nextInt(random(), 1, 3); + final String[] absPaths = new String[numPaths]; + for (int i = 0; i < numPaths; i++) { + absPaths[i] = createTempDir().toAbsolutePath().toString(); + } + return absPaths; + } + + public NodeEnvironment newNodeEnvironment() throws IOException { + return newNodeEnvironment(ImmutableSettings.EMPTY); + } + + public NodeEnvironment newNodeEnvironment(Settings settings) throws IOException { + Settings build = ImmutableSettings.builder() + .put(settings) + .put("path.home", createTempDir().toAbsolutePath()) + .putArray("path.data", tmpPaths()).build(); + return new NodeEnvironment(build, new Environment(build)); + } + + /** Return consistent index settings for the provided index version. */ public static ImmutableSettings.Builder settings(Version version) { ImmutableSettings.Builder builder = ImmutableSettings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version); if (version.before(Version.V_2_0_0)) { @@ -393,6 +512,10 @@ public abstract class ElasticsearchTestCase extends AbstractRandomizedTest { return builder; } + // ----------------------------------------------------------------- + // Failure utilities + // ----------------------------------------------------------------- + static final class ElasticsearchUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler { private final Thread.UncaughtExceptionHandler parent; @@ -401,22 +524,20 @@ public abstract class ElasticsearchTestCase extends AbstractRandomizedTest { private ElasticsearchUncaughtExceptionHandler(Thread.UncaughtExceptionHandler parent) { this.parent = parent; } - - + @Override public void uncaughtException(Thread t, Throwable e) { if (e instanceof EsRejectedExecutionException) { - if (e.getMessage().contains(EsAbortPolicy.SHUTTING_DOWN_KEY)) { + if (e.getMessage() != null && e.getMessage().contains(EsAbortPolicy.SHUTTING_DOWN_KEY)) { return; // ignore the EsRejectedExecutionException when a node shuts down } } else if (e instanceof OutOfMemoryError) { - if (e.getMessage().contains("unable to create new native thread")) { + if (e.getMessage() != null && e.getMessage().contains("unable to create new native thread")) { printStackDump(logger); } } parent.uncaughtException(t, e); } - } protected static final void printStackDump(ESLogger logger) { @@ -425,9 +546,7 @@ public abstract class ElasticsearchTestCase extends AbstractRandomizedTest { logger.error(formatThreadStacks(allStackTraces)); } - /** - * Dump threads and their current stack trace. - */ + /** Dump threads and their current stack trace. */ private static String formatThreadStacks(Map threads) { StringBuilder message = new StringBuilder(); int cnt = 1; @@ -463,135 +582,4 @@ public abstract class ElasticsearchTestCase extends AbstractRandomizedTest { } } - public static T randomFrom(T... values) { - return RandomizedTest.randomFrom(values); - } - - public static String[] generateRandomStringArray(int maxArraySize, int maxStringSize, boolean allowNull) { - if (allowNull && randomBoolean()) { - return null; - } - String[] array = new String[randomInt(maxArraySize)]; // allow empty arrays - for (int i = 0; i < array.length; i++) { - array[i] = randomAsciiOfLength(maxStringSize); - } - return array; - } - - public static String[] generateRandomStringArray(int maxArraySize, int maxStringSize) { - return generateRandomStringArray(maxArraySize, maxStringSize, false); - } - - - /** - * If a test is annotated with {@link org.elasticsearch.test.ElasticsearchTestCase.CompatibilityVersion} - * all randomized settings will only contain settings or mappings which are compatible with the specified version ID. - */ - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.TYPE}) - @Ignore - public @interface CompatibilityVersion { - int version(); - } - - /** - * Returns a global compatibility version that is set via the - * {@value #TESTS_COMPATIBILITY} or {@value #TESTS_BACKWARDS_COMPATIBILITY_VERSION} system property. - * If both are unset the current version is used as the global compatibility version. This - * compatibility version is used for static randomization. For per-suite compatibility version see - * {@link #compatibilityVersion()} - */ - public static Version globalCompatibilityVersion() { - return GLOABL_COMPATIBILITY_VERSION; - } - - /** - * Retruns the tests compatibility version. - */ - public Version compatibilityVersion() { - return compatibilityVersion(getClass()); - } - - private Version compatibilityVersion(Class clazz) { - if (clazz == Object.class || clazz == ElasticsearchIntegrationTest.class) { - return globalCompatibilityVersion(); - } - CompatibilityVersion annotation = clazz.getAnnotation(CompatibilityVersion.class); - if (annotation != null) { - return Version.smallest(Version.fromId(annotation.version()), compatibilityVersion(clazz.getSuperclass())); - } - return compatibilityVersion(clazz.getSuperclass()); - } - - private static String compatibilityVersionProperty() { - final String version = System.getProperty(TESTS_COMPATIBILITY); - if (Strings.hasLength(version)) { - return version; - } - return System.getProperty(TESTS_BACKWARDS_COMPATIBILITY_VERSION); - } - - - public static boolean terminate(ExecutorService... services) throws InterruptedException { - boolean terminated = true; - for (ExecutorService service : services) { - if (service != null) { - terminated &= ThreadPool.terminate(service, 10, TimeUnit.SECONDS); - } - } - return terminated; - } - - public static boolean terminate(ThreadPool service) throws InterruptedException { - return ThreadPool.terminate(service, 10, TimeUnit.SECONDS); - } - - // TODO: these method names stink, but are a temporary solution. - // see https://github.com/carrotsearch/randomizedtesting/pull/178 - - /** - * Returns a temporary file - */ - public Path newTempFilePath() { - return newTempFile().toPath(); - } - - /** - * Returns a temporary directory - */ - public Path newTempDirPath() { - return newTempDir().toPath(); - } - - /** - * Returns a temporary directory - */ - public static Path newTempDirPath(LifecycleScope scope) { - return newTempDir(scope).toPath(); - } - - /** - * Returns a random number of temporary paths. - */ - public String[] tmpPaths() { - final int numPaths = randomIntBetween(1, 3); - final String[] absPaths = new String[numPaths]; - for (int i = 0; i < numPaths; i++) { - absPaths[i] = newTempDirPath().toAbsolutePath().toString(); - } - return absPaths; - } - - public NodeEnvironment newNodeEnvironment() throws IOException { - return newNodeEnvironment(ImmutableSettings.EMPTY); - } - - public NodeEnvironment newNodeEnvironment(Settings settings) throws IOException { - Settings build = ImmutableSettings.builder() - .put(settings) - .put("path.home", newTempDirPath().toAbsolutePath()) - .putArray("path.data", tmpPaths()).build(); - return new NodeEnvironment(build, new Environment(build)); - } - } diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchTokenStreamTestCase.java b/src/test/java/org/elasticsearch/test/ElasticsearchTokenStreamTestCase.java index 783ce9dbc00..a61fe704867 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchTokenStreamTestCase.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchTokenStreamTestCase.java @@ -20,10 +20,8 @@ package org.elasticsearch.test; import com.carrotsearch.randomizedtesting.annotations.Listeners; -import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters; -import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; -import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope; import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite; + import org.apache.lucene.analysis.BaseTokenStreamTestCase; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TimeUnits; @@ -36,6 +34,7 @@ import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter; ReproduceInfoPrinter.class }) @TimeoutSuite(millis = TimeUnits.HOUR) +@LuceneTestCase.SuppressReproduceLine @LuceneTestCase.SuppressSysoutChecks(bugUrl = "we log a lot on purpose") /** * Basic test case for token streams. the assertion methods in this class will @@ -43,8 +42,12 @@ import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter; */ public abstract class ElasticsearchTokenStreamTestCase extends BaseTokenStreamTestCase { + static { + SecurityHack.ensureInitialized(); + } + public static Version randomVersion() { - return ElasticsearchTestCase.randomVersion(random()); + return VersionUtils.randomVersion(random()); } public ImmutableSettings.Builder newAnalysisSettingsBuilder() { diff --git a/src/test/java/org/elasticsearch/test/ExternalNode.java b/src/test/java/org/elasticsearch/test/ExternalNode.java index 69d7e886b3f..705f07d3e2a 100644 --- a/src/test/java/org/elasticsearch/test/ExternalNode.java +++ b/src/test/java/org/elasticsearch/test/ExternalNode.java @@ -27,6 +27,7 @@ import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.cluster.ClusterName; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.ImmutableSettings; @@ -127,7 +128,7 @@ final class ExternalNode implements Closeable { params.add("-Des." + entry.getKey() + "=" + entry.getValue()); } - params.add("-Des.path.home=" + Paths.get(".").toAbsolutePath()); + params.add("-Des.path.home=" + PathUtils.get(".").toAbsolutePath()); params.add("-Des.path.conf=" + path + "/config"); ProcessBuilder builder = new ProcessBuilder(params); diff --git a/src/test/java/org/elasticsearch/test/InternalTestCluster.java b/src/test/java/org/elasticsearch/test/InternalTestCluster.java index b60567fe9ac..6c0f41eb493 100644 --- a/src/test/java/org/elasticsearch/test/InternalTestCluster.java +++ b/src/test/java/org/elasticsearch/test/InternalTestCluster.java @@ -20,6 +20,7 @@ package org.elasticsearch.test; import com.carrotsearch.randomizedtesting.RandomizedTest; import com.carrotsearch.randomizedtesting.SeedUtils; +import com.carrotsearch.randomizedtesting.SysGlobals; import com.carrotsearch.randomizedtesting.generators.RandomInts; import com.carrotsearch.randomizedtesting.generators.RandomPicks; import com.carrotsearch.randomizedtesting.generators.RandomStrings; @@ -35,7 +36,6 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; -import org.apache.lucene.util.AbstractRandomizedTest; import org.apache.lucene.util.IOUtils; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchIllegalStateException; @@ -174,6 +174,9 @@ public final class InternalTestCluster extends TestCluster { */ public static final String SETTING_CLUSTER_NODE_SEED = "test.cluster.node.seed"; + private static final int JVM_ORDINAL = Integer.parseInt(System.getProperty(SysGlobals.CHILDVM_SYSPROP_JVM_ID, "0")); + public static final int BASE_PORT = 9300 + 100 * (JVM_ORDINAL + 1); + private static final boolean ENABLE_MOCK_MODULES = RandomizedTest.systemPropertyAsBoolean(TESTS_ENABLE_MOCK_MODULES, true); static final int DEFAULT_MIN_NUM_DATA_NODES = 2; @@ -222,13 +225,13 @@ public final class InternalTestCluster extends TestCluster { private ServiceDisruptionScheme activeDisruptionScheme; public InternalTestCluster(long clusterSeed, Path baseDir, int minNumDataNodes, int maxNumDataNodes, String clusterName, int numClientNodes, - boolean enableHttpPipelining, int jvmOrdinal, String nodePrefix) { - this(clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName, DEFAULT_SETTINGS_SOURCE, numClientNodes, enableHttpPipelining, jvmOrdinal, nodePrefix); + boolean enableHttpPipelining, String nodePrefix) { + this(clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName, DEFAULT_SETTINGS_SOURCE, numClientNodes, enableHttpPipelining, nodePrefix); } public InternalTestCluster(long clusterSeed, Path baseDir, int minNumDataNodes, int maxNumDataNodes, String clusterName, SettingsSource settingsSource, int numClientNodes, - boolean enableHttpPipelining, int jvmOrdinal, String nodePrefix) { + boolean enableHttpPipelining, String nodePrefix) { super(clusterSeed); this.baseDir = baseDir; this.clusterName = clusterName; @@ -289,9 +292,8 @@ public final class InternalTestCluster extends TestCluster { } } builder.put("path.home", baseDir); - final int basePort = 9300 + (100 * (jvmOrdinal+1)); - builder.put("transport.tcp.port", basePort + "-" + (basePort+100)); - builder.put("http.port", basePort+101 + "-" + (basePort+200)); + builder.put("transport.tcp.port", BASE_PORT + "-" + (BASE_PORT+100)); + builder.put("http.port", BASE_PORT+101 + "-" + (BASE_PORT+200)); builder.put("config.ignore_system_properties", true); builder.put("node.mode", NODE_MODE); builder.put("http.pipelining", enableHttpPipelining); @@ -415,10 +417,10 @@ public final class InternalTestCluster extends TestCluster { } } } + if (random.nextInt(10) == 0) { - builder.put(EsExecutors.PROCESSORS, 1 + random.nextInt(AbstractRandomizedTest.TESTS_PROCESSORS)); - } else { - builder.put(EsExecutors.PROCESSORS, AbstractRandomizedTest.TESTS_PROCESSORS); + // node gets an extra cpu this time + builder.put(EsExecutors.PROCESSORS, 1 + EsExecutors.boundedNumberOfProcessors(ImmutableSettings.EMPTY)); } if (random.nextBoolean()) { diff --git a/src/test/java/org/elasticsearch/test/SecurityHack.java b/src/test/java/org/elasticsearch/test/SecurityHack.java new file mode 100644 index 00000000000..092eda99f7d --- /dev/null +++ b/src/test/java/org/elasticsearch/test/SecurityHack.java @@ -0,0 +1,45 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.test; + +import org.apache.lucene.util.TestSecurityManager; + +import static com.carrotsearch.randomizedtesting.RandomizedTest.systemPropertyAsBoolean; + +/** + * Installs test security manager (ensures it happens regardless of which + * test case happens to be first, test ordering, etc). + *

    + * Note that this is BS, this should be done by the jvm (by passing -Djava.security.manager). + * turning it on/off needs to be the role of maven, not this stuff. + */ +class SecurityHack { + + static { + // for IDEs, we check that security.policy is set + if (systemPropertyAsBoolean("tests.security.manager", true) && + System.getProperty("java.security.policy") != null) { + System.setSecurityManager(new TestSecurityManager()); + } + } + + // does nothing, just easy way to make sure the class is loaded. + static void ensureInitialized() {} +} diff --git a/src/test/java/org/elasticsearch/test/VersionUtils.java b/src/test/java/org/elasticsearch/test/VersionUtils.java new file mode 100644 index 00000000000..316a3926d5d --- /dev/null +++ b/src/test/java/org/elasticsearch/test/VersionUtils.java @@ -0,0 +1,107 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.test; + +import com.google.common.collect.ImmutableList; +import org.elasticsearch.Version; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Random; +import java.util.Set; + +/** Utilities for selecting versions in tests */ +public class VersionUtils { + + private static final List SORTED_VERSIONS; + static { + Field[] declaredFields = Version.class.getDeclaredFields(); + Set ids = new HashSet<>(); + for (Field field : declaredFields) { + final int mod = field.getModifiers(); + if (Modifier.isStatic(mod) && Modifier.isFinal(mod) && Modifier.isPublic(mod)) { + if (field.getType() == Version.class) { + try { + Version object = (Version) field.get(null); + ids.add(object.id); + } catch (Throwable e) { + throw new RuntimeException(e); + } + } + } + } + List idList = new ArrayList<>(ids); + Collections.sort(idList); + ImmutableList.Builder version = ImmutableList.builder(); + for (Integer integer : idList) { + version.add(Version.fromId(integer)); + } + SORTED_VERSIONS = version.build(); + } + + /** Returns immutable list of all known versions. */ + public static List allVersions() { + return Collections.unmodifiableList(SORTED_VERSIONS); + } + + /** Returns the {@link Version} before the {@link Version#CURRENT} */ + public static Version getPreviousVersion() { + Version version = SORTED_VERSIONS.get(SORTED_VERSIONS.size() - 2); + assert version.before(Version.CURRENT); + return version; + } + + /** Returns the oldest {@link Version} */ + public static Version getFirstVersion() { + return SORTED_VERSIONS.get(0); + } + + /** Returns a random {@link Version} from all available versions. */ + public static Version randomVersion(Random random) { + return SORTED_VERSIONS.get(random.nextInt(SORTED_VERSIONS.size())); + } + + /** Returns a random {@link Version} between minVersion and maxVersion (inclusive). */ + public static Version randomVersionBetween(Random random, Version minVersion, Version maxVersion) { + int minVersionIndex = 0; + if (minVersion != null) { + minVersionIndex = SORTED_VERSIONS.indexOf(minVersion); + } + int maxVersionIndex = SORTED_VERSIONS.size() - 1; + if (maxVersion != null) { + maxVersionIndex = SORTED_VERSIONS.indexOf(maxVersion); + } + if (minVersionIndex == -1) { + throw new IllegalArgumentException("minVersion [" + minVersion + "] does not exist."); + } else if (maxVersionIndex == -1) { + throw new IllegalArgumentException("maxVersion [" + maxVersion + "] does not exist."); + } else if (minVersionIndex > maxVersionIndex) { + throw new IllegalArgumentException("maxVersion [" + maxVersion + "] cannot be less than minVersion [" + minVersion + "]"); + } else { + // minVersionIndex is inclusive so need to add 1 to this index + int range = maxVersionIndex + 1 - minVersionIndex; + return SORTED_VERSIONS.get(minVersionIndex + random.nextInt(range)); + } + } +} diff --git a/src/test/java/org/elasticsearch/test/discovery/ClusterDiscoveryConfiguration.java b/src/test/java/org/elasticsearch/test/discovery/ClusterDiscoveryConfiguration.java index 30063c56b8f..1be28a9a8a1 100644 --- a/src/test/java/org/elasticsearch/test/discovery/ClusterDiscoveryConfiguration.java +++ b/src/test/java/org/elasticsearch/test/discovery/ClusterDiscoveryConfiguration.java @@ -23,7 +23,6 @@ import com.google.common.primitives.Ints; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.InternalTestCluster; import org.elasticsearch.test.SettingsSource; import org.elasticsearch.transport.local.LocalTransport; @@ -41,10 +40,6 @@ public class ClusterDiscoveryConfiguration extends SettingsSource { final Settings nodeSettings; final Settings transportClientSettings; - public ClusterDiscoveryConfiguration(int numOfNodes) { - this(numOfNodes, ImmutableSettings.EMPTY); - } - public ClusterDiscoveryConfiguration(int numOfNodes, Settings extraSettings) { this.numOfNodes = numOfNodes; this.nodeSettings = ImmutableSettings.builder().put(DEFAULT_NODE_SETTINGS).put(extraSettings).build(); @@ -114,9 +109,7 @@ public class ClusterDiscoveryConfiguration extends SettingsSource { } private static int calcBasePort() { - // note that this has properly co-exist with the port logic at InternalTestCluster's constructor - return 30000 + - 1000 * (ElasticsearchIntegrationTest.CHILD_JVM_ID); + return 30000 + InternalTestCluster.BASE_PORT; } @Override diff --git a/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java b/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java index cc0d0c59ff4..485a553e753 100644 --- a/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java +++ b/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java @@ -64,6 +64,7 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.suggest.Suggest; +import org.elasticsearch.test.VersionUtils; import org.elasticsearch.test.engine.AssertingSearcher; import org.elasticsearch.test.engine.MockInternalEngine; import org.elasticsearch.test.engine.MockShadowEngine; @@ -82,6 +83,7 @@ import java.util.concurrent.TimeUnit; import static com.google.common.base.Predicates.isNull; import static org.elasticsearch.test.ElasticsearchTestCase.*; +import static org.elasticsearch.test.VersionUtils.randomVersion; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; @@ -585,8 +587,8 @@ public class ElasticsearchAssertions { } public static void assertVersionSerializable(Streamable streamable) { - assertTrue(Version.CURRENT.after(getPreviousVersion())); - assertVersionSerializable(randomVersion(), streamable); + assertTrue(Version.CURRENT.after(VersionUtils.getPreviousVersion())); + assertVersionSerializable(randomVersion(random()), streamable); } public static void assertVersionSerializable(Version version, Streamable streamable) { diff --git a/src/test/java/org/elasticsearch/test/junit/listeners/ReproduceInfoPrinter.java b/src/test/java/org/elasticsearch/test/junit/listeners/ReproduceInfoPrinter.java index ebfef8e2b70..e57732bf5f8 100644 --- a/src/test/java/org/elasticsearch/test/junit/listeners/ReproduceInfoPrinter.java +++ b/src/test/java/org/elasticsearch/test/junit/listeners/ReproduceInfoPrinter.java @@ -21,7 +21,7 @@ package org.elasticsearch.test.junit.listeners; import com.carrotsearch.randomizedtesting.RandomizedContext; import com.carrotsearch.randomizedtesting.ReproduceErrorMessageBuilder; import com.carrotsearch.randomizedtesting.TraceFormatting; -import org.apache.lucene.util.AbstractRandomizedTest; + import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; @@ -35,9 +35,14 @@ import org.junit.runner.notification.RunListener; import java.util.Locale; import java.util.TimeZone; -import static com.carrotsearch.randomizedtesting.SysGlobals.*; +import static com.carrotsearch.randomizedtesting.SysGlobals.SYSPROP_ITERATIONS; +import static com.carrotsearch.randomizedtesting.SysGlobals.SYSPROP_PREFIX; +import static com.carrotsearch.randomizedtesting.SysGlobals.SYSPROP_TESTMETHOD; import static org.elasticsearch.test.ElasticsearchIntegrationTest.TESTS_CLUSTER; -import static org.elasticsearch.test.rest.ElasticsearchRestTests.*; +import static org.elasticsearch.test.rest.ElasticsearchRestTestCase.REST_TESTS_BLACKLIST; +import static org.elasticsearch.test.rest.ElasticsearchRestTestCase.REST_TESTS_SPEC; +import static org.elasticsearch.test.rest.ElasticsearchRestTestCase.REST_TESTS_SUITE; +import static org.elasticsearch.test.rest.ElasticsearchRestTestCase.Rest; /** * A {@link RunListener} that emits to {@link System#err} a string with command @@ -49,12 +54,12 @@ public class ReproduceInfoPrinter extends RunListener { @Override public void testStarted(Description description) throws Exception { - logger.info("Test {} started", description.getDisplayName()); + logger.trace("Test {} started", description.getDisplayName()); } @Override public void testFinished(Description description) throws Exception { - logger.info("Test {} finished", description.getDisplayName()); + logger.trace("Test {} finished", description.getDisplayName()); } @Override @@ -64,10 +69,8 @@ public class ReproduceInfoPrinter extends RunListener { return; } - final Description d = failure.getDescription(); final StringBuilder b = new StringBuilder(); - b.append("FAILURE : ").append(d.getDisplayName()).append("\n"); - b.append("REPRODUCE WITH : mvn clean test"); + b.append("REPRODUCE WITH: mvn test -Pdev"); MavenMessageBuilder mavenMessageBuilder = new MavenMessageBuilder(b); mavenMessageBuilder.appendAllOpts(failure.getDescription()); @@ -76,13 +79,7 @@ public class ReproduceInfoPrinter extends RunListener { mavenMessageBuilder.appendRestTestsProperties(); } - b.append("\n"); - b.append("Throwable:\n"); - if (failure.getException() != null) { - traces().formatThrowable(b, failure.getException()); - } - - logger.error(b.toString()); + System.err.println(b.toString()); } protected TraceFormatting traces() { @@ -151,7 +148,6 @@ public class ReproduceInfoPrinter extends RunListener { } appendOpt("tests.locale", Locale.getDefault().toString()); appendOpt("tests.timezone", TimeZone.getDefault().getID()); - appendOpt(AbstractRandomizedTest.SYSPROP_PROCESSORS, Integer.toString(AbstractRandomizedTest.TESTS_PROCESSORS)); return this; } diff --git a/src/test/java/org/elasticsearch/test/rest/ElasticsearchRestTests.java b/src/test/java/org/elasticsearch/test/rest/ElasticsearchRestTestCase.java similarity index 69% rename from src/test/java/org/elasticsearch/test/rest/ElasticsearchRestTests.java rename to src/test/java/org/elasticsearch/test/rest/ElasticsearchRestTestCase.java index 0267b3d9cc8..e221533e044 100644 --- a/src/test/java/org/elasticsearch/test/rest/ElasticsearchRestTests.java +++ b/src/test/java/org/elasticsearch/test/rest/ElasticsearchRestTestCase.java @@ -25,9 +25,13 @@ import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; import com.carrotsearch.randomizedtesting.annotations.TestGroup; import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite; import com.google.common.collect.Lists; -import org.apache.lucene.util.AbstractRandomizedTest; + +import org.apache.lucene.util.LuceneTestCase.Slow; +import org.apache.lucene.util.LuceneTestCase.SuppressCodecs; +import org.apache.lucene.util.LuceneTestCase.SuppressFsync; import org.apache.lucene.util.TimeUnits; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.node.Node; @@ -36,7 +40,11 @@ import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope; import org.elasticsearch.test.rest.client.RestException; import org.elasticsearch.test.rest.parser.RestTestParseException; import org.elasticsearch.test.rest.parser.RestTestSuiteParser; -import org.elasticsearch.test.rest.section.*; +import org.elasticsearch.test.rest.section.DoSection; +import org.elasticsearch.test.rest.section.ExecutableSection; +import org.elasticsearch.test.rest.section.RestTestSuite; +import org.elasticsearch.test.rest.section.SkipSection; +import org.elasticsearch.test.rest.section.TestSection; import org.elasticsearch.test.rest.spec.RestApi; import org.elasticsearch.test.rest.spec.RestSpec; import org.elasticsearch.test.rest.support.FileUtils; @@ -46,22 +54,44 @@ import org.junit.BeforeClass; import org.junit.Test; import java.io.IOException; -import java.nio.file.FileSystems; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.nio.file.Path; import java.nio.file.PathMatcher; -import java.nio.file.Paths; -import java.util.*; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * Runs the clients test suite against an elasticsearch cluster. */ -//tests distribution disabled for now since it causes reporting problems, -// due to the non unique suite name -//@ReplicateOnEachVm -@AbstractRandomizedTest.Rest +@ElasticsearchRestTestCase.Rest +@Slow +@SuppressFsync // we aren't trying to test this here, and it can make the test slow +@SuppressCodecs("*") // requires custom completion postings format @ClusterScope(randomDynamicTemplates = false) @TimeoutSuite(millis = 40 * TimeUnits.MINUTE) // timeout the suite after 40min and fail the test. -public class ElasticsearchRestTests extends ElasticsearchIntegrationTest { +public abstract class ElasticsearchRestTestCase extends ElasticsearchIntegrationTest { + + /** + * Property that allows to control whether the REST tests are run (default) or not + */ + public static final String TESTS_REST = "tests.rest"; + + /** + * Annotation for REST tests + */ + @Inherited + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.TYPE) + @TestGroup(enabled = true, sysProperty = ElasticsearchRestTestCase.TESTS_REST) + public @interface Rest { + } /** * Property that allows to control which REST tests get run. Supports comma separated list of tests @@ -90,19 +120,16 @@ public class ElasticsearchRestTests extends ElasticsearchIntegrationTest { private final PathMatcher[] blacklistPathMatchers; private static RestTestExecutionContext restTestExecutionContext; - //private static final int JVM_COUNT = systemPropertyAsInt(SysGlobals.CHILDVM_SYSPROP_JVM_COUNT, 1); - //private static final int CURRENT_JVM_ID = systemPropertyAsInt(SysGlobals.CHILDVM_SYSPROP_JVM_ID, 0); - private final RestTestCandidate testCandidate; - public ElasticsearchRestTests(@Name("yaml") RestTestCandidate testCandidate) { + public ElasticsearchRestTestCase(RestTestCandidate testCandidate) { this.testCandidate = testCandidate; String[] blacklist = resolvePathsProperty(REST_TESTS_BLACKLIST, null); if (blacklist != null) { blacklistPathMatchers = new PathMatcher[blacklist.length]; int i = 0; for (String glob : blacklist) { - blacklistPathMatchers[i++] = FileSystems.getDefault().getPathMatcher("glob:" + glob); + blacklistPathMatchers[i++] = PathUtils.getDefaultFileSystem().getPathMatcher("glob:" + glob); } } else { blacklistPathMatchers = new PathMatcher[0]; @@ -115,9 +142,8 @@ public class ElasticsearchRestTests extends ElasticsearchIntegrationTest { .put(Node.HTTP_ENABLED, true) .put(super.nodeSettings(nodeOrdinal)).build(); } - - @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + + public static Iterable createParameters(int id, int count) throws IOException, RestTestParseException { TestGroup testGroup = Rest.class.getAnnotation(TestGroup.class); String sysProperty = TestGroup.Utilities.getSysProperty(Rest.class); boolean enabled; @@ -131,7 +157,7 @@ public class ElasticsearchRestTests extends ElasticsearchIntegrationTest { return Lists.newArrayList(); } //parse tests only if rest test group is enabled, otherwise rest tests might not even be available on file system - List restTestCandidates = collectTestCandidates(); + List restTestCandidates = collectTestCandidates(id, count); List objects = Lists.newArrayList(); for (RestTestCandidate restTestCandidate : restTestCandidates) { objects.add(new Object[]{restTestCandidate}); @@ -139,7 +165,7 @@ public class ElasticsearchRestTests extends ElasticsearchIntegrationTest { return objects; } - private static List collectTestCandidates() throws RestTestParseException, IOException { + private static List collectTestCandidates(int id, int count) throws RestTestParseException, IOException { String[] paths = resolvePathsProperty(REST_TESTS_SUITE, DEFAULT_TESTS_PATH); Map> yamlSuites = FileUtils.findYamlSuites(DEFAULT_TESTS_PATH, paths); @@ -149,14 +175,13 @@ public class ElasticsearchRestTests extends ElasticsearchIntegrationTest { for (String api : yamlSuites.keySet()) { List yamlFiles = Lists.newArrayList(yamlSuites.get(api)); for (Path yamlFile : yamlFiles) { - //tests distribution disabled for now since it causes reporting problems, - // due to the non unique suite name - //if (mustExecute(yamlFile.getAbsolutePath())) { + String key = api + yamlFile.getFileName().toString(); + if (mustExecute(key, id, count)) { RestTestSuite restTestSuite = restTestSuiteParser.parse(api, yamlFile); for (TestSection testSection : restTestSuite.getTestSections()) { testCandidates.add(new RestTestCandidate(restTestSuite, testSection)); } - //} + } } } @@ -170,17 +195,11 @@ public class ElasticsearchRestTests extends ElasticsearchIntegrationTest { return testCandidates; } - - /*private static boolean mustExecute(String test) { - //we distribute the tests across the forked jvms if > 1 - if (JVM_COUNT > 1) { - int jvmId = MathUtils.mod(DjbHashFunction.DJB_HASH(test), JVM_COUNT); - if (jvmId != CURRENT_JVM_ID) { - return false; - } - } - return true; - }*/ + + private static boolean mustExecute(String test, int id, int count) { + int hash = (int) (Math.abs((long)test.hashCode()) % count); + return hash == id; + } private static String[] resolvePathsProperty(String propertyName, String defaultValue) { String property = System.getProperty(propertyName); @@ -251,7 +270,7 @@ public class ElasticsearchRestTests extends ElasticsearchIntegrationTest { //we need to replace a few characters otherwise the test section name can't be parsed as a path on windows String testSection = testCandidate.getTestSection().getName().replace("*", "").replace("\\", "/").replaceAll("\\s+/", "/").trim(); String testPath = testCandidate.getSuitePath() + "/" + testSection; - assumeFalse("[" + testCandidate.getTestPath() + "] skipped, reason: blacklisted", blacklistedPathMatcher.matches(Paths.get(testPath))); + assumeFalse("[" + testCandidate.getTestPath() + "] skipped, reason: blacklisted", blacklistedPathMatcher.matches(PathUtils.get(testPath))); } //The client needs non static info to get initialized, therefore it can't be initialized in the before class restTestExecutionContext.initClient(cluster().httpAddresses(), restClientSettings()); @@ -302,4 +321,86 @@ public class ElasticsearchRestTests extends ElasticsearchIntegrationTest { executableSection.execute(restTestExecutionContext); } } + + // don't look any further: NO TOUCHY! + + public static class Rest0Tests extends ElasticsearchRestTestCase { + public Rest0Tests(@Name("yaml") RestTestCandidate testCandidate) { + super(testCandidate); + } + @ParametersFactory + public static Iterable parameters() throws IOException, RestTestParseException { + return createParameters(0, 8); + } + } + + public static class Rest1Tests extends ElasticsearchRestTestCase { + public Rest1Tests(@Name("yaml") RestTestCandidate testCandidate) { + super(testCandidate); + } + @ParametersFactory + public static Iterable parameters() throws IOException, RestTestParseException { + return createParameters(1, 8); + } + } + + public static class Rest2Tests extends ElasticsearchRestTestCase { + public Rest2Tests(@Name("yaml") RestTestCandidate testCandidate) { + super(testCandidate); + } + @ParametersFactory + public static Iterable parameters() throws IOException, RestTestParseException { + return createParameters(2, 8); + } + } + + public static class Rest3Tests extends ElasticsearchRestTestCase { + public Rest3Tests(@Name("yaml") RestTestCandidate testCandidate) { + super(testCandidate); + } + @ParametersFactory + public static Iterable parameters() throws IOException, RestTestParseException { + return createParameters(3, 8); + } + } + + public static class Rest4Tests extends ElasticsearchRestTestCase { + public Rest4Tests(@Name("yaml") RestTestCandidate testCandidate) { + super(testCandidate); + } + @ParametersFactory + public static Iterable parameters() throws IOException, RestTestParseException { + return createParameters(4, 8); + } + } + + public static class Rest5Tests extends ElasticsearchRestTestCase { + public Rest5Tests(@Name("yaml") RestTestCandidate testCandidate) { + super(testCandidate); + } + @ParametersFactory + public static Iterable parameters() throws IOException, RestTestParseException { + return createParameters(5, 8); + } + } + + public static class Rest6Tests extends ElasticsearchRestTestCase { + public Rest6Tests(@Name("yaml") RestTestCandidate testCandidate) { + super(testCandidate); + } + @ParametersFactory + public static Iterable parameters() throws IOException, RestTestParseException { + return createParameters(6, 8); + } + } + + public static class Rest7Tests extends ElasticsearchRestTestCase { + public Rest7Tests(@Name("yaml") RestTestCandidate testCandidate) { + super(testCandidate); + } + @ParametersFactory + public static Iterable parameters() throws IOException, RestTestParseException { + return createParameters(7, 8); + } + } } diff --git a/src/test/java/org/elasticsearch/test/rest/RestTestExecutionContext.java b/src/test/java/org/elasticsearch/test/rest/RestTestExecutionContext.java index 26dbf7547b8..e10582d11b4 100644 --- a/src/test/java/org/elasticsearch/test/rest/RestTestExecutionContext.java +++ b/src/test/java/org/elasticsearch/test/rest/RestTestExecutionContext.java @@ -19,6 +19,7 @@ package org.elasticsearch.test.rest; import com.google.common.collect.Maps; +import org.elasticsearch.Version; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; @@ -145,7 +146,7 @@ public class RestTestExecutionContext implements Closeable { /** * Returns the current es version as a string */ - public String esVersion() { + public Version esVersion() { return restClient.getEsVersion(); } diff --git a/src/test/java/org/elasticsearch/test/rest/client/RestClient.java b/src/test/java/org/elasticsearch/test/rest/client/RestClient.java index 4ac0cc270d3..495fabc8e7b 100644 --- a/src/test/java/org/elasticsearch/test/rest/client/RestClient.java +++ b/src/test/java/org/elasticsearch/test/rest/client/RestClient.java @@ -25,6 +25,7 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.lucene.util.IOUtils; +import org.elasticsearch.Version; import org.elasticsearch.client.support.Headers; import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.ESLogger; @@ -54,7 +55,7 @@ public class RestClient implements Closeable { private final CloseableHttpClient httpClient; private final Headers headers; private final InetSocketAddress[] addresses; - private final String esVersion; + private final Version esVersion; public RestClient(RestSpec restSpec, Settings settings, InetSocketAddress[] addresses) throws IOException, RestException { assert addresses.length > 0; @@ -66,7 +67,7 @@ public class RestClient implements Closeable { logger.info("REST client initialized {}, elasticsearch version: [{}]", addresses, esVersion); } - private String readAndCheckVersion() throws IOException, RestException { + private Version readAndCheckVersion() throws IOException, RestException { //we make a manual call here without using callApi method, mainly because we are initializing //and the randomized context doesn't exist for the current thread (would be used to choose the method otherwise) RestApi restApi = restApi("info"); @@ -93,10 +94,10 @@ public class RestClient implements Closeable { } } } - return version; + return Version.fromString(version); } - public String getEsVersion() { + public Version getEsVersion() { return esVersion; } diff --git a/src/test/java/org/elasticsearch/test/rest/section/SkipSection.java b/src/test/java/org/elasticsearch/test/rest/section/SkipSection.java index 9e2f5d67511..bf8fe82a2c1 100644 --- a/src/test/java/org/elasticsearch/test/rest/section/SkipSection.java +++ b/src/test/java/org/elasticsearch/test/rest/section/SkipSection.java @@ -19,9 +19,10 @@ package org.elasticsearch.test.rest.section; import com.google.common.collect.Lists; +import org.elasticsearch.Version; import org.elasticsearch.common.Strings; +import org.elasticsearch.test.VersionUtils; import org.elasticsearch.test.rest.support.Features; -import org.elasticsearch.test.rest.support.VersionUtils; import java.util.List; @@ -33,20 +34,36 @@ import java.util.List; */ public class SkipSection { - public static final SkipSection EMPTY = new SkipSection("", Lists.newArrayList(), ""); + public static final SkipSection EMPTY = new SkipSection(); - private final String version; + private final Version lowerVersion; + private final Version upperVersion; private final List features; private final String reason; + + private SkipSection() { + this.lowerVersion = null; + this.upperVersion = null; + this.features = Lists.newArrayList(); + this.reason = null; + } - public SkipSection(String version, List features, String reason) { - this.version = version; + public SkipSection(String versionRange, List features, String reason) { + assert features != null; + assert versionRange != null && features.isEmpty() || versionRange == null && features.isEmpty() == false; + Version[] versions = parseVersionRange(versionRange); + this.lowerVersion = versions[0]; + this.upperVersion = versions[1]; this.features = features; this.reason = reason; } - public String getVersion() { - return version; + public Version getLowerVersion() { + return lowerVersion; + } + + public Version getUpperVersion() { + return upperVersion; } public List getFeatures() { @@ -57,27 +74,39 @@ public class SkipSection { return reason; } - public boolean skip(String currentVersion) { + public boolean skip(Version currentVersion) { if (isEmpty()) { return false; } - - if (version != null) { - return VersionUtils.skipCurrentVersion(version, currentVersion); + if (isVersionCheck()) { + return currentVersion.onOrAfter(lowerVersion) && currentVersion.onOrBefore(upperVersion); + } else { + return Features.areAllSupported(features) == false; } - - if (features != null && !this.features.isEmpty()) { - return !Features.areAllSupported(this.features); - } - - throw new IllegalArgumentException("version or feature should be not null in a non empty skip section"); } public boolean isVersionCheck() { - return Strings.hasLength(version); + return features.isEmpty(); } public boolean isEmpty() { return EMPTY.equals(this); } + + private Version[] parseVersionRange(String versionRange) { + if (versionRange == null) { + return new Version[] { null, null }; + } + String[] skipVersions = versionRange.split("-"); + if (skipVersions.length > 2) { + throw new IllegalArgumentException("version range malformed: " + versionRange); + } + + String lower = skipVersions[0].trim(); + String upper = skipVersions[1].trim(); + return new Version[] { + lower.isEmpty() ? VersionUtils.getFirstVersion() : Version.fromString(lower), + upper.isEmpty() ? Version.CURRENT : Version.fromString(upper) + }; + } } diff --git a/src/test/java/org/elasticsearch/test/rest/support/FileUtils.java b/src/test/java/org/elasticsearch/test/rest/support/FileUtils.java index 922cd625d8a..28c3f597f9f 100644 --- a/src/test/java/org/elasticsearch/test/rest/support/FileUtils.java +++ b/src/test/java/org/elasticsearch/test/rest/support/FileUtils.java @@ -22,9 +22,11 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.io.PathUtils; import java.io.IOException; import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.file.DirectoryStream; import java.nio.file.FileSystems; @@ -106,7 +108,11 @@ public final class FileUtils { } } - return Paths.get(URI.create(resource.toString())); + try { + return PathUtils.get(resource.toURI()); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } } private static URL findResource(String path, String optionalFileSuffix) { @@ -121,9 +127,9 @@ public final class FileUtils { } private static Path findFile(String path, String optionalFileSuffix) { - Path file = Paths.get(path); + Path file = PathUtils.get(path); if (!Files.exists(file)) { - file = Paths.get(path + optionalFileSuffix); + file = PathUtils.get(path + optionalFileSuffix); } return file; } diff --git a/src/test/java/org/elasticsearch/test/rest/support/VersionUtils.java b/src/test/java/org/elasticsearch/test/rest/support/VersionUtils.java deleted file mode 100644 index 9c19210bc6a..00000000000 --- a/src/test/java/org/elasticsearch/test/rest/support/VersionUtils.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.test.rest.support; - -public final class VersionUtils { - - private VersionUtils() { - - } - - /** - * Parses an elasticsearch version string into an int array with an element per part - * e.g. 0.90.7 => [0,90,7] - */ - public static int[] parseVersionNumber(String version) { - String[] split = version.split("\\."); - //we only take the first 3 parts if there are more, but less is ok too (e.g. 999) - int length = Math.min(3, split.length); - int[] versionNumber = new int[length]; - for (int i = 0; i < length; i++) { - try { - versionNumber[i] = Integer.valueOf(split[i]); - } catch (NumberFormatException e) { - throw new IllegalArgumentException("version is not a number", e); - } - - } - return versionNumber; - } - - /** - * Compares the skip version read from a test fragment with the elasticsearch version - * the tests are running against and determines whether the test fragment needs to be skipped - */ - public static boolean skipCurrentVersion(String skipVersion, String currentVersion) { - int[] currentVersionNumber = parseVersionNumber(currentVersion); - - String[] skipVersions = skipVersion.split("-"); - if (skipVersions.length > 2) { - throw new IllegalArgumentException("too many skip versions found"); - } - - String skipVersionLowerBound = skipVersions[0].trim(); - String skipVersionUpperBound = skipVersions[1].trim(); - - int[] skipVersionLowerBoundNumber = parseVersionNumber(skipVersionLowerBound); - int[] skipVersionUpperBoundNumber = parseVersionNumber(skipVersionUpperBound); - - int length = Math.min(skipVersionLowerBoundNumber.length, currentVersionNumber.length); - for (int i = 0; i < length; i++) { - if (currentVersionNumber[i] < skipVersionLowerBoundNumber[i]) { - return false; - } - if (currentVersionNumber[i] > skipVersionLowerBoundNumber[i]) { - break; - } - } - - length = Math.min(skipVersionUpperBoundNumber.length, currentVersionNumber.length); - for (int i = 0; i < length; i++) { - if (currentVersionNumber[i] > skipVersionUpperBoundNumber[i]) { - return false; - } - if (currentVersionNumber[i] < skipVersionUpperBoundNumber[i]) { - break; - } - } - - return true; - } -} diff --git a/src/test/java/org/elasticsearch/test/rest/test/FileUtilsTests.java b/src/test/java/org/elasticsearch/test/rest/test/FileUtilsTests.java index 39ad622ae00..f35daa926a1 100644 --- a/src/test/java/org/elasticsearch/test/rest/test/FileUtilsTests.java +++ b/src/test/java/org/elasticsearch/test/rest/test/FileUtilsTests.java @@ -76,7 +76,7 @@ public class FileUtilsTests extends ElasticsearchTestCase { assertThat(yamlSuites.get("index").size(), greaterThan(1)); //files can be loaded from classpath and from file system too - Path dir = newTempDirPath(); + Path dir = createTempDir(); Path file = dir.resolve("test_loading.yaml"); Files.createFile(file); diff --git a/src/test/java/org/elasticsearch/test/rest/test/RestTestParserTests.java b/src/test/java/org/elasticsearch/test/rest/test/RestTestParserTests.java index 5d3cc2ce982..34b2e9462f7 100644 --- a/src/test/java/org/elasticsearch/test/rest/test/RestTestParserTests.java +++ b/src/test/java/org/elasticsearch/test/rest/test/RestTestParserTests.java @@ -18,9 +18,11 @@ */ package org.elasticsearch.test.rest.test; +import org.elasticsearch.Version; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.yaml.YamlXContent; import org.elasticsearch.test.ElasticsearchTestCase; +import org.elasticsearch.test.VersionUtils; import org.elasticsearch.test.rest.parser.RestTestParseException; import org.elasticsearch.test.rest.parser.RestTestSuiteParseContext; import org.elasticsearch.test.rest.parser.RestTestSuiteParser; @@ -72,7 +74,7 @@ public class RestTestParserTests extends ElasticsearchTestCase { "\"Get type mapping - pre 1.0\":\n" + "\n" + " - skip:\n" + - " version: \"0.90.9 - 999\"\n" + + " version: \"0.90.9 - \"\n" + " reason: \"for newer versions the index name is always returned\"\n" + "\n" + " - do:\n" + @@ -119,7 +121,8 @@ public class RestTestParserTests extends ElasticsearchTestCase { assertThat(restTestSuite.getTestSections().get(1).getName(), equalTo("Get type mapping - pre 1.0")); assertThat(restTestSuite.getTestSections().get(1).getSkipSection().isEmpty(), equalTo(false)); assertThat(restTestSuite.getTestSections().get(1).getSkipSection().getReason(), equalTo("for newer versions the index name is always returned")); - assertThat(restTestSuite.getTestSections().get(1).getSkipSection().getVersion(), equalTo("0.90.9 - 999")); + assertThat(restTestSuite.getTestSections().get(1).getSkipSection().getLowerVersion(), equalTo(Version.V_0_90_9)); + assertThat(restTestSuite.getTestSections().get(1).getSkipSection().getUpperVersion(), equalTo(Version.CURRENT)); assertThat(restTestSuite.getTestSections().get(1).getExecutableSections().size(), equalTo(3)); assertThat(restTestSuite.getTestSections().get(1).getExecutableSections().get(0), instanceOf(DoSection.class)); doSection = (DoSection) restTestSuite.getTestSections().get(1).getExecutableSections().get(0); diff --git a/src/test/java/org/elasticsearch/test/rest/test/SetupSectionParserTests.java b/src/test/java/org/elasticsearch/test/rest/test/SetupSectionParserTests.java index 2c0d351caca..d2427e0bb45 100644 --- a/src/test/java/org/elasticsearch/test/rest/test/SetupSectionParserTests.java +++ b/src/test/java/org/elasticsearch/test/rest/test/SetupSectionParserTests.java @@ -18,6 +18,7 @@ */ package org.elasticsearch.test.rest.test; +import org.elasticsearch.Version; import org.elasticsearch.common.xcontent.yaml.YamlXContent; import org.elasticsearch.test.rest.parser.RestTestSuiteParseContext; import org.elasticsearch.test.rest.parser.SetupSectionParser; @@ -84,7 +85,8 @@ public class SetupSectionParserTests extends AbstractParserTests { assertThat(setupSection, notNullValue()); assertThat(setupSection.getSkipSection().isEmpty(), equalTo(false)); assertThat(setupSection.getSkipSection(), notNullValue()); - assertThat(setupSection.getSkipSection().getVersion(), equalTo("0.90.0 - 0.90.7")); + assertThat(setupSection.getSkipSection().getLowerVersion(), equalTo(Version.V_0_90_0)); + assertThat(setupSection.getSkipSection().getUpperVersion(), equalTo(Version.V_0_90_7)); assertThat(setupSection.getSkipSection().getReason(), equalTo("Update doesn't return metadata fields, waiting for #3259")); assertThat(setupSection.getDoSections().size(), equalTo(2)); assertThat(setupSection.getDoSections().get(0).getApiCallSection().getApi(), equalTo("index1")); diff --git a/src/test/java/org/elasticsearch/test/rest/test/SkipSectionParserTests.java b/src/test/java/org/elasticsearch/test/rest/test/SkipSectionParserTests.java index 899ea1da04c..5d940a10b56 100644 --- a/src/test/java/org/elasticsearch/test/rest/test/SkipSectionParserTests.java +++ b/src/test/java/org/elasticsearch/test/rest/test/SkipSectionParserTests.java @@ -18,7 +18,9 @@ */ package org.elasticsearch.test.rest.test; +import org.elasticsearch.Version; import org.elasticsearch.common.xcontent.yaml.YamlXContent; +import org.elasticsearch.test.VersionUtils; import org.elasticsearch.test.rest.parser.RestTestParseException; import org.elasticsearch.test.rest.parser.RestTestSuiteParseContext; import org.elasticsearch.test.rest.parser.SkipSectionParser; @@ -32,7 +34,7 @@ public class SkipSectionParserTests extends AbstractParserTests { @Test public void testParseSkipSectionVersionNoFeature() throws Exception { parser = YamlXContent.yamlXContent.createParser( - "version: \"0 - 0.90.2\"\n" + + "version: \" - 0.90.2\"\n" + "reason: Delete ignores the parent param" ); @@ -41,7 +43,8 @@ public class SkipSectionParserTests extends AbstractParserTests { SkipSection skipSection = skipSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); assertThat(skipSection, notNullValue()); - assertThat(skipSection.getVersion(), equalTo("0 - 0.90.2")); + assertThat(skipSection.getLowerVersion(), equalTo(VersionUtils.getFirstVersion())); + assertThat(skipSection.getUpperVersion(), equalTo(Version.V_0_90_2)); assertThat(skipSection.getFeatures().size(), equalTo(0)); assertThat(skipSection.getReason(), equalTo("Delete ignores the parent param")); } @@ -57,7 +60,7 @@ public class SkipSectionParserTests extends AbstractParserTests { SkipSection skipSection = skipSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); assertThat(skipSection, notNullValue()); - assertThat(skipSection.getVersion(), nullValue()); + assertThat(skipSection.isVersionCheck(), equalTo(false)); assertThat(skipSection.getFeatures().size(), equalTo(1)); assertThat(skipSection.getFeatures().get(0), equalTo("regex")); assertThat(skipSection.getReason(), nullValue()); @@ -74,7 +77,7 @@ public class SkipSectionParserTests extends AbstractParserTests { SkipSection skipSection = skipSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); assertThat(skipSection, notNullValue()); - assertThat(skipSection.getVersion(), nullValue()); + assertThat(skipSection.isVersionCheck(), equalTo(false)); assertThat(skipSection.getFeatures().size(), equalTo(3)); assertThat(skipSection.getFeatures().get(0), equalTo("regex1")); assertThat(skipSection.getFeatures().get(1), equalTo("regex2")); @@ -85,7 +88,7 @@ public class SkipSectionParserTests extends AbstractParserTests { @Test(expected = RestTestParseException.class) public void testParseSkipSectionBothFeatureAndVersion() throws Exception { parser = YamlXContent.yamlXContent.createParser( - "version: \"0 - 0.90.2\"\n" + + "version: \" - 0.90.2\"\n" + "features: regex\n" + "reason: Delete ignores the parent param" ); @@ -98,7 +101,7 @@ public class SkipSectionParserTests extends AbstractParserTests { @Test(expected = RestTestParseException.class) public void testParseSkipSectionNoReason() throws Exception { parser = YamlXContent.yamlXContent.createParser( - "version: \"0 - 0.90.2\"\n" + "version: \" - 0.90.2\"\n" ); SkipSectionParser skipSectionParser = new SkipSectionParser(); diff --git a/src/test/java/org/elasticsearch/test/rest/test/TestSectionParserTests.java b/src/test/java/org/elasticsearch/test/rest/test/TestSectionParserTests.java index 3ef2f234502..374ade56c9a 100644 --- a/src/test/java/org/elasticsearch/test/rest/test/TestSectionParserTests.java +++ b/src/test/java/org/elasticsearch/test/rest/test/TestSectionParserTests.java @@ -18,6 +18,7 @@ */ package org.elasticsearch.test.rest.test; +import org.elasticsearch.Version; import org.elasticsearch.common.xcontent.yaml.YamlXContent; import org.elasticsearch.test.rest.parser.RestTestSectionParser; import org.elasticsearch.test.rest.parser.RestTestSuiteParseContext; @@ -78,7 +79,8 @@ public class TestSectionParserTests extends AbstractParserTests { assertThat(testSection, notNullValue()); assertThat(testSection.getName(), equalTo("First test section")); assertThat(testSection.getSkipSection(), notNullValue()); - assertThat(testSection.getSkipSection().getVersion(), equalTo("0.90.0 - 0.90.7")); + assertThat(testSection.getSkipSection().getLowerVersion(), equalTo(Version.V_0_90_0)); + assertThat(testSection.getSkipSection().getUpperVersion(), equalTo(Version.V_0_90_7)); assertThat(testSection.getSkipSection().getReason(), equalTo("Update doesn't return metadata fields, waiting for #3259")); assertThat(testSection.getExecutableSections().size(), equalTo(2)); DoSection doSection = (DoSection)testSection.getExecutableSections().get(0); diff --git a/src/test/java/org/elasticsearch/test/rest/test/VersionUtilsTests.java b/src/test/java/org/elasticsearch/test/rest/test/VersionUtilsTests.java deleted file mode 100644 index 3960012ed9c..00000000000 --- a/src/test/java/org/elasticsearch/test/rest/test/VersionUtilsTests.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.test.rest.test; - -import org.elasticsearch.test.ElasticsearchTestCase; -import org.junit.Test; - -import static org.elasticsearch.test.rest.support.VersionUtils.parseVersionNumber; -import static org.elasticsearch.test.rest.support.VersionUtils.skipCurrentVersion; -import static org.hamcrest.Matchers.*; - -public class VersionUtilsTests extends ElasticsearchTestCase { - - @Test - public void testParseVersionNumber() { - - int[] versionNumber = parseVersionNumber("0.90.6"); - assertThat(versionNumber.length, equalTo(3)); - assertThat(versionNumber[0], equalTo(0)); - assertThat(versionNumber[1], equalTo(90)); - assertThat(versionNumber[2], equalTo(6)); - - versionNumber = parseVersionNumber("0.90.999"); - assertThat(versionNumber.length, equalTo(3)); - assertThat(versionNumber[0], equalTo(0)); - assertThat(versionNumber[1], equalTo(90)); - assertThat(versionNumber[2], equalTo(999)); - - versionNumber = parseVersionNumber("0.20.11"); - assertThat(versionNumber.length, equalTo(3)); - assertThat(versionNumber[0], equalTo(0)); - assertThat(versionNumber[1], equalTo(20)); - assertThat(versionNumber[2], equalTo(11)); - - versionNumber = parseVersionNumber("1.0.0.Beta1"); - assertThat(versionNumber.length, equalTo(3)); - assertThat(versionNumber[0], equalTo(1)); - assertThat(versionNumber[1], equalTo(0)); - assertThat(versionNumber[2], equalTo(0)); - - versionNumber = parseVersionNumber("1.0.0.RC1"); - assertThat(versionNumber.length, equalTo(3)); - assertThat(versionNumber[0], equalTo(1)); - assertThat(versionNumber[1], equalTo(0)); - assertThat(versionNumber[2], equalTo(0)); - - versionNumber = parseVersionNumber("1.0.0"); - assertThat(versionNumber.length, equalTo(3)); - assertThat(versionNumber[0], equalTo(1)); - assertThat(versionNumber[1], equalTo(0)); - assertThat(versionNumber[2], equalTo(0)); - - versionNumber = parseVersionNumber("1.0"); - assertThat(versionNumber.length, equalTo(2)); - assertThat(versionNumber[0], equalTo(1)); - assertThat(versionNumber[1], equalTo(0)); - - versionNumber = parseVersionNumber("999"); - assertThat(versionNumber.length, equalTo(1)); - assertThat(versionNumber[0], equalTo(999)); - - versionNumber = parseVersionNumber("0"); - assertThat(versionNumber.length, equalTo(1)); - assertThat(versionNumber[0], equalTo(0)); - - try { - parseVersionNumber("1.0.Beta1"); - fail("parseVersionNumber should have thrown an error"); - } catch(IllegalArgumentException e) { - assertThat(e.getMessage(), containsString("version is not a number")); - assertThat(e.getCause(), instanceOf(NumberFormatException.class)); - } - } - - @Test - public void testSkipCurrentVersion() { - assertThat(skipCurrentVersion("0.90.2 - 0.90.6", "0.90.2"), equalTo(true)); - assertThat(skipCurrentVersion("0.90.2 - 0.90.6", "0.90.3"), equalTo(true)); - assertThat(skipCurrentVersion("0.90.2 - 0.90.6", "0.90.6"), equalTo(true)); - - assertThat(skipCurrentVersion("0.90.2 - 0.90.6", "0.20.10"), equalTo(false)); - assertThat(skipCurrentVersion("0.90.2 - 0.90.6", "0.90.1"), equalTo(false)); - assertThat(skipCurrentVersion("0.90.2 - 0.90.6", "0.90.7"), equalTo(false)); - assertThat(skipCurrentVersion("0.90.2 - 0.90.6", "1.0.0"), equalTo(false)); - - assertThat(skipCurrentVersion(" 0.90.2 - 0.90.999 ", "0.90.15"), equalTo(true)); - assertThat(skipCurrentVersion("0.90.2 - 0.90.999", "1.0.0"), equalTo(false)); - - assertThat(skipCurrentVersion("0 - 999", "0.90.15"), equalTo(true)); - assertThat(skipCurrentVersion("0 - 999", "0.20.1"), equalTo(true)); - assertThat(skipCurrentVersion("0 - 999", "1.0.0"), equalTo(true)); - - assertThat(skipCurrentVersion("0.90.9 - 999", "1.0.0"), equalTo(true)); - assertThat(skipCurrentVersion("0.90.9 - 999", "0.90.8"), equalTo(false)); - - try { - assertThat(skipCurrentVersion("0.90.2 - 0.90.999 - 1.0.0", "1.0.0"), equalTo(false)); - fail("skipCurrentVersion should have thrown an error"); - } catch(IllegalArgumentException e) { - assertThat(e.getMessage(), containsString("too many skip versions found")); - } - - } -} diff --git a/src/test/java/org/elasticsearch/test/store/MockDirectoryHelper.java b/src/test/java/org/elasticsearch/test/store/MockDirectoryHelper.java index 9b4f5efe7da..def8c09a3f3 100644 --- a/src/test/java/org/elasticsearch/test/store/MockDirectoryHelper.java +++ b/src/test/java/org/elasticsearch/test/store/MockDirectoryHelper.java @@ -45,7 +45,6 @@ import java.util.Set; public class MockDirectoryHelper { public static final String RANDOM_IO_EXCEPTION_RATE = "index.store.mock.random.io_exception_rate"; public static final String RANDOM_IO_EXCEPTION_RATE_ON_OPEN = "index.store.mock.random.io_exception_rate_on_open"; - public static final String RANDOM_THROTTLE = "index.store.mock.random.throttle"; public static final String RANDOM_PREVENT_DOUBLE_WRITE = "index.store.mock.random.prevent_double_write"; public static final String RANDOM_NO_DELETE_OPEN_FILE = "index.store.mock.random.no_delete_open_file"; public static final String CRASH_INDEX = "index.store.mock.random.crash_index"; @@ -70,7 +69,7 @@ public class MockDirectoryHelper { preventDoubleWrite = indexSettings.getAsBoolean(RANDOM_PREVENT_DOUBLE_WRITE, true); // true is default in MDW noDeleteOpenFile = indexSettings.getAsBoolean(RANDOM_NO_DELETE_OPEN_FILE, random.nextBoolean()); // true is default in MDW random.nextInt(shardId.getId() + 1); // some randomness per shard - throttle = Throttling.valueOf(indexSettings.get(RANDOM_THROTTLE, random.nextDouble() < 0.1 ? "SOMETIMES" : "NEVER")); + throttle = Throttling.NEVER; crashIndex = indexSettings.getAsBoolean(CRASH_INDEX, true); if (logger.isDebugEnabled()) { @@ -92,6 +91,7 @@ public class MockDirectoryHelper { // TODO: make this test robust to virus scanner w.setEnableVirusScanner(false); w.setNoDeleteOpenFile(noDeleteOpenFile); + w.setUseSlowOpenClosers(false); wrappers.add(w); return w; } @@ -115,7 +115,10 @@ public class MockDirectoryHelper { case 1: return new MmapFsDirectoryService(shardId, indexSettings, indexStore); case 0: - return new SimpleFsDirectoryService(shardId, indexSettings, indexStore); + if (random.nextInt(10) == 0) { + // use simplefs less, it synchronizes all threads reads + return new SimpleFsDirectoryService(shardId, indexSettings, indexStore); + } default: return new NioFsDirectoryService(shardId, indexSettings, indexStore); } @@ -184,7 +187,7 @@ public class MockDirectoryHelper { @Override public synchronized void sync(Collection names) throws IOException { // don't wear out our hardware so much in tests. - if (LuceneTestCase.rarely(superRandomState) || mustSync()) { + if (superRandomState.nextInt(100) == 0 || mustSync()) { super.sync(names); } else { superUnSyncedFiles.removeAll(names); diff --git a/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java b/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java index 718342f4c59..66af8d912da 100644 --- a/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java +++ b/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java @@ -20,12 +20,12 @@ package org.elasticsearch.test.store; import com.google.common.base.Charsets; + import org.apache.lucene.index.CheckIndex; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.store.Directory; import org.apache.lucene.store.LockFactory; import org.apache.lucene.store.StoreRateLimiting; -import org.apache.lucene.util.AbstractRandomizedTest; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.inject.Inject; @@ -44,6 +44,7 @@ import org.elasticsearch.index.store.distributor.Distributor; import org.elasticsearch.index.store.fs.FsDirectoryService; import org.elasticsearch.indices.IndicesLifecycle; import org.elasticsearch.indices.IndicesService; +import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.test.ElasticsearchIntegrationTest; import java.io.IOException; @@ -130,7 +131,7 @@ public class MockFSDirectoryService extends FsDirectoryService { return; } if (IndexWriter.isLocked(dir)) { - AbstractRandomizedTest.checkIndexFailed = true; + ElasticsearchTestCase.checkIndexFailed = true; throw new IllegalStateException("IndexWriter is still open on shard " + shardId); } try (CheckIndex checkIndex = new CheckIndex(dir)) { @@ -140,7 +141,7 @@ public class MockFSDirectoryService extends FsDirectoryService { out.flush(); CheckIndex.Status status = checkIndex.checkIndex(); if (!status.clean) { - AbstractRandomizedTest.checkIndexFailed = true; + ElasticsearchTestCase.checkIndexFailed = true; logger.warn("check index [failure] index files={}\n{}", Arrays.toString(dir.listAll()), new String(os.bytes().toBytes(), Charsets.UTF_8)); diff --git a/src/test/java/org/elasticsearch/test/test/InternalTestClusterTests.java b/src/test/java/org/elasticsearch/test/test/InternalTestClusterTests.java index 215023b9ce4..47bcff77b99 100644 --- a/src/test/java/org/elasticsearch/test/test/InternalTestClusterTests.java +++ b/src/test/java/org/elasticsearch/test/test/InternalTestClusterTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.test.test; import com.google.common.collect.ImmutableSet; import org.apache.lucene.util.IOUtils; +import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.common.settings.Settings; @@ -41,6 +42,7 @@ import static org.hamcrest.Matchers.hasEntry; * Basic test that ensure that the internal cluster reproduces the same * configuration given the same seed / input. */ +@LuceneTestCase.SuppressFileSystems("ExtrasFS") // doesn't work with potential multi data path from test cluster yet public class InternalTestClusterTests extends ElasticsearchTestCase { public void testInitializiationIsConsistent() { @@ -50,14 +52,12 @@ public class InternalTestClusterTests extends ElasticsearchTestCase { String clusterName = randomRealisticUnicodeOfCodepointLengthBetween(1, 10); SettingsSource settingsSource = SettingsSource.EMPTY; int numClientNodes = randomIntBetween(0, 10); - boolean enableRandomBenchNodes = randomBoolean(); boolean enableHttpPipelining = randomBoolean(); - int jvmOrdinal = randomIntBetween(0, 10); String nodePrefix = randomRealisticUnicodeOfCodepointLengthBetween(1, 10); - Path baseDir = newTempDirPath(); - InternalTestCluster cluster0 = new InternalTestCluster(clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName, settingsSource, numClientNodes, enableHttpPipelining, jvmOrdinal, nodePrefix); - InternalTestCluster cluster1 = new InternalTestCluster(clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName, settingsSource, numClientNodes, enableHttpPipelining, jvmOrdinal, nodePrefix); + Path baseDir = createTempDir(); + InternalTestCluster cluster0 = new InternalTestCluster(clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName, settingsSource, numClientNodes, enableHttpPipelining, nodePrefix); + InternalTestCluster cluster1 = new InternalTestCluster(clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName, settingsSource, numClientNodes, enableHttpPipelining, nodePrefix); assertClusters(cluster0, cluster1, true); } @@ -88,20 +88,20 @@ public class InternalTestClusterTests extends ElasticsearchTestCase { long clusterSeed = randomLong(); int minNumDataNodes = randomIntBetween(0, 3); int maxNumDataNodes = randomIntBetween(minNumDataNodes, 4); - final String clusterName = clusterName("shared", Integer.toString(CHILD_JVM_ID), clusterSeed); - String clusterName1 = clusterName("shared", Integer.toString(CHILD_JVM_ID), clusterSeed); - while (clusterName.equals(clusterName1)) { + final String clusterName1 = "shared1";//clusterName("shared1", clusterSeed); + final String clusterName2 = "shared2";//clusterName("shared", Integer.toString(CHILD_JVM_ID), clusterSeed); + /*while (clusterName.equals(clusterName1)) { clusterName1 = clusterName("shared", Integer.toString(CHILD_JVM_ID), clusterSeed); // spin until the time changes - } + }*/ SettingsSource settingsSource = SettingsSource.EMPTY; int numClientNodes = randomIntBetween(0, 2); boolean enableHttpPipelining = randomBoolean(); int jvmOrdinal = randomIntBetween(0, 10); String nodePrefix = "foobar"; - Path baseDir = newTempDirPath(); - InternalTestCluster cluster0 = new InternalTestCluster(clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName, settingsSource, numClientNodes, enableHttpPipelining, jvmOrdinal, nodePrefix); - InternalTestCluster cluster1 = new InternalTestCluster(clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName1, settingsSource, numClientNodes, enableHttpPipelining, jvmOrdinal, nodePrefix); + Path baseDir = createTempDir(); + InternalTestCluster cluster0 = new InternalTestCluster(clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName1, settingsSource, numClientNodes, enableHttpPipelining, nodePrefix); + InternalTestCluster cluster1 = new InternalTestCluster(clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName2, settingsSource, numClientNodes, enableHttpPipelining, nodePrefix); assertClusters(cluster0, cluster1, false); long seed = randomLong(); diff --git a/src/test/java/org/elasticsearch/test/test/SuiteScopeClusterTests.java b/src/test/java/org/elasticsearch/test/test/SuiteScopeClusterTests.java index 3252daf5c5d..bb6e4e976e1 100644 --- a/src/test/java/org/elasticsearch/test/test/SuiteScopeClusterTests.java +++ b/src/test/java/org/elasticsearch/test/test/SuiteScopeClusterTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.test.test; import com.carrotsearch.randomizedtesting.annotations.Repeat; + import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.TestCluster; import org.junit.Test; diff --git a/src/test/java/org/elasticsearch/test/test/VersionUtilsTests.java b/src/test/java/org/elasticsearch/test/test/VersionUtilsTests.java new file mode 100644 index 00000000000..e368a063b6b --- /dev/null +++ b/src/test/java/org/elasticsearch/test/test/VersionUtilsTests.java @@ -0,0 +1,83 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.elasticsearch.test.test; + +import org.elasticsearch.Version; +import org.elasticsearch.test.ElasticsearchTestCase; +import org.elasticsearch.test.VersionUtils; + +import java.util.List; + +public class VersionUtilsTests extends ElasticsearchTestCase { + + public void testAllVersionsSorted() { + List allVersions = VersionUtils.allVersions(); + for (int i = 0, j = 1; j < allVersions.size(); ++i, ++j) { + assertTrue(allVersions.get(i).before(allVersions.get(j))); + } + } + + public void testRandomVersionBetween() { + // full range + Version got = VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(), Version.CURRENT); + assertTrue(got.onOrAfter(VersionUtils.getFirstVersion())); + assertTrue(got.onOrBefore(Version.CURRENT)); + got = VersionUtils.randomVersionBetween(random(), null, Version.CURRENT); + assertTrue(got.onOrAfter(VersionUtils.getFirstVersion())); + assertTrue(got.onOrBefore(Version.CURRENT)); + got = VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(), null); + assertTrue(got.onOrAfter(VersionUtils.getFirstVersion())); + assertTrue(got.onOrBefore(Version.CURRENT)); + + // sub range + got = VersionUtils.randomVersionBetween(random(), Version.V_0_90_12, Version.V_1_4_5); + assertTrue(got.onOrAfter(Version.V_0_90_12)); + assertTrue(got.onOrBefore(Version.V_1_4_5)); + + // unbounded lower + got = VersionUtils.randomVersionBetween(random(), null, Version.V_1_4_5); + assertTrue(got.onOrAfter(VersionUtils.getFirstVersion())); + assertTrue(got.onOrBefore(Version.V_1_4_5)); + got = VersionUtils.randomVersionBetween(random(), null, VersionUtils.allVersions().get(0)); + assertTrue(got.onOrAfter(VersionUtils.getFirstVersion())); + assertTrue(got.onOrBefore(VersionUtils.allVersions().get(0))); + + // unbounded upper + got = VersionUtils.randomVersionBetween(random(), Version.V_0_90_12, null); + assertTrue(got.onOrAfter(Version.V_0_90_12)); + assertTrue(got.onOrBefore(Version.CURRENT)); + got = VersionUtils.randomVersionBetween(random(), VersionUtils.getPreviousVersion(), null); + assertTrue(got.onOrAfter(VersionUtils.getPreviousVersion())); + assertTrue(got.onOrBefore(Version.CURRENT)); + + // range of one + got = VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(), VersionUtils.getFirstVersion()); + assertEquals(got, VersionUtils.getFirstVersion()); + got = VersionUtils.randomVersionBetween(random(), Version.CURRENT, Version.CURRENT); + assertEquals(got, Version.CURRENT); + got = VersionUtils.randomVersionBetween(random(), Version.V_1_2_4, Version.V_1_2_4); + assertEquals(got, Version.V_1_2_4); + + // implicit range of one + got = VersionUtils.randomVersionBetween(random(), null, VersionUtils.getFirstVersion()); + assertEquals(got, VersionUtils.getFirstVersion()); + got = VersionUtils.randomVersionBetween(random(), Version.CURRENT, null); + assertEquals(got, Version.CURRENT); + } +} diff --git a/src/test/java/org/elasticsearch/test/transport/AssertingLocalTransport.java b/src/test/java/org/elasticsearch/test/transport/AssertingLocalTransport.java index 5a2f4f560fb..f5dc92ba3d1 100644 --- a/src/test/java/org/elasticsearch/test/transport/AssertingLocalTransport.java +++ b/src/test/java/org/elasticsearch/test/transport/AssertingLocalTransport.java @@ -24,7 +24,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ElasticsearchIntegrationTest; -import org.elasticsearch.test.ElasticsearchTestCase; +import org.elasticsearch.test.VersionUtils; import org.elasticsearch.test.hamcrest.ElasticsearchAssertions; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.*; @@ -55,13 +55,13 @@ public class AssertingLocalTransport extends LocalTransport { @Override protected void handleParsedResponse(final TransportResponse response, final TransportResponseHandler handler) { - ElasticsearchAssertions.assertVersionSerializable(ElasticsearchTestCase.randomVersionBetween(random, minVersion, maxVersion), response); + ElasticsearchAssertions.assertVersionSerializable(VersionUtils.randomVersionBetween(random, minVersion, maxVersion), response); super.handleParsedResponse(response, handler); } @Override public void sendRequest(final DiscoveryNode node, final long requestId, final String action, final TransportRequest request, TransportRequestOptions options) throws IOException, TransportException { - ElasticsearchAssertions.assertVersionSerializable(ElasticsearchTestCase.randomVersionBetween(random, minVersion, maxVersion), request); + ElasticsearchAssertions.assertVersionSerializable(VersionUtils.randomVersionBetween(random, minVersion, maxVersion), request); super.sendRequest(node, requestId, action, request, options); } } diff --git a/src/test/java/org/elasticsearch/transport/netty/SimpleNettyTransportTests.java b/src/test/java/org/elasticsearch/transport/netty/SimpleNettyTransportTests.java index ab169618ddf..8b30fd44136 100644 --- a/src/test/java/org/elasticsearch/transport/netty/SimpleNettyTransportTests.java +++ b/src/test/java/org/elasticsearch/transport/netty/SimpleNettyTransportTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.transport.netty; +import org.apache.lucene.util.LuceneTestCase.Slow; import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.network.NetworkService; @@ -31,6 +32,7 @@ import org.elasticsearch.transport.AbstractSimpleTransportTests; import org.elasticsearch.transport.ConnectTransportException; import org.junit.Test; +@Slow public class SimpleNettyTransportTests extends AbstractSimpleTransportTests { @Override diff --git a/src/test/java/org/elasticsearch/tribe/TribeTests.java b/src/test/java/org/elasticsearch/tribe/TribeTests.java index f2f25e4d776..880f88ef4d1 100644 --- a/src/test/java/org/elasticsearch/tribe/TribeTests.java +++ b/src/test/java/org/elasticsearch/tribe/TribeTests.java @@ -19,8 +19,8 @@ package org.elasticsearch.tribe; -import com.carrotsearch.randomizedtesting.LifecycleScope; import com.google.common.collect.ImmutableMap; +import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; import org.elasticsearch.client.Client; @@ -39,6 +39,7 @@ import org.elasticsearch.node.NodeBuilder; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.InternalTestCluster; import org.elasticsearch.test.TestCluster; +import org.apache.lucene.util.LuceneTestCase.Slow; import org.junit.After; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -57,6 +58,8 @@ import static org.hamcrest.Matchers.notNullValue; * Note, when talking to tribe client, no need to set the local flag on master read operations, it * does it by default. */ +@Slow +@LuceneTestCase.SuppressFileSystems("ExtrasFS") // doesn't work with potential multi data path from test cluster yet public class TribeTests extends ElasticsearchIntegrationTest { public static final String SECOND_CLUSTER_NODE_PREFIX = "node_tribe2"; @@ -70,7 +73,7 @@ public class TribeTests extends ElasticsearchIntegrationTest { public static void setupSecondCluster() throws Exception { ElasticsearchIntegrationTest.beforeClass(); // create another cluster - cluster2 = new InternalTestCluster(randomLong(), newTempDirPath(LifecycleScope.SUITE), 2, 2, Strings.randomBase64UUID(getRandom()), 0, false, CHILD_JVM_ID, SECOND_CLUSTER_NODE_PREFIX); + cluster2 = new InternalTestCluster(randomLong(), createTempDir(), 2, 2, Strings.randomBase64UUID(getRandom()), 0, false, SECOND_CLUSTER_NODE_PREFIX); cluster2.beforeTest(getRandom(), 0.1); cluster2.ensureAtLeastNumDataNodes(2); } diff --git a/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java b/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java index b7524dfc8a7..2089404165c 100644 --- a/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java +++ b/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java @@ -19,7 +19,6 @@ package org.elasticsearch.tribe; -import com.carrotsearch.randomizedtesting.LifecycleScope; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -34,7 +33,6 @@ import org.junit.BeforeClass; import org.junit.Test; import java.nio.file.Path; -import java.nio.file.Paths; import static org.hamcrest.CoreMatchers.either; import static org.hamcrest.CoreMatchers.equalTo; @@ -57,7 +55,7 @@ public class TribeUnitTests extends ElasticsearchTestCase { .put("config.ignore_system_properties", true) .put("http.enabled", false) .put("node.mode", NODE_MODE) - .put("path.home", newTempDirPath(LifecycleScope.SUITE)).build(); + .put("path.home", createTempDir()).build(); tribe1 = NodeBuilder.nodeBuilder().settings(ImmutableSettings.builder().put(baseSettings).put("cluster.name", "tribe1").put("node.name", "tribe1_node")).node(); tribe2 = NodeBuilder.nodeBuilder().settings(ImmutableSettings.builder().put(baseSettings).put("cluster.name", "tribe2").put("node.name", "tribe2_node")).node(); @@ -88,7 +86,7 @@ public class TribeUnitTests extends ElasticsearchTestCase { @Test public void testThatTribeClientsIgnoreGlobalConfig() throws Exception { - Path pathConf = Paths.get(TribeUnitTests.class.getResource("elasticsearch.yml").toURI()).getParent(); + Path pathConf = getDataPath("elasticsearch.yml").getParent(); Settings settings = ImmutableSettings.builder().put("config.ignore_system_properties", true).put("path.conf", pathConf).build(); assertTribeNodeSuccesfullyCreated(settings); } diff --git a/src/test/java/org/elasticsearch/update/UpdateTests.java b/src/test/java/org/elasticsearch/update/UpdateTests.java index 3c0581b3206..8d58a9b763e 100644 --- a/src/test/java/org/elasticsearch/update/UpdateTests.java +++ b/src/test/java/org/elasticsearch/update/UpdateTests.java @@ -19,7 +19,6 @@ package org.elasticsearch.update; -import org.apache.lucene.util.LuceneTestCase.Slow; import org.elasticsearch.ElasticsearchTimeoutException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequestValidationException; diff --git a/src/test/java/org/elasticsearch/validate/SimpleValidateQueryTests.java b/src/test/java/org/elasticsearch/validate/SimpleValidateQueryTests.java index c51e57e0f1f..8ef7cfc2428 100644 --- a/src/test/java/org/elasticsearch/validate/SimpleValidateQueryTests.java +++ b/src/test/java/org/elasticsearch/validate/SimpleValidateQueryTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.validate; import com.google.common.base.Charsets; + import org.elasticsearch.action.admin.indices.alias.Alias; import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse; import org.elasticsearch.client.Client; diff --git a/src/test/java/org/elasticsearch/versioning/SimpleVersioningTests.java b/src/test/java/org/elasticsearch/versioning/SimpleVersioningTests.java index d47b9bab562..641b41afc17 100644 --- a/src/test/java/org/elasticsearch/versioning/SimpleVersioningTests.java +++ b/src/test/java/org/elasticsearch/versioning/SimpleVersioningTests.java @@ -27,6 +27,7 @@ import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; +import com.carrotsearch.randomizedtesting.RandomizedTest; import org.apache.lucene.util.LuceneTestCase.Slow; import org.apache.lucene.util.TestUtil; import org.elasticsearch.action.ActionResponse; @@ -556,7 +557,7 @@ public class SimpleVersioningTests extends ElasticsearchIntegrationTest { } int numIDs; - if (isNightly()) { + if (TEST_NIGHTLY) { numIDs = scaledRandomIntBetween(300, 1000); } else { numIDs = scaledRandomIntBetween(50, 100); @@ -572,7 +573,7 @@ public class SimpleVersioningTests extends ElasticsearchIntegrationTest { // Attach random versions to them: long version = 0; - final IDAndVersion[] idVersions = new IDAndVersion[TestUtil.nextInt(random, numIDs/2, numIDs*(isNightly() ? 8 : 2))]; + final IDAndVersion[] idVersions = new IDAndVersion[TestUtil.nextInt(random, numIDs/2, numIDs*(TEST_NIGHTLY ? 8 : 2))]; final Map truth = new HashMap<>(); if (VERBOSE) { @@ -615,7 +616,7 @@ public class SimpleVersioningTests extends ElasticsearchIntegrationTest { final AtomicInteger upto = new AtomicInteger(); final CountDownLatch startingGun = new CountDownLatch(1); - Thread[] threads = new Thread[TestUtil.nextInt(random, 1, isNightly() ? 20 : 5)]; + Thread[] threads = new Thread[TestUtil.nextInt(random, 1, TEST_NIGHTLY ? 20 : 5)]; final long startTime = System.nanoTime(); for(int i=0;i