use of org.sonar.server.es.newindex.TestNewIndex in project sonarqube by SonarSource.
the class IndexDefinitionHashTest method hash_changes_if_refreshInterval_changes.
@Test
public void hash_changes_if_refreshInterval_changes() {
Index index = Index.simple("foo");
IndexMainType mainType = IndexMainType.main(index, "bar");
Configuration emptySettings = new MapSettings().asConfig();
SettingsConfiguration defaultRefreshInterval = SettingsConfiguration.newBuilder(emptySettings).build();
SettingsConfiguration noRefreshInterval = SettingsConfiguration.newBuilder(emptySettings).setRefreshInterval(-1).build();
SettingsConfiguration refreshInterval30 = SettingsConfiguration.newBuilder(emptySettings).setRefreshInterval(30).build();
SettingsConfiguration someRefreshInterval = SettingsConfiguration.newBuilder(emptySettings).setRefreshInterval(56).build();
assertThat(hashOf(new TestNewIndex(mainType, defaultRefreshInterval))).isEqualTo(hashOf(new TestNewIndex(mainType, defaultRefreshInterval))).isEqualTo(hashOf(new TestNewIndex(mainType, refreshInterval30))).isNotEqualTo(hashOf(new TestNewIndex(mainType, noRefreshInterval))).isNotEqualTo(hashOf(new TestNewIndex(mainType, someRefreshInterval)));
assertThat(hashOf(new TestNewIndex(mainType, noRefreshInterval))).isNotEqualTo(hashOf(new TestNewIndex(mainType, someRefreshInterval)));
}
use of org.sonar.server.es.newindex.TestNewIndex in project sonarqube by SonarSource.
the class IndexDefinitionHashTest method hash_is_the_same_if_only_relations_order_changes.
@Test
public void hash_is_the_same_if_only_relations_order_changes() {
Index index = Index.withRelations("foo");
IndexMainType mainType = IndexMainType.main(index, "bar");
TestNewIndex indexTwoRelations = new TestNewIndex(mainType, settingsConfiguration).addRelation("donut1").addRelation("donut2").addRelation("donut3");
TestNewIndex indexTwoRelationsOtherOrder = new TestNewIndex(mainType, settingsConfiguration).addRelation("donut2").addRelation("donut1").addRelation("donut3");
TestNewIndex indexTwoRelationsOtherOrder2 = new TestNewIndex(mainType, settingsConfiguration).addRelation("donut2").addRelation("donut3").addRelation("donut1");
assertThat(hashOf(indexTwoRelations)).isEqualTo(hashOf(indexTwoRelationsOtherOrder)).isEqualTo(hashOf(indexTwoRelationsOtherOrder2));
}
use of org.sonar.server.es.newindex.TestNewIndex in project sonarqube by SonarSource.
the class IndexDefinitionHashTest method computeAndVerifyAllDifferentHashesOnMapping.
@SafeVarargs
private final void computeAndVerifyAllDifferentHashesOnMapping(IndexMainType mainType, Consumer<TypeMapping>... fieldTypes) {
List<TestNewIndex> mainIndices = Arrays.stream(fieldTypes).map(consumer -> {
TestNewIndex mainTypeMapping = new TestNewIndex(mainType, settingsConfiguration);
consumer.accept(mainTypeMapping.getMainTypeMapping());
return mainTypeMapping;
}).collect(toList());
List<TestNewIndex> relationIndices = Arrays.stream(fieldTypes).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(fieldTypes.length);
assertThat(relationHashes).isEqualTo(relationIndices.stream().map(IndexDefinitionHashTest::hashOf).collect(toSet())).doesNotContainAnyElementsOf(mainHashes).hasSize(fieldTypes.length);
}
use of org.sonar.server.es.newindex.TestNewIndex in project sonarqube by SonarSource.
the class IndexDefinitionHashTest method hash_changes_if_mainType_is_different.
@Test
public void hash_changes_if_mainType_is_different() {
Index simpleIndex = Index.simple("foo");
Index withRelationsIndex = Index.withRelations("foo");
IndexMainType mainTypeBar = IndexMainType.main(simpleIndex, "bar");
TestNewIndex indexSimpleBar = new TestNewIndex(mainTypeBar, settingsConfiguration);
TestNewIndex indexSimpleDonut = new TestNewIndex(IndexMainType.main(simpleIndex, "donut"), settingsConfiguration);
TestNewIndex indexWithRelationsBar = new TestNewIndex(IndexMainType.main(withRelationsIndex, "bar"), settingsConfiguration);
assertThat(hashOf(indexSimpleBar)).isEqualTo(hashOf(new TestNewIndex(mainTypeBar, settingsConfiguration))).isNotEqualTo(hashOf(indexSimpleDonut)).isNotEqualTo(hashOf(indexWithRelationsBar));
assertThat(hashOf(indexSimpleDonut)).isNotEqualTo(hashOf(indexWithRelationsBar));
}
use of org.sonar.server.es.newindex.TestNewIndex in project sonarqube by SonarSource.
the class IndexDefinitionHashTest method hash_is_the_same_if_only_fields_order_changes.
@Test
public void hash_is_the_same_if_only_fields_order_changes() {
Index index = Index.withRelations("foo");
IndexMainType mainType = IndexMainType.main(index, "bar");
TestNewIndex indexTwoFields = new TestNewIndex(mainType, settingsConfiguration);
indexTwoFields.getMainTypeMapping().createBooleanField("donut1").createBooleanField("donut2").createBooleanField("donut3");
TestNewIndex indexTwoFieldsOtherOrder = new TestNewIndex(mainType, settingsConfiguration);
indexTwoFieldsOtherOrder.getMainTypeMapping().createBooleanField("donut2").createBooleanField("donut1").createBooleanField("donut3");
TestNewIndex indexTwoFieldsOtherOrder2 = new TestNewIndex(mainType, settingsConfiguration);
indexTwoFieldsOtherOrder2.getMainTypeMapping().createBooleanField("donut2").createBooleanField("donut3").createBooleanField("donut1");
assertThat(hashOf(indexTwoFields)).isEqualTo(hashOf(indexTwoFieldsOtherOrder)).isEqualTo(hashOf(indexTwoFieldsOtherOrder2));
}
Aggregations