From 34911bf5358b11a8828b4f34b83ab14d34b0326f Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 9 Jan 2015 14:57:38 +0100 Subject: [PATCH] SONAR-5801 utLineHits, utConditions, utCoveredConditions, ... should be defined as integer instead of short --- .../index/SourceLineIndexDefinition.java | 18 ++++----- .../source/index/SourceLineIndexerTest.java | 39 ++++++++++++++++++- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineIndexDefinition.java b/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineIndexDefinition.java index 7bc5a70e887..0b6a677dc7f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineIndexDefinition.java +++ b/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineIndexDefinition.java @@ -81,15 +81,15 @@ public class SourceLineIndexDefinition implements IndexDefinition { sourceLineMapping.createDateTimeField(FIELD_SCM_DATE); sourceLineMapping.stringFieldBuilder(FIELD_HIGHLIGHTING).build(); sourceLineMapping.stringFieldBuilder(FIELD_SOURCE).build(); - sourceLineMapping.createShortField(FIELD_UT_LINE_HITS); - sourceLineMapping.createShortField(FIELD_UT_CONDITIONS); - sourceLineMapping.createShortField(FIELD_UT_COVERED_CONDITIONS); - sourceLineMapping.createShortField(FIELD_IT_LINE_HITS); - sourceLineMapping.createShortField(FIELD_IT_CONDITIONS); - sourceLineMapping.createShortField(FIELD_IT_COVERED_CONDITIONS); - sourceLineMapping.createShortField(FIELD_OVERALL_LINE_HITS); - sourceLineMapping.createShortField(FIELD_OVERALL_CONDITIONS); - sourceLineMapping.createShortField(FIELD_OVERALL_COVERED_CONDITIONS); + sourceLineMapping.createIntegerField(FIELD_UT_LINE_HITS); + sourceLineMapping.createIntegerField(FIELD_UT_CONDITIONS); + sourceLineMapping.createIntegerField(FIELD_UT_COVERED_CONDITIONS); + sourceLineMapping.createIntegerField(FIELD_IT_LINE_HITS); + sourceLineMapping.createIntegerField(FIELD_IT_CONDITIONS); + sourceLineMapping.createIntegerField(FIELD_IT_COVERED_CONDITIONS); + sourceLineMapping.createIntegerField(FIELD_OVERALL_LINE_HITS); + sourceLineMapping.createIntegerField(FIELD_OVERALL_CONDITIONS); + sourceLineMapping.createIntegerField(FIELD_OVERALL_COVERED_CONDITIONS); sourceLineMapping.stringFieldBuilder(FIELD_SYMBOLS).build(); sourceLineMapping.createShortField(FIELD_DUPLICATIONS); sourceLineMapping.createDateTimeField(BaseNormalizer.UPDATED_AT_FIELD); diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineIndexerTest.java index cc195db8434..aea3a46ed50 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineIndexerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/source/index/SourceLineIndexerTest.java @@ -113,7 +113,7 @@ public class SourceLineIndexerTest { MapAssert.entry(FIELD_SCM_AUTHOR, "polop"), MapAssert.entry(FIELD_SOURCE, "package org.sonar.server.source;"), MapAssert.entry(FIELD_DUPLICATIONS, duplications) - ); + ); } @Test @@ -146,6 +146,43 @@ public class SourceLineIndexerTest { assertThat(document.get(FIELD_PROJECT_UUID)).isEqualTo("plmn"); } + @Test + public void index_source_lines_with_big_test_data() throws Exception { + Integer bigValue = Short.MAX_VALUE * 2; + SourceLineDoc line1 = new SourceLineDoc(ImmutableMap.builder() + .put(FIELD_PROJECT_UUID, "abcd") + .put(FIELD_FILE_UUID, "efgh") + .put(FIELD_LINE, 1) + .put(FIELD_SOURCE, "package org.sonar.server.source;") + .put(FIELD_UT_LINE_HITS, bigValue) + .put(FIELD_UT_CONDITIONS, bigValue) + .put(FIELD_UT_COVERED_CONDITIONS, bigValue) + .put(FIELD_IT_LINE_HITS, bigValue) + .put(FIELD_IT_CONDITIONS, bigValue) + .put(FIELD_IT_COVERED_CONDITIONS, bigValue) + .put(FIELD_OVERALL_LINE_HITS, bigValue) + .put(FIELD_OVERALL_CONDITIONS, bigValue) + .put(FIELD_OVERALL_COVERED_CONDITIONS, bigValue) + .put(BaseNormalizer.UPDATED_AT_FIELD, new Date()) + .build()); + SourceLineResultSetIterator.SourceFile file = new SourceLineResultSetIterator.SourceFile("efgh", System.currentTimeMillis()); + file.addLine(line1); + indexer.index(Iterators.singletonIterator(file)); + + List hits = getDocuments(); + assertThat(hits).hasSize(1); + Map document = hits.get(0).getSource(); + assertThat(document.get(FIELD_UT_LINE_HITS)).isEqualTo(bigValue); + assertThat(document.get(FIELD_UT_CONDITIONS)).isEqualTo(bigValue); + assertThat(document.get(FIELD_UT_COVERED_CONDITIONS)).isEqualTo(bigValue); + assertThat(document.get(FIELD_IT_LINE_HITS)).isEqualTo(bigValue); + assertThat(document.get(FIELD_IT_CONDITIONS)).isEqualTo(bigValue); + assertThat(document.get(FIELD_IT_COVERED_CONDITIONS)).isEqualTo(bigValue); + assertThat(document.get(FIELD_OVERALL_LINE_HITS)).isEqualTo(bigValue); + assertThat(document.get(FIELD_OVERALL_CONDITIONS)).isEqualTo(bigValue); + assertThat(document.get(FIELD_OVERALL_COVERED_CONDITIONS)).isEqualTo(bigValue); + } + private void addSource(String fileName) throws Exception { prepareIndex() .setSource(IOUtils.toString(new FileInputStream(TestUtils.getResource(this.getClass(), fileName)))) -- 2.39.5