]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6137 Handle lower bound for createdAt facet when no document match
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 9 Feb 2015 13:52:29 +0000 (14:52 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 9 Feb 2015 15:30:53 +0000 (16:30 +0100)
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java

index 5120987859812a7b1e4f52771ca1759966795a9e..7b7b11590c261fc5618cf24414525d6b1291c9a5 100644 (file)
@@ -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) {
index 8f55539d654d5a0be1fa96bff82d5cfdda9e09fb..acb942e098a27d7d8d8afd6c8580475f2695b731 100644 (file)
@@ -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);