import java.util.List;
import javax.annotation.Nullable;
import org.elasticsearch.action.update.UpdateRequest;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
String projectUuid = rs.getString(1);
String fileUuid = rs.getString(2);
Date updatedAt = new Date(rs.getLong(3));
- InputStream dataInput = rs.getBinaryStream(4);
- List<DbFileSources.Test> data;
+ List<DbFileSources.Test> tests = parseData(fileUuid, rs.getBinaryStream(4));
+ return toRow(projectUuid, fileUuid, updatedAt, tests);
+ }
+
+ private static List<DbFileSources.Test> parseData(String fileUuid, @Nullable InputStream dataInput) {
+ List<DbFileSources.Test> tests = Collections.emptyList();
if (dataInput != null) {
- data = FileSourceDto.decodeTestData(dataInput);
- } else {
- data = Collections.emptyList();
+ try {
+ tests = FileSourceDto.decodeTestData(dataInput);
+ } catch (Exception e) {
+ Loggers.get(TestResultSetIterator.class).warn(String.format("Invalid file_sources.binary_data on row with file_uuid='%s', test file will be ignored", fileUuid), e);
+ }
}
- return toRow(projectUuid, fileUuid, updatedAt, data);
+ return tests;
}
/**
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.System2;
+import org.sonar.api.utils.log.LogTester;
+import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.db.DbTester;
import org.sonar.db.protobuf.DbFileSources;
import org.sonar.server.source.index.FileSourcesUpdaterHelper;
import org.sonar.server.test.db.TestTesting;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.data.MapEntry.entry;
import static org.sonar.server.test.index.TestIndexDefinition.FIELD_COVERED_FILES;
import static org.sonar.server.test.index.TestIndexDefinition.FIELD_DURATION_IN_MS;
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ @Rule
+ public LogTester logTester = new LogTester();
+
TestResultSetIterator underTest;
private static List<DbFileSources.Test> newFakeTests(int numberOfTests) {
}
@Test
- public void fail_on_bad_data_format() throws Exception {
+ public void read_does_not_fail_if_corrupted_data() throws Exception {
dbTester.prepareDbUnit(getClass(), "shared.xml");
TestTesting.updateDataColumn(dbTester.getSession(), "F1", "THIS_IS_NOT_PROTOBUF".getBytes());
underTest = TestResultSetIterator.create(dbTester.getDbClient(), dbTester.getSession(), 0L, null);
- try {
- assertThat(underTest.hasNext()).isTrue();
- underTest.next();
- fail("it should not be possible to go through not compliant data");
- } catch (IllegalStateException e) {
- // ok
- }
+ FileSourcesUpdaterHelper.Row row = underTest.next();
+ assertThat(row.getFileUuid()).isEqualTo("F1");
+ assertThat(row.getUpdateRequests()).isEmpty();
+ assertThat(underTest.hasNext()).isFalse();
+
+ assertThat(logTester.logs(LoggerLevel.WARN)).contains("Invalid file_sources.binary_data on row with file_uuid='F1', test file will be ignored");
}
@Test