Search in sources :

Example 6 with IndexMainType

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

the class IndexDefinitionHashTest method hash_changes_if_textFieldBuilder_options_change.

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

Example 7 with IndexMainType

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

the class NewIndex method createTypeMapping.

protected TypeMapping createTypeMapping(IndexRelationType relationType) {
    checkAcceptsRelations();
    IndexMainType mainType = getMainType();
    checkArgument(relationType.getMainType().equals(mainType), "mainType of relation must be %s", mainType);
    String relationName = relationType.getName();
    checkArgument(!relations.containsKey(relationName), "relation %s already exists", relationName);
    relations.put(relationName, relationType);
    return new TypeMapping(this);
}
Also used : IndexMainType(org.sonar.server.es.IndexType.IndexMainType)

Example 8 with IndexMainType

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

the class MetadataIndexImpl method initializedId.

private static String initializedId(IndexType indexType) {
    if (indexType instanceof IndexMainType) {
        IndexMainType mainType = (IndexMainType) indexType;
        return mainType.getIndex().getName() + "." + mainType.getType() + ".initialized";
    }
    if (indexType instanceof IndexRelationType) {
        IndexRelationType relationType = (IndexRelationType) indexType;
        IndexMainType mainType = relationType.getMainType();
        return mainType.getIndex().getName() + "." + mainType.getType() + "." + relationType.getName() + ".initialized";
    }
    throw new IllegalArgumentException("Unsupported IndexType " + indexType.getClass());
}
Also used : IndexRelationType(org.sonar.server.es.IndexType.IndexRelationType) IndexMainType(org.sonar.server.es.IndexType.IndexMainType)

Example 9 with IndexMainType

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

the class NewIndexTest method createTypeMapping_with_IndexRelationType_fails_with_ISE_if_index_does_not_allow_relations.

@Test
public void createTypeMapping_with_IndexRelationType_fails_with_ISE_if_index_does_not_allow_relations() {
    IndexType.IndexRelationType indexRelationType = IndexType.relation(IndexType.main(Index.withRelations(someIndexName), "bar"), "bar");
    Index index = Index.simple(someIndexName);
    IndexMainType mainType = IndexType.main(index, "foo");
    NewIndex underTest = new NewIndex(index, defaultSettingsConfiguration) {

        @Override
        public IndexMainType getMainType() {
            return mainType;
        }

        @Override
        public BuiltIndex build() {
            throw new UnsupportedOperationException("build not implemented");
        }
    };
    assertThatThrownBy(() -> underTest.createTypeMapping(indexRelationType)).isInstanceOf(IllegalStateException.class).hasMessage("Index is not configured to accept relations. Update IndexDefinition.Descriptor instance for this index");
}
Also used : Index(org.sonar.server.es.Index) IndexMainType(org.sonar.server.es.IndexType.IndexMainType) IndexType(org.sonar.server.es.IndexType) Test(org.junit.Test)

Example 10 with IndexMainType

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

the class NewIndexTest method indexAndTypeMappings.

@DataProvider
public static Object[][] indexAndTypeMappings() {
    String indexName = randomAlphabetic(5).toLowerCase();
    MapSettings settings = new MapSettings();
    SettingsConfiguration defaultSettingsConfiguration = newBuilder(settings.asConfig()).build();
    Index index = Index.withRelations(indexName);
    IndexMainType mainType = IndexType.main(index, "foo");
    SimplestNewIndex newIndex = new SimplestNewIndex(mainType, defaultSettingsConfiguration);
    TypeMapping mainMapping = newIndex.createTypeMapping(mainType);
    TypeMapping relationMapping = newIndex.createTypeMapping(IndexType.relation(mainType, "bar"));
    return new Object[][] { { newIndex, mainMapping }, { newIndex, relationMapping } };
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) Index(org.sonar.server.es.Index) IndexMainType(org.sonar.server.es.IndexType.IndexMainType) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider)

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