Search in sources :

Example 21 with IndexMainType

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

the class NewIndexTest method fail_when_replica_customization_cant_be_parsed.

@Test
@UseDataProvider("indexWithAndWithoutRelations")
public void fail_when_replica_customization_cant_be_parsed(Index index) {
    settings.setProperty(CLUSTER_ENABLED.getKey(), "true");
    settings.setProperty(SEARCH_REPLICAS.getKey(), "ꝱꝲꝳପ");
    SettingsConfiguration settingsConfiguration = newBuilder(settings.asConfig()).setDefaultNbOfShards(5).build();
    IndexMainType mainType = IndexType.main(index, "foo");
    assertThatThrownBy(() -> new SimplestNewIndex(mainType, settingsConfiguration)).isInstanceOf(IllegalStateException.class).hasMessage("The property 'sonar.search.replicas' is not an int value: For input string: \"ꝱꝲꝳପ\"");
}
Also used : IndexMainType(org.sonar.server.es.IndexType.IndexMainType) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 22 with IndexMainType

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

Example 23 with IndexMainType

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

the class IndexDefinitionHashTest method hash_changes_if_relations_are_different.

@Test
public void hash_changes_if_relations_are_different() {
    Index index = Index.withRelations("foo");
    IndexMainType mainType = IndexMainType.main(index, "bar");
    TestNewIndex indexNoRelation = new TestNewIndex(mainType, settingsConfiguration);
    TestNewIndex indexOneRelation = new TestNewIndex(mainType, settingsConfiguration).addRelation("donut1");
    TestNewIndex indexOneOtherRelation = new TestNewIndex(mainType, settingsConfiguration).addRelation("donut2");
    TestNewIndex indexTwoRelations = new TestNewIndex(mainType, settingsConfiguration).addRelation("donut1").addRelation("donut2");
    TestNewIndex indexTwoOtherRelations = new TestNewIndex(mainType, settingsConfiguration).addRelation("donut1").addRelation("donut3");
    assertThat(hashOf(indexNoRelation)).isEqualTo(hashOf(new TestNewIndex(mainType, settingsConfiguration))).isNotEqualTo(hashOf(indexOneRelation)).isNotEqualTo(hashOf(indexOneOtherRelation)).isNotEqualTo(hashOf(indexTwoRelations)).isNotEqualTo(hashOf(indexTwoOtherRelations));
    assertThat(hashOf(indexOneRelation)).isEqualTo(hashOf(new TestNewIndex(mainType, settingsConfiguration).addRelation("donut1"))).isNotEqualTo(hashOf(indexOneOtherRelation)).isNotEqualTo(hashOf(indexTwoRelations)).isNotEqualTo(hashOf(indexTwoOtherRelations));
    assertThat(hashOf(indexTwoRelations)).isEqualTo(hashOf(new TestNewIndex(mainType, settingsConfiguration).addRelation("donut1").addRelation("donut2"))).isNotEqualTo(hashOf(indexOneRelation)).isNotEqualTo(hashOf(indexOneOtherRelation)).isNotEqualTo(hashOf(indexTwoOtherRelations));
}
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 24 with IndexMainType

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

the class IndexDefinitionHashTest method hash_changes_if_field_type_changes.

@Test
public void hash_changes_if_field_type_changes() {
    Index index = Index.withRelations("foo");
    IndexMainType mainType = IndexMainType.main(index, "bar");
    String fieldName = "field1";
    computeAndVerifyAllDifferentHashesOnMapping(mainType, (mapping) -> mapping.createBooleanField(fieldName), (mapping) -> mapping.createIntegerField(fieldName), (mapping) -> mapping.createByteField(fieldName), (mapping) -> mapping.createDateTimeField(fieldName), (mapping) -> mapping.createDoubleField(fieldName), (mapping) -> mapping.createLongField(fieldName), (mapping) -> mapping.createShortField(fieldName), (mapping) -> mapping.createUuidPathField(fieldName), (mapping) -> mapping.keywordFieldBuilder(fieldName).build(), (mapping) -> mapping.textFieldBuilder(fieldName).build(), (mapping) -> mapping.nestedFieldBuilder(fieldName).addKeywordField("bar").build());
}
Also used : TestNewIndex(org.sonar.server.es.newindex.TestNewIndex) IndexMainType(org.sonar.server.es.IndexType.IndexMainType) Test(org.junit.Test)

Example 25 with IndexMainType

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

the class IndexDefinitionHashTest method hash_changes_if_number_of_shards_changes.

@Test
public void hash_changes_if_number_of_shards_changes() {
    Index index = Index.simple("foo");
    IndexMainType mainType = IndexMainType.main(index, "bar");
    Configuration emptySettings = new MapSettings().asConfig();
    SettingsConfiguration defaultNbOfShards = SettingsConfiguration.newBuilder(emptySettings).build();
    SettingsConfiguration specifiedDefaultNbOfShards = SettingsConfiguration.newBuilder(emptySettings).setDefaultNbOfShards(5).build();
    SettingsConfiguration specifyDefaultNbOfShards = SettingsConfiguration.newBuilder(new MapSettings().setProperty("sonar.search." + index.getName() + ".shards", 1).asConfig()).setDefaultNbOfShards(1).build();
    SettingsConfiguration specifiedNbOfShards = SettingsConfiguration.newBuilder(new MapSettings().setProperty("sonar.search." + index.getName() + ".shards", 10).asConfig()).setDefaultNbOfShards(5).build();
    assertThat(hashOf(new TestNewIndex(mainType, defaultNbOfShards))).isEqualTo(hashOf(new TestNewIndex(mainType, defaultNbOfShards))).isEqualTo(hashOf(new TestNewIndex(mainType, specifyDefaultNbOfShards))).isNotEqualTo(hashOf(new TestNewIndex(mainType, specifiedDefaultNbOfShards))).isNotEqualTo(hashOf(new TestNewIndex(mainType, specifiedNbOfShards)));
    assertThat(hashOf(new TestNewIndex(mainType, specifiedDefaultNbOfShards))).isEqualTo(hashOf(new TestNewIndex(mainType, specifiedDefaultNbOfShards))).isNotEqualTo(hashOf(new TestNewIndex(mainType, specifyDefaultNbOfShards)));
}
Also used : SettingsConfiguration(org.sonar.server.es.newindex.SettingsConfiguration) Configuration(org.sonar.api.config.Configuration) MapSettings(org.sonar.api.config.internal.MapSettings) SettingsConfiguration(org.sonar.server.es.newindex.SettingsConfiguration) 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