use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.
the class InternalCeQueueImplTest method peek_resets_to_pending_any_task_in_progress_for_specified_worker_uuid_and_only_this_uuid.
@Test
public void peek_resets_to_pending_any_task_in_progress_for_specified_worker_uuid_and_only_this_uuid() {
// add a pending one that will be picked so that u1 isn't peek and status reset is visible in DB
insertPending("u0");
CeQueueDto u1 = insertInProgress("u1", WORKER_UUID_1);
CeQueueDto u2 = insertInProgress("u2", WORKER_UUID_2);
CeQueueDto u3 = insertInProgress("u3", WORKER_UUID_1);
CeQueueDto u4 = insertInProgress("u4", WORKER_UUID_2);
assertThat(underTest.peek(WORKER_UUID_1, true).get().getUuid()).isEqualTo("u0");
verifyResetTask(u1);
verifyUnmodifiedTask(u2);
verifyResetTask(u3);
verifyUnmodifiedTask(u4);
}
use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.
the class UpdateVisibilityActionTest method insertCeQueueDto.
private void insertCeQueueDto(ComponentDto project, CeQueueDto.Status status) {
dbClient.ceQueueDao().insert(dbTester.getSession(), new CeQueueDto().setUuid("pending" + counter++).setComponent(project).setTaskType("foo").setStatus(status));
dbTester.commit();
}
use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.
the class CeQueueImpl method loadTasks.
private List<CeTask> loadTasks(DbSession dbSession, List<CeQueueDto> dtos) {
// load components, if defined
Set<String> componentUuids = dtos.stream().flatMap(dto -> Stream.of(dto.getComponentUuid(), dto.getMainComponentUuid())).filter(Objects::nonNull).collect(Collectors.toSet());
Map<String, ComponentDto> componentsByUuid = dbClient.componentDao().selectByUuids(dbSession, componentUuids).stream().collect(uniqueIndex(ComponentDto::uuid));
// load characteristics
// TODO could be avoided, characteristics are already present in submissions
Set<String> taskUuids = dtos.stream().map(CeQueueDto::getUuid).collect(MoreCollectors.toSet(dtos.size()));
Multimap<String, CeTaskCharacteristicDto> characteristicsByTaskUuid = dbClient.ceTaskCharacteristicsDao().selectByTaskUuids(dbSession, taskUuids).stream().collect(MoreCollectors.index(CeTaskCharacteristicDto::getTaskUuid));
List<CeTask> result = new ArrayList<>();
for (CeQueueDto dto : dtos) {
ComponentDto component = ofNullable(dto.getComponentUuid()).map(componentsByUuid::get).orElse(null);
ComponentDto mainComponent = ofNullable(dto.getMainComponentUuid()).map(componentsByUuid::get).orElse(null);
Map<String, String> characteristics = characteristicsByTaskUuid.get(dto.getUuid()).stream().collect(uniqueIndex(CeTaskCharacteristicDto::getKey, CeTaskCharacteristicDto::getValue));
result.add(convertToTask(dbSession, dto, characteristics, component, mainComponent));
}
return result;
}
use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.
the class CeQueueImpl method addToQueueInDb.
private CeQueueDto addToQueueInDb(DbSession dbSession, CeTaskSubmit submission) {
for (Map.Entry<String, String> characteristic : submission.getCharacteristics().entrySet()) {
CeTaskCharacteristicDto characteristicDto = new CeTaskCharacteristicDto();
characteristicDto.setUuid(uuidFactory.create());
characteristicDto.setTaskUuid(submission.getUuid());
characteristicDto.setKey(characteristic.getKey());
characteristicDto.setValue(characteristic.getValue());
dbClient.ceTaskCharacteristicsDao().insert(dbSession, characteristicDto);
}
CeQueueDto dto = new CeQueueDto();
dto.setUuid(submission.getUuid());
dto.setTaskType(submission.getType());
submission.getComponent().ifPresent(component -> dto.setComponentUuid(component.getUuid()).setMainComponentUuid(component.getMainComponentUuid()));
dto.setStatus(PENDING);
dto.setSubmitterUuid(submission.getSubmitterUuid());
dbClient.ceQueueDao().insert(dbSession, dto);
return dto;
}
use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.
the class PurgeDaoTest method insertCeActivity.
private CeActivityDto insertCeActivity(ComponentDto component) {
Status unusedStatus = Status.values()[RandomUtils.nextInt(Status.values().length)];
CeQueueDto queueDto = createCeQueue(component, unusedStatus);
CeActivityDto dto = new CeActivityDto(queueDto);
dto.setStatus(CeActivityDto.Status.SUCCESS);
dto.setStartedAt(1_500_000_000_000L);
dto.setExecutedAt(1_500_000_000_500L);
dto.setExecutionTimeMs(500L);
dbClient.ceActivityDao().insert(dbSession, dto);
return dto;
}
Aggregations