Search in sources :

Example 46 with Version

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

the class NGramTokenizerFactoryTests method randomVersion.

private Version randomVersion(Random random) throws IllegalArgumentException, IllegalAccessException {
    Field[] declaredFields = Version.class.getFields();
    List<Field> versionFields = new ArrayList<>();
    for (Field field : declaredFields) {
        if ((field.getModifiers() & Modifier.STATIC) != 0 && field.getName().startsWith("V_") && field.getType() == Version.class) {
            versionFields.add(field);
        }
    }
    return (Version) versionFields.get(random.nextInt(versionFields.size())).get(Version.class);
}
Also used : Field(java.lang.reflect.Field) Version(org.elasticsearch.Version) ArrayList(java.util.ArrayList)

Example 47 with Version

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

the class PreBuiltAnalyzerTests method testThatAnalyzersAreUsedInMapping.

public void testThatAnalyzersAreUsedInMapping() throws IOException {
    int randomInt = randomInt(PreBuiltAnalyzers.values().length - 1);
    PreBuiltAnalyzers randomPreBuiltAnalyzer = PreBuiltAnalyzers.values()[randomInt];
    String analyzerName = randomPreBuiltAnalyzer.name().toLowerCase(Locale.ROOT);
    Version randomVersion = randomVersion(random());
    Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, randomVersion).build();
    NamedAnalyzer namedAnalyzer = new PreBuiltAnalyzerProvider(analyzerName, AnalyzerScope.INDEX, randomPreBuiltAnalyzer.getAnalyzer(randomVersion)).get();
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field").field("type", "text").field("analyzer", analyzerName).endObject().endObject().endObject().endObject().string();
    DocumentMapper docMapper = createIndex("test", indexSettings).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
    FieldMapper fieldMapper = docMapper.mappers().getMapper("field");
    assertThat(fieldMapper.fieldType().searchAnalyzer(), instanceOf(NamedAnalyzer.class));
    NamedAnalyzer fieldMapperNamedAnalyzer = fieldMapper.fieldType().searchAnalyzer();
    assertThat(fieldMapperNamedAnalyzer.analyzer(), is(namedAnalyzer.analyzer()));
}
Also used : Version(org.elasticsearch.Version) VersionUtils.randomVersion(org.elasticsearch.test.VersionUtils.randomVersion) PreBuiltAnalyzers(org.elasticsearch.indices.analysis.PreBuiltAnalyzers) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) FieldMapper(org.elasticsearch.index.mapper.FieldMapper) Settings(org.elasticsearch.common.settings.Settings)

Example 48 with Version

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

the class IndexSettingsTests method testRunListener.

public void testRunListener() {
    Version version = VersionUtils.getPreviousVersion();
    Settings theSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).put(IndexMetaData.SETTING_INDEX_UUID, "0xdeadbeef").build();
    final AtomicInteger integer = new AtomicInteger(0);
    Setting<Integer> integerSetting = Setting.intSetting("index.test.setting.int", -1, Property.Dynamic, Property.IndexScope);
    IndexMetaData metaData = newIndexMeta("index", theSettings);
    IndexSettings settings = newIndexSettings(newIndexMeta("index", theSettings), Settings.EMPTY, integerSetting);
    settings.getScopedSettings().addSettingsUpdateConsumer(integerSetting, integer::set);
    assertEquals(version, settings.getIndexVersionCreated());
    assertEquals("0xdeadbeef", settings.getUUID());
    assertFalse(settings.updateIndexMetaData(metaData));
    assertEquals(metaData.getSettings().getAsMap(), settings.getSettings().getAsMap());
    assertEquals(0, integer.get());
    assertTrue(settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(theSettings).put("index.test.setting.int", 42).build())));
    assertEquals(42, integer.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Version(org.elasticsearch.Version) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) Settings(org.elasticsearch.common.settings.Settings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 49 with Version

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

the class IndexSettingsTests method testSettingsUpdateValidator.

public void testSettingsUpdateValidator() {
    Version version = VersionUtils.getPreviousVersion();
    Settings theSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).put(IndexMetaData.SETTING_INDEX_UUID, "0xdeadbeef").build();
    final AtomicInteger integer = new AtomicInteger(0);
    Setting<Integer> integerSetting = Setting.intSetting("index.test.setting.int", -1, Property.Dynamic, Property.IndexScope);
    IndexMetaData metaData = newIndexMeta("index", theSettings);
    IndexSettings settings = newIndexSettings(newIndexMeta("index", theSettings), Settings.EMPTY, integerSetting);
    settings.getScopedSettings().addSettingsUpdateConsumer(integerSetting, integer::set, (i) -> {
        if (i == 42)
            throw new AssertionError("boom");
    });
    assertEquals(version, settings.getIndexVersionCreated());
    assertEquals("0xdeadbeef", settings.getUUID());
    assertFalse(settings.updateIndexMetaData(metaData));
    assertEquals(metaData.getSettings().getAsMap(), settings.getSettings().getAsMap());
    assertEquals(0, integer.get());
    expectThrows(IllegalArgumentException.class, () -> settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(theSettings).put("index.test.setting.int", 42).build())));
    assertTrue(settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(theSettings).put("index.test.setting.int", 41).build())));
    assertEquals(41, integer.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Version(org.elasticsearch.Version) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) Settings(org.elasticsearch.common.settings.Settings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 50 with Version

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

the class IndexSettingsTests method testSettingsConsistency.

public void testSettingsConsistency() {
    Version version = VersionUtils.getPreviousVersion();
    IndexMetaData metaData = newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build());
    IndexSettings settings = new IndexSettings(metaData, Settings.EMPTY);
    assertEquals(version, settings.getIndexVersionCreated());
    assertEquals("_na_", settings.getUUID());
    try {
        settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("index.test.setting.int", 42).build()));
        fail("version has changed");
    } catch (IllegalArgumentException ex) {
        assertTrue(ex.getMessage(), ex.getMessage().startsWith("version mismatch on settings update expected: "));
    }
    // use version number that is unknown
    metaData = newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.fromId(999999)).build());
    settings = new IndexSettings(metaData, Settings.EMPTY);
    assertEquals(Version.fromId(999999), settings.getIndexVersionCreated());
    assertEquals("_na_", settings.getUUID());
    settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.fromId(999999)).put("index.test.setting.int", 42).build()));
    metaData = newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_INDEX_UUID, "0xdeadbeef").build());
    settings = new IndexSettings(metaData, Settings.EMPTY);
    try {
        settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put("index.test.setting.int", 42).build()));
        fail("uuid missing/change");
    } catch (IllegalArgumentException ex) {
        assertEquals("uuid mismatch on settings update expected: 0xdeadbeef but was: _na_", ex.getMessage());
    }
    assertEquals(metaData.getSettings().getAsMap(), settings.getSettings().getAsMap());
}
Also used : Version(org.elasticsearch.Version) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

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