try {
long start = System.currentTimeMillis();
- SourceFileResultSetIterator it = SourceFileResultSetIterator.create(dbClient, connection, 0L);
+ SourceFileResultSetIterator it = SourceFileResultSetIterator.create(dbClient, connection, 0L, null);
while (it.hasNext()) {
SourceFileResultSetIterator.Row row = it.next();
assertThat(row.getLineUpdateRequests().size()).isEqualTo(NUMBER_OF_LINES);
import org.sonar.server.source.db.FileSourceDb;
import java.io.Serializable;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import static com.google.common.collect.Lists.newArrayList;
-import static com.google.common.collect.Maps.newHashMap;
-import static com.google.common.collect.Sets.newHashSet;
public class SymbolsLineReader implements LineReader {
this.symbols = newArrayList(symbols);
// Sort symbols to have deterministic results and avoid false variation that would lead to an unnecessary update of the source files
// data
- Collections.sort(this.symbols, new SymbolsDuplication());
+ Collections.sort(this.symbols, new SymbolsComparator());
this.idsBySymbol = createIdsBySymbolMap(this.symbols);
}
}
private List<BatchReport.Symbols.Symbol> findSymbolsMatchingLine(int line) {
- List<BatchReport.Symbols.Symbol> lineSymbols = newArrayList();
- Set<BatchReport.Symbols.Symbol> symbolsIndex = newHashSet();
+ List<BatchReport.Symbols.Symbol> lineSymbols = new ArrayList<>();
+ Set<BatchReport.Symbols.Symbol> symbolsIndex = new HashSet<>();
for (BatchReport.Symbols.Symbol symbol : symbols) {
if (matchLine(symbol.getDeclaration(), line) && !symbolsIndex.contains(symbol)) {
lineSymbols.add(symbol);
}
private Map<BatchReport.Symbols.Symbol, Integer> createIdsBySymbolMap(List<BatchReport.Symbols.Symbol> symbols) {
- Map<BatchReport.Symbols.Symbol, Integer> map = newHashMap();
+ Map<BatchReport.Symbols.Symbol, Integer> map = new HashMap<>();
int symbolId = 1;
for (BatchReport.Symbols.Symbol symbol : symbols) {
map.put(symbol, symbolId);
return map;
}
- private static class SymbolsDuplication implements Comparator<BatchReport.Symbols.Symbol>, Serializable {
+ private static class SymbolsComparator implements Comparator<BatchReport.Symbols.Symbol>, Serializable {
@Override
public int compare(BatchReport.Symbols.Symbol o1, BatchReport.Symbols.Symbol o2) {
if (o1.getDeclaration().getStartLine() == o2.getDeclaration().getStartLine()) {
package org.sonar.server.computation.step;
import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.utils.System2;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.MyBatis;
import org.sonar.server.computation.ComputationContext;
-import org.sonar.server.db.DbClient;
import org.sonar.server.source.index.SourceLineIndexer;
public class IndexSourceLinesStep implements ComputationStep {
- private final DbClient dbClient;
- private final System2 system2;
private final SourceLineIndexer indexer;
- public IndexSourceLinesStep(DbClient dbClient, System2 system2, SourceLineIndexer indexer) {
- this.dbClient = dbClient;
- this.system2 = system2;
+ public IndexSourceLinesStep(SourceLineIndexer indexer) {
this.indexer = indexer;
}
@Override
public void execute(ComputationContext context) {
- updateSourceUpdateDate(context.getProject().uuid());
- indexer.index();
- }
-
- // Temporary solution to only index in E/S updated sources from current project
- // Should be removed when source wil be persisted in compute engine
- private void updateSourceUpdateDate(String projectUuid){
- DbSession session = dbClient.openSession(true);
- try {
- dbClient.fileSourceDao().updateDateWhenUpdatedDateIsZero(session, projectUuid, system2.now());
- session.commit();
- } finally {
- MyBatis.closeQuietly(session);
- }
+ indexer.index(context.getProject().uuid());
}
@Override
import org.sonar.core.persistence.MyBatis;
import org.sonar.core.source.db.FileSourceDto;
import org.sonar.server.computation.ComputationContext;
-import org.sonar.server.computation.source.*;
+import org.sonar.server.computation.source.ComputeFileSourceData;
+import org.sonar.server.computation.source.CoverageLineReader;
+import org.sonar.server.computation.source.DuplicationLineReader;
+import org.sonar.server.computation.source.HighlightingLineReader;
+import org.sonar.server.computation.source.LineReader;
+import org.sonar.server.computation.source.ReportIterator;
+import org.sonar.server.computation.source.ScmLineReader;
+import org.sonar.server.computation.source.SymbolsLineReader;
import org.sonar.server.db.DbClient;
import org.sonar.server.source.db.FileSourceDb;
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import static com.google.common.collect.Lists.newArrayList;
-
public class PersistFileSourcesStep implements ComputationStep {
private final DbClient dbClient;
.setDataHash(dataHash)
.setLineHashes(lineHashes)
.setCreatedAt(system2.now())
- // TODO set current date here when indexing sources in E/S will be done in this class
- .setUpdatedAt(0L);
+ .setUpdatedAt(system2.now());
dbClient.fileSourceDao().insert(fileSourcesContext.session, dto);
fileSourcesContext.session.commit();
} else {
.setLineHashes(lineHashes);
// Optimization only change updated at when updating binary data to avoid unecessary indexation by E/S
if (binaryDataUpdated) {
- // TODO set current date here when indexing sources in E/S will be done in this class
- previousDto.setUpdatedAt(0L);
+ previousDto.setUpdatedAt(system2.now());
}
dbClient.fileSourceDao().update(previousDto);
fileSourcesContext.session.commit();
}
private static class LineReaders {
- private final List<LineReader> lineReaders = newArrayList();
- private final List<ReportIterator> reportIterators = newArrayList();
+ private final List<LineReader> lineReaders = new ArrayList<>();
+ private final List<ReportIterator> reportIterators = new ArrayList<>();
LineReaders(BatchReportReader reportReader, int componentRef) {
File coverageFile = reportReader.readComponentCoverage(componentRef);
private boolean enabled = false;
protected BaseIndexer(EsClient client, long threadKeepAliveSeconds, String indexName, String typeName,
- String dateFieldName) {
+ String dateFieldName) {
this.indexName = indexName;
this.typeName = typeName;
this.dateFieldName = dateFieldName;
threadKeepAliveSeconds, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
}
- public void index() {
+ public void index(final IndexerTask task) {
if (enabled) {
final long requestedAt = System.currentTimeMillis();
Future submit = executor.submit(new Runnable() {
@Override
public void run() {
if (requestedAt > lastUpdatedAt) {
- long l = doIndex(lastUpdatedAt);
+ long l = task.index(lastUpdatedAt);
// l can be 0 if no documents were indexed
lastUpdatedAt = Math.max(l, lastUpdatedAt);
}
}
}
+ public void index() {
+ index(new IndexerTask() {
+ @Override
+ public long index(long lastUpdatedAt) {
+ return doIndex(lastUpdatedAt);
+ }
+ });
+ }
+
protected abstract long doIndex(long lastUpdatedAt);
public BaseIndexer setEnabled(boolean b) {
executor.shutdown();
}
+ public interface IndexerTask {
+ long index(long lastUpdatedAt);
+ }
+
}
import org.sonar.server.es.EsUtils;
import org.sonar.server.source.db.FileSourceDb;
+import javax.annotation.Nullable;
+
import java.io.ByteArrayOutputStream;
import java.io.OutputStreamWriter;
import java.sql.Connection;
"updated_at",
"binary_data"
};
- private static final String SQL_ALL = "select " + StringUtils.join(FIELDS, ",") + " from file_sources";
- private static final String SQL_AFTER_DATE = SQL_ALL + " where updated_at>?";
- public static SourceFileResultSetIterator create(DbClient dbClient, Connection connection, long afterDate) {
+ private static final String SQL_ALL = "SELECT " + StringUtils.join(FIELDS, ",") + " FROM file_sources ";
+ private static final String AFTER_DATE_FILTER = "updated_at>? ";
+ private static final String PROJECT_FILTER = "project_uuid=? ";
+
+ public static SourceFileResultSetIterator create(DbClient dbClient, Connection connection, long afterDate, @Nullable String projectUuid) {
try {
- String sql = afterDate > 0L ? SQL_AFTER_DATE : SQL_ALL;
+ String sql = createSQL(afterDate, projectUuid);
// rows are big, so they are scrolled once at a time (one row in memory at a time)
PreparedStatement stmt = dbClient.newScrollingSingleRowSelectStatement(connection, sql);
+ int index = 1;
if (afterDate > 0L) {
- stmt.setLong(1, afterDate);
+ stmt.setLong(index, afterDate);
+ index++;
+ }
+ if (projectUuid != null) {
+ stmt.setString(index, projectUuid);
}
return new SourceFileResultSetIterator(stmt);
} catch (SQLException e) {
}
}
+ private static String createSQL(long afterDate, @Nullable String projectUuid) {
+ String sql = SQL_ALL;
+ if (afterDate > 0L || projectUuid != null) {
+ sql += "WHERE ";
+ boolean isFirst = true;
+ if (afterDate > 0L) {
+ sql += AFTER_DATE_FILTER;
+ isFirst = false;
+ }
+ if (projectUuid != null) {
+ if (!isFirst) {
+ sql += "AND ";
+ }
+ sql += PROJECT_FILTER;
+ }
+ }
+ return sql;
+ }
+
private SourceFileResultSetIterator(PreparedStatement stmt) throws SQLException {
super(stmt);
}
// unit tests
if (line.hasUtLineHits()) {
- writer.prop(SourceLineIndexDefinition.FIELD_UT_LINE_HITS, line.getUtLineHits());
+ writer.prop(SourceLineIndexDefinition.FIELD_UT_LINE_HITS, line.getUtLineHits());
} else {
writer.name(SourceLineIndexDefinition.FIELD_UT_LINE_HITS).valueObject(null);
}
if (line.hasUtConditions()) {
- writer.prop(SourceLineIndexDefinition.FIELD_UT_CONDITIONS, line.getUtConditions());
+ writer.prop(SourceLineIndexDefinition.FIELD_UT_CONDITIONS, line.getUtConditions());
} else {
writer.name(SourceLineIndexDefinition.FIELD_UT_CONDITIONS).valueObject(null);
}
if (line.hasUtCoveredConditions()) {
- writer.prop(SourceLineIndexDefinition.FIELD_UT_COVERED_CONDITIONS, line.getUtCoveredConditions());
+ writer.prop(SourceLineIndexDefinition.FIELD_UT_COVERED_CONDITIONS, line.getUtCoveredConditions());
} else {
writer.name(SourceLineIndexDefinition.FIELD_UT_COVERED_CONDITIONS).valueObject(null);
}
// IT
if (line.hasItLineHits()) {
- writer.prop(SourceLineIndexDefinition.FIELD_IT_LINE_HITS, line.getItLineHits());
+ writer.prop(SourceLineIndexDefinition.FIELD_IT_LINE_HITS, line.getItLineHits());
} else {
writer.name(SourceLineIndexDefinition.FIELD_IT_LINE_HITS).valueObject(null);
}
if (line.hasItConditions()) {
- writer.prop(SourceLineIndexDefinition.FIELD_IT_CONDITIONS, line.getItConditions());
+ writer.prop(SourceLineIndexDefinition.FIELD_IT_CONDITIONS, line.getItConditions());
} else {
writer.name(SourceLineIndexDefinition.FIELD_IT_CONDITIONS).valueObject(null);
}
if (line.hasItCoveredConditions()) {
- writer.prop(SourceLineIndexDefinition.FIELD_IT_COVERED_CONDITIONS, line.getItCoveredConditions());
+ writer.prop(SourceLineIndexDefinition.FIELD_IT_COVERED_CONDITIONS, line.getItCoveredConditions());
} else {
writer.name(SourceLineIndexDefinition.FIELD_IT_COVERED_CONDITIONS).valueObject(null);
}
// Overall coverage
if (line.hasOverallLineHits()) {
- writer.prop(SourceLineIndexDefinition.FIELD_OVERALL_LINE_HITS, line.getOverallLineHits());
+ writer.prop(SourceLineIndexDefinition.FIELD_OVERALL_LINE_HITS, line.getOverallLineHits());
} else {
writer.name(SourceLineIndexDefinition.FIELD_OVERALL_LINE_HITS).valueObject(null);
}
if (line.hasOverallConditions()) {
- writer.prop(SourceLineIndexDefinition.FIELD_OVERALL_CONDITIONS, line.getOverallConditions());
+ writer.prop(SourceLineIndexDefinition.FIELD_OVERALL_CONDITIONS, line.getOverallConditions());
} else {
writer.name(SourceLineIndexDefinition.FIELD_OVERALL_CONDITIONS).valueObject(null);
}
if (line.hasOverallCoveredConditions()) {
- writer.prop(SourceLineIndexDefinition.FIELD_OVERALL_COVERED_CONDITIONS, line.getOverallCoveredConditions());
+ writer.prop(SourceLineIndexDefinition.FIELD_OVERALL_COVERED_CONDITIONS, line.getOverallCoveredConditions());
} else {
writer.name(SourceLineIndexDefinition.FIELD_OVERALL_COVERED_CONDITIONS).valueObject(null);
}
if (line.hasHighlighting()) {
- writer.prop(SourceLineIndexDefinition.FIELD_HIGHLIGHTING, line.getHighlighting());
+ writer.prop(SourceLineIndexDefinition.FIELD_HIGHLIGHTING, line.getHighlighting());
} else {
writer.name(SourceLineIndexDefinition.FIELD_HIGHLIGHTING).valueObject(null);
}
if (line.hasSymbols()) {
- writer.prop(SourceLineIndexDefinition.FIELD_SYMBOLS, line.getSymbols());
+ writer.prop(SourceLineIndexDefinition.FIELD_SYMBOLS, line.getSymbols());
} else {
writer.name(SourceLineIndexDefinition.FIELD_SYMBOLS).valueObject(null);
}
import org.sonar.server.es.BulkIndexer;
import org.sonar.server.es.EsClient;
+import javax.annotation.Nullable;
+
import java.sql.Connection;
import java.util.Iterator;
this.dbClient = dbClient;
}
+ public void index(final String projectUuid){
+ super.index(new IndexerTask() {
+ @Override
+ public long index(long lastUpdatedAt) {
+ return doIndex(lastUpdatedAt, projectUuid);
+ }
+ });
+ }
+
@Override
protected long doIndex(long lastUpdatedAt) {
+ return doIndex(lastUpdatedAt, null);
+ }
+
+ private long doIndex(long lastUpdatedAt, @Nullable String projectUuid) {
final BulkIndexer bulk = new BulkIndexer(esClient, SourceLineIndexDefinition.INDEX);
bulk.setLarge(lastUpdatedAt == 0L);
DbSession dbSession = dbClient.openSession(false);
Connection dbConnection = dbSession.getConnection();
try {
- SourceFileResultSetIterator rowIt = SourceFileResultSetIterator.create(dbClient, dbConnection, lastUpdatedAt);
+ SourceFileResultSetIterator rowIt = SourceFileResultSetIterator.create(dbClient, dbConnection, lastUpdatedAt, projectUuid);
long maxUpdatedAt = doIndex(bulk, rowIt);
rowIt.close();
return maxUpdatedAt;
import org.junit.Test;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.utils.System2;
import org.sonar.batch.protocol.output.BatchReportReader;
import org.sonar.core.persistence.DbTester;
import org.sonar.core.source.db.FileSourceDao;
import java.io.IOException;
import java.sql.Connection;
-import java.util.Date;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
public class IndexSourceLinesStepTest extends BaseStepTest {
@ClassRule
public static EsTester esTester = new EsTester().addDefinitions(new SourceLineIndexDefinition(new Settings()));
- System2 system2;
-
DbClient dbClient;
@Before
public void setUp() throws Exception {
dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), new FileSourceDao(null));
- system2 = mock(System2.class);
}
@Override
protected ComputationStep step() throws IOException {
SourceLineIndexer sourceLineIndexer = new SourceLineIndexer(dbClient, esTester.client());
sourceLineIndexer.setEnabled(true);
- return new IndexSourceLinesStep(dbClient, system2, sourceLineIndexer);
+ return new IndexSourceLinesStep(sourceLineIndexer);
}
@Test
}
@Test
- public void update_source_date_on_sources_with_update_at_to_zero() throws Exception {
- when(system2.now()).thenReturn(150000000002L);
- dbTester.prepareDbUnit(getClass(), "update_source_date_on_sources_with_update_at_to_zero.xml");
+ public void index_source() throws Exception {
+ dbTester.prepareDbUnit(getClass(), "index_source.xml");
Connection connection = dbTester.openConnection();
FileSourceTesting.updateDataColumn(connection, "FILE1_UUID", FileSourceTesting.newRandomData(1).build());
connection.close();
step().execute(new ComputationContext(mock(BatchReportReader.class), ComponentTesting.newProjectDto("ABCD")));
- dbTester.assertDbUnit(getClass(), "update_source_date_on_sources_with_update_at_to_zero-result.xml");
-
List<SearchHit> docs = esTester.getDocuments(SourceLineIndexDefinition.INDEX, SourceLineIndexDefinition.TYPE);
assertThat(docs).hasSize(1);
SourceLineDoc doc = new SourceLineDoc(docs.get(0).sourceAsMap());
assertThat(doc.projectUuid()).isEqualTo("ABCD");
assertThat(doc.fileUuid()).isEqualTo("FILE1_UUID");
- assertThat(doc.updateDate()).isEqualTo(new Date(system2.now()));
}
}
import com.google.common.collect.Lists;
import org.apache.commons.io.FileUtils;
-import org.junit.*;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.utils.System2;
assertThat(fileSourceDto.getDataHash()).isNotEmpty();
assertThat(fileSourceDto.getLineHashes()).isNotEmpty();
assertThat(fileSourceDto.getCreatedAt()).isEqualTo(now);
- assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(0L);
+ assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(now);
FileSourceDb.Data data = FileSourceDto.decodeData(fileSourceDto.getBinaryData());
assertThat(data.getLinesCount()).isEqualTo(2);
assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
FileSourceDto fileSourceDto = dbClient.fileSourceDao().select(FILE_UUID);
assertThat(fileSourceDto.getCreatedAt()).isEqualTo(past);
- assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(0L);
+ assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(now);
}
@Test
@Test
public void index_nothing() throws Exception {
IssueAuthorizationIndexer indexer = createIndexer();
- indexer.doIndex(0L);
+ indexer.index();
assertThat(esTester.countDocuments("issues", "authorization")).isZero();
}
Connection connection;
+ SourceFileResultSetIterator iterator;
+
@Before
public void setUp() throws Exception {
dbClient = new DbClient(db.database(), db.myBatis());
@After
public void after() throws Exception {
+ if (iterator != null) {
+ iterator.close();
+ }
connection.close();
}
db.prepareDbUnit(getClass(), "shared.xml");
FileSourceTesting.updateDataColumn(connection, "F1", FileSourceTesting.newFakeData(3).build());
- SourceFileResultSetIterator it = SourceFileResultSetIterator.create(dbClient, connection, 0L);
- assertThat(it.hasNext()).isTrue();
- SourceFileResultSetIterator.Row row = it.next();
+ iterator = SourceFileResultSetIterator.create(dbClient, connection, 0L, null);
+ assertThat(iterator.hasNext()).isTrue();
+ SourceFileResultSetIterator.Row row = iterator.next();
assertThat(row.getProjectUuid()).isEqualTo("P1");
assertThat(row.getFileUuid()).isEqualTo("F1");
assertThat(row.getUpdatedAt()).isEqualTo(1416239042000L);
MapEntry.entry(SourceLineIndexDefinition.FIELD_OVERALL_LINE_HITS, 7),
MapEntry.entry(SourceLineIndexDefinition.FIELD_OVERALL_CONDITIONS, 8),
MapEntry.entry(SourceLineIndexDefinition.FIELD_OVERALL_COVERED_CONDITIONS, 9)
- );
- it.close();
+ );
}
/**
dataBuilder.addLinesBuilder().setLine(1).build();
FileSourceTesting.updateDataColumn(connection, "F1", dataBuilder.build());
- SourceFileResultSetIterator it = SourceFileResultSetIterator.create(dbClient, connection, 0L);
- SourceFileResultSetIterator.Row row = it.next();
+ iterator = SourceFileResultSetIterator.create(dbClient, connection, 0L, null);
+ SourceFileResultSetIterator.Row row = iterator.next();
assertThat(row.getProjectUuid()).isEqualTo("P1");
assertThat(row.getFileUuid()).isEqualTo("F1");
assertThat(row.getUpdatedAt()).isEqualTo(1416239042000L);
MapEntry.entry(SourceLineIndexDefinition.FIELD_PROJECT_UUID, "P1"),
MapEntry.entry(SourceLineIndexDefinition.FIELD_FILE_UUID, "F1"),
MapEntry.entry(SourceLineIndexDefinition.FIELD_LINE, 1)
- );
+ );
// null values
assertThat(doc).containsKeys(
SourceLineIndexDefinition.FIELD_SCM_REVISION,
SourceLineIndexDefinition.FIELD_OVERALL_CONDITIONS,
SourceLineIndexDefinition.FIELD_OVERALL_COVERED_CONDITIONS
);
- it.close();
}
@Test
public void filter_by_date() throws Exception {
db.prepareDbUnit(getClass(), "shared.xml");
- SourceFileResultSetIterator iterator = SourceFileResultSetIterator.create(dbClient, connection, 2000000000000L);
+ iterator = SourceFileResultSetIterator.create(dbClient, connection, 2000000000000L, null);
+ assertThat(iterator.hasNext()).isFalse();
+ }
+
+ @Test
+ public void filter_by_project() throws Exception {
+ db.prepareDbUnit(getClass(), "filter_by_project.xml");
+ FileSourceDb.Data.Builder dataBuilder = FileSourceDb.Data.newBuilder();
+ dataBuilder.addLinesBuilder().setLine(1).build();
+ FileSourceTesting.updateDataColumn(connection, "F1", dataBuilder.build());
+
+ iterator = SourceFileResultSetIterator.create(dbClient, connection, 0L, "P1");
+
+ SourceFileResultSetIterator.Row row = iterator.next();
+ assertThat(row.getProjectUuid()).isEqualTo("P1");
+ assertThat(row.getFileUuid()).isEqualTo("F1");
+
+ // File from other project P2 is not returned
+ assertThat(iterator.hasNext()).isFalse();
+ }
+
+ @Test
+ public void filter_by_project_and_date() throws Exception {
+ db.prepareDbUnit(getClass(), "filter_by_project_and_date.xml");
+ FileSourceDb.Data.Builder dataBuilder = FileSourceDb.Data.newBuilder();
+ dataBuilder.addLinesBuilder().setLine(1).build();
+ FileSourceTesting.updateDataColumn(connection, "F1", dataBuilder.build());
+
+ iterator = SourceFileResultSetIterator.create(dbClient, connection, 1400000000000L, "P1");
+
+ SourceFileResultSetIterator.Row row = iterator.next();
+ assertThat(row.getProjectUuid()).isEqualTo("P1");
+ assertThat(row.getFileUuid()).isEqualTo("F1");
+
+ // File F2 is not returned
assertThat(iterator.hasNext()).isFalse();
- iterator.close();
}
@Test
FileSourceTesting.updateDataColumn(connection, "F1", "THIS_IS_NOT_PROTOBUF".getBytes());
- SourceFileResultSetIterator iterator = SourceFileResultSetIterator.create(dbClient, connection, 0L);
+ iterator = SourceFileResultSetIterator.create(dbClient, connection, 0L, null);
try {
assertThat(iterator.hasNext()).isTrue();
iterator.next();
} catch (IllegalStateException e) {
// ok
}
- iterator.close();
}
}
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
-import static org.sonar.server.source.index.SourceLineIndexDefinition.*;
+import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_DUPLICATIONS;
+import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_FILE_UUID;
+import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_IT_CONDITIONS;
+import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_IT_COVERED_CONDITIONS;
+import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_IT_LINE_HITS;
+import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_LINE;
+import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_OVERALL_CONDITIONS;
+import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_OVERALL_COVERED_CONDITIONS;
+import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_OVERALL_LINE_HITS;
+import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_PROJECT_UUID;
+import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_SCM_AUTHOR;
+import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_SCM_REVISION;
+import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_SOURCE;
+import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_UT_CONDITIONS;
+import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_UT_COVERED_CONDITIONS;
+import static org.sonar.server.source.index.SourceLineIndexDefinition.FIELD_UT_LINE_HITS;
+import static org.sonar.server.source.index.SourceLineIndexDefinition.INDEX;
+import static org.sonar.server.source.index.SourceLineIndexDefinition.TYPE;
@Category(DbTests.class)
public class SourceLineIndexerTest {
}
@Test
- public void index_source_lines_from_db() throws Exception {
+ public void index_source_lines() throws Exception {
db.prepareDbUnit(getClass(), "db.xml");
Connection connection = db.openConnection();
assertThat(countDocuments()).isEqualTo(3);
}
+ @Test
+ public void index_source_lines_from_project() throws Exception {
+ db.prepareDbUnit(getClass(), "db.xml");
+
+ Connection connection = db.openConnection();
+ FileSourceTesting.updateDataColumn(connection, "FILE_UUID", FileSourceTesting.newRandomData(3).build());
+ connection.close();
+
+ indexer.index("PROJECT_UUID");
+ assertThat(countDocuments()).isEqualTo(3);
+ }
+
+ @Test
+ public void index_nothing_from_unknown_project() throws Exception {
+ db.prepareDbUnit(getClass(), "db.xml");
+
+ Connection connection = db.openConnection();
+ FileSourceTesting.updateDataColumn(connection, "FILE_UUID", FileSourceTesting.newRandomData(3).build());
+ connection.close();
+
+ indexer.index("UNKNOWN");
+ assertThat(countDocuments()).isZero();
+ }
+
/**
* File F1 in project P1 has one line -> to be updated
* File F2 in project P1 has one line -> untouched
--- /dev/null
+<dataset>
+
+ <file_sources id="101" project_uuid="ABCD" file_uuid="FILE1_UUID"
+ binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
+ test_data="[null]"
+ created_at="1500000000000" updated_at="0"/>
+
+ <file_sources id="102" project_uuid="DCBA" file_uuid="FILE2_UUID"
+ binary_data="edcba" data_hash="hash2" line_hashes="CBA\nFDE\nIHG" src_hash="FILE2_HASH"
+ created_at="1500000000000" updated_at="0"/>
+
+</dataset>
+++ /dev/null
-<dataset>
-
- <file_sources id="101" project_uuid="ABCD" file_uuid="FILE1_UUID"
- binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
- test_data="[null]"
- created_at="1500000000000" updated_at="1500000000002"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <file_sources id="101" project_uuid="ABCD" file_uuid="FILE1_UUID"
- binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
- test_data="[null]"
- created_at="1500000000000" updated_at="0"/>
-
-</dataset>
--- /dev/null
+<dataset>
+
+ <file_sources id="1" project_uuid="P1" file_uuid="F1" created_at="1416238020000" updated_at="1416239042000"
+ binary_data="" data_hash="" />
+
+ <file_sources id="2" project_uuid="P2" file_uuid="F2" created_at="1416238020000" updated_at="1416239042000"
+ binary_data="" data_hash="" />
+
+</dataset>
--- /dev/null
+<dataset>
+
+ <file_sources id="1" project_uuid="P1" file_uuid="F1" created_at="1416238020000" updated_at="1416239042000"
+ binary_data="" data_hash="" />
+
+ <file_sources id="2" project_uuid="P1" file_uuid="F2" created_at="1416238020000" updated_at="1300000000000"
+ binary_data="" data_hash="" />
+
+</dataset>
/**
* <code>optional string key = 2;</code>
+ *
+ * <pre>
+ *TODO TBE - should the key and long_name specified directly ?
+ * </pre>
*/
boolean hasKey();
/**
* <code>optional string key = 2;</code>
+ *
+ * <pre>
+ *TODO TBE - should the key and long_name specified directly ?
+ * </pre>
*/
java.lang.String getKey();
/**
* <code>optional string key = 2;</code>
+ *
+ * <pre>
+ *TODO TBE - should the key and long_name specified directly ?
+ * </pre>
*/
com.google.protobuf.ByteString
getKeyBytes();
private java.lang.Object key_;
/**
* <code>optional string key = 2;</code>
+ *
+ * <pre>
+ *TODO TBE - should the key and long_name specified directly ?
+ * </pre>
*/
public boolean hasKey() {
return ((bitField0_ & 0x00000002) == 0x00000002);
}
/**
* <code>optional string key = 2;</code>
+ *
+ * <pre>
+ *TODO TBE - should the key and long_name specified directly ?
+ * </pre>
*/
public java.lang.String getKey() {
java.lang.Object ref = key_;
}
/**
* <code>optional string key = 2;</code>
+ *
+ * <pre>
+ *TODO TBE - should the key and long_name specified directly ?
+ * </pre>
*/
public com.google.protobuf.ByteString
getKeyBytes() {
private java.lang.Object key_ = "";
/**
* <code>optional string key = 2;</code>
+ *
+ * <pre>
+ *TODO TBE - should the key and long_name specified directly ?
+ * </pre>
*/
public boolean hasKey() {
return ((bitField0_ & 0x00000002) == 0x00000002);
}
/**
* <code>optional string key = 2;</code>
+ *
+ * <pre>
+ *TODO TBE - should the key and long_name specified directly ?
+ * </pre>
*/
public java.lang.String getKey() {
java.lang.Object ref = key_;
}
/**
* <code>optional string key = 2;</code>
+ *
+ * <pre>
+ *TODO TBE - should the key and long_name specified directly ?
+ * </pre>
*/
public com.google.protobuf.ByteString
getKeyBytes() {
}
/**
* <code>optional string key = 2;</code>
+ *
+ * <pre>
+ *TODO TBE - should the key and long_name specified directly ?
+ * </pre>
*/
public Builder setKey(
java.lang.String value) {
}
/**
* <code>optional string key = 2;</code>
+ *
+ * <pre>
+ *TODO TBE - should the key and long_name specified directly ?
+ * </pre>
*/
public Builder clearKey() {
bitField0_ = (bitField0_ & ~0x00000002);
}
/**
* <code>optional string key = 2;</code>
+ *
+ * <pre>
+ *TODO TBE - should the key and long_name specified directly ?
+ * </pre>
*/
public Builder setKeyBytes(
com.google.protobuf.ByteString value) {