use of org.sonar.server.es.newindex.TestNewIndex in project sonarqube by SonarSource.
the class IndexDefinitionHashTest method hash_changes_if_clustering_is_enabled_or_not.
@Test
public void hash_changes_if_clustering_is_enabled_or_not() {
Index index = Index.simple("foo");
IndexMainType mainType = IndexMainType.main(index, "bar");
MapSettings empty = new MapSettings();
MapSettings clusterDisabled = new MapSettings().setProperty(CLUSTER_ENABLED.getKey(), false);
MapSettings clusterEnabled = new MapSettings().setProperty(CLUSTER_ENABLED.getKey(), true);
assertThat(hashOf(new TestNewIndex(mainType, settingsConfigurationOf(empty)))).isEqualTo(hashOf(new TestNewIndex(mainType, settingsConfigurationOf(empty)))).isEqualTo(hashOf(new TestNewIndex(mainType, settingsConfigurationOf(clusterDisabled)))).isNotEqualTo(hashOf(new TestNewIndex(mainType, settingsConfigurationOf(clusterEnabled))));
}
use of org.sonar.server.es.newindex.TestNewIndex 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);
}
use of org.sonar.server.es.newindex.TestNewIndex 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));
}
use of org.sonar.server.es.newindex.TestNewIndex 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)));
}
use of org.sonar.server.es.newindex.TestNewIndex 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));
}
Aggregations