aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2015-02-09 14:52:29 +0100
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2015-02-09 16:30:53 +0100
commit19a55559d19158b88fa5ce6d3ed1ae975132f8bd (patch)
treec25b0f330572d1b0b01fbd2b1fbd551291f34c7c
parentf617ae594747af8ea73de552bc3250b4488edd82 (diff)
downloadsonarqube-19a55559d19158b88fa5ce6d3ed1ae975132f8bd.tar.gz
sonarqube-19a55559d19158b88fa5ce6d3ed1ae975132f8bd.zip
SONAR-6137 Handle lower bound for createdAt facet when no document match
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java7
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java16
2 files changed, 16 insertions, 7 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
index 51209878598..7b7b11590c2 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
@@ -495,7 +495,12 @@ public class IssueIndex extends BaseIndex {
}
esRequest.addAggregation(AggregationBuilders.min(facetNameAndField).field(facetNameAndField));
Min minValue = esRequest.get().getAggregations().get(facetNameAndField);
- return (long) minValue.getValue();
+ Double actualValue = minValue.getValue();
+ if (actualValue.isInfinite()) {
+ return Long.MIN_VALUE;
+ } else {
+ return actualValue.longValue();
+ }
}
private AggregationBuilder createAssigneesFacet(IssueQuery query, Map<String, FilterBuilder> filters, QueryBuilder queryBuilder) {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java
index 8f55539d654..acb942e098a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java
@@ -44,12 +44,7 @@ import org.sonar.server.view.index.ViewIndexer;
import javax.annotation.Nullable;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
@@ -750,6 +745,15 @@ public class IssueIndexMediumTest {
entry("2016-01-01T01:00:00+0000", 0L));
}
+ @Test
+ public void facet_on_created_at_without_issues() throws Exception {
+ SearchOptions SearchOptions = new SearchOptions().addFacets("createdAt");
+
+ Map<String, Long> createdAt = index.search(IssueQuery.builder().build(),
+ SearchOptions).getFacets().get("createdAt");
+ assertThat(createdAt).isEmpty();
+ }
+
protected SearchOptions fixtureForCreatedAtFacet() {
ComponentDto project = ComponentTesting.newProjectDto();
ComponentDto file = ComponentTesting.newFileDto(project);