import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
-import org.sonar.db.ce.CeActivityDto.Status;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
.mapToObj(i -> new ComponentUuidFromDatePair(componentUuids.get(i), fromDates.get(i)))
.collect(MoreCollectors.toList(componentUuids.size()));
- return executeLargeInputs(componentUuidFromDatePairs, partition -> mapper(dbSession).selectFinishedByComponentUuidsAndFromDates(partition, Status.SUCCESS), i -> i / 2);
+ return executeLargeInputs(componentUuidFromDatePairs, partition -> mapper(dbSession).selectFinishedByComponentUuidsAndFromDates(partition), i -> i / 2);
}
public void switchIsLastFlagAndSetProcessedStatus(DbSession dbSession, String componentUuid, String analysisUuid) {
import javax.annotation.CheckForNull;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
-import org.sonar.db.ce.CeActivityDto;
import org.sonar.db.component.SnapshotDao.ComponentUuidFromDatePair;
public interface SnapshotMapper {
void update(SnapshotDto analysis);
- List<SnapshotDto> selectFinishedByComponentUuidsAndFromDates(@Param("componentUuidFromDatePairs") List<ComponentUuidFromDatePair> pairs,
- @Param("ceStatus") CeActivityDto.Status ceStatus);
+ List<SnapshotDto> selectFinishedByComponentUuidsAndFromDates(@Param("componentUuidFromDatePairs") List<ComponentUuidFromDatePair> pairs);
}
from snapshots s
inner join projects p on p.uuid=s.component_uuid and p.enabled=${_true}
inner join project_branches pb on pb.uuid=p.uuid
- inner join ce_activity ca on ca.analysis_uuid = s.uuid and ca.component_uuid = pb.project_uuid
where
<foreach collection="componentUuidFromDatePairs" open="(" close=")" item="componentUuidFromDatePair" separator=" or ">
(pb.project_uuid=#{componentUuidFromDatePair.componentUuid, jdbcType=VARCHAR} and s.created_at >= #{componentUuidFromDatePair.from, jdbcType=BIGINT})
</foreach>
and s.status = 'P'
- and ca.status=#{ceStatus, jdbcType=VARCHAR}
order by
s.created_at
</select>
}
@Test
- public void selectFinishedByComponentUuidsAndFromDates_ignores_unsuccessful_analysis() {
+ public void selectFinishedByComponentUuidsAndFromDates_returns_processed_analysis_even_if_analysis_failed() {
long from = 1_500_000_000_000L;
ComponentDto project = db.components().insertMainBranch();
SnapshotDto unprocessedAnalysis = db.components().insertSnapshot(project, s -> s.setStatus(STATUS_UNPROCESSED).setCreatedAt(from + 1_000_000L));
List<SnapshotDto> result = underTest.selectFinishedByComponentUuidsAndFromDates(dbSession, singletonList(project.uuid()), singletonList(from));
assertThat(result).extracting(SnapshotDto::getUuid)
- .containsExactlyInAnyOrder(finishedAnalysis.getUuid());
+ .containsExactlyInAnyOrder(finishedAnalysis.getUuid(), canceledAnalysis.getUuid());
}
@Test