Search in sources :

Example 26 with IndexMainType

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

the class IndexDefinitionHashTest method hash_changes_if_fields_on_main_type_mapping_are_different.

@Test
public void hash_changes_if_fields_on_main_type_mapping_are_different() {
    Index index = Index.withRelations("foo");
    IndexMainType mainType = IndexMainType.main(index, "bar");
    TestNewIndex indexNoField = new TestNewIndex(mainType, settingsConfiguration);
    TestNewIndex indexOneField = new TestNewIndex(mainType, settingsConfiguration);
    indexOneField.getMainTypeMapping().createIntegerField("field1");
    TestNewIndex indexOneFieldAgain = new TestNewIndex(mainType, settingsConfiguration);
    indexOneFieldAgain.getMainTypeMapping().createIntegerField("field1");
    TestNewIndex indexOneOtherField = new TestNewIndex(mainType, settingsConfiguration);
    indexOneOtherField.getMainTypeMapping().createIntegerField("field2");
    TestNewIndex indexTwoFields = new TestNewIndex(mainType, settingsConfiguration);
    indexTwoFields.getMainTypeMapping().createIntegerField("field1").createIntegerField("field2");
    TestNewIndex indexTwoFieldsAgain = new TestNewIndex(mainType, settingsConfiguration);
    indexTwoFieldsAgain.getMainTypeMapping().createIntegerField("field1").createIntegerField("field2");
    TestNewIndex indexTwoOtherFields = new TestNewIndex(mainType, settingsConfiguration);
    indexTwoOtherFields.getMainTypeMapping().createIntegerField("field1").createIntegerField("field3");
    assertThat(hashOf(indexNoField)).isEqualTo(hashOf(new TestNewIndex(mainType, settingsConfiguration))).isNotEqualTo(hashOf(indexOneField)).isNotEqualTo(hashOf(indexOneOtherField)).isNotEqualTo(hashOf(indexTwoFields)).isNotEqualTo(hashOf(indexTwoOtherFields));
    assertThat(hashOf(indexOneField)).isEqualTo(hashOf(indexOneFieldAgain)).isNotEqualTo(hashOf(indexOneOtherField)).isNotEqualTo(hashOf(indexTwoFields)).isNotEqualTo(hashOf(indexTwoOtherFields));
    assertThat(hashOf(indexTwoFields)).isEqualTo(hashOf(indexTwoFieldsAgain)).isNotEqualTo(hashOf(indexOneField)).isNotEqualTo(hashOf(indexOneOtherField)).isNotEqualTo(hashOf(indexTwoOtherFields));
}
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 27 with IndexMainType

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

the class IndexTypeTest method parseMainType_from_main_type_without_relations.

@Test
public void parseMainType_from_main_type_without_relations() {
    IndexMainType type1 = IndexType.main(Index.simple("foo"), "bar");
    assertThat(type1.format()).isEqualTo("foo/bar");
    SimpleIndexMainType type2 = IndexType.parseMainType(type1.format());
    assertThat(type2).extracting(SimpleIndexMainType::getIndex, SimpleIndexMainType::getType).containsExactly("foo", "bar");
}
Also used : IndexMainType(org.sonar.server.es.IndexType.IndexMainType) SimpleIndexMainType(org.sonar.server.es.IndexType.SimpleIndexMainType) SimpleIndexMainType(org.sonar.server.es.IndexType.SimpleIndexMainType) Test(org.junit.Test)

Example 28 with IndexMainType

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

the class IndexTypeTest method parseMainType_from_relationtype.

@Test
public void parseMainType_from_relationtype() {
    IndexMainType mainType = IndexType.main(Index.withRelations("foo"), "bar");
    IndexRelationType type1 = IndexType.relation(mainType, "donut");
    assertThat(type1.format()).isEqualTo("foo/bar/donut");
    SimpleIndexMainType type2 = IndexType.parseMainType(type1.format());
    assertThat(type2).extracting(SimpleIndexMainType::getIndex, SimpleIndexMainType::getType).containsExactly("foo", "bar");
}
Also used : IndexRelationType(org.sonar.server.es.IndexType.IndexRelationType) IndexMainType(org.sonar.server.es.IndexType.IndexMainType) SimpleIndexMainType(org.sonar.server.es.IndexType.SimpleIndexMainType) SimpleIndexMainType(org.sonar.server.es.IndexType.SimpleIndexMainType) Test(org.junit.Test)

Example 29 with IndexMainType

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

the class IndexCreatorTest method start_makes_index_read_write_if_read_only.

@Test
public void start_makes_index_read_write_if_read_only() {
    FakeIndexDefinition fakeIndexDefinition = new FakeIndexDefinition();
    IndexMainType fakeIndexMainType = FakeIndexDefinition.INDEX_TYPE.getMainType();
    run(fakeIndexDefinition);
    IndexMainType mainType = MetadataIndexDefinition.TYPE_METADATA;
    makeReadOnly(mainType);
    makeReadOnly(fakeIndexMainType);
    run(fakeIndexDefinition);
    assertThat(isNotReadOnly(mainType)).isTrue();
    assertThat(isNotReadOnly(fakeIndexMainType)).isTrue();
}
Also used : IndexMainType(org.sonar.server.es.IndexType.IndexMainType) Test(org.junit.Test)

Example 30 with IndexMainType

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

the class IndexCreatorTest method start_makes_metadata_index_read_write_if_read_only.

@Test
public void start_makes_metadata_index_read_write_if_read_only() {
    run(new FakeIndexDefinition());
    IndexMainType mainType = MetadataIndexDefinition.TYPE_METADATA;
    makeReadOnly(mainType);
    run(new FakeIndexDefinition());
    assertThat(isNotReadOnly(mainType)).isTrue();
}
Also used : IndexMainType(org.sonar.server.es.IndexType.IndexMainType) 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