Search in sources :

Example 11 with IndexMainType

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

the class IndexDefinitionHashTest method hash_changes_if_keyword_options_change.

@Test
public void hash_changes_if_keyword_options_change() {
    Index index = Index.withRelations("foo");
    IndexMainType mainType = IndexMainType.main(index, "bar");
    String fieldName = "field1";
    computeAndVerifyAllDifferentHashesOnMapping(mainType, (mapping) -> mapping.keywordFieldBuilder(fieldName).build(), (mapping) -> mapping.keywordFieldBuilder(fieldName).disableSortingAndAggregating().build(), (mapping) -> mapping.keywordFieldBuilder(fieldName).disableSortingAndAggregating().disableNorms().build(), (mapping) -> mapping.keywordFieldBuilder(fieldName).disableSortingAndAggregating().disableSearch().build(), (mapping) -> mapping.keywordFieldBuilder(fieldName).disableSortingAndAggregating().disableNorms().disableSearch().build(), (mapping) -> mapping.keywordFieldBuilder(fieldName).disableNorms().build(), (mapping) -> mapping.keywordFieldBuilder(fieldName).disableNorms().disableSearch().build(), (mapping) -> mapping.keywordFieldBuilder(fieldName).disableSearch().build());
}
Also used : TestNewIndex(org.sonar.server.es.newindex.TestNewIndex) IndexMainType(org.sonar.server.es.IndexType.IndexMainType) Test(org.junit.Test)

Example 12 with IndexMainType

use of org.sonar.server.es.IndexType.IndexMainType 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 13 with IndexMainType

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

the class IndexDefinitionHashTest method hash_changes_if_mainType_is_different.

@Test
public void hash_changes_if_mainType_is_different() {
    Index simpleIndex = Index.simple("foo");
    Index withRelationsIndex = Index.withRelations("foo");
    IndexMainType mainTypeBar = IndexMainType.main(simpleIndex, "bar");
    TestNewIndex indexSimpleBar = new TestNewIndex(mainTypeBar, settingsConfiguration);
    TestNewIndex indexSimpleDonut = new TestNewIndex(IndexMainType.main(simpleIndex, "donut"), settingsConfiguration);
    TestNewIndex indexWithRelationsBar = new TestNewIndex(IndexMainType.main(withRelationsIndex, "bar"), settingsConfiguration);
    assertThat(hashOf(indexSimpleBar)).isEqualTo(hashOf(new TestNewIndex(mainTypeBar, settingsConfiguration))).isNotEqualTo(hashOf(indexSimpleDonut)).isNotEqualTo(hashOf(indexWithRelationsBar));
    assertThat(hashOf(indexSimpleDonut)).isNotEqualTo(hashOf(indexWithRelationsBar));
}
Also used : TestNewIndex(org.sonar.server.es.newindex.TestNewIndex) IndexMainType(org.sonar.server.es.IndexType.IndexMainType) TestNewIndex(org.sonar.server.es.newindex.TestNewIndex) Test(org.junit.Test)

Example 14 with IndexMainType

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

the class IndexDefinitionHashTest method hash_is_the_same_if_only_fields_order_changes.

@Test
public void hash_is_the_same_if_only_fields_order_changes() {
    Index index = Index.withRelations("foo");
    IndexMainType mainType = IndexMainType.main(index, "bar");
    TestNewIndex indexTwoFields = new TestNewIndex(mainType, settingsConfiguration);
    indexTwoFields.getMainTypeMapping().createBooleanField("donut1").createBooleanField("donut2").createBooleanField("donut3");
    TestNewIndex indexTwoFieldsOtherOrder = new TestNewIndex(mainType, settingsConfiguration);
    indexTwoFieldsOtherOrder.getMainTypeMapping().createBooleanField("donut2").createBooleanField("donut1").createBooleanField("donut3");
    TestNewIndex indexTwoFieldsOtherOrder2 = new TestNewIndex(mainType, settingsConfiguration);
    indexTwoFieldsOtherOrder2.getMainTypeMapping().createBooleanField("donut2").createBooleanField("donut3").createBooleanField("donut1");
    assertThat(hashOf(indexTwoFields)).isEqualTo(hashOf(indexTwoFieldsOtherOrder)).isEqualTo(hashOf(indexTwoFieldsOtherOrder2));
}
Also used : TestNewIndex(org.sonar.server.es.newindex.TestNewIndex) IndexMainType(org.sonar.server.es.IndexType.IndexMainType) TestNewIndex(org.sonar.server.es.newindex.TestNewIndex) Test(org.junit.Test)

Example 15 with IndexMainType

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

the class IndexDefinitionHashTest method hash_changes_if_clustering_is_enabled_or_not.

@Test
public void hash_changes_if_clustering_is_enabled_or_not() {
    Index index = Index.simple("foo");
    IndexMainType mainType = IndexMainType.main(index, "bar");
    MapSettings empty = new MapSettings();
    MapSettings clusterDisabled = new MapSettings().setProperty(CLUSTER_ENABLED.getKey(), false);
    MapSettings clusterEnabled = new MapSettings().setProperty(CLUSTER_ENABLED.getKey(), true);
    assertThat(hashOf(new TestNewIndex(mainType, settingsConfigurationOf(empty)))).isEqualTo(hashOf(new TestNewIndex(mainType, settingsConfigurationOf(empty)))).isEqualTo(hashOf(new TestNewIndex(mainType, settingsConfigurationOf(clusterDisabled)))).isNotEqualTo(hashOf(new TestNewIndex(mainType, settingsConfigurationOf(clusterEnabled))));
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) TestNewIndex(org.sonar.server.es.newindex.TestNewIndex) IndexMainType(org.sonar.server.es.IndexType.IndexMainType) TestNewIndex(org.sonar.server.es.newindex.TestNewIndex) 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