Search in sources :

Example 56 with Version

use of org.elasticsearch.Version in project elasticsearch by elastic.

the class PreBuiltAnalyzerIntegrationIT method testThatPreBuiltAnalyzersAreNotClosedOnIndexClose.

public void testThatPreBuiltAnalyzersAreNotClosedOnIndexClose() throws Exception {
    Map<PreBuiltAnalyzers, List<Version>> loadedAnalyzers = new HashMap<>();
    List<String> indexNames = new ArrayList<>();
    final int numIndices = scaledRandomIntBetween(2, 4);
    for (int i = 0; i < numIndices; i++) {
        String indexName = randomAsciiOfLength(10).toLowerCase(Locale.ROOT);
        indexNames.add(indexName);
        int randomInt = randomInt(PreBuiltAnalyzers.values().length - 1);
        PreBuiltAnalyzers preBuiltAnalyzer = PreBuiltAnalyzers.values()[randomInt];
        String name = preBuiltAnalyzer.name().toLowerCase(Locale.ROOT);
        Version randomVersion = randomVersion(random());
        if (!loadedAnalyzers.containsKey(preBuiltAnalyzer)) {
            loadedAnalyzers.put(preBuiltAnalyzer, new ArrayList<Version>());
        }
        loadedAnalyzers.get(preBuiltAnalyzer).add(randomVersion);
        final XContentBuilder mapping = jsonBuilder().startObject().startObject("type").startObject("properties").startObject("foo").field("type", "text").field("analyzer", name).endObject().endObject().endObject().endObject();
        Settings versionSettings = settings(randomVersion).build();
        client().admin().indices().prepareCreate(indexName).addMapping("type", mapping).setSettings(versionSettings).get();
    }
    ensureGreen();
    final int numDocs = randomIntBetween(10, 100);
    // index some amount of data
    for (int i = 0; i < numDocs; i++) {
        String randomIndex = indexNames.get(randomInt(indexNames.size() - 1));
        String randomId = randomInt() + "";
        Map<String, Object> data = new HashMap<>();
        data.put("foo", randomAsciiOfLength(scaledRandomIntBetween(5, 50)));
        index(randomIndex, "type", randomId, data);
    }
    refresh();
    // close some of the indices
    int amountOfIndicesToClose = randomInt(numIndices - 1);
    for (int i = 0; i < amountOfIndicesToClose; i++) {
        String indexName = indexNames.get(i);
        client().admin().indices().prepareClose(indexName).execute().actionGet();
    }
    ensureGreen();
    // check that all above configured analyzers have been loaded
    assertThatAnalyzersHaveBeenLoaded(loadedAnalyzers);
    // check that all of the prebuilt analyzers are still open
    assertLuceneAnalyzersAreNotClosed(loadedAnalyzers);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Version(org.elasticsearch.Version) VersionUtils.randomVersion(org.elasticsearch.test.VersionUtils.randomVersion) ArrayList(java.util.ArrayList) List(java.util.List) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Settings(org.elasticsearch.common.settings.Settings)

Example 57 with Version

use of org.elasticsearch.Version in project elasticsearch by elastic.

the class OldIndexUtils method getIndexDir.

public static Path getIndexDir(final Logger logger, final String indexName, final String indexFile, final Path dataDir) throws IOException {
    final Version version = Version.fromString(indexName.substring("index-".length()));
    if (version.before(Version.V_5_0_0_alpha1)) {
        // the bwc scripts packs the indices under this path
        Path src = dataDir.resolve("nodes/0/indices/" + indexName);
        assertTrue("[" + indexFile + "] missing index dir: " + src.toString(), Files.exists(src));
        return src;
    } else {
        final List<Path> indexFolders = new ArrayList<>();
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(dataDir.resolve("0/indices"), (p) -> p.getFileName().toString().startsWith("extra") == false)) {
            // extra FS can break this...
            for (final Path path : stream) {
                indexFolders.add(path);
            }
        }
        assertThat(indexFolders.toString(), indexFolders.size(), equalTo(1));
        final IndexMetaData indexMetaData = IndexMetaData.FORMAT.loadLatestState(logger, NamedXContentRegistry.EMPTY, indexFolders.get(0));
        assertNotNull(indexMetaData);
        assertThat(indexFolders.get(0).getFileName().toString(), equalTo(indexMetaData.getIndexUUID()));
        assertThat(indexMetaData.getCreationVersion(), equalTo(version));
        return indexFolders.get(0);
    }
}
Also used : Path(java.nio.file.Path) Version(org.elasticsearch.Version) ArrayList(java.util.ArrayList) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 58 with Version

use of org.elasticsearch.Version in project elasticsearch by elastic.

the class AbstractQueryTestCase method beforeClass.

@BeforeClass
public static void beforeClass() {
    // we have to prefer CURRENT since with the range of versions we support it's rather unlikely to get the current actually.
    Version indexVersionCreated = randomBoolean() ? Version.CURRENT : VersionUtils.randomVersionBetween(random(), null, Version.CURRENT);
    nodeSettings = Settings.builder().put("node.name", AbstractQueryTestCase.class.toString()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), false).build();
    indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, indexVersionCreated).build();
    index = new Index(randomAsciiOfLengthBetween(1, 10), "_na_");
    //create some random type with some default field, those types will stick around for all of the subclasses
    currentTypes = new String[randomIntBetween(0, 5)];
    for (int i = 0; i < currentTypes.length; i++) {
        String type = randomAsciiOfLengthBetween(1, 10);
        currentTypes[i] = type;
    }
    //set some random types to be queried as part the search request, before each test
    randomTypes = getRandomTypes();
}
Also used : Version(org.elasticsearch.Version) Index(org.elasticsearch.index.Index) Matchers.containsString(org.hamcrest.Matchers.containsString) BeforeClass(org.junit.BeforeClass)

Example 59 with Version

use of org.elasticsearch.Version in project elasticsearch by elastic.

the class NodeTests method testWarnIfPreRelease.

public void testWarnIfPreRelease() {
    final Logger logger = mock(Logger.class);
    final int id = randomIntBetween(1, 9) * 1000000;
    final Version releaseVersion = Version.fromId(id + 99);
    final Version preReleaseVersion = Version.fromId(id + randomIntBetween(0, 98));
    Node.warnIfPreRelease(releaseVersion, false, logger);
    verifyNoMoreInteractions(logger);
    reset(logger);
    Node.warnIfPreRelease(releaseVersion, true, logger);
    verify(logger).warn("version [{}] is a pre-release version of Elasticsearch and is not suitable for production", releaseVersion + "-SNAPSHOT");
    reset(logger);
    final boolean isSnapshot = randomBoolean();
    Node.warnIfPreRelease(preReleaseVersion, isSnapshot, logger);
    verify(logger).warn("version [{}] is a pre-release version of Elasticsearch and is not suitable for production", preReleaseVersion + (isSnapshot ? "-SNAPSHOT" : ""));
}
Also used : Version(org.elasticsearch.Version) Logger(org.apache.logging.log4j.Logger)

Example 60 with Version

use of org.elasticsearch.Version in project elasticsearch by elastic.

the class VersionUtilsTests method testRandomVersionBetween.

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_2_0_0, Version.V_5_0_0_alpha1);
    assertTrue(got.onOrAfter(Version.V_2_0_0));
    assertTrue(got.onOrBefore(Version.V_5_0_0_alpha1));
    // unbounded lower
    got = VersionUtils.randomVersionBetween(random(), null, Version.V_5_0_0_alpha1);
    assertTrue(got.onOrAfter(VersionUtils.getFirstVersion()));
    assertTrue(got.onOrBefore(Version.V_5_0_0_alpha1));
    got = VersionUtils.randomVersionBetween(random(), null, VersionUtils.allReleasedVersions().get(0));
    assertTrue(got.onOrAfter(VersionUtils.getFirstVersion()));
    assertTrue(got.onOrBefore(VersionUtils.allReleasedVersions().get(0)));
    // unbounded upper
    got = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, null);
    assertTrue(got.onOrAfter(Version.V_2_0_0));
    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_5_0_0_alpha1, Version.V_5_0_0_alpha1);
    assertEquals(got, Version.V_5_0_0_alpha1);
    // 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);
}
Also used : Version(org.elasticsearch.Version)

Aggregations

Version (org.elasticsearch.Version)124 Settings (org.elasticsearch.common.settings.Settings)51 StreamInput (org.elasticsearch.common.io.stream.StreamInput)21 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)20 HashMap (java.util.HashMap)17 ArrayList (java.util.ArrayList)16 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)16 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)14 IOException (java.io.IOException)13 SearchResponse (org.elasticsearch.action.search.SearchResponse)12 List (java.util.List)11 Map (java.util.Map)11 ClusterState (org.elasticsearch.cluster.ClusterState)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 ClusterName (org.elasticsearch.cluster.ClusterName)9 TimeValue (org.elasticsearch.common.unit.TimeValue)9 VersionUtils.randomVersion (org.elasticsearch.test.VersionUtils.randomVersion)9 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)8 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)8 GeoPoint (org.elasticsearch.common.geo.GeoPoint)8