Search in sources :

Example 16 with IndexMainType

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

the class IndexTypeTest method parseMainType_from_maintype_with_relations.

@Test
public void parseMainType_from_maintype_with_relations() {
    IndexMainType type1 = IndexType.main(Index.withRelations("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 17 with IndexMainType

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

the class IndexTypeTest method relation_fails_with_IAE_if_index_name_is_null_or_empty.

@Test
@UseDataProvider("nullOrEmpty")
public void relation_fails_with_IAE_if_index_name_is_null_or_empty(String nullOrEmpty) {
    Index index = Index.withRelations("foo");
    IndexMainType mainType = IndexType.main(index, "foobar");
    assertThatThrownBy(() -> IndexType.relation(mainType, nullOrEmpty)).isInstanceOf(IllegalArgumentException.class).hasMessage("type name can't be null nor empty");
}
Also used : IndexMainType(org.sonar.server.es.IndexType.IndexMainType) SimpleIndexMainType(org.sonar.server.es.IndexType.SimpleIndexMainType) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 18 with IndexMainType

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

the class IndexTypeTest method IndexRelationType_equals_and_hashCode.

@Test
public void IndexRelationType_equals_and_hashCode() {
    IndexMainType mainType1 = IndexType.main(Index.withRelations("foo"), "bar");
    IndexMainType mainType2 = IndexType.main(Index.withRelations("foo"), "baz");
    IndexRelationType type1 = IndexType.relation(mainType1, "donut");
    IndexRelationType type1b = IndexType.relation(mainType1, "donut");
    IndexRelationType type2 = IndexType.relation(mainType1, "donuz");
    IndexRelationType type3 = IndexType.relation(mainType2, "donut");
    assertThat(type1).isEqualTo(type1).isEqualTo(type1b).isNotEqualTo(type2).isNotEqualTo(type3).hasSameHashCodeAs(type1).hasSameHashCodeAs(type1b);
    assertThat(type2.hashCode()).isNotEqualTo(type1.hashCode());
    assertThat(type3.hashCode()).isNotEqualTo(type2.hashCode()).isNotEqualTo(type1.hashCode());
}
Also used : IndexRelationType(org.sonar.server.es.IndexType.IndexRelationType) IndexMainType(org.sonar.server.es.IndexType.IndexMainType) SimpleIndexMainType(org.sonar.server.es.IndexType.SimpleIndexMainType) Test(org.junit.Test)

Example 19 with IndexMainType

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

the class IndexTypeTest method IndexMainType_equals_and_hashCode.

@Test
public void IndexMainType_equals_and_hashCode() {
    IndexMainType type1 = IndexType.main(Index.simple("foo"), "bar");
    IndexMainType type1b = IndexType.main(Index.simple("foo"), "bar");
    IndexMainType type1c = IndexType.main(Index.withRelations("foo"), "bar");
    IndexMainType type2 = IndexType.main(Index.simple("foo"), "baz");
    assertThat(type1).isEqualTo(type1).isEqualTo(type1b).isNotEqualTo(type1c).isNotEqualTo(type2).hasSameHashCodeAs(type1).hasSameHashCodeAs(type1b);
    assertThat(type1.hashCode()).isNotEqualTo(type1c.hashCode());
    assertThat(type2.hashCode()).isNotEqualTo(type1.hashCode());
}
Also used : IndexMainType(org.sonar.server.es.IndexType.IndexMainType) SimpleIndexMainType(org.sonar.server.es.IndexType.SimpleIndexMainType) Test(org.junit.Test)

Example 20 with IndexMainType

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

the class RecoveryIndexerTest method successfully_recover_indexing_requests.

@Test
public void successfully_recover_indexing_requests() {
    EsQueueDto item1a = insertItem(FOO_TYPE, "f1");
    EsQueueDto item1b = insertItem(FOO_TYPE, "f2");
    IndexMainType type2 = IndexType.main(Index.simple("bars"), "bar");
    EsQueueDto item2 = insertItem(type2, "b1");
    SuccessfulFakeIndexer indexer1 = new SuccessfulFakeIndexer(FOO_TYPE);
    SuccessfulFakeIndexer indexer2 = new SuccessfulFakeIndexer(type2);
    advanceInTime();
    underTest = newRecoveryIndexer(indexer1, indexer2);
    underTest.recover();
    assertThatQueueHasSize(0);
    assertThatLogsContain(INFO, "Elasticsearch recovery - 3 documents processed [0 failures]");
    assertThat(indexer1.called).hasSize(1);
    assertThat(indexer1.called.get(0)).extracting(EsQueueDto::getUuid).containsExactlyInAnyOrder(item1a.getUuid(), item1b.getUuid());
    assertThatLogsContain(TRACE, "Elasticsearch recovery - processing 2 [foos/foo]");
    assertThat(indexer2.called).hasSize(1);
    assertThat(indexer2.called.get(0)).extracting(EsQueueDto::getUuid).containsExactlyInAnyOrder(item2.getUuid());
    assertThatLogsContain(TRACE, "Elasticsearch recovery - processing 1 [bars/bar]");
}
Also used : EsQueueDto(org.sonar.db.es.EsQueueDto) 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