Search in sources :

Example 31 with IndexMainType

use of org.sonar.server.es.IndexType.IndexMainType in project sonarqube by SonarSource.

the class IndexCreatorTest method recreate_index_on_definition_changes.

@Test
public void recreate_index_on_definition_changes() {
    // v1
    run(new FakeIndexDefinition());
    IndexMainType fakeIndexType = main(Index.simple("fakes"), "fake");
    String id = "1";
    es.client().index(new IndexRequest(fakeIndexType.getIndex().getName(), fakeIndexType.getType()).id(id).source(new FakeDoc().getFields()).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE));
    assertThat(es.client().get(new GetRequest(fakeIndexType.getIndex().getName(), fakeIndexType.getType(), id)).isExists()).isTrue();
    // v2
    run(new FakeIndexDefinitionV2());
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetadata>> mappings = mappings();
    MappingMetadata mapping = mappings.get("fakes").get("fake");
    assertThat(countMappingFields(mapping)).isEqualTo(3);
    assertThat(field(mapping, "updatedAt")).containsEntry("type", "date");
    assertThat(field(mapping, "newField")).containsEntry("type", "integer");
    assertThat(es.client().get(new GetRequest(fakeIndexType.getIndex().getName(), fakeIndexType.getType(), id)).isExists()).isFalse();
}
Also used : GetRequest(org.elasticsearch.action.get.GetRequest) IndexMainType(org.sonar.server.es.IndexType.IndexMainType) IndexRequest(org.elasticsearch.action.index.IndexRequest) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) MappingMetadata(org.elasticsearch.cluster.metadata.MappingMetadata) Test(org.junit.Test)

Aggregations

IndexMainType (org.sonar.server.es.IndexType.IndexMainType)31 Test (org.junit.Test)27 TestNewIndex (org.sonar.server.es.newindex.TestNewIndex)15 MapSettings (org.sonar.api.config.internal.MapSettings)6 SimpleIndexMainType (org.sonar.server.es.IndexType.SimpleIndexMainType)6 Configuration (org.sonar.api.config.Configuration)4 SettingsConfiguration (org.sonar.server.es.newindex.SettingsConfiguration)4 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)3 IndexRelationType (org.sonar.server.es.IndexType.IndexRelationType)3 Arrays (java.util.Arrays)2 List (java.util.List)2 Set (java.util.Set)2 Consumer (java.util.function.Consumer)2 Collectors.toList (java.util.stream.Collectors.toList)2 Collectors.toSet (java.util.stream.Collectors.toSet)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 CLUSTER_ENABLED (org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED)2 Index (org.sonar.server.es.Index)2 TypeMapping (org.sonar.server.es.newindex.TypeMapping)2 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1