Search in sources :

Example 1 with Index

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

the class NewRegularIndexTest method build_does_not_enforce_routing_if_mainType_does_not_accepts_relations.

@Test
public void build_does_not_enforce_routing_if_mainType_does_not_accepts_relations() {
    Index someIndex = Index.simple(SOME_INDEX_NAME);
    NewRegularIndex underTest = new NewRegularIndex(someIndex, defaultSettingsConfiguration);
    underTest.createTypeMapping(IndexType.main(someIndex, "foo"));
    BuiltIndex<NewRegularIndex> builtIndex = underTest.build();
    assertThat(builtIndex.getAttributes().get("_routing")).isNull();
}
Also used : Index(org.sonar.server.es.Index) Test(org.junit.Test)

Example 2 with Index

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

the class NewRegularIndexTest method createTypeMapping_with_IndexRelationType_fails_with_ISE_if_called_before_createType_with_IndexMainType.

@Test
public void createTypeMapping_with_IndexRelationType_fails_with_ISE_if_called_before_createType_with_IndexMainType() {
    Index index = Index.withRelations(SOME_INDEX_NAME);
    NewRegularIndex underTest = new NewRegularIndex(index, defaultSettingsConfiguration);
    assertThatThrownBy(() -> underTest.createTypeMapping(IndexType.relation(IndexType.main(index, "foo"), "bar"))).isInstanceOf(IllegalStateException.class).hasMessage("Mapping for main type must be created first");
}
Also used : Index(org.sonar.server.es.Index) Test(org.junit.Test)

Example 3 with Index

use of org.sonar.server.es.Index 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 4 with Index

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

Example 5 with Index

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

the class NewAuthorizedIndexTest method constructor_fails_with_IAE_if_index_does_not_support_relations.

@Test
public void constructor_fails_with_IAE_if_index_does_not_support_relations() {
    Index simpleIndex = Index.simple(someIndexName);
    assertThatThrownBy(() -> new NewAuthorizedIndex(simpleIndex, defaultSettingsConfiguration)).isInstanceOf(IllegalArgumentException.class).hasMessage("Index must accept relations");
}
Also used : Index(org.sonar.server.es.Index) Test(org.junit.Test)

Aggregations

Index (org.sonar.server.es.Index)11 Test (org.junit.Test)10 ImmutableMap (com.google.common.collect.ImmutableMap)4 Map (java.util.Map)4 IndexType (org.sonar.server.es.IndexType)3 IndexMainType (org.sonar.server.es.IndexType.IndexMainType)2 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 HashMap (java.util.HashMap)1 MapSettings (org.sonar.api.config.internal.MapSettings)1 BaseDoc (org.sonar.server.es.BaseDoc)1