Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move tests persistence from batch to compute - SONAR-6255
- define index and check the 3 use cases - define batch report format - create file_sources.test_data
- Loading branch information
Showing
47 changed files
with
6,236 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
server/sonar-server/src/main/java/org/sonar/server/test/index/TestDoc.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,105 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* SonarQube is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
|
|||
package org.sonar.server.test.index; | |||
|
|||
import com.google.common.annotations.VisibleForTesting; | |||
import com.google.common.collect.Maps; | |||
import org.sonar.server.search.BaseDoc; | |||
|
|||
import java.util.List; | |||
import java.util.Map; | |||
|
|||
import static org.sonar.server.test.index.TestIndexDefinition.*; | |||
|
|||
public class TestDoc extends BaseDoc { | |||
public TestDoc(Map<String, Object> fields) { | |||
super(fields); | |||
} | |||
|
|||
@VisibleForTesting | |||
TestDoc() { | |||
super(Maps.<String, Object>newHashMapWithExpectedSize(7)); | |||
} | |||
|
|||
public String uuid() { | |||
return getField(FIELD_UUID); | |||
} | |||
|
|||
public TestDoc setUuid(String uuid) { | |||
setField(FIELD_UUID, uuid); | |||
return this; | |||
} | |||
|
|||
public String name() { | |||
return getField(FIELD_NAME); | |||
} | |||
|
|||
public TestDoc setName(String name) { | |||
setField(FIELD_NAME, name); | |||
return this; | |||
} | |||
|
|||
public String status() { | |||
return getField(FIELD_STATUS); | |||
} | |||
|
|||
public TestDoc setStatus(String status) { | |||
setField(FIELD_STATUS, status); | |||
return this; | |||
} | |||
|
|||
public String message() { | |||
return getField(FIELD_MESSAGE); | |||
} | |||
|
|||
public TestDoc setMessage(String message) { | |||
setField(FIELD_MESSAGE, message); | |||
return this; | |||
} | |||
|
|||
public String stackTrace() { | |||
return getField(FIELD_STACKTRACE); | |||
} | |||
|
|||
public TestDoc setStackTrace(String stackTrace) { | |||
setField(FIELD_STACKTRACE, stackTrace); | |||
return this; | |||
} | |||
|
|||
public String type() { | |||
return getField(FIELD_TYPE); | |||
} | |||
|
|||
public TestDoc setType(String type) { | |||
setField(FIELD_TYPE, type); | |||
return this; | |||
} | |||
|
|||
// TODO TBE - it should be a CoverageBlockDoc list | |||
public List<Map<String, Object>> coverageBlocks() { | |||
return getField(FIELD_COVERAGE_BLOCKS); | |||
} | |||
|
|||
public TestDoc setCoverageBlocks(List<Map<String, Object>> coverageBlocks) { | |||
setField(FIELD_COVERAGE_BLOCKS, coverageBlocks); | |||
return this; | |||
} | |||
} |
85 changes: 85 additions & 0 deletions
85
server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndex.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,85 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* SonarQube is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
|
|||
package org.sonar.server.test.index; | |||
|
|||
import org.elasticsearch.index.query.FilterBuilders; | |||
import org.elasticsearch.index.query.QueryBuilders; | |||
import org.elasticsearch.search.SearchHit; | |||
import org.sonar.server.es.BaseIndex; | |||
import org.sonar.server.es.EsClient; | |||
|
|||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.Map; | |||
|
|||
import static org.sonar.server.test.index.TestIndexDefinition.*; | |||
|
|||
public class TestIndex extends BaseIndex { | |||
public TestIndex(EsClient client) { | |||
super(client); | |||
} | |||
|
|||
public List<Map<String, Object>> coveredLines(String testFileUuid, String methodName) { | |||
List<Map<String, Object>> coverageBlocks = new ArrayList<>(); | |||
|
|||
for (SearchHit hit : getClient().prepareSearch(TestIndexDefinition.INDEX) | |||
.setTypes(TestIndexDefinition.TYPE) | |||
.setSize(1) | |||
.setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), FilterBuilders.boolFilter() | |||
.must(FilterBuilders.termFilter(FIELD_UUID, testFileUuid).cache(false)) | |||
.must(FilterBuilders.termFilter(TestIndexDefinition.FIELD_NAME, methodName).cache(false)))) | |||
.get().getHits().getHits()) { | |||
coverageBlocks.addAll(new TestDoc(hit.sourceAsMap()).coverageBlocks()); | |||
} | |||
|
|||
return coverageBlocks; | |||
} | |||
|
|||
public List<TestDoc> testMethods(String testFileUuid) { | |||
List<TestDoc> testDocs = new ArrayList<>(); | |||
|
|||
for (SearchHit hit : getClient().prepareSearch(TestIndexDefinition.INDEX) | |||
.setTypes(TestIndexDefinition.TYPE) | |||
.setSize(10_000) | |||
.setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), FilterBuilders.termFilter(FIELD_UUID, testFileUuid))) | |||
.get().getHits().getHits()) { | |||
testDocs.add(new TestDoc(hit.sourceAsMap())); | |||
} | |||
|
|||
return testDocs; | |||
} | |||
|
|||
public List<TestDoc> testsCovering(String mainFileUuid, int line) { | |||
List<TestDoc> testDocs = new ArrayList<>(); | |||
|
|||
for (SearchHit hit : getClient().prepareSearch(TestIndexDefinition.INDEX) | |||
.setTypes(TestIndexDefinition.TYPE) | |||
.setSize(10_000) | |||
.setQuery(QueryBuilders.nestedQuery(FIELD_COVERAGE_BLOCKS, FilterBuilders.boolFilter() | |||
.must(FilterBuilders.termFilter(FIELD_COVERAGE_BLOCKS + "." + FIELD_COVERAGE_BLOCK_UUID, mainFileUuid).cache(false)) | |||
.must(FilterBuilders.termFilter(FIELD_COVERAGE_BLOCKS + "." + FIELD_COVERAGE_BLOCK_LINES, line).cache(false)))) | |||
.get().getHits().getHits()) { | |||
testDocs.add(new TestDoc(hit.sourceAsMap())); | |||
} | |||
|
|||
return testDocs; | |||
} | |||
} |
Oops, something went wrong.