Search in sources :

Example 6 with TypeMapping

use of org.sonar.server.es.newindex.TypeMapping in project sonarqube by SonarSource.

the class IndexDefinitionHashTest method computeAndVerifyAllDifferentHashesOnMapping.

@SafeVarargs
private final void computeAndVerifyAllDifferentHashesOnMapping(IndexMainType mainType, Consumer<TypeMapping>... fieldTypes) {
    List<TestNewIndex> mainIndices = Arrays.stream(fieldTypes).map(consumer -> {
        TestNewIndex mainTypeMapping = new TestNewIndex(mainType, settingsConfiguration);
        consumer.accept(mainTypeMapping.getMainTypeMapping());
        return mainTypeMapping;
    }).collect(toList());
    List<TestNewIndex> relationIndices = Arrays.stream(fieldTypes).map(consumer -> {
        TestNewIndex relationTypeMapping = new TestNewIndex(mainType, settingsConfiguration);
        consumer.accept(relationTypeMapping.createRelationMapping("donut"));
        return relationTypeMapping;
    }).collect(toList());
    Set<String> mainHashes = mainIndices.stream().map(IndexDefinitionHashTest::hashOf).collect(toSet());
    Set<String> relationHashes = relationIndices.stream().map(IndexDefinitionHashTest::hashOf).collect(toSet());
    assertThat(mainHashes).isEqualTo(mainIndices.stream().map(IndexDefinitionHashTest::hashOf).collect(toSet())).doesNotContainAnyElementsOf(relationHashes).hasSize(fieldTypes.length);
    assertThat(relationHashes).isEqualTo(relationIndices.stream().map(IndexDefinitionHashTest::hashOf).collect(toSet())).doesNotContainAnyElementsOf(mainHashes).hasSize(fieldTypes.length);
}
Also used : Arrays(java.util.Arrays) CLUSTER_ENABLED(org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Test(org.junit.Test) MapSettings(org.sonar.api.config.internal.MapSettings) TestNewIndex(org.sonar.server.es.newindex.TestNewIndex) Consumer(java.util.function.Consumer) SettingsConfiguration(org.sonar.server.es.newindex.SettingsConfiguration) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) IndexMainType(org.sonar.server.es.IndexType.IndexMainType) Configuration(org.sonar.api.config.Configuration) TypeMapping(org.sonar.server.es.newindex.TypeMapping) Collectors.toSet(java.util.stream.Collectors.toSet) TestNewIndex(org.sonar.server.es.newindex.TestNewIndex)

Example 7 with TypeMapping

use of org.sonar.server.es.newindex.TypeMapping in project sonarqube by SonarSource.

the class ComponentIndexDefinition method define.

@Override
public void define(IndexDefinitionContext context) {
    NewAuthorizedIndex index = context.createWithAuthorization(DESCRIPTOR, newBuilder(config).setRefreshInterval(MANUAL_REFRESH_INTERVAL).setDefaultNbOfShards(DEFAULT_NUMBER_OF_SHARDS).build()).setEnableSource(enableSource);
    TypeMapping mapping = index.createTypeMapping(TYPE_COMPONENT);
    mapping.keywordFieldBuilder(FIELD_UUID).disableNorms().build();
    mapping.keywordFieldBuilder(FIELD_PROJECT_UUID).disableNorms().build();
    mapping.keywordFieldBuilder(FIELD_KEY).addSubFields(SORTABLE_ANALYZER).build();
    mapping.textFieldBuilder(FIELD_NAME).withFieldData().store().termVectorWithPositionOffsets().addSubFields(NAME_ANALYZERS).build();
    mapping.keywordFieldBuilder(FIELD_QUALIFIER).build();
}
Also used : NewAuthorizedIndex(org.sonar.server.es.newindex.NewAuthorizedIndex) TypeMapping(org.sonar.server.es.newindex.TypeMapping)

Example 8 with TypeMapping

use of org.sonar.server.es.newindex.TypeMapping in project sonarqube by SonarSource.

the class IndexDefinitionHashTest method computeAndVerifyAllSameHashesOnMapping.

@SafeVarargs
private final void computeAndVerifyAllSameHashesOnMapping(IndexMainType mainType, Consumer<TypeMapping>... fieldTypes) {
    List<Consumer<TypeMapping>> fieldTypes1 = Arrays.asList(fieldTypes);
    List<TestNewIndex> mainIndices = fieldTypes1.stream().map(consumer -> {
        TestNewIndex mainTypeMapping = new TestNewIndex(mainType, settingsConfiguration);
        consumer.accept(mainTypeMapping.getMainTypeMapping());
        return mainTypeMapping;
    }).collect(toList());
    List<TestNewIndex> relationIndices = fieldTypes1.stream().map(consumer -> {
        TestNewIndex relationTypeMapping = new TestNewIndex(mainType, settingsConfiguration);
        consumer.accept(relationTypeMapping.createRelationMapping("donut"));
        return relationTypeMapping;
    }).collect(toList());
    Set<String> mainHashes = mainIndices.stream().map(IndexDefinitionHashTest::hashOf).collect(toSet());
    Set<String> relationHashes = relationIndices.stream().map(IndexDefinitionHashTest::hashOf).collect(toSet());
    assertThat(mainHashes).isEqualTo(mainIndices.stream().map(IndexDefinitionHashTest::hashOf).collect(toSet())).doesNotContainAnyElementsOf(relationHashes).hasSize(1);
    assertThat(relationHashes).isEqualTo(relationIndices.stream().map(IndexDefinitionHashTest::hashOf).collect(toSet())).doesNotContainAnyElementsOf(mainHashes).hasSize(1);
}
Also used : Arrays(java.util.Arrays) CLUSTER_ENABLED(org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Test(org.junit.Test) MapSettings(org.sonar.api.config.internal.MapSettings) TestNewIndex(org.sonar.server.es.newindex.TestNewIndex) Consumer(java.util.function.Consumer) SettingsConfiguration(org.sonar.server.es.newindex.SettingsConfiguration) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) IndexMainType(org.sonar.server.es.IndexType.IndexMainType) Configuration(org.sonar.api.config.Configuration) TypeMapping(org.sonar.server.es.newindex.TypeMapping) Collectors.toSet(java.util.stream.Collectors.toSet) Consumer(java.util.function.Consumer) TestNewIndex(org.sonar.server.es.newindex.TestNewIndex)

Aggregations

TypeMapping (org.sonar.server.es.newindex.TypeMapping)8 NewAuthorizedIndex (org.sonar.server.es.newindex.NewAuthorizedIndex)3 NewRegularIndex (org.sonar.server.es.newindex.NewRegularIndex)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 Test (org.junit.Test)2 Configuration (org.sonar.api.config.Configuration)2 MapSettings (org.sonar.api.config.internal.MapSettings)2 CLUSTER_ENABLED (org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED)2 IndexMainType (org.sonar.server.es.IndexType.IndexMainType)2 SettingsConfiguration (org.sonar.server.es.newindex.SettingsConfiguration)2 TestNewIndex (org.sonar.server.es.newindex.TestNewIndex)2