import org.sonar.db.ce.CeActivityDto;
import org.sonar.db.ce.CeQueueDto;
import org.sonar.db.ce.CeTaskTypes;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
+import org.sonar.db.entity.EntityDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.user.UserDto;
import org.sonar.db.user.UserTesting;
import org.sonar.server.platform.NodeInformation;
import static org.assertj.core.api.Assertions.tuple;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_MAIN_COMPONENT;
+import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_ENTITY;
import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_TASK_TYPE;
public class CeQueueImplIT {
CeTask task = underTest.submit(taskSubmit);
- verifyCeTask(taskSubmit, task, null, userDto);
+ verifyCeTask(taskSubmit, task, null, null, userDto);
verifyCeQueueDtoForTaskSubmit(taskSubmit);
}
@Test
public void submit_populates_component_name_and_key_of_CeTask_if_component_exists() {
- ComponentDto componentDto = insertComponent(ComponentTesting.newPrivateProjectDto("PROJECT_1"));
- CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(componentDto.uuid(), componentDto.uuid()), null);
+ ProjectData projectData = db.components().insertPrivateProject("PROJECT_1");
+ CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(projectData.getMainBranchDto()), null);
CeTask task = underTest.submit(taskSubmit);
- verifyCeTask(taskSubmit, task, componentDto, null);
+ verifyCeTask(taskSubmit, task, projectData.getProjectDto(), projectData.getMainBranchDto(), null);
}
@Test
CeTask task = underTest.submit(taskSubmit);
- verifyCeTask(taskSubmit, task, null, null);
+ verifyCeTask(taskSubmit, task, null, null, null);
}
@Test
CeTask task = underTest.submit(taskSubmit);
- verifyCeTask(taskSubmit, task, null, userDto);
+ verifyCeTask(taskSubmit, task, null, null, userDto);
}
@Test
CeTaskSubmit taskSubmit = createTaskSubmit("no_component");
CeQueueDto dto = insertPendingInQueue(null);
- Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+ Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_ENTITY);
assertThat(task).isNotEmpty();
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null);
CeQueueDto dto = insertPendingInQueue(newComponent(otherMainComponentUuid));
- Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+ Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_ENTITY);
assertThat(task).isNotEmpty();
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null);
CeQueueDto dto = insertPendingInQueue(newComponent(mainComponentUuid));
- Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+ Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_ENTITY);
assertThat(task).isEmpty();
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
.map(CeQueueDto::getUuid)
.toArray(String[]::new);
- Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+ Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_ENTITY);
assertThat(task).isEmpty();
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
List<CeTask> tasks = underTest.massSubmit(asList(taskSubmit1, taskSubmit2));
assertThat(tasks).hasSize(2);
- verifyCeTask(taskSubmit1, tasks.get(0), null, userDto1);
- verifyCeTask(taskSubmit2, tasks.get(1), null, null);
+ verifyCeTask(taskSubmit1, tasks.get(0), null, null, userDto1);
+ verifyCeTask(taskSubmit2, tasks.get(1), null, null, null);
verifyCeQueueDtoForTaskSubmit(taskSubmit1);
verifyCeQueueDtoForTaskSubmit(taskSubmit2);
}
@Test
public void massSubmit_populates_component_name_and_key_of_CeTask_if_project_exists() {
- ComponentDto componentDto1 = insertComponent(ComponentTesting.newPrivateProjectDto("PROJECT_1"));
- CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(componentDto1.uuid(), componentDto1.uuid()), null);
+ ProjectData projectData = db.components().insertPrivateProject("PROJECT_1");
+ CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(projectData.getMainBranchDto()), null);
CeTaskSubmit taskSubmit2 = createTaskSubmit("something", newComponent(randomAlphabetic(12)), null);
List<CeTask> tasks = underTest.massSubmit(asList(taskSubmit1, taskSubmit2));
assertThat(tasks).hasSize(2);
- verifyCeTask(taskSubmit1, tasks.get(0), componentDto1, null);
- verifyCeTask(taskSubmit2, tasks.get(1), null, null);
+ verifyCeTask(taskSubmit1, tasks.get(0), projectData.getProjectDto(), projectData.getMainBranchDto(), null);
+ verifyCeTask(taskSubmit2, tasks.get(1), null, null, null);
}
@Test
public void massSubmit_populates_component_name_and_key_of_CeTask_if_project_and_branch_exists() {
- ComponentDto project = db.components().insertPublicProject(p -> p.setUuid("PROJECT_1").setBranchUuid("PROJECT_1")).getMainBranchComponent();
- ComponentDto branch1 = db.components().insertProjectBranch(project);
- ComponentDto branch2 = db.components().insertProjectBranch(project);
- CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(branch1.uuid(), project.uuid()), null);
- CeTaskSubmit taskSubmit2 = createTaskSubmit("something", Component.fromDto(branch2.uuid(), project.uuid()), null);
+ ProjectDto project = db.components().insertPublicProject(p -> p.setUuid("PROJECT_1").setBranchUuid("PROJECT_1")).getProjectDto();
+ BranchDto branch1 = db.components().insertProjectBranch(project);
+ BranchDto branch2 = db.components().insertProjectBranch(project);
+ CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(branch1.getUuid(), project.getUuid()), null);
+ CeTaskSubmit taskSubmit2 = createTaskSubmit("something", Component.fromDto(branch2.getUuid(), project.getUuid()), null);
List<CeTask> tasks = underTest.massSubmit(asList(taskSubmit1, taskSubmit2));
assertThat(tasks).hasSize(2);
- verifyCeTask(taskSubmit1, tasks.get(0), branch1, project, null);
- verifyCeTask(taskSubmit2, tasks.get(1), branch2, project, null);
+ verifyCeTask(taskSubmit1, tasks.get(0), project, branch1, null);
+ verifyCeTask(taskSubmit2, tasks.get(1), project, branch2, null);
}
@Test
CeTaskSubmit taskSubmit = createTaskSubmit("no_component");
CeQueueDto dto = insertPendingInQueue(null);
- List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+ List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_ENTITY);
assertThat(tasks).hasSize(1);
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null);
CeQueueDto dto = insertPendingInQueue(newComponent(otherMainComponentUuid));
- List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+ List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_ENTITY);
assertThat(tasks).hasSize(1);
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null);
CeQueueDto dto = insertPendingInQueue(newComponent(mainComponentUuid));
- List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+ List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_ENTITY);
assertThat(tasks).isEmpty();
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
.map(CeQueueDto::getUuid)
.toArray(String[]::new);
- List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+ List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_ENTITY);
assertThat(tasks).isEmpty();
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
CeTaskSubmit taskSubmit5 = createTaskSubmit("with_pending_2", newComponent(mainComponentUuid5), null);
CeQueueDto dto5 = insertPendingInQueue(newComponent(mainComponentUuid5));
- List<CeTask> tasks = underTest.massSubmit(of(taskSubmit1, taskSubmit2, taskSubmit3, taskSubmit4, taskSubmit5), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
+ List<CeTask> tasks = underTest.massSubmit(of(taskSubmit1, taskSubmit2, taskSubmit3, taskSubmit4, taskSubmit5), UNIQUE_QUEUE_PER_ENTITY);
assertThat(tasks)
.hasSize(2)
- .extracting(task -> task.getComponent().get().getUuid(), task -> task.getMainComponent().get().getUuid())
- .containsOnly(tuple(componentForMainComponentUuid2.getUuid(), componentForMainComponentUuid2.getMainComponentUuid()),
- tuple(componentForMainComponentUuid4.getUuid(), componentForMainComponentUuid4.getMainComponentUuid()));
+ .extracting(task -> task.getComponent().get().getUuid(), task -> task.getEntity().get().getUuid())
+ .containsOnly(tuple(componentForMainComponentUuid2.getUuid(), componentForMainComponentUuid2.getEntityUuid()),
+ tuple(componentForMainComponentUuid4.getUuid(), componentForMainComponentUuid4.getEntityUuid()));
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession()))
.extracting(CeQueueDto::getUuid)
.hasSize(1 + uuids3.length + 1 + tasks.size())
.hasMessage("Task is not in-progress and can't be marked as failed [uuid=" + task.getUuid() + "]");
}
- private void verifyCeTask(CeTaskSubmit taskSubmit, CeTask task, @Nullable ComponentDto componentDto, UserDto userDto) {
- verifyCeTask(taskSubmit, task, componentDto, componentDto, userDto);
- }
-
- private void verifyCeTask(CeTaskSubmit taskSubmit, CeTask task, @Nullable ComponentDto componentDto, @Nullable ComponentDto mainComponentDto, @Nullable UserDto userDto) {
+ private void verifyCeTask(CeTaskSubmit taskSubmit, CeTask task, @Nullable EntityDto entityDto, @Nullable BranchDto branch, @Nullable UserDto userDto) {
assertThat(task.getUuid()).isEqualTo(taskSubmit.getUuid());
- if (componentDto != null) {
+ if (branch != null) {
CeTask.Component component = task.getComponent().get();
- assertThat(component.getUuid()).isEqualTo(componentDto.uuid());
- assertThat(component.getKey()).contains(componentDto.getKey());
- assertThat(component.getName()).contains(componentDto.name());
+ assertThat(component.getUuid()).isEqualTo(branch.getUuid());
+ assertThat(component.getKey()).contains(entityDto.getKey());
+ assertThat(component.getName()).contains(entityDto.getName());
} else if (taskSubmit.getComponent().isPresent()) {
assertThat(task.getComponent()).contains(new CeTask.Component(taskSubmit.getComponent().get().getUuid(), null, null));
} else {
assertThat(task.getComponent()).isEmpty();
}
- if (mainComponentDto != null) {
- CeTask.Component component = task.getMainComponent().get();
- assertThat(component.getUuid()).isEqualTo(mainComponentDto.uuid());
- assertThat(component.getKey()).contains(mainComponentDto.getKey());
- assertThat(component.getName()).contains(mainComponentDto.name());
+ if (entityDto != null) {
+ CeTask.Component component = task.getEntity().get();
+ assertThat(component.getUuid()).isEqualTo(entityDto.getUuid());
+ assertThat(component.getKey()).contains(entityDto.getKey());
+ assertThat(component.getName()).contains(entityDto.getName());
} else if (taskSubmit.getComponent().isPresent()) {
- assertThat(task.getMainComponent()).contains(new CeTask.Component(taskSubmit.getComponent().get().getMainComponentUuid(), null, null));
+ assertThat(task.getEntity()).contains(new CeTask.Component(taskSubmit.getComponent().get().getEntityUuid(), null, null));
} else {
- assertThat(task.getMainComponent()).isEmpty();
+ assertThat(task.getEntity()).isEmpty();
}
assertThat(task.getType()).isEqualTo(taskSubmit.getType());
if (taskSubmit.getSubmitterUuid() != null) {
Optional<Component> component = taskSubmit.getComponent();
if (component.isPresent()) {
assertThat(queueDto.get().getComponentUuid()).isEqualTo(component.get().getUuid());
- assertThat(queueDto.get().getMainComponentUuid()).isEqualTo(component.get().getMainComponentUuid());
+ assertThat(queueDto.get().getEntityUuid()).isEqualTo(component.get().getEntityUuid());
} else {
assertThat(queueDto.get().getComponentUuid()).isNull();
assertThat(queueDto.get().getComponentUuid()).isNull();
.setStatus(CeQueueDto.Status.PENDING);
if (component != null) {
dto.setComponentUuid(component.getUuid())
- .setMainComponentUuid(component.getMainComponentUuid());
+ .setEntityUuid(component.getEntityUuid());
}
db.getDbClient().ceQueueDao().insert(db.getSession(), dto);
db.commit();
* <p>
* This method is equivalent to calling {@code massSubmit(Collections.singletonList(submission))}.
*
- * @return empty if {@code options} contains {@link SubmitOption#UNIQUE_QUEUE_PER_MAIN_COMPONENT UNIQUE_QUEUE_PER_MAIN_COMPONENT}
+ * @return empty if {@code options} contains {@link SubmitOption#UNIQUE_QUEUE_PER_ENTITY UNIQUE_QUEUE_PER_MAIN_COMPONENT}
* and there's already a queued task, otherwise the created task.
*/
Optional<CeTask> submit(CeTaskSubmit submission, SubmitOption... options);
int clear();
enum SubmitOption {
- UNIQUE_QUEUE_PER_MAIN_COMPONENT,
+ UNIQUE_QUEUE_PER_ENTITY,
UNIQUE_QUEUE_PER_TASK_TYPE
}
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
-import java.util.stream.Stream;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.api.server.ServerSide;
import org.sonar.db.ce.CeTaskQuery;
import org.sonar.db.ce.DeleteIf;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.entity.EntityDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.platform.NodeInformation;
import org.sonar.server.property.InternalProperties;
import static com.google.common.base.Preconditions.checkState;
-import static java.util.Collections.emptyMap;
import static java.util.Collections.singleton;
import static java.util.Optional.ofNullable;
-import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_MAIN_COMPONENT;
+import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_ENTITY;
import static org.sonar.core.util.stream.MoreCollectors.toEnumSet;
import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.db.ce.CeQueueDto.Status.IN_PROGRESS;
CeTaskQuery query = new CeTaskQuery();
for (SubmitOption option : submitOptions) {
switch (option) {
- case UNIQUE_QUEUE_PER_MAIN_COMPONENT -> submission.getComponent()
- .flatMap(component -> Optional.ofNullable(component.getMainComponentUuid()))
- .ifPresent(mainComponentUuid -> query.setMainComponentUuid(mainComponentUuid).setStatuses(List.of(PENDING.name())));
+ case UNIQUE_QUEUE_PER_ENTITY -> submission.getComponent()
+ .flatMap(component -> Optional.ofNullable(component.getEntityUuid()))
+ .ifPresent(entityUuid -> query.setEntityUuid(entityUuid).setStatuses(List.of(PENDING.name())));
case UNIQUE_QUEUE_PER_TASK_TYPE -> query.setType(submission.getType());
}
}
- boolean queryNonEmpty = query.getMainComponentUuids() != null || query.getStatuses() != null || query.getType() != null;
+ boolean queryNonEmpty = query.getEntityUuids() != null || query.getStatuses() != null || query.getType() != null;
if (queryNonEmpty && dbClient.ceQueueDao().countByQuery(dbSession, query) > 0) {
return Optional.empty();
}
}
private CeTask convertQueueDtoToTask(DbSession dbSession, CeQueueDto queueDto, CeTaskSubmit submission) {
- Map<String, ComponentDto> componentsByUuid = loadComponentDtos(dbSession, queueDto);
- if (componentsByUuid.isEmpty()) {
- return convertToTask(dbSession, queueDto, submission.getCharacteristics(), null, null);
- }
- return convertToTask(dbSession, queueDto, submission.getCharacteristics(),
- ofNullable(queueDto.getComponentUuid()).map(componentsByUuid::get).orElse(null),
- ofNullable(queueDto.getMainComponentUuid()).map(componentsByUuid::get).orElse(null));
+ return convertToTask(dbSession, queueDto, submission.getCharacteristics());
}
- Map<String, ComponentDto> loadComponentDtos(DbSession dbSession, CeQueueDto taskDto) {
- Set<String> componentUuids = Stream.of(taskDto.getComponentUuid(), taskDto.getMainComponentUuid())
- .filter(Objects::nonNull)
- .collect(MoreCollectors.toSet(2));
- if (componentUuids.isEmpty()) {
- return emptyMap();
+ protected CeTask convertToTask(DbSession dbSession, CeQueueDto queueDto, Map<String, String> characteristicDto) {
+ ComponentDto component = null;
+ EntityDto entity = null;
+
+ if (queueDto.getComponentUuid() != null) {
+ component = dbClient.componentDao().selectByUuid(dbSession, queueDto.getComponentUuid()).orElse(null);
}
+ if (queueDto.getEntityUuid() != null) {
+ entity = dbClient.entityDao().selectByUuid(dbSession, queueDto.getEntityUuid()).orElse(null);
+ }
+
+ return convertToTask(dbSession, queueDto, characteristicDto, component, entity);
- return dbClient.componentDao().selectByUuids(dbSession, componentUuids)
- .stream()
- .collect(uniqueIndex(ComponentDto::uuid, 2));
}
@Override
private Predicate<CeTaskSubmit> filterBySubmitOptions(SubmitOption[] options, Collection<CeTaskSubmit> submissions, DbSession dbSession) {
EnumSet<SubmitOption> submitOptions = toSet(options);
- if (submitOptions.contains(UNIQUE_QUEUE_PER_MAIN_COMPONENT)) {
+ if (submitOptions.contains(UNIQUE_QUEUE_PER_ENTITY)) {
Set<String> mainComponentUuids = submissions.stream()
.map(CeTaskSubmit::getComponent)
.filter(Optional::isPresent)
.map(Optional::get)
- .map(CeTaskSubmit.Component::getMainComponentUuid)
+ .map(CeTaskSubmit.Component::getEntityUuid)
.collect(MoreCollectors.toSet(submissions.size()));
if (mainComponentUuids.isEmpty()) {
return t -> true;
private final Map<String, Integer> queuedItemsByMainComponentUuid;
private NoPendingTaskFilter(DbSession dbSession, Set<String> projectUuids) {
- queuedItemsByMainComponentUuid = dbClient.ceQueueDao().countByStatusAndMainComponentUuids(dbSession, PENDING, projectUuids);
+ queuedItemsByMainComponentUuid = dbClient.ceQueueDao().countByStatusAndEntityUuids(dbSession, PENDING, projectUuids);
}
@Override
public boolean test(CeTaskSubmit ceTaskSubmit) {
return ceTaskSubmit.getComponent()
- .map(component -> queuedItemsByMainComponentUuid.getOrDefault(component.getMainComponentUuid(), 0) == 0)
+ .map(component -> queuedItemsByMainComponentUuid.getOrDefault(component.getEntityUuid(), 0) == 0)
.orElse(true);
}
}
dto.setTaskType(submission.getType());
submission.getComponent().ifPresent(component -> dto
.setComponentUuid(component.getUuid())
- .setMainComponentUuid(component.getMainComponentUuid()));
+ .setEntityUuid(component.getEntityUuid()));
dto.setStatus(PENDING);
dto.setSubmitterUuid(submission.getSubmitterUuid());
dbClient.ceQueueDao().insert(dbSession, dto);
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()))
+ .map(CeQueueDto::getComponentUuid)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
+ // these components correspond to a branch or a portfolio (analysis target)
Map<String, ComponentDto> componentsByUuid = dbClient.componentDao()
.selectByUuids(dbSession, componentUuids).stream()
.collect(uniqueIndex(ComponentDto::uuid));
+ Set<String> entityUuids = dtos.stream().map(CeQueueDto::getEntityUuid).filter(Objects::nonNull).collect(Collectors.toSet());
+ Map<String, EntityDto> entitiesByUuid = dbClient.entityDao().selectByUuids(dbSession, entityUuids).stream()
+ .collect(Collectors.toMap(EntityDto::getUuid, e -> e));
// load characteristics
// TODO could be avoided, characteristics are already present in submissions
ComponentDto component = ofNullable(dto.getComponentUuid())
.map(componentsByUuid::get)
.orElse(null);
- ComponentDto mainComponent = ofNullable(dto.getMainComponentUuid())
- .map(componentsByUuid::get)
+ EntityDto entity = ofNullable(dto.getEntityUuid())
+ .map(entitiesByUuid::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));
+ result.add(convertToTask(dbSession, dto, characteristics, component, entity));
}
return result;
}
return cancelAll(true);
}
- CeTask convertToTask(DbSession dbSession, CeQueueDto taskDto, Map<String, String> characteristics, @Nullable ComponentDto component, @Nullable ComponentDto mainComponent) {
+ CeTask convertToTask(DbSession dbSession, CeQueueDto taskDto, Map<String, String> characteristics, @Nullable ComponentDto component, @Nullable EntityDto entity) {
CeTask.Builder builder = new CeTask.Builder()
.setUuid(taskDto.getUuid())
.setType(taskDto.getTaskType())
builder.setComponent(new CeTask.Component(componentUuid, null, null));
}
- String mainComponentUuid = taskDto.getMainComponentUuid();
- if (mainComponent != null) {
- builder.setMainComponent(new CeTask.Component(mainComponent.uuid(), mainComponent.getKey(), mainComponent.name()));
- } else if (mainComponentUuid != null) {
- builder.setMainComponent(new CeTask.Component(mainComponentUuid, null, null));
+ String entityUuid = taskDto.getEntityUuid();
+ if (entity != null) {
+ builder.setEntity(new CeTask.Component(entity.getUuid(), entity.getKey(), entity.getName()));
+ } else if (entityUuid != null) {
+ builder.setEntity(new CeTask.Component(entityUuid, null, null));
}
return builder.build();
import javax.annotation.concurrent.Immutable;
import org.sonar.db.component.BranchDto;
import org.sonar.db.portfolio.PortfolioDto;
-import org.sonar.db.project.ProjectDto;
import static com.google.common.base.Strings.emptyToNull;
import static com.google.common.base.Strings.nullToEmpty;
}
public static class Component {
- private String uuid;
- private String mainComponentUuid;
+ private final String uuid;
+ private final String entityUuid;
- public Component(String uuid, String mainComponentUuid) {
+ public Component(String uuid, String entityUuid) {
this.uuid = requireNonNull(nullToEmpty(uuid), "uuid can't be null");
- this.mainComponentUuid = requireNonNull(nullToEmpty(mainComponentUuid), "mainComponentUuid can't be null");
- }
-
- public static Component fromDto(String componentUuid, String mainComponentUuid) {
- return new Component(componentUuid, mainComponentUuid);
+ this.entityUuid = requireNonNull(nullToEmpty(entityUuid), "mainComponentUuid can't be null");
}
- public static Component fromDto(ProjectDto dto) {
- return new Component(dto.getUuid(), dto.getUuid());
+ public static Component fromDto(String componentUuid, String entityUuid) {
+ return new Component(componentUuid, entityUuid);
}
public static Component fromDto(PortfolioDto dto) {
return new Component(dto.getUuid(), dto.getProjectUuid());
}
- public static Component fromProjectUuid(String projectUuid) {
- return new Component(projectUuid, projectUuid);
- }
-
public String getUuid() {
return uuid;
}
- public String getMainComponentUuid() {
- return mainComponentUuid;
+ public String getEntityUuid() {
+ return entityUuid;
}
@Override
public String toString() {
return "Component{" +
"uuid='" + uuid + '\'' +
- ", mainComponentUuid='" + mainComponentUuid + '\'' +
+ ", entityUuid='" + entityUuid + '\'' +
'}';
}
return false;
}
Component component = (Component) o;
- return uuid.equals(component.uuid) && mainComponentUuid.equals(component.mainComponentUuid);
+ return uuid.equals(component.uuid) && entityUuid.equals(component.entityUuid);
}
@Override
public int hashCode() {
- return Objects.hash(uuid, mainComponentUuid);
+ return Objects.hash(uuid, entityUuid);
}
}
}
@Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
private final Branch mockedBranch = mock(Branch.class);
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
@Test
public void getOrCreateForKey_when_existingComponentsInDbForMainBranch_should_load() {
@Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
public TestSystem2 system2 = new TestSystem2();
@Test
public void update_description() {
- ProjectDto p1 = dbTester.components().insertPublicProject(
- c -> c.setUuid("PROJECT_UUID").setKey(ROOT.getKey()).setName(ROOT.getName()).setDescription("OLD_DESC")).getProjectDto();
+ ProjectDto p1 = dbTester.components().insertPublicProject("PROJECT_UUID",
+ p -> p.setKey(ROOT.getKey()).setName(ROOT.getName()).setDescription("OLD_DESC")).getProjectDto();
assertProject("OLD_DESC", ROOT.getName(), p1.getUpdatedAt());
underTest.persist(dbTester.getSession());
@Test
public void update_name() {
- ProjectDto p1 = dbTester.components().insertPublicProject(
- c -> c.setUuid("PROJECT_UUID").setKey(ROOT.getKey()).setName("OLD_NAME").setDescription(ROOT.getDescription())).getProjectDto();
+ ProjectDto p1 = dbTester.components().insertPublicProject("PROJECT_UUID",
+ p -> p.setKey(ROOT.getKey()).setName("OLD_NAME").setDescription(ROOT.getDescription())).getProjectDto();
assertProject(ROOT.getDescription(), "OLD_NAME", p1.getUpdatedAt());
underTest.persist(dbTester.getSession());
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
private ReferenceBranchComponentUuids underTest;
private Branch branch = mock(Branch.class);
public AnalysisMetadataHolderRule metadataHolder = new AnalysisMetadataHolderRule();
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
private SiblingComponentsWithOpenIssues underTest;
@Rule
public MutableMovedFilesRepositoryRule movedFilesRepository = new MutableMovedFilesRepositoryRule();
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public LogTester logTester = new LogTester();
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.source.FileSourceDto;
import org.sonar.server.project.Project;
@Rule
public MutableMovedFilesRepositoryRule movedFilesRepository = new MutableMovedFilesRepositoryRule();
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public LogTester logTester = new LogTester();
private ComponentDto branch;
- private ComponentDto project;
+ private ComponentDto mainBranch;
+ private ProjectDto project;
private final DbClient dbClient = dbTester.getDbClient();
private final AnalysisMetadataHolderRule analysisMetadataHolder = mock(AnalysisMetadataHolderRule.class);
@Before
public void setUp() throws Exception {
- project = dbTester.components().insertPrivateProject().getMainBranchComponent();
- branch = dbTester.components().insertProjectBranch(project, branchDto -> branchDto.setUuid(BRANCH_UUID).setKey(TARGET_BRANCH));
- treeRootHolder.setRoot(builder(Component.Type.PROJECT, Integer.parseInt(ROOT_REF)).setUuid(project.uuid()).build());
+ ProjectData projectData = dbTester.components().insertPrivateProject();
+ mainBranch = projectData.getMainBranchComponent();
+ project = projectData.getProjectDto();
+ branch = dbTester.components().insertProjectBranch(mainBranch, branchDto -> branchDto.setUuid(BRANCH_UUID).setKey(TARGET_BRANCH));
+ treeRootHolder.setRoot(builder(Component.Type.PROJECT, Integer.parseInt(ROOT_REF)).setUuid(mainBranch.uuid()).build());
}
@Test
private void insertFileComponentsInReport(Set<Component> files) {
treeRootHolder
.setRoot(builder(PROJECT, Integer.parseInt(ROOT_REF))
- .setUuid(project.uuid())
+ .setUuid(mainBranch.uuid())
.addChildren(files.toArray(Component[]::new))
.build());
}
private ComponentDto composeComponentDto(String uuid) {
return ComponentTesting
- .newFileDto(project)
+ .newFileDto(mainBranch)
.setBranchUuid(branch.uuid())
.setKey("key_" + uuid)
.setUuid(uuid)
public class AdHocRuleCreatorIT {
@org.junit.Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
@org.junit.Rule
public EsTester es = EsTester.create();
private static final Date DATE_LIMIT_30_DAYS_BACK_MIDNIGHT = parseDateTime("2018-07-18T00:00:00+0000");
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
private final DbClient dbClient = db.getDbClient();
private final System2 system2 = mock(System2.class);
public static final String PROJECT_KEY = "PROJECT_KEY";
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
private final MapSettings settings = new MapSettings();
private final ConfigurationRepository settingsRepository = new TestSettingsRepository(settings.asConfig());
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule
@Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule().setAnalysisDate(ANALYSIS_DATE);
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public ActiveRulesHolderRule activeRulesHolderRule = new ActiveRulesHolderRule();
@Rule
public class ScmAccountToUserLoaderIT {
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
@Rule
public EsTester es = EsTester.create();
@Rule
private final Branch branch = mock(Branch.class);
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule()
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.protobuf.DbProjectBranches;
import org.sonar.server.project.Project;
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
private SourceBranchComponentUuids underTest;
private final Branch branch = mock(Branch.class);
analysisMetadataHolder.setProject(project);
analysisMetadataHolder.setBranch(branch);
- ComponentDto projectDto = db.components().insertPublicProject().getMainBranchComponent();
- when(project.getUuid()).thenReturn(projectDto.uuid());
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto projectDto = projectData.getMainBranchComponent();
+ when(project.getUuid()).thenReturn(projectData.projectUuid());
branch1 = db.components().insertProjectBranch(projectDto, b -> b.setKey(BRANCH_KEY));
ComponentDto pr1branch = db.components().insertProjectBranch(projectDto, b -> b.setKey(PR_KEY)
.setBranchType(BranchType.PULL_REQUEST)
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.protobuf.DbProjectBranches;
import org.sonar.server.project.Project;
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
private TargetBranchComponentUuids underTest;
private final Branch branch = mock(Branch.class);
analysisMetadataHolder.setProject(project);
analysisMetadataHolder.setBranch(branch);
- ComponentDto projectDto = db.components().insertPublicProject().getMainBranchComponent();
- when(project.getUuid()).thenReturn(projectDto.uuid());
- branch1 = db.components().insertProjectBranch(projectDto, b -> b.setKey(BRANCH_KEY));
- ComponentDto pr1branch = db.components().insertProjectBranch(projectDto, b -> b.setKey(PR_KEY)
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ when(project.getUuid()).thenReturn(projectData.projectUuid());
+ branch1 = db.components().insertProjectBranch(mainBranch, b -> b.setKey(BRANCH_KEY));
+ ComponentDto pr1branch = db.components().insertProjectBranch(mainBranch, b -> b.setKey(PR_KEY)
.setBranchType(BranchType.PULL_REQUEST)
.setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setTarget(BRANCH_KEY).build())
- .setMergeBranchUuid(projectDto.uuid()));
+ .setMergeBranchUuid(mainBranch.uuid()));
branch1File = ComponentTesting.newFileDto(branch1, null, "file").setUuid("branch1File");
pr1File = ComponentTesting.newFileDto(pr1branch, null, "file").setUuid("file1");
db.components().insertComponents(branch1File, pr1File);
private final static String COMPONENT_UUID = "uuid1";
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
private ComponentIssuesLoader componentIssuesLoader = mock(ComponentIssuesLoader.class);
private ReferenceBranchComponentUuids referenceBranchComponentUuids = mock(ReferenceBranchComponentUuids.class);
private final static String COMPONENT_UUID = "uuid1";
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
private final ComponentIssuesLoader componentIssuesLoader = mock(ComponentIssuesLoader.class);
private final SourceBranchComponentUuids sourceBranchComponentUuids = mock(SourceBranchComponentUuids.class);
private final static String ORIGINAL_COMPONENT_UUID = "uuid2";
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
private final ComponentIssuesLoader componentIssuesLoader = mock(ComponentIssuesLoader.class);
private final TargetBranchComponentUuids targetBranchComponentUuids = mock(TargetBranchComponentUuids.class);
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public BatchReportReaderRule reportReader = new BatchReportReaderRule();
private static final String SOME_UUID = "uuid";
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
private DbClient dbClient = dbTester.getDbClient();
private MetricRepositoryImpl underTest = new MetricRepositoryImpl(dbClient);
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.newcodeperiod.NewCodePeriodType;
import org.sonar.server.project.Project;
@Rule
public PeriodHolderRule periodHolder = new PeriodHolderRule();
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
private NewCodeReferenceBranchComponentUuids underTest = new NewCodeReferenceBranchComponentUuids(analysisMetadataHolder, periodHolder, db.getDbClient());
public void setUp() {
analysisMetadataHolder.setProject(project);
- ComponentDto projectDto = db.components().insertPublicProject().getMainBranchComponent();
- when(project.getUuid()).thenReturn(projectDto.uuid());
- branch1 = db.components().insertProjectBranch(projectDto, b -> b.setKey("branch1"));
- branch2 = db.components().insertProjectBranch(projectDto, b -> b.setKey("branch2"));
- pr1 = db.components().insertProjectBranch(projectDto, b -> b.setKey("pr1").setBranchType(BranchType.PULL_REQUEST).setMergeBranchUuid(branch1.uuid()));
- pr2 = db.components().insertProjectBranch(projectDto, b -> b.setKey("pr2").setBranchType(BranchType.PULL_REQUEST).setMergeBranchUuid(branch1.uuid()));
+ ProjectData projectData = db.components().insertPublicProject();
+ when(project.getUuid()).thenReturn(projectData.projectUuid());
+ branch1 = db.components().insertProjectBranch(projectData.getMainBranchComponent(), b -> b.setKey("branch1"));
+ branch2 = db.components().insertProjectBranch(projectData.getMainBranchComponent(), b -> b.setKey("branch2"));
+ pr1 = db.components().insertProjectBranch(projectData.getMainBranchComponent(), b -> b.setKey("pr1").setBranchType(BranchType.PULL_REQUEST).setMergeBranchUuid(branch1.uuid()));
+ pr2 = db.components().insertProjectBranch(projectData.getMainBranchComponent(), b -> b.setKey("pr2").setBranchType(BranchType.PULL_REQUEST).setMergeBranchUuid(branch1.uuid()));
branch1File = ComponentTesting.newFileDto(branch1, null, "file").setUuid("branch1File");
branch2File = ComponentTesting.newFileDto(branch2, null, "file").setUuid("branch2File");
pr1File = ComponentTesting.newFileDto(pr1, null, "file").setUuid("file1");
@Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public BatchReportReaderRule reportReader = new BatchReportReaderRule();
@Rule
public class DbLineHashVersionIT {
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
- private AnalysisMetadataHolder analysisMetadataHolder = mock(AnalysisMetadataHolder.class);
- private ReferenceBranchComponentUuids referenceBranchComponentUuids = mock(ReferenceBranchComponentUuids.class);
- private DbLineHashVersion underTest = new DbLineHashVersion(db.getDbClient(), analysisMetadataHolder, referenceBranchComponentUuids);
+ private final AnalysisMetadataHolder analysisMetadataHolder = mock(AnalysisMetadataHolder.class);
+ private final ReferenceBranchComponentUuids referenceBranchComponentUuids = mock(ReferenceBranchComponentUuids.class);
+ private final DbLineHashVersion underTest = new DbLineHashVersion(db.getDbClient(), analysisMetadataHolder, referenceBranchComponentUuids);
@Test
public void hasLineHashWithSignificantCode_should_return_true() {
private final System2 system2 = mock(System2.class);
@Rule
- public DbTester dbTester = DbTester.create(system2);
+ public DbTester dbTester = DbTester.create(system2, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
private static final long ANALYSIS_DATE = 123456789L;
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public BatchReportReaderRule reportReader = new BatchReportReaderRule().setMetadata(createReportMetadata(NO_SCANNER_PROJECT_VERSION, NO_SCANNER_BUILD_STRING));
@Rule
public class CleanIssueChangesStepIT {
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
private final IssueChangesToDeleteRepository repository = new IssueChangesToDeleteRepository();
private final CleanIssueChangesStep cleanIssueChangesStep = new CleanIssueChangesStep(repository, db.getDbClient());
private final TestComputationStepContext context = new TestComputationStepContext();
private static final String CURRENT_ANALYSIS_UUID = "ANALYSIS_2";
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
private MutableBatchReportDirectoryHolder reportDirectoryHolder = new BatchReportDirectoryHolderImpl();
private CeTask ceTask = new CeTask.Builder()
private CrossProjectDuplicationStatusHolder crossProjectDuplicationStatusHolder = mock(CrossProjectDuplicationStatusHolder.class);
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
private DbClient dbClient = dbTester.getDbClient();
private DbSession dbSession = dbTester.getSession();
public class LoadFileHashesAndStatusStepIT {
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
public PreviousSourceHashRepositoryImpl previousFileHashesRepository = new PreviousSourceHashRepositoryImpl();
@RunWith(DataProviderRunner.class)
public class LoadPeriodsStepIT extends BaseStepTest {
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.server.project.DefaultBranchNameResolver;
import org.sonar.server.project.Project;
private static final long ANALYSIS_DATE = 123456789L;
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public BatchReportReaderRule reportReader = new BatchReportReaderRule();
@Rule
private final DbClient dbClient = db.getDbClient();
private final TestPluginRepository pluginRepository = new TestPluginRepository();
- private ComponentDto project;
+ private ProjectDto project;
private ComputationStep underTest;
@Before
public void setUp() {
CeTask defaultOrgCeTask = createCeTask(PROJECT_KEY);
underTest = createStep(defaultOrgCeTask);
- project = db.components().insertPublicProject(p -> p.setKey(PROJECT_KEY)).getMainBranchComponent();
+ project = db.components().insertPublicProject(p -> p.setKey(PROJECT_KEY)).getProjectDto();
}
@Test
underTest.execute(new TestComputationStepContext());
Project project = analysisMetadataHolder.getProject();
- assertThat(project.getUuid()).isEqualTo(this.project.uuid());
+ assertThat(project.getUuid()).isEqualTo(this.project.getUuid());
assertThat(project.getKey()).isEqualTo(this.project.getKey());
- assertThat(project.getName()).isEqualTo(this.project.name());
- assertThat(project.getDescription()).isEqualTo(this.project.description());
+ assertThat(project.getName()).isEqualTo(this.project.getName());
+ assertThat(project.getDescription()).isEqualTo(this.project.getDescription());
}
@Test
CeTask res = mock(CeTask.class);
Optional<CeTask.Component> component = Optional.of(new CeTask.Component("main_prj_uuid", null, null));
when(res.getComponent()).thenReturn(component);
- when(res.getMainComponent()).thenReturn(component);
+ when(res.getEntity()).thenReturn(component);
reportReader.setMetadata(ScannerReport.Metadata.newBuilder().build());
ComputationStep underTest = createStep(res);
assertThatThrownBy(() -> underTest.execute(new TestComputationStepContext()))
.isInstanceOf(MessageException.class)
- .hasMessage("Compute Engine task main component key is null. Project with UUID main_prj_uuid must have been deleted since report was uploaded. Can not proceed.");
+ .hasMessage("Compute Engine task entity key is null. Project with UUID main_prj_uuid must have been deleted since report was uploaded. Can not proceed.");
}
@Test
CeTask res = mock(CeTask.class);
Optional<CeTask.Component> component = Optional.of(new CeTask.Component("prj_uuid", null, null));
when(res.getComponent()).thenReturn(component);
- when(res.getMainComponent()).thenReturn(Optional.of(new CeTask.Component("main_prj_uuid", "main_prj_key", null)));
+ when(res.getEntity()).thenReturn(Optional.of(new CeTask.Component("main_prj_uuid", "main_prj_key", null)));
reportReader.setMetadata(ScannerReport.Metadata.newBuilder().build());
ComputationStep underTest = createStep(res);
private CeTask createCeTask(String projectKey) {
CeTask res = mock(CeTask.class);
- Optional<CeTask.Component> component = Optional.of(new CeTask.Component(projectKey + "_uuid", projectKey, projectKey + "_name"));
+ Optional<CeTask.Component> entity = Optional.of(new CeTask.Component(projectKey + "_uuid", projectKey, projectKey + "_name"));
+ Optional<CeTask.Component> component = Optional.of(new CeTask.Component(projectKey + "branch_uuid", projectKey, projectKey + "_name"));
when(res.getComponent()).thenReturn(component);
- when(res.getMainComponent()).thenReturn(component);
+ when(res.getEntity()).thenReturn(entity);
return res;
}
public class PersistAdHocRulesStepIT extends BaseStepTest {
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
private DbClient dbClient = db.getDbClient();
private static final String SCM_REV_ID = "sha1";
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
private BatchReportReader batchReportReader = mock(BatchReportReader.class);
private AnalysisMetadataHolder analysisMetadataHolder = mock(AnalysisMetadataHolder.class);
private static final String BASE_ANALYSIS_UUID = "base analysis uuid";
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public BatchReportReaderRule reportReader = new BatchReportReaderRule();
@Rule
private static final String FILE_2_UUID = "u3";
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule()
.setRoot(
System2 system2 = mock(System2.class);
@Rule
- public DbTester dbTester = DbTester.create(system2);
+ public DbTester dbTester = DbTester.create(system2, true);
@Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
@Rule
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public BatchReportReaderRule reportReader = new BatchReportReaderRule();
@Rule
private static final int REF_4 = 4;
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule
private static final int REF_4 = 4;
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule
@Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule
private final TestSystem2 system2 = new TestSystem2().setNow(1L);
@Rule
- public DbTester db = DbTester.create(system2);
+ public DbTester db = DbTester.create(system2, true);
public final PushEventFactory pushEventFactory = mock(PushEventFactory.class);
@Rule
@Test
public void store_push_events_for_branch() {
- var project = db.components().insertPrivateProject().getMainBranchComponent();
+ var project = db.components().insertPrivateProject().getProjectDto();
db.components().insertProjectBranch(project, b -> b.setUuid("uuid_1"));
protoIssueCache.newAppender()
.setComponentKey("ck2"))
.close();
- when(pushEventFactory.raiseEventOnIssue(eq(project.uuid()), any(DefaultIssue.class))).thenReturn(
+ when(pushEventFactory.raiseEventOnIssue(eq(project.getUuid()), any(DefaultIssue.class))).thenReturn(
Optional.of(createPushEvent()),
Optional.of(createPushEvent()));
@Rule
public BatchReportReaderRule reader = new BatchReportReaderRule();
@Rule
- public DbTester dbTester = DbTester.create();
+ public DbTester dbTester = DbTester.create(true);
private final DbClient client = dbTester.getDbClient();
private final TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
private final PersistScannerAnalysisCacheStep step = new PersistScannerAnalysisCacheStep(reader, dbTester.getDbClient(), treeRootHolder);
private static final String ANALYSIS_UUID = "UUID";
@ClassRule
- public static final DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public static final DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public BatchReportReaderRule reportReader = new BatchReportReaderRule();
import org.sonar.ce.task.step.TestComputationStepContext;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.metric.MetricDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.server.project.Project;
import static java.util.Collections.emptyList;
public class ProjectNclocComputationStepIT {
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
private final DbClient dbClient = db.getDbClient();
@Rule
@Test
public void test_computing_branch_ncloc() {
MetricDto ncloc = db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.toString()));
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- ComponentDto branch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
+ BranchDto branch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
db.measures().insertLiveMeasure(branch1, ncloc, m -> m.setValue(200d));
- ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
+ BranchDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
db.measures().insertLiveMeasure(branch2, ncloc, m -> m.setValue(10d));
- analysisMetadataHolder.setProject(new Project(project.uuid(), project.getKey(), project.name(), project.description(), emptyList()));
+ analysisMetadataHolder.setProject(new Project(project.getUuid(), project.getKey(), project.getName(), project.getDescription(), emptyList()));
step.execute(TestComputationStepContext.TestStatistics::new);
assertThat(dbClient.projectDao().getNclocSum(db.getSession())).isEqualTo(200L);
private static final String REVISION_ID = "5f6432a1";
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule
private static final String PROJECT_KEY = "PROJECT_KEY";
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
private final Random random = new Random();
private final RuleType[] RULE_TYPES_EXCEPT_HOTSPOTS = Stream.of(RuleType.values()).filter(r -> r != SECURITY_HOTSPOT).toArray(RuleType[]::new);
private static final Component PROJECT = ReportComponent.DUMB_PROJECT;
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule().setRoot(PROJECT);
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule().setAnalysisDate(ANALYSIS_DATE);
static final Branch DEFAULT_BRANCH = new DefaultBranchImpl(DEFAULT_MAIN_BRANCH_NAME);
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule
private static final String ANALYSIS_UUID = "U1";
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule
private static final String PROJECT_VIEW_1_UUID = "PV1_UUID";
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
.setValue(MONTHLY.name());
@Rule
- public final DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public final DbTester dbTester = DbTester.create(System2.INSTANCE, true);
private final DbClient dbClient = dbTester.getDbClient();
private final System2 system2 = new System2();
@Rule
- public final DbTester db = DbTester.create(system2);
+ public final DbTester db = DbTester.create(system2, true);
private final AuditHousekeepingFrequencyHelper auditHousekeepingFrequencyHelper = mock(AuditHousekeepingFrequencyHelper.class);
import static org.sonar.db.component.BranchType.BRANCH;
public class IgnoreOrphanBranchStepIT {
-
- private String BRANCH_UUID = "branch_uuid";
+ private final String ENTITY_UUID = "entity_uuid";
+ private final String BRANCH_UUID = "branch_uuid";
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
- private CeTask.Component component = new CeTask.Component(BRANCH_UUID, "component key", "component name");
- private CeTask ceTask = new CeTask.Builder()
+ private final CeTask.Component entity = new CeTask.Component(ENTITY_UUID, "component key", "component name");
+ private final CeTask.Component component = new CeTask.Component(BRANCH_UUID, "component key", "component name");
+ private final CeTask ceTask = new CeTask.Builder()
.setType("type")
.setUuid("uuid")
.setComponent(component)
- .setMainComponent(component)
+ .setEntity(entity)
.build();
- private DbClient dbClient = dbTester.getDbClient();
- private IgnoreOrphanBranchStep underTest = new IgnoreOrphanBranchStep(ceTask, dbClient);
+ private final DbClient dbClient = dbTester.getDbClient();
+ private final IgnoreOrphanBranchStep underTest = new IgnoreOrphanBranchStep(ceTask, dbClient);
@Test
public void execute() {
.setType("type")
.setUuid("uuid")
.setComponent(null)
- .setMainComponent(null)
+ .setEntity(null)
.build();
IgnoreOrphanBranchStep underTest = new IgnoreOrphanBranchStep(ceTask, dbClient);
assertThatThrownBy(() -> underTest.execute(() -> null))
.isInstanceOf(UnsupportedOperationException.class)
- .hasMessage("main component not found in task");
+ .hasMessage("entity not found in task");
}
@Test
import static org.sonar.db.component.BranchType.BRANCH;
public class IndexIssuesStepIT {
-
- private String BRANCH_UUID = "branch_uuid";
-
+ private final String ENTITY_UUID = "entity_uuid";
+ private final String BRANCH_UUID = "branch_uuid";
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
-
- private DbClient dbClient = dbTester.getDbClient();
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
- private CeTask.Component component = new CeTask.Component(BRANCH_UUID, "component key", "component name");
- private CeTask ceTask = new CeTask.Builder()
+ private final DbClient dbClient = dbTester.getDbClient();
+ private final CeTask.Component entity = new CeTask.Component(ENTITY_UUID, "component key", "component name");
+ private final CeTask.Component component = new CeTask.Component(BRANCH_UUID, "component key", "component name");
+ private final CeTask ceTask = new CeTask.Builder()
.setType("type")
.setUuid("uuid")
.setComponent(component)
- .setMainComponent(component)
+ .setEntity(entity)
.build();
@Rule
public EsTester es = EsTester.create();
- private System2 system2 = new System2();
- @Rule
- public DbTester db = DbTester.create(system2);
-
- private IssueIndexer issueIndexer = mock(IssueIndexer.class);
- private IndexIssuesStep underTest = new IndexIssuesStep(ceTask, dbClient, issueIndexer);
+ private final IssueIndexer issueIndexer = mock(IssueIndexer.class);
+ private final IndexIssuesStep underTest = new IndexIssuesStep(ceTask, dbClient, issueIndexer);
@Test
public void execute() {
.setType("type")
.setUuid("uuid")
.setComponent(null)
- .setMainComponent(null)
+ .setEntity(null)
.build();
IndexIssuesStep underTest = new IndexIssuesStep(ceTask, dbClient, issueIndexer);
.setBranchUuid(PROJECT_UUID);
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public LogTester logTester = new LogTester();
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.project.ProjectExportMapper;
import static java.util.stream.Collectors.toMap;
public class ExportBranchesStepIT {
private static final String PROJECT_UUID = "PROJECT_UUID";
- private static final ComponentDto PROJECT = new ComponentDto()
- // no id yet
- .setScope(Scopes.PROJECT)
- .setQualifier(Qualifiers.PROJECT)
- .setKey("the_project")
- .setName("The Project")
- .setDescription("The project description")
- .setEnabled(true)
- .setUuid(PROJECT_UUID)
- .setUuidPath(UUID_PATH_OF_ROOT)
- .setBranchUuid(PROJECT_UUID);
@Rule
- public DbTester dbTester = DbTester.createWithExtensionMappers(System2.INSTANCE, ProjectExportMapper.class);
+ public DbTester dbTester = DbTester.createWithExtensionMappers(System2.INSTANCE, true, ProjectExportMapper.class);
@Rule
public LogTester logTester = new LogTester();
public void setUp() {
logTester.setLevel(Level.DEBUG);
Date createdAt = new Date();
- ComponentDto projectDto = dbTester.components().insertPublicProject(PROJECT).getMainBranchComponent().setCreatedAt(createdAt);
+ ProjectData projectData = dbTester.components().insertPublicProject(PROJECT_UUID);
for (BranchDto branch : branches) {
createdAt = DateUtils.addMinutes(createdAt, 10);
- dbTester.components().insertProjectBranch(PROJECT, branch).setCreatedAt(createdAt);
+ dbTester.components().insertProjectBranch(projectData.getProjectDto(), branch).setCreatedAt(createdAt);
}
dbTester.commit();
- when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDtoByMainBranch(projectDto));
+ when(projectHolder.projectDto()).thenReturn(projectData.getProjectDto());
}
@Test
.stream()
.collect(toMap(ProjectDump.Branch::getUuid, Function.identity()));
assertThat(branches).hasSize(3);
- ProjectDump.Branch mainBranch = branches.get(PROJECT_UUID);
+ ProjectDump.Branch mainBranch = branches.values().stream().filter(ProjectDump.Branch::getIsMain).findFirst().get();
assertThat(mainBranch).isNotNull();
assertThat(mainBranch.getKee()).isEqualTo(BranchDto.DEFAULT_MAIN_BRANCH_NAME);
assertThat(mainBranch.getProjectUuid()).isEqualTo(PROJECT_UUID);
.setBranchUuid(PROJECT_UUID);
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public LogTester logTester = new LogTester();
private static final String FILE_UUID_2 = "file-2-uuid";
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public LogTester logTester = new LogTester();
- private DbClient dbClient = dbTester.getDbClient();
- private DbSession dbSession = dbClient.openSession(false);
- private FakeDumpWriter dumpWriter = new FakeDumpWriter();
- private MutableComponentRepository componentRepository = new ComponentRepositoryImpl();
-
- private ExportLineHashesStep underTest = new ExportLineHashesStep(dbClient, dumpWriter, componentRepository);
+ private final DbClient dbClient = dbTester.getDbClient();
+ private final DbSession dbSession = dbClient.openSession(false);
+ private final FakeDumpWriter dumpWriter = new FakeDumpWriter();
+ private final MutableComponentRepository componentRepository = new ComponentRepositoryImpl();
+ private final ExportLineHashesStep underTest = new ExportLineHashesStep(dbClient, dumpWriter, componentRepository);
@Before
public void before() {
import org.sonar.db.DbTester;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.BranchType;
-import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.issue.IssueChangeDto;
import org.sonar.db.issue.IssueDto;
+import org.sonar.db.project.ProjectDto;
-import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
private static final String ISSUE_CLOSED_UUID = "issue closed uuid";
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public LogTester logTester = new LogTester();
private final FakeDumpWriter dumpWriter = new FakeDumpWriter();
private final ExportIssuesChangelogStep underTest = new ExportIssuesChangelogStep(dbClient, projectHolder, dumpWriter);
+ private BranchDto mainBranch;
private int issueChangeUuidGenerator = 0;
@Before
public void setUp() {
logTester.setLevel(Level.DEBUG);
- ComponentDto projectDto = dbTester.components().insertPublicProject(p -> p.setUuid(PROJECT_UUID)).getMainBranchComponent();
- when(projectHolder.projectDto()).thenReturn(dbTester.components().getProjectDtoByMainBranch(projectDto));
- when(projectHolder.branches()).thenReturn(newArrayList(
- new BranchDto().setBranchType(BranchType.BRANCH).setKey("master").setProjectUuid(PROJECT_UUID).setUuid(PROJECT_UUID)));
-
- insertIssue(PROJECT_UUID, ISSUE_OPEN_UUID, STATUS_OPEN);
- insertIssue(PROJECT_UUID, ISSUE_CONFIRMED_UUID, STATUS_CONFIRMED);
- insertIssue(PROJECT_UUID, ISSUE_REOPENED_UUID, STATUS_REOPENED);
- insertIssue(PROJECT_UUID, ISSUE_RESOLVED_UUID, STATUS_RESOLVED);
- insertIssue(PROJECT_UUID, ISSUE_CLOSED_UUID, STATUS_CLOSED);
+ ProjectData projectData = dbTester.components().insertPublicProject(PROJECT_UUID);
+ mainBranch = projectData.getMainBranchDto();
+ when(projectHolder.projectDto()).thenReturn(projectData.getProjectDto());
+ when(projectHolder.branches()).thenReturn(List.of(mainBranch));
+
+ insertIssue(mainBranch.getUuid(), ISSUE_OPEN_UUID, STATUS_OPEN);
+ insertIssue(mainBranch.getUuid(), ISSUE_CONFIRMED_UUID, STATUS_CONFIRMED);
+ insertIssue(mainBranch.getUuid(), ISSUE_REOPENED_UUID, STATUS_REOPENED);
+ insertIssue(mainBranch.getUuid(), ISSUE_RESOLVED_UUID, STATUS_RESOLVED);
+ insertIssue(mainBranch.getUuid(), ISSUE_CLOSED_UUID, STATUS_CLOSED);
}
@After
.setChangeType("change type")
.setUserUuid("user_uuid")
.setIssueChangeCreationDate(454135L)
- .setProjectUuid(PROJECT_UUID);
+ .setProjectUuid(mainBranch.getUuid());
insertIssueChange(issueChangeDto);
underTest.execute(new TestComputationStepContext());
@Test
public void execute_sets_createAt_to_zero_if_both_createdAt_and_issueChangeDate_are_null() {
- insertIssueChange(new IssueChangeDto().setUuid(Uuids.createFast()).setIssueKey(ISSUE_REOPENED_UUID).setProjectUuid(PROJECT_UUID));
+ insertIssueChange(new IssueChangeDto().setUuid(Uuids.createFast()).setIssueKey(ISSUE_REOPENED_UUID).setProjectUuid(mainBranch.getUuid()));
underTest.execute(new TestComputationStepContext());
return dto;
}
- private void insertIssue(String projectUuid, String uuid, String status) {
+ private void insertIssue(String branchUuid, String uuid, String status) {
IssueDto dto = new IssueDto()
.setKee(uuid)
- .setProjectUuid(projectUuid)
+ .setProjectUuid(branchUuid)
.setStatus(status);
dbClient.issueDao().insert(dbSession, dto);
dbSession.commit();
public static final DbIssues.MessageFormatting MESSAGE_FORMATTING = DbIssues.MessageFormatting.newBuilder().setStart(0).setEnd(4).setType(MessageFormattingType.CODE).build();
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public LogTester logTester = new LogTester();
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.rule.RuleDto;
public class ExportAdHocRulesStepIT {
private static final String PROJECT_UUID = "some-uuid";
-
- private static final ComponentDto PROJECT = new ComponentDto()
- // no id yet
- .setScope(Scopes.PROJECT)
- .setQualifier(Qualifiers.PROJECT)
- .setKey("the_project")
- .setName("The Project")
- .setDescription("The project description")
- .setEnabled(true)
- .setUuid(PROJECT_UUID)
- .setUuidPath(UUID_PATH_OF_ROOT)
- .setBranchUuid(PROJECT_UUID);
-
private static final List<BranchDto> BRANCHES = ImmutableList.of(
new BranchDto().setBranchType(BranchType.PULL_REQUEST).setProjectUuid(PROJECT_UUID).setKey("pr-1").setUuid("pr-1-uuid").setMergeBranchUuid("master").setIsMain(false),
new BranchDto().setBranchType(BranchType.BRANCH).setProjectUuid(PROJECT_UUID).setKey("branch-2").setUuid("branch-2-uuid").setMergeBranchUuid("master")
@Rule
public LogTester logTester = new LogTester();
-
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
private int issueUuidGenerator = 1;
- private FakeDumpWriter dumpWriter = new FakeDumpWriter();
- private ProjectHolder projectHolder = mock(ProjectHolder.class);
- private ExportAdHocRulesStep underTest = new ExportAdHocRulesStep(dbTester.getDbClient(), projectHolder, dumpWriter);
+ private ComponentDto mainBranch;
+ private final FakeDumpWriter dumpWriter = new FakeDumpWriter();
+ private final ProjectHolder projectHolder = mock(ProjectHolder.class);
+ private final ExportAdHocRulesStep underTest = new ExportAdHocRulesStep(dbTester.getDbClient(), projectHolder, dumpWriter);
@Before
public void setup() {
RuleDto rule2 = insertAddHocRule( "rule-2");
insertAddHocRule( "rule-3");
insertIssue(rule1, differentProject, differentProject);
- insertIssue(rule2, PROJECT_UUID, PROJECT_UUID);
+ insertIssue(rule2, mainBranch.uuid(), mainBranch.uuid());
underTest.execute(new TestComputationStepContext());
RuleDto rule1 = insertStandardRule("rule-1");
RuleDto rule2 = insertExternalRule("rule-2");
RuleDto rule3 = insertAddHocRule("rule-3");
- insertIssue(rule1, PROJECT_UUID, PROJECT_UUID);
- insertIssue(rule2, PROJECT_UUID, PROJECT_UUID);
- insertIssue(rule3, PROJECT_UUID, PROJECT_UUID);
+ insertIssue(rule1, mainBranch.uuid(), mainBranch.uuid());
+ insertIssue(rule2, mainBranch.uuid(), mainBranch.uuid());
+ insertIssue(rule3, mainBranch.uuid(), mainBranch.uuid());
underTest.execute(new TestComputationStepContext());
RuleDto rule1 = insertAddHocRule("rule-1");
RuleDto rule2 = insertAddHocRule("rule-2");
RuleDto rule3 = insertAddHocRule("rule-3");
- insertIssue(rule1, PROJECT_UUID, PROJECT_UUID);
- insertIssue(rule2, PROJECT_UUID, PROJECT_UUID);
- insertIssue(rule3, PROJECT_UUID, PROJECT_UUID);
+ insertIssue(rule1, mainBranch.uuid(), mainBranch.uuid());
+ insertIssue(rule2, mainBranch.uuid(), mainBranch.uuid());
+ insertIssue(rule3, mainBranch.uuid(), mainBranch.uuid());
dumpWriter.failIfMoreThan(2, DumpElement.AD_HOC_RULES);
assertThatThrownBy(() -> underTest.execute(new TestComputationStepContext()))
private ProjectDto createProject() {
Date createdAt = new Date();
- ComponentDto projectDto = dbTester.components().insertPublicProject(PROJECT).getMainBranchComponent();
- BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(projectDto, branch).setCreatedAt(createdAt));
+ ProjectData projectData = dbTester.components().insertPublicProject(PROJECT_UUID);
+ mainBranch = projectData.getMainBranchComponent();
+ BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(projectData.getProjectDto(), branch).setCreatedAt(createdAt));
dbTester.commit();
- return dbTester.components().getProjectDtoByMainBranch(projectDto);
+ return projectData.getProjectDto();
}
- private void insertIssue(RuleDto ruleDto, String projectUuid, String componentUuid) {
- IssueDto dto = createBaseIssueDto(ruleDto, projectUuid, componentUuid);
+ private void insertIssue(RuleDto ruleDto, String branchUuid, String componentUuid) {
+ IssueDto dto = createBaseIssueDto(ruleDto, branchUuid, componentUuid);
insertIssue(dto);
}
dbTester.commit();
}
- private IssueDto createBaseIssueDto(RuleDto ruleDto, String projectUuid, String componentUuid) {
+ private IssueDto createBaseIssueDto(RuleDto ruleDto, String branchUuid, String componentUuid) {
return new IssueDto()
.setKee("issue_uuid_" + issueUuidGenerator++)
.setComponentUuid(componentUuid)
- .setProjectUuid(projectUuid)
+ .setProjectUuid(branchUuid)
.setRuleUuid(ruleDto.getUuid())
.setStatus("OPEN");
}
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public LogTester logTester = new LogTester();
.setBranchUuid(PROJECT_UUID);
@Rule
- public DbTester db = DbTester.createWithExtensionMappers(System2.INSTANCE, ProjectExportMapper.class);
+ public DbTester db = DbTester.createWithExtensionMappers(System2.INSTANCE, true, ProjectExportMapper.class);
@Rule
@Rule
public LogTester logTester = new LogTester();
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
- private ComponentRepositoryImpl componentRepository = new ComponentRepositoryImpl();
- private MutableMetricRepository metricRepository = new MutableMetricRepositoryImpl();
- private ProjectHolder projectHolder = mock(ProjectHolder.class);
- private FakeDumpWriter dumpWriter = new FakeDumpWriter();
- private ExportLiveMeasuresStep underTest = new ExportLiveMeasuresStep(dbTester.getDbClient(), projectHolder, componentRepository, metricRepository, dumpWriter);
+ private final ComponentRepositoryImpl componentRepository = new ComponentRepositoryImpl();
+ private final MutableMetricRepository metricRepository = new MutableMetricRepositoryImpl();
+ private final ProjectHolder projectHolder = mock(ProjectHolder.class);
+ private final FakeDumpWriter dumpWriter = new FakeDumpWriter();
+ private final ExportLiveMeasuresStep underTest = new ExportLiveMeasuresStep(dbTester.getDbClient(), projectHolder, componentRepository, metricRepository, dumpWriter);
@Before
public void before() {
public LogTester logTester = new LogTester();
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
private ComponentRepositoryImpl componentRepository = new ComponentRepositoryImpl();
private MutableMetricRepository metricRepository = new MutableMetricRepositoryImpl();
public LogTester logTester = new LogTester();
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
MutableMetricRepository metricsHolder = new MutableMetricRepositoryImpl();
FakeDumpWriter dumpWriter = new FakeDumpWriter();
import org.sonar.db.component.ComponentDto;
import org.sonar.db.newcodeperiod.NewCodePeriodDto;
import org.sonar.db.newcodeperiod.NewCodePeriodType;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.project.ProjectExportMapper;
import static org.assertj.core.api.Assertions.assertThat;
private static final String PROJECT_UUID = "project_uuid";
private static final String ANOTHER_PROJECT_UUID = "another_project_uuid";
- private static final ComponentDto PROJECT = new ComponentDto()
- .setUuid(PROJECT_UUID)
- .setUuidPath(UUID_PATH_OF_ROOT)
- .setBranchUuid(PROJECT_UUID)
- .setQualifier(Qualifiers.PROJECT)
- .setName("project")
- .setKey("the_project");
private static final ComponentDto ANOTHER_PROJECT = new ComponentDto()
.setUuid(ANOTHER_PROJECT_UUID)
.setUuidPath(UUID_PATH_OF_ROOT)
new BranchDto().setBranchType(BranchType.BRANCH).setProjectUuid(ANOTHER_PROJECT_UUID).setKey("branch-3").setUuid("branch-uuid-3").setMergeBranchUuid("master")
.setExcludeFromPurge(true).setIsMain(false));
+ private ProjectDto project;
+
@Rule
public LogTester logTester = new LogTester();
@Rule
- public DbTester dbTester = DbTester.createWithExtensionMappers(System2.INSTANCE, ProjectExportMapper.class);
+ public DbTester dbTester = DbTester.createWithExtensionMappers(System2.INSTANCE, true, ProjectExportMapper.class);
private MutableProjectHolder projectHolder = new MutableProjectHolderImpl();
private FakeDumpWriter dumpWriter = new FakeDumpWriter();
public void setUp() {
logTester.setLevel(Level.DEBUG);
Date createdAt = new Date();
- ComponentDto projectDto = dbTester.components().insertPublicProject(PROJECT).getMainBranchComponent();
- PROJECT_BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(projectDto, branch).setCreatedAt(createdAt));
+ project = dbTester.components().insertPrivateProject(PROJECT_UUID).getProjectDto();
+ PROJECT_BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(project, branch).setCreatedAt(createdAt));
ComponentDto anotherProjectDto = dbTester.components().insertPublicProject(ANOTHER_PROJECT).getMainBranchComponent();
ANOTHER_PROJECT_BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(anotherProjectDto, branch).setCreatedAt(createdAt));
dbTester.commit();
- projectHolder.setProjectDto(dbTester.components().getProjectDtoByMainBranch(PROJECT));
+ projectHolder.setProjectDto(project);
}
@Test
@Test
public void export_only_project_new_code_periods_on_branches_excluded_from_purge() {
- NewCodePeriodDto newCodePeriod1 = newDto("uuid1", PROJECT.uuid(), null, SPECIFIC_ANALYSIS, "analysis-uuid");
- NewCodePeriodDto newCodePeriod2 = newDto("uuid2", PROJECT.uuid(), "branch-uuid-1", SPECIFIC_ANALYSIS, "analysis-uuid");
+ NewCodePeriodDto newCodePeriod1 = newDto("uuid1", project.getUuid(), null, SPECIFIC_ANALYSIS, "analysis-uuid");
+ NewCodePeriodDto newCodePeriod2 = newDto("uuid2", project.getUuid(), "branch-uuid-1", SPECIFIC_ANALYSIS, "analysis-uuid");
// the following new code periods are not exported
- NewCodePeriodDto newCodePeriod3 = newDto("uuid3", PROJECT.uuid(), "branch-uuid-2", SPECIFIC_ANALYSIS, "analysis-uuid");
+ NewCodePeriodDto newCodePeriod3 = newDto("uuid3", project.getUuid(), "branch-uuid-2", SPECIFIC_ANALYSIS, "analysis-uuid");
NewCodePeriodDto anotherProjectNewCodePeriods = newDto("uuid4", ANOTHER_PROJECT.uuid(), "branch-uuid-3", SPECIFIC_ANALYSIS, "analysis-uuid");
NewCodePeriodDto globalNewCodePeriod = newDto("uuid5", null, null, PREVIOUS_VERSION, null);
insertNewCodePeriods(newCodePeriod1, newCodePeriod2, newCodePeriod3, anotherProjectNewCodePeriods, globalNewCodePeriod);
@Test
public void test_exported_fields() {
- NewCodePeriodDto dto = newDto("uuid1", PROJECT.uuid(), "branch-uuid-1", SPECIFIC_ANALYSIS, "analysis-uuid");
+ NewCodePeriodDto dto = newDto("uuid1", project.getUuid(), "branch-uuid-1", SPECIFIC_ANALYSIS, "analysis-uuid");
insertNewCodePeriods(dto);
underTest.execute(new TestComputationStepContext());
public void throws_ISE_if_error() {
dumpWriter.failIfMoreThan(1, DumpElement.NEW_CODE_PERIODS);
insertNewCodePeriods(
- newDto("uuid1", PROJECT.uuid(), null, SPECIFIC_ANALYSIS, "analysis-uuid"),
- newDto("uuid2", PROJECT.uuid(), "branch-uuid-1", SPECIFIC_ANALYSIS, "analysis-uuid"));
+ newDto("uuid1", project.getUuid(), null, SPECIFIC_ANALYSIS, "analysis-uuid"),
+ newDto("uuid2", project.getUuid(), "branch-uuid-1", SPECIFIC_ANALYSIS, "analysis-uuid"));
assertThatThrownBy(() -> underTest.execute(new TestComputationStepContext()))
.isInstanceOf(IllegalStateException.class)
@Rule
public LogTester logTester = new LogTester();
@Rule
- public DbTester dbTester = DbTester.createWithExtensionMappers(System2.INSTANCE, ProjectExportMapper.class);
- private MutableComponentRepository componentRepository = new ComponentRepositoryImpl();
- private MutableProjectHolder projectHolder = new MutableProjectHolderImpl();
- private FakeDumpWriter dumpWriter = new FakeDumpWriter();
- private ExportSettingsStep underTest = new ExportSettingsStep(dbTester.getDbClient(), projectHolder, componentRepository, dumpWriter);
+ public DbTester dbTester = DbTester.createWithExtensionMappers(System2.INSTANCE, true, ProjectExportMapper.class);
+ private final MutableComponentRepository componentRepository = new ComponentRepositoryImpl();
+ private final MutableProjectHolder projectHolder = new MutableProjectHolderImpl();
+ private final FakeDumpWriter dumpWriter = new FakeDumpWriter();
+ private final ExportSettingsStep underTest = new ExportSettingsStep(dbTester.getDbClient(), projectHolder, componentRepository, dumpWriter);
@Before
public void setUp() {
private static final String PROJECT_KEY = "project_key";
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
private final ProjectDescriptor descriptor = new ProjectDescriptor("project_uuid", PROJECT_KEY, "Project Name");
private final MutableProjectHolder definitionHolder = new MutableProjectHolderImpl();
}
private static Project createProject(org.sonar.ce.task.CeTask ceTask) {
- return ceTask.getMainComponent()
+ return ceTask.getEntity()
.map(c -> new ProjectImpl(
c.getUuid(),
c.getKey().orElseThrow(() -> new IllegalStateException("Missing project key")),
private class FileSourceVisitor extends TypeAwareVisitorAdapter {
private final DbSession session;
- private String projectUuid;
+ private String branchUuid;
private FileSourceVisitor(DbSession session) {
super(CrawlerDepthLimit.FILE, PRE_ORDER);
}
@Override
- public void visitProject(Component project) {
- this.projectUuid = project.getUuid();
+ public void visitProject(Component branch) {
+ this.branchUuid = branch.getUuid();
}
@Override
if (previousDto == null) {
FileSourceDto dto = new FileSourceDto()
.setUuid(uuidFactory.create())
- .setProjectUuid(projectUuid)
+ .setProjectUuid(branchUuid)
.setFileUuid(file.getUuid())
.setBinaryData(binaryData)
.setSrcHash(srcHash)
* @return a {@link Runnable} to execute some checks on the project at the end of the step
*/
private Runnable loadProject(ScannerReport.Metadata reportMetadata) {
- CeTask.Component mainComponent = mandatoryComponent(ceTask.getMainComponent());
- String mainComponentKey = mainComponent.getKey()
+ CeTask.Component entity = mandatoryComponent(ceTask.getEntity());
+ String entityKey = entity.getKey()
.orElseThrow(() -> MessageException.of(format(
- "Compute Engine task main component key is null. Project with UUID %s must have been deleted since report was uploaded. Can not proceed.",
- mainComponent.getUuid())));
+ "Compute Engine task entity key is null. Project with UUID %s must have been deleted since report was uploaded. Can not proceed.",
+ entity.getUuid())));
CeTask.Component component = mandatoryComponent(ceTask.getComponent());
if (!component.getKey().isPresent()) {
throw MessageException.of(format(
ProjectDto dto = toProject(reportMetadata.getProjectKey());
analysisMetadata.setProject(Project.fromProjectDtoWithTags(dto));
return () -> {
- if (!mainComponentKey.equals(reportMetadata.getProjectKey())) {
+ if (!entityKey.equals(reportMetadata.getProjectKey())) {
throw MessageException.of(format(
"ProjectKey in report (%s) is not consistent with projectKey under which the report has been submitted (%s)",
reportMetadata.getProjectKey(),
- mainComponentKey));
+ entityKey));
}
};
}
- private static CeTask.Component mandatoryComponent(Optional<CeTask.Component> mainComponent) {
- return mainComponent
- .orElseThrow(() -> new IllegalStateException("component missing on ce task"));
+ private static CeTask.Component mandatoryComponent(Optional<CeTask.Component> entity) {
+ return entity.orElseThrow(() -> new IllegalStateException("component missing on ce task"));
}
private void loadQualityProfiles(ScannerReport.Metadata reportMetadata) {
@Override
public void execute(Context context) {
- String mainComponentUuid = ceTask.getMainComponent().orElseThrow(() -> new UnsupportedOperationException("main component not found in task")).getUuid();
+ String entityUuid = ceTask.getEntity().orElseThrow(() -> new UnsupportedOperationException("entity not found in task")).getUuid();
String componentUuid = ceTask.getComponent().orElseThrow(() -> new UnsupportedOperationException("component not found in task")).getUuid();
try (DbSession dbSession = dbClient.openSession(false)) {
- Optional<ComponentDto> componentDto = dbClient.componentDao().selectByUuid(dbSession, mainComponentUuid);
+ Optional<ComponentDto> componentDto = dbClient.componentDao().selectByUuid(dbSession, entityUuid);
if(!componentDto.isPresent()){
LOG.info("reindexation task has been trigger on an orphan branch. removing any exclude_from_purge flag, and skip the indexation");
dbClient.branchDao().updateExcludeFromPurge(dbSession, componentUuid, false);
private static final String STATUS_CLOSED = "CLOSED";
private static final String QUERY = "select" +
" ic.kee, ic.issue_key, ic.change_type, ic.change_data, ic.user_login," +
- " ic.issue_change_creation_date, ic.created_at, p.uuid" +
+ " ic.issue_change_creation_date, ic.created_at, pb.uuid" +
" from issue_changes ic" +
" join issues i on i.kee = ic.issue_key" +
- " join projects p on p.uuid = i.project_uuid" +
- " join project_branches pb on pb.uuid = p.uuid" +
+ " join project_branches pb on pb.uuid = i.project_uuid" +
" where pb.project_uuid = ? and pb.branch_type = 'BRANCH' and pb.exclude_from_purge = ? " +
" and i.status <> ?" +
" order by ic.created_at asc";
}
private static void failIfNotMain(CeTask.Component exportComponent, CeTask task) {
- task.getMainComponent().filter(mainComponent -> mainComponent.equals(exportComponent))
- .orElseThrow(() -> new IllegalStateException("Component of task must be the same as main component"));
+ task.getEntity().filter(entity -> entity.equals(exportComponent))
+ .orElseThrow(() -> new IllegalStateException("Component of task must be the same as entity"));
}
private static CeTask.Component mandatoryComponent(CeTask task, String type) {
private final ArgumentCaptor<PostProjectAnalysisTask.Context> taskContextCaptor = ArgumentCaptor.forClass(PostProjectAnalysisTask.Context.class);
private final CeTask.Component component = new CeTask.Component("component uuid", "component key", "component name");
+ private final CeTask.Component entity = new CeTask.Component("entity uuid", "component key", "component name");
private final CeTask ceTask = new CeTask.Builder()
.setType("type")
.setUuid("uuid")
.setComponent(component)
- .setMainComponent(component)
+ .setEntity(entity)
.build();
private final PostProjectAnalysisTask postProjectAnalysisTask = newPostProjectAnalysisTask("PT1");
private final PostProjectAnalysisTasksExecutor underTest = new PostProjectAnalysisTasksExecutor(
verify(postProjectAnalysisTask).finished(taskContextCaptor.capture());
Project project = taskContextCaptor.getValue().getProjectAnalysis().getProject();
- assertThat(project.getUuid()).isEqualTo(ceTask.getComponent().get().getUuid());
- assertThat(project.getKey()).isEqualTo(ceTask.getComponent().get().getKey().get());
- assertThat(project.getName()).isEqualTo(ceTask.getComponent().get().getName().get());
+ assertThat(project.getUuid()).isEqualTo(ceTask.getEntity().get().getUuid());
+ assertThat(project.getKey()).isEqualTo(ceTask.getEntity().get().getKey().get());
+ assertThat(project.getName()).isEqualTo(ceTask.getEntity().get().getName().get());
}
@Test
private final String type;
private final String uuid;
private final Component component;
- private final Component mainComponent;
+ private final Component entity;
private final User submitter;
private final Map<String, String> characteristics;
private CeTask(Builder builder) {
this.uuid = requireNonNull(emptyToNull(builder.uuid), "uuid can't be null nor empty");
this.type = requireNonNull(emptyToNull(builder.type), "type can't be null nor empty");
- checkArgument((builder.component == null) == (builder.mainComponent == null),
- "None or both component and main component must be non null");
+ checkArgument((builder.component == null) == (builder.entity == null),
+ "None or both component and entity must be non null");
this.component = builder.component;
- this.mainComponent = builder.mainComponent;
+ this.entity = builder.entity;
this.submitter = builder.submitter;
if (builder.characteristics == null) {
this.characteristics = emptyMap();
return Optional.ofNullable(component);
}
- public Optional<Component> getMainComponent() {
- return Optional.ofNullable(mainComponent);
+ public Optional<Component> getEntity() {
+ return Optional.ofNullable(entity);
}
@CheckForNull
.add("type", type)
.add("uuid", uuid)
.add("component", component)
- .add("mainComponent", mainComponent)
+ .add("entity", entity)
.add("submitter", submitter)
.toString();
}
private String uuid;
private String type;
private Component component;
- private Component mainComponent;
+ private Component entity;
private User submitter;
private Map<String, String> characteristics;
return this;
}
- public Builder setMainComponent(@Nullable Component mainComponent) {
- this.mainComponent = mainComponent;
+ public Builder setEntity(@Nullable Component entity) {
+ this.entity = entity;
return this;
}
private CeTask.Builder underTest = new CeTask.Builder();
@Test
- @UseDataProvider("oneAndOnlyOneOfComponentAndMainComponent")
- public void build_fails_with_IAE_if_only_one_of_component_and_main_component_is_non_null(CeTask.Component component, CeTask.Component mainComponent) {
+ @UseDataProvider("oneAndOnlyOneOfComponentAndEntity")
+ public void build_fails_with_IAE_if_only_one_of_component_and_main_component_is_non_null(CeTask.Component component, CeTask.Component entity) {
underTest.setType("TYPE_1");
underTest.setUuid("UUID_1");
underTest.setComponent(component);
- underTest.setMainComponent(mainComponent);
+ underTest.setEntity(entity);
assertThatThrownBy(() -> underTest.build())
.isInstanceOf(IllegalArgumentException.class)
- .hasMessage("None or both component and main component must be non null");
+ .hasMessage("None or both component and entity must be non null");
}
@DataProvider
- public static Object[][] oneAndOnlyOneOfComponentAndMainComponent() {
+ public static Object[][] oneAndOnlyOneOfComponentAndEntity() {
CeTask.Component component = new CeTask.Component("COMPONENT_UUID_1", "COMPONENT_KEY_1", "The component");
return new Object[][] {
{component, null},
@Test
public void verify_getters() {
CeTask.Component component = new CeTask.Component("COMPONENT_UUID_1", "COMPONENT_KEY_1", "The component");
- CeTask.Component mainComponent = new CeTask.Component("MAIN_COMPONENT_UUID_1", "MAIN_COMPONENT_KEY_1", "The main component");
+ CeTask.Component entity = new CeTask.Component("ENTITY_UUID_1", "ENTITY_KEY_1", "The entity");
CeTask.User submitter = new CeTask.User("UUID_USER_1", "LOGIN_1");
underTest.setType("TYPE_1");
underTest.setUuid("UUID_1");
underTest.setSubmitter(submitter);
underTest.setComponent(component);
- underTest.setMainComponent(mainComponent);
+ underTest.setEntity(entity);
underTest.setCharacteristics(ImmutableMap.of("k1", "v1", "k2", "v2"));
CeTask task = underTest.build();
assertThat(task.getType()).isEqualTo("TYPE_1");
assertThat(task.getSubmitter()).isEqualTo(submitter);
assertThat(task.getComponent()).contains(component);
- assertThat(task.getMainComponent()).contains(mainComponent);
+ assertThat(task.getEntity()).contains(entity);
assertThat(task.getCharacteristics())
.hasSize(2)
.containsEntry("k1", "v1")
@Test
public void verify_toString() {
CeTask.Component component = new CeTask.Component("COMPONENT_UUID_1", "COMPONENT_KEY_1", "The component");
- CeTask.Component mainComponent = new CeTask.Component("MAIN_COMPONENT_UUID_1", "MAIN_COMPONENT_KEY_1", "The main component");
+ CeTask.Component entity = new CeTask.Component("ENTITY_UUID_1", "ENTITY_KEY_1", "The entity");
underTest.setType("TYPE_1");
underTest.setUuid("UUID_1");
underTest.setComponent(component);
- underTest.setMainComponent(mainComponent);
+ underTest.setEntity(entity);
underTest.setSubmitter(new CeTask.User("UUID_USER_1", "LOGIN_1"));
underTest.setCharacteristics(ImmutableMap.of("k1", "v1", "k2", "v2"));
"type=TYPE_1, " +
"uuid=UUID_1, " +
"component=Component{uuid='COMPONENT_UUID_1', key='COMPONENT_KEY_1', name='The component'}, " +
- "mainComponent=Component{uuid='MAIN_COMPONENT_UUID_1', key='MAIN_COMPONENT_KEY_1', name='The main component'}, " +
+ "entity=Component{uuid='ENTITY_UUID_1', key='ENTITY_KEY_1', name='The entity'}, " +
"submitter=User{uuid='UUID_USER_1', login='LOGIN_1'}" +
"}");
}
import org.sonar.db.ce.CeQueueDto;
import org.sonar.db.ce.CeQueueTesting;
import org.sonar.db.ce.CeTaskTypes;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.platform.NodeInformation;
private static final String WORKER_UUID_2 = "worker uuid 2";
private static final String NODE_NAME = "nodeName1";
- private System2 system2 = new AlwaysIncreasingSystem2();
+ private final System2 system2 = new AlwaysIncreasingSystem2();
@Rule
public DbTester db = DbTester.create(system2);
- private DbSession session = db.getSession();
-
- private UuidFactory uuidFactory = UuidFactoryImpl.INSTANCE;
- private CEQueueStatus queueStatus = new CEQueueStatusImpl(db.getDbClient(), mock(System2.class));
- private ComputeEngineStatus computeEngineStatus = mock(ComputeEngineStatus.class);
- private Configuration config = mock(Configuration.class);
- private NextPendingTaskPicker nextPendingTaskPicker = new NextPendingTaskPicker(config, db.getDbClient());
- private NodeInformation nodeInformation = mock(NodeInformation.class);
- private InternalCeQueue underTest = new InternalCeQueueImpl(system2, db.getDbClient(), uuidFactory, queueStatus,
+ private final DbSession session = db.getSession();
+ private final UuidFactory uuidFactory = UuidFactoryImpl.INSTANCE;
+ private final CEQueueStatus queueStatus = new CEQueueStatusImpl(db.getDbClient(), mock(System2.class));
+ private final ComputeEngineStatus computeEngineStatus = mock(ComputeEngineStatus.class);
+ private final Configuration config = mock(Configuration.class);
+ private final NextPendingTaskPicker nextPendingTaskPicker = new NextPendingTaskPicker(config, db.getDbClient());
+ private final NodeInformation nodeInformation = mock(NodeInformation.class);
+ private final InternalCeQueue underTest = new InternalCeQueueImpl(system2, db.getDbClient(), uuidFactory, queueStatus,
computeEngineStatus, nextPendingTaskPicker, nodeInformation);
@Before
@Test
public void submit_returns_task_populated_from_CeTaskSubmit_and_creates_CeQueue_row() {
- ComponentDto project1 = newProjectDto("PROJECT_1");
- CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, project1, project1, "rob");
+ CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, "entity", "component", "rob");
CeTask task = underTest.submit(taskSubmit);
UserDto userDto = db.getDbClient().userDao().selectByUuid(db.getSession(), taskSubmit.getSubmitterUuid());
verifyCeTask(taskSubmit, task, null, userDto);
@Test
public void submit_populates_component_name_and_key_of_CeTask_if_component_exists() {
- ComponentDto componentDto = insertComponent(newProjectDto("PROJECT_1"));
- CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, componentDto, componentDto, null);
+ ProjectData projectData = newProject("PROJECT_1");
+ CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, projectData, null);
CeTask task = underTest.submit(taskSubmit);
- verifyCeTask(taskSubmit, task, componentDto, null);
+ verifyCeTask(taskSubmit, task, projectData.getMainBranchComponent(), null);
}
@Test
@Test
public void massSubmit_returns_tasks_for_each_CeTaskSubmit_populated_from_CeTaskSubmit_and_creates_CeQueue_row_for_each() {
- ComponentDto project1 = newProjectDto("PROJECT_1");
- CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, project1, project1, "rob");
+ CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, "entity", "component", "rob");
CeTaskSubmit taskSubmit2 = createTaskSubmit("some type");
List<CeTask> tasks = underTest.massSubmit(asList(taskSubmit1, taskSubmit2));
@Test
public void massSubmit_populates_component_name_and_key_of_CeTask_if_component_exists() {
- ComponentDto componentDto1 = insertComponent(newProjectDto("PROJECT_1"));
- CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, componentDto1, componentDto1, null);
- ComponentDto nonExistingComponent = newProjectDto("non existing component uuid");
- CeTaskSubmit taskSubmit2 = createTaskSubmit("something", nonExistingComponent, nonExistingComponent, null);
+ ProjectData project = newProject("PROJECT_1");
+ CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, project, null);
+ CeTaskSubmit taskSubmit2 = createTaskSubmit("something", project.projectUuid(), "non-existing", null);
List<CeTask> tasks = underTest.massSubmit(asList(taskSubmit1, taskSubmit2));
assertThat(tasks).hasSize(2);
- verifyCeTask(taskSubmit1, tasks.get(0), componentDto1, null);
+ verifyCeTask(taskSubmit1, tasks.get(0), project.getMainBranchComponent(), null);
verifyCeTask(taskSubmit2, tasks.get(1), null, null);
}
@Test
public void test_remove() {
- CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+ CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
underTest.remove(peek.get(), CeActivityDto.Status.SUCCESS, null, null);
@Test
public void remove_does_not_set_analysisUuid_in_CeActivity_when_CeTaskResult_has_no_analysis_uuid() {
- CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+ CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
underTest.remove(peek.get(), CeActivityDto.Status.SUCCESS, newTaskResult(null), null);
@Test
public void remove_sets_analysisUuid_in_CeActivity_when_CeTaskResult_has_analysis_uuid() {
- CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+ CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
Optional<CeTask> peek = underTest.peek(WORKER_UUID_2, true);
underTest.remove(peek.get(), CeActivityDto.Status.SUCCESS, newTaskResult(AN_ANALYSIS_UUID), null);
@Test
public void remove_sets_nodeName_in_CeActivity_when_nodeInformation_defines_node_name() {
when(nodeInformation.getNodeName()).thenReturn(Optional.of(NODE_NAME));
- CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+ CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
Optional<CeTask> peek = underTest.peek(WORKER_UUID_2, true);
underTest.remove(peek.get(), CeActivityDto.Status.SUCCESS, newTaskResult(AN_ANALYSIS_UUID), null);
@Test
public void remove_do_not_set_nodeName_in_CeActivity_when_nodeInformation_does_not_define_node_name() {
when(nodeInformation.getNodeName()).thenReturn(Optional.empty());
- CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+ CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
Optional<CeTask> peek = underTest.peek(WORKER_UUID_2, true);
underTest.remove(peek.get(), CeActivityDto.Status.SUCCESS, newTaskResult(AN_ANALYSIS_UUID), null);
public void remove_saves_error_message_and_stacktrace_when_exception_is_provided() {
Throwable error = new NullPointerException("Fake NPE to test persistence to DB");
- CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+ CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
underTest.remove(peek.get(), CeActivityDto.Status.FAILED, null, error);
public void remove_saves_error_when_TypedMessageException_is_provided() {
Throwable error = new TypedExceptionImpl("aType", "aMessage");
- CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+ CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
underTest.remove(peek.get(), CeActivityDto.Status.FAILED, null, error);
public void remove_updates_queueStatus_success_even_if_task_does_not_exist_in_DB() {
CEQueueStatus queueStatus = mock(CEQueueStatus.class);
- CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+ CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
db.getDbClient().ceQueueDao().deleteByUuid(db.getSession(), task.getUuid());
db.commit();
public void remove_updates_queueStatus_failure_even_if_task_does_not_exist_in_DB() {
CEQueueStatus queueStatusMock = mock(CEQueueStatus.class);
- CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+ CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
db.getDbClient().ceQueueDao().deleteByUuid(db.getSession(), task.getUuid());
db.commit();
InternalCeQueueImpl underTest = new InternalCeQueueImpl(system2, db.getDbClient(), null, queueStatusMock, null, null, nodeInformation);
CEQueueStatus queueStatusMock = mock(CEQueueStatus.class);
- CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+ CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
db.executeUpdateSql("update ce_queue set status = 'PENDING', started_at = 123 where uuid = '" + task.getUuid() + "'");
db.commit();
InternalCeQueueImpl underTest = new InternalCeQueueImpl(system2, db.getDbClient(), null, queueStatusMock, null, null, nodeInformation);
@Test
public void fail_to_remove_if_not_in_queue() {
- CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+ CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
underTest.remove(task, CeActivityDto.Status.SUCCESS, null, null);
assertThatThrownBy(() -> underTest.remove(task, CeActivityDto.Status.SUCCESS, null, null))
@Test
public void test_peek() {
- CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+ ProjectData projectData = newProject("PROJECT_1");
+ ComponentDto mainBranchComponent = projectData.getMainBranchComponent();
+ CeTask task = submit(CeTaskTypes.REPORT, projectData);
Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
assertThat(peek).isPresent();
assertThat(peek.get().getUuid()).isEqualTo(task.getUuid());
assertThat(peek.get().getType()).isEqualTo(CeTaskTypes.REPORT);
- assertThat(peek.get().getComponent()).contains(new CeTask.Component("PROJECT_1", null, null));
- assertThat(peek.get().getMainComponent()).contains(peek.get().getComponent().get());
+ assertThat(peek.get().getComponent()).contains(new CeTask.Component(mainBranchComponent.uuid(), mainBranchComponent.getKey(), mainBranchComponent.name()));
+ assertThat(peek.get().getEntity()).contains(peek.get().getComponent().get());
// no more pending tasks
peek = underTest.peek(WORKER_UUID_2, true);
@Test
public void peek_populates_name_and_key_for_existing_component_and_main_component() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto branch = db.components().insertProjectBranch(project);
- CeTask task = submit(CeTaskTypes.REPORT, project, branch);
+ ProjectDto project = db.components().insertPrivateProject().getProjectDto();
+ BranchDto branch = db.components().insertProjectBranch(project);
+ CeTask task = submit(CeTaskTypes.REPORT, branch);
Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
assertThat(peek).isPresent();
assertThat(peek.get().getUuid()).isEqualTo(task.getUuid());
assertThat(peek.get().getType()).isEqualTo(CeTaskTypes.REPORT);
- assertThat(peek.get().getComponent()).contains(new CeTask.Component(branch.uuid(), branch.getKey(), branch.name()));
- assertThat(peek.get().getMainComponent()).contains(new CeTask.Component(project.uuid(), project.getKey(), project.name()));
+ assertThat(peek.get().getComponent()).contains(new CeTask.Component(branch.getUuid(), project.getKey(), project.getName()));
+ assertThat(peek.get().getEntity()).contains(new CeTask.Component(project.getUuid(), project.getKey(), project.getName()));
// no more pending tasks
peek = underTest.peek(WORKER_UUID_2, true);
@Test
public void peek_is_paused_then_resumed() {
- CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+ CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
underTest.pauseWorkers();
Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
@Test
public void peek_nothing_if_application_status_stopping() {
- submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+ submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
when(computeEngineStatus.getStatus()).thenReturn(STOPPING);
Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
@Test
public void cancel_pending() {
- CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+ CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
CeQueueDto queueDto = db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), task.getUuid()).get();
underTest.cancel(db.getSession(), queueDto);
@Test
public void fail_to_cancel_if_in_progress() {
- CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
+ CeTask task = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
underTest.peek(WORKER_UUID_2, true);
CeQueueDto queueDto = db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), task.getUuid()).get();
@Test
public void cancelAll_pendings_but_not_in_progress() {
- CeTask inProgressTask = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
- CeTask pendingTask1 = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_2"));
- CeTask pendingTask2 = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_3"));
+ CeTask inProgressTask = submit(CeTaskTypes.REPORT, newProject("PROJECT_1"));
+ CeTask pendingTask1 = submit(CeTaskTypes.REPORT, newProject("PROJECT_2"));
+ CeTask pendingTask2 = submit(CeTaskTypes.REPORT, newProject("PROJECT_3"));
underTest.peek(WORKER_UUID_2, true);
int canceledCount = underTest.cancelAll();
assertThat(dto.getTaskType()).isEqualTo(taskSubmit.getType());
Optional<CeTaskSubmit.Component> component = taskSubmit.getComponent();
if (component.isPresent()) {
- assertThat(dto.getMainComponentUuid()).isEqualTo(component.get().getMainComponentUuid());
+ assertThat(dto.getEntityUuid()).isEqualTo(component.get().getEntityUuid());
assertThat(dto.getComponentUuid()).isEqualTo(component.get().getUuid());
} else {
- assertThat(dto.getMainComponentUuid()).isNull();
+ assertThat(dto.getEntityUuid()).isNull();
assertThat(dto.getComponentUuid()).isNull();
}
assertThat(dto.getSubmitterUuid()).isEqualTo(taskSubmit.getSubmitterUuid());
assertThat(dto.getCreatedAt()).isEqualTo(dto.getUpdatedAt());
}
- private ComponentDto newProjectDto(String uuid) {
- return ComponentTesting.newPublicProjectDto(uuid).setName("name_" + uuid).setKey("key_" + uuid);
+ private ProjectData newProject(String uuid) {
+ return db.components().insertPublicProject(uuid);
}
- private CeTask submit(String reportType, ComponentDto mainBranchComponent) {
- return underTest.submit(createTaskSubmit(reportType, mainBranchComponent, mainBranchComponent, null));
+ private CeTask submit(String reportType, BranchDto branchDto) {
+ return underTest.submit(createTaskSubmit(reportType, branchDto.getProjectUuid(), branchDto.getUuid(), null));
}
- private CeTask submit(String reportType, ComponentDto mainBranchComponent, ComponentDto branchComponent) {
- return underTest.submit(createTaskSubmit(reportType, mainBranchComponent, branchComponent, null));
+ private CeTask submit(String reportType, ProjectData projectData) {
+ return underTest.submit(createTaskSubmit(reportType, projectData.getProjectDto().getUuid(), projectData.getMainBranchDto().getUuid(), null));
}
private CeTaskSubmit createTaskSubmit(String type) {
return createTaskSubmit(type, null, null, null);
}
- private CeTaskSubmit createTaskSubmit(String type, @Nullable ComponentDto mainBranchComponentDto, @Nullable ComponentDto componentDto,
- @Nullable String submitterUuid) {
+ private CeTaskSubmit createTaskSubmit(String type, ProjectData projectData, @Nullable String submitterUuid) {
+ return createTaskSubmit(type, projectData.projectUuid(), projectData.getMainBranchDto().getUuid(), submitterUuid);
+ }
+
+ private CeTaskSubmit createTaskSubmit(String type, @Nullable String entityUuid, @Nullable String componentUuid, @Nullable String submitterUuid) {
CeTaskSubmit.Builder builder = underTest.prepareSubmit()
.setType(type)
.setSubmitterUuid(submitterUuid)
.setCharacteristics(emptyMap());
- if (componentDto != null && mainBranchComponentDto != null) {
- builder.setComponent(CeTaskSubmit.Component.fromDto(componentDto.uuid(), mainBranchComponentDto.uuid()));
+ if (componentUuid != null && entityUuid != null) {
+ builder.setComponent(CeTaskSubmit.Component.fromDto(componentUuid, entityUuid));
}
return builder.build();
}
return taskResult;
}
- private ComponentDto insertComponent(ComponentDto componentDto) {
- return db.components().insertComponent(componentDto);
- }
-
private CeQueueDto makeInProgress(CeQueueDto ceQueueDto, String workerUuid) {
CeQueueTesting.makeInProgress(session, workerUuid, system2.now(), ceQueueDto);
return db.getDbClient().ceQueueDao().selectByUuid(session, ceQueueDto.getUuid()).get();
// we have branch task in progress.
insertInProgress("1");
// The PR can run in parallel, but needs to wait for this other project to finish. We dont allow PRs to jump ahead
- insertPending("2", c -> c.setMainComponentUuid("different project"));
+ insertPending("2", c -> c.setEntityUuid("different project"));
insertPendingPullRequest("3");
Optional<CeQueueDto> ceQueueDto = underTest.findPendingTask("workerUuid", db.getSession(), true);
insertInProgress("1");
// The PR can run in parallel and is ahead of the other project
insertPendingPullRequest("2");
- insertPending("3", c -> c.setMainComponentUuid("different project"));
+ insertPending("3", c -> c.setEntityUuid("different project"));
Optional<CeQueueDto> ceQueueDto = underTest.findPendingTask("workerUuid", db.getSession(), true);
public void findPendingTask_excludingViewPickUpOrphanBranches() {
insertPending("1", dto -> dto
.setComponentUuid("1")
- .setMainComponentUuid("non-existing-uuid")
+ .setEntityUuid("non-existing-uuid")
.setStatus(PENDING)
.setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC)
.setCreatedAt(100_000L));
@Test
public void exclude_portfolios_computation_when_indexing_issues() {
String taskUuid1 = "1", taskUuid2 = "2";
- String mainComponentUuid = "1";
- insertBranch(mainComponentUuid);
+ String branchUuid = "1";
+ insertBranch(branchUuid);
insertPending(taskUuid1, dto -> dto
- .setComponentUuid(mainComponentUuid)
- .setMainComponentUuid(mainComponentUuid)
+ .setComponentUuid(branchUuid)
+ .setEntityUuid("entity_uuid")
.setStatus(PENDING)
.setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC)
.setCreatedAt(100_000L));
insertView(view_uuid);
insertPending(taskUuid2, dto -> dto
.setComponentUuid(view_uuid)
- .setMainComponentUuid(view_uuid)
+ .setEntityUuid(view_uuid)
.setStatus(PENDING)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));
dto.setStatus(status);
dto.setSubmitterUuid("henri");
dto.setComponentUuid(UUID.randomUUID().toString());
- dto.setMainComponentUuid("1");
+ dto.setEntityUuid("1");
if (ceQueueDtoConsumer != null) {
ceQueueDtoConsumer.accept(dto);
}
for (int i = 0; i < characteristics.length; i += 2) {
characteristicMap.put(characteristics[i], characteristics[i + 1]);
}
- CeTask.Component component = new CeTask.Component("PROJECT_1", null, null);
+ CeTask.Component entity = new CeTask.Component("PROJECT_1", null, null);
+ CeTask.Component component = new CeTask.Component("BRANCH_1", null, null);
return new CeTask.Builder()
.setUuid("TASK_1").setType(CeTaskTypes.REPORT)
.setComponent(component)
- .setMainComponent(component)
+ .setEntity(entity)
.setSubmitter(submitter)
.setCharacteristics(characteristicMap)
.build();
@Override
public Optional<Long> getLongestTimePending() {
try (DbSession dbSession = dbClient.openSession(false)) {
- return dbClient.ceQueueDao().selectCreationDateOfOldestPendingByMainComponentUuid(dbSession, null)
+ return dbClient.ceQueueDao().selectCreationDateOfOldestPendingByEntityUuid(dbSession, null)
.map(creationDate -> system.now() - creationDate);
}
}
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.utils.System2;
import org.slf4j.Logger;
import org.sonar.db.ce.CeActivityDto;
import org.sonar.db.ce.CeQueueDto;
import org.sonar.db.ce.CeTaskCharacteristicDto;
-import org.sonar.db.component.ComponentDto;
import org.sonar.server.platform.NodeInformation;
import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
import static java.util.Collections.singletonList;
import static java.util.Objects.requireNonNull;
-import static java.util.Optional.ofNullable;
import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
@ComputeEngineSide
return Optional.empty();
}
CeQueueDto taskDto = opt.get();
- Map<String, ComponentDto> componentsByUuid = loadComponentDtos(dbSession, taskDto);
Map<String, String> characteristics = dbClient.ceTaskCharacteristicsDao().selectByTaskUuids(dbSession, singletonList(taskDto.getUuid())).stream()
.collect(uniqueIndex(CeTaskCharacteristicDto::getKey, CeTaskCharacteristicDto::getValue));
- CeTask task = convertToTask(dbSession, taskDto, characteristics,
- ofNullable(taskDto.getComponentUuid()).map(componentsByUuid::get).orElse(null),
- ofNullable(taskDto.getMainComponentUuid()).map(componentsByUuid::get).orElse(null));
+ CeTask task = convertToTask(dbSession, taskDto, characteristics);
queueStatus.addInProgress();
return Optional.of(task);
}
}
private static List<PrOrBranchTask> filterOldestPerProject(List<PrOrBranchTask> queuedPrOrBranches) {
- Set<String> mainComponentUuidsSeen = new HashSet<>();
- return queuedPrOrBranches.stream().filter(t -> mainComponentUuidsSeen.add(t.getMainComponentUuid())).toList();
+ Set<String> entityUuidsSeen = new HashSet<>();
+ return queuedPrOrBranches.stream().filter(t -> entityUuidsSeen.add(t.getEntityUuid())).toList();
}
/**
* This method returns the longest waiting branch in the queue which can be scheduled concurrently with pull requests.
*/
private static boolean canRunBranch(PrOrBranchTask task, List<PrOrBranchTask> inProgress) {
- String mainComponentUuid = task.getMainComponentUuid();
+ String entityUuid = task.getEntityUuid();
List<PrOrBranchTask> sameComponentTasks = inProgress.stream()
- .filter(t -> t.getMainComponentUuid().equals(mainComponentUuid))
+ .filter(t -> t.getEntityUuid().equals(entityUuid))
.toList();
//we can peek branch analysis task only if all the other in progress tasks for this component uuid are pull requests
return sameComponentTasks.stream().map(PrOrBranchTask::getBranchType).allMatch(s -> Objects.equals(s, PULL_REQUEST));
private static boolean canRunPr(PrOrBranchTask task, List<PrOrBranchTask> inProgress) {
// return true unless the same PR is already in progress
return inProgress.stream()
- .noneMatch(pr -> pr.getMainComponentUuid().equals(task.getMainComponentUuid()) && Objects.equals(pr.getBranchType(), PULL_REQUEST) &&
+ .noneMatch(pr -> pr.getEntityUuid().equals(task.getEntityUuid()) && Objects.equals(pr.getBranchType(), PULL_REQUEST) &&
Objects.equals(pr.getComponentUuid(), (task.getComponentUuid())));
}
}
private static Profiler startLogProfiler(CeTask task) {
Profiler profiler = Profiler.create(LOG)
.logTimeLast(true)
- .addContext("project", task.getMainComponent().flatMap(CeTask.Component::getKey).orElse(null))
+ .addContext("project", task.getEntity().flatMap(CeTask.Component::getKey).orElse(null))
.addContext("type", task.getType());
for (Map.Entry<String, String> characteristic : task.getCharacteristics().entrySet()) {
profiler.addContext(characteristic.getKey(), characteristic.getValue());
private static CeTask createCeTask(String ceTaskType, String key) {
CeTask.Component component = new CeTask.Component("uuid_" + key, key, "name_" + key);
+ CeTask.Component entity = new CeTask.Component("uuid_entity_" + key, key, "name_" + key);
+
return new CeTask.Builder()
.setType(ceTaskType)
.setUuid("task_uuid_" + key)
.setComponent(component)
- .setMainComponent(component)
+ .setEntity(entity)
.build();
}
@RunWith(DataProviderRunner.class)
public class CeActivityDaoIT {
- private static final String MAINCOMPONENT_1 = randomAlphabetic(12);
+ private static final String ENTITY_1 = randomAlphabetic(12);
private static final String MAINCOMPONENT_2 = randomAlphabetic(13);
private static final String COMPONENT_1 = randomAlphabetic(14);
@Test
public void test_insert() {
- CeActivityDto inserted = insert("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, SUCCESS);
+ CeActivityDto inserted = insert("TASK_1", REPORT, COMPONENT_1, ENTITY_1, SUCCESS);
Optional<CeActivityDto> saved = underTest.selectByUuid(db.getSession(), "TASK_1");
assertThat(saved).isPresent();
CeActivityDto dto = saved.get();
assertThat(dto.getUuid()).isEqualTo("TASK_1");
assertThat(dto.getNodeName()).isEqualTo(NODE_NAME);
- assertThat(dto.getMainComponentUuid()).isEqualTo(MAINCOMPONENT_1);
+ assertThat(dto.getEntityUuid()).isEqualTo(ENTITY_1);
assertThat(dto.getComponentUuid()).isEqualTo(COMPONENT_1);
assertThat(dto.getStatus()).isEqualTo(SUCCESS);
assertThat(dto.getSubmitterUuid()).isEqualTo("submitter uuid");
assertThat(dto.getIsLast()).isTrue();
assertThat(dto.getMainIsLast()).isTrue();
assertThat(dto.getIsLastKey()).isEqualTo("REPORT" + COMPONENT_1);
- assertThat(dto.getMainIsLastKey()).isEqualTo("REPORT" + MAINCOMPONENT_1);
+ assertThat(dto.getMainIsLastKey()).isEqualTo("REPORT" + ENTITY_1);
assertThat(dto.getCreatedAt()).isEqualTo(INITIAL_TIME + 1);
assertThat(dto.getStartedAt()).isEqualTo(1_500_000_000_000L);
assertThat(dto.getExecutedAt()).isEqualTo(1_500_000_000_500L);
@Test
public void test_insert_of_errorMessage_of_1_000_chars() {
- CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED)
+ CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, ENTITY_1, FAILED)
.setErrorMessage(Strings.repeat("x", 1_000));
underTest.insert(db.getSession(), dto);
@Test
public void test_insert_of_errorMessage_of_1_001_chars_is_truncated_to_1000() {
String expected = Strings.repeat("x", 1_000);
- CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED)
+ CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, ENTITY_1, FAILED)
.setErrorMessage(expected + "y");
underTest.insert(db.getSession(), dto);
@Test
public void test_insert_error_message_and_stacktrace() {
- CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED)
+ CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, ENTITY_1, FAILED)
.setErrorStacktrace("error stack");
underTest.insert(db.getSession(), dto);
@Test
public void test_insert_error_message_only() {
- CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED);
+ CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, ENTITY_1, FAILED);
underTest.insert(db.getSession(), dto);
Optional<CeActivityDto> saved = underTest.selectByUuid(db.getSession(), "TASK_1");
@Test
public void insert_must_set_relevant_is_last_field() {
// only a single task on MAINCOMPONENT_1 -> is_last=true
- insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
+ insert("TASK_1", REPORT, ENTITY_1, SUCCESS);
assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").get().getIsLast()).isTrue();
// only a single task on MAINCOMPONENT_2 -> is_last=true
assertThat(underTest.selectByUuid(db.getSession(), "TASK_2").get().getIsLast()).isTrue();
// two tasks on MAINCOMPONENT_1, the most recent one is TASK_3
- insert("TASK_3", REPORT, MAINCOMPONENT_1, FAILED);
+ insert("TASK_3", REPORT, ENTITY_1, FAILED);
assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").get().getIsLast()).isFalse();
assertThat(underTest.selectByUuid(db.getSession(), "TASK_2").get().getIsLast()).isTrue();
assertThat(underTest.selectByUuid(db.getSession(), "TASK_3").get().getIsLast()).isTrue();
// inserting a cancelled task does not change the last task
- insert("TASK_4", REPORT, MAINCOMPONENT_1, CANCELED);
+ insert("TASK_4", REPORT, ENTITY_1, CANCELED);
assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").get().getIsLast()).isFalse();
assertThat(underTest.selectByUuid(db.getSession(), "TASK_2").get().getIsLast()).isTrue();
assertThat(underTest.selectByUuid(db.getSession(), "TASK_3").get().getIsLast()).isTrue();
@Test
public void test_selectByQuery() {
- insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
- insert("TASK_2", REPORT, MAINCOMPONENT_1, FAILED);
+ insert("TASK_1", REPORT, ENTITY_1, SUCCESS);
+ insert("TASK_2", REPORT, ENTITY_1, FAILED);
insert("TASK_3", REPORT, MAINCOMPONENT_2, SUCCESS);
insert("TASK_4", "views", null, SUCCESS);
assertThat(dtos).extracting("uuid").containsExactly("TASK_4", "TASK_3", "TASK_2", "TASK_1");
// select by component uuid
- query = new CeTaskQuery().setMainComponentUuid(MAINCOMPONENT_1);
+ query = new CeTaskQuery().setEntityUuid(ENTITY_1);
dtos = underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100));
assertThat(dtos).extracting("uuid").containsExactly("TASK_2", "TASK_1");
assertThat(dtos).extracting("uuid").containsExactly("TASK_4");
// select by multiple conditions
- query = new CeTaskQuery().setType(REPORT).setOnlyCurrents(true).setMainComponentUuid(MAINCOMPONENT_1);
+ query = new CeTaskQuery().setType(REPORT).setOnlyCurrents(true).setEntityUuid(ENTITY_1);
dtos = underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100));
assertThat(dtos).extracting("uuid").containsExactly("TASK_2");
}
@Test
public void test_selectByQuery_verify_order_if_same_date() {
system2.setNow(INITIAL_TIME);
- insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
+ insert("TASK_1", REPORT, ENTITY_1, SUCCESS);
system2.setNow(INITIAL_TIME);
- insert("TASK_2", REPORT, MAINCOMPONENT_1, FAILED);
+ insert("TASK_2", REPORT, ENTITY_1, FAILED);
system2.setNow(INITIAL_TIME);
insert("TASK_3", REPORT, MAINCOMPONENT_2, SUCCESS);
system2.setNow(INITIAL_TIME);
assertThat(dtos).extracting("uuid").containsExactly("TASK_4", "TASK_3", "TASK_2", "TASK_1");
// select by component uuid
- query = new CeTaskQuery().setMainComponentUuid(MAINCOMPONENT_1);
+ query = new CeTaskQuery().setEntityUuid(ENTITY_1);
dtos = underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100));
assertThat(dtos).extracting("uuid").containsExactly("TASK_2", "TASK_1");
assertThat(dtos).extracting("uuid").containsExactly("TASK_4");
// select by multiple conditions
- query = new CeTaskQuery().setType(REPORT).setOnlyCurrents(true).setMainComponentUuid(MAINCOMPONENT_1);
+ query = new CeTaskQuery().setType(REPORT).setOnlyCurrents(true).setEntityUuid(ENTITY_1);
dtos = underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100));
assertThat(dtos).extracting("uuid").containsExactly("TASK_2");
}
@Test
public void selectByQuery_does_not_populate_errorStacktrace_field() {
- insert("TASK_1", REPORT, MAINCOMPONENT_1, FAILED);
- underTest.insert(db.getSession(), createActivityDto("TASK_2", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED).setErrorStacktrace("some stack"));
+ insert("TASK_1", REPORT, ENTITY_1, FAILED);
+ underTest.insert(db.getSession(), createActivityDto("TASK_2", REPORT, COMPONENT_1, ENTITY_1, FAILED).setErrorStacktrace("some stack"));
- List<CeActivityDto> dtos = underTest.selectByQuery(db.getSession(), new CeTaskQuery().setMainComponentUuid(MAINCOMPONENT_1), forPage(1).andSize(100));
+ List<CeActivityDto> dtos = underTest.selectByQuery(db.getSession(), new CeTaskQuery().setEntityUuid(ENTITY_1), forPage(1).andSize(100));
assertThat(dtos)
.hasSize(2)
@Test
public void selectByQuery_populates_hasScannerContext_flag() {
- insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
+ insert("TASK_1", REPORT, ENTITY_1, SUCCESS);
CeActivityDto dto2 = insert("TASK_2", REPORT, MAINCOMPONENT_2, SUCCESS);
insertScannerContext(dto2.getUuid());
- CeActivityDto dto = underTest.selectByQuery(db.getSession(), new CeTaskQuery().setMainComponentUuid(MAINCOMPONENT_1), forPage(1).andSize(100)).iterator().next();
+ CeActivityDto dto = underTest.selectByQuery(db.getSession(), new CeTaskQuery().setEntityUuid(ENTITY_1), forPage(1).andSize(100)).iterator().next();
assertThat(dto.isHasScannerContext()).isFalse();
- dto = underTest.selectByQuery(db.getSession(), new CeTaskQuery().setMainComponentUuid(MAINCOMPONENT_2), forPage(1).andSize(100)).iterator().next();
+ dto = underTest.selectByQuery(db.getSession(), new CeTaskQuery().setEntityUuid(MAINCOMPONENT_2), forPage(1).andSize(100)).iterator().next();
assertThat(dto.isHasScannerContext()).isTrue();
}
.containsExactly(tuple("TASK_4", 60), tuple("TASK_3", 10), tuple("TASK_2", 30), tuple("TASK_1", moreThan1));
// select by component uuid
- query = new CeTaskQuery().setMainComponentUuid("PROJECT_1");
+ query = new CeTaskQuery().setEntityUuid("PROJECT_1");
assertThat(underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100)))
.extracting(CeActivityDto::getUuid, ceActivityDto -> ceActivityDto.getCeTaskMessageDtos().size())
.containsExactly(tuple("TASK_2", 30), tuple("TASK_1", moreThan1));
.containsExactly(tuple("TASK_4", 60));
// select by multiple conditions
- query = new CeTaskQuery().setType(REPORT).setOnlyCurrents(true).setMainComponentUuid("PROJECT_1");
+ query = new CeTaskQuery().setType(REPORT).setOnlyCurrents(true).setEntityUuid("PROJECT_1");
assertThat(underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100)))
.extracting(CeActivityDto::getUuid, ceActivityDto -> ceActivityDto.getCeTaskMessageDtos().size())
.containsExactly(tuple("TASK_2", 30));
@Test
public void selectByQuery_is_paginated_and_return_results_sorted_from_last_to_first() {
- insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
- insert("TASK_2", REPORT, MAINCOMPONENT_1, FAILED);
+ insert("TASK_1", REPORT, ENTITY_1, SUCCESS);
+ insert("TASK_2", REPORT, ENTITY_1, FAILED);
insert("TASK_3", REPORT, MAINCOMPONENT_2, SUCCESS);
insert("TASK_4", "views", null, SUCCESS);
@Test
public void selectByQuery_no_results_if_shortcircuited_by_component_uuids() {
- insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
+ insert("TASK_1", REPORT, ENTITY_1, SUCCESS);
CeTaskQuery query = new CeTaskQuery();
- query.setMainComponentUuids(Collections.emptyList());
+ query.setEntityUuids(Collections.emptyList());
assertThat(underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(1))).isEmpty();
}
@Test
public void selectOlderThan_does_not_populate_errorStacktrace() {
- insert("TASK_1", REPORT, MAINCOMPONENT_1, FAILED);
- underTest.insert(db.getSession(), createActivityDto("TASK_2", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED).setErrorStacktrace("some stack"));
+ insert("TASK_1", REPORT, ENTITY_1, FAILED);
+ underTest.insert(db.getSession(), createActivityDto("TASK_2", REPORT, COMPONENT_1, ENTITY_1, FAILED).setErrorStacktrace("some stack"));
List<CeActivityDto> dtos = underTest.selectOlderThan(db.getSession(), system2.now() + 1_000_000L);
@Test
public void deleteByUuids() {
- insert("TASK_1", "REPORT", MAINCOMPONENT_1, SUCCESS);
- insert("TASK_2", "REPORT", MAINCOMPONENT_1, SUCCESS);
- insert("TASK_3", "REPORT", MAINCOMPONENT_1, SUCCESS);
+ insert("TASK_1", "REPORT", ENTITY_1, SUCCESS);
+ insert("TASK_2", "REPORT", ENTITY_1, SUCCESS);
+ insert("TASK_3", "REPORT", ENTITY_1, SUCCESS);
underTest.deleteByUuids(db.getSession(), ImmutableSet.of("TASK_1", "TASK_3"));
assertThat(underTest.selectByUuid(db.getSession(), "TASK_1")).isEmpty();
@Test
public void deleteByUuids_does_nothing_if_uuid_does_not_exist() {
- insert("TASK_1", "REPORT", MAINCOMPONENT_1, SUCCESS);
+ insert("TASK_1", "REPORT", ENTITY_1, SUCCESS);
// must not fail
underTest.deleteByUuids(db.getSession(), singleton("TASK_2"));
}
@Test
- public void count_last_by_status_and_main_component_uuid() {
- insert("TASK_1", CeTaskTypes.REPORT, MAINCOMPONENT_1, SUCCESS);
+ public void count_last_by_status_and_entity_uuid() {
+ insert("TASK_1", CeTaskTypes.REPORT, ENTITY_1, SUCCESS);
// component 2
insert("TASK_2", CeTaskTypes.REPORT, MAINCOMPONENT_2, SUCCESS);
// status failed
- insert("TASK_3", CeTaskTypes.REPORT, MAINCOMPONENT_1, FAILED);
+ insert("TASK_3", CeTaskTypes.REPORT, ENTITY_1, FAILED);
// status canceled
- insert("TASK_4", CeTaskTypes.REPORT, MAINCOMPONENT_1, CANCELED);
- insert("TASK_5", CeTaskTypes.REPORT, MAINCOMPONENT_1, SUCCESS);
+ insert("TASK_4", CeTaskTypes.REPORT, ENTITY_1, CANCELED);
+ insert("TASK_5", CeTaskTypes.REPORT, ENTITY_1, SUCCESS);
db.commit();
- assertThat(underTest.countLastByStatusAndMainComponentUuid(dbSession, SUCCESS, MAINCOMPONENT_1)).isOne();
- assertThat(underTest.countLastByStatusAndMainComponentUuid(dbSession, SUCCESS, null)).isEqualTo(2);
+ assertThat(underTest.countLastByStatusAndEntityUuid(dbSession, SUCCESS, ENTITY_1)).isOne();
+ assertThat(underTest.countLastByStatusAndEntityUuid(dbSession, SUCCESS, null)).isEqualTo(2);
}
@Test
public void selectLastByComponentUuidAndTaskType_returns_task_of_given_type() {
- insert("TASK_1", "VIEW_REFRESH", MAINCOMPONENT_1, MAINCOMPONENT_1, SUCCESS);
- insert("TASK_2", CeTaskTypes.REPORT, MAINCOMPONENT_1, MAINCOMPONENT_1, SUCCESS);
- insert("TASK_3", "PROJECT_EXPORT", MAINCOMPONENT_1, MAINCOMPONENT_1, SUCCESS);
- insert("TASK_4", "PROJECT_IMPORT", MAINCOMPONENT_1, MAINCOMPONENT_1, SUCCESS);
+ insert("TASK_1", "VIEW_REFRESH", ENTITY_1, ENTITY_1, SUCCESS);
+ insert("TASK_2", CeTaskTypes.REPORT, ENTITY_1, ENTITY_1, SUCCESS);
+ insert("TASK_3", "PROJECT_EXPORT", ENTITY_1, ENTITY_1, SUCCESS);
+ insert("TASK_4", "PROJECT_IMPORT", ENTITY_1, ENTITY_1, SUCCESS);
db.commit();
- Optional<CeActivityDto> result = underTest.selectLastByComponentUuidAndTaskType(db.getSession(), MAINCOMPONENT_1, "PROJECT_EXPORT");
+ Optional<CeActivityDto> result = underTest.selectLastByComponentUuidAndTaskType(db.getSession(), ENTITY_1, "PROJECT_EXPORT");
assertThat(result).hasValueSatisfying(value -> assertThat(value.getUuid()).isEqualTo("TASK_3"));
}
@Test
public void selectLastByComponentUuidAndTaskType_returns_empty_if_task_of_given_type_does_not_exist() {
- insert("TASK_1", CeTaskTypes.REPORT, MAINCOMPONENT_1, SUCCESS);
+ insert("TASK_1", CeTaskTypes.REPORT, ENTITY_1, SUCCESS);
db.commit();
- Optional<CeActivityDto> result = underTest.selectLastByComponentUuidAndTaskType(db.getSession(), MAINCOMPONENT_1, "PROJECT_EXPORT");
+ Optional<CeActivityDto> result = underTest.selectLastByComponentUuidAndTaskType(db.getSession(), ENTITY_1, "PROJECT_EXPORT");
assertThat(result).isEmpty();
}
@Test
public void selectByTaskType() {
- insert("TASK_1", CeTaskTypes.REPORT, MAINCOMPONENT_1, SUCCESS);
- insert("TASK_2", CeTaskTypes.BRANCH_ISSUE_SYNC, MAINCOMPONENT_1, SUCCESS);
+ insert("TASK_1", CeTaskTypes.REPORT, ENTITY_1, SUCCESS);
+ insert("TASK_2", CeTaskTypes.BRANCH_ISSUE_SYNC, ENTITY_1, SUCCESS);
db.commit();
assertThat(underTest.selectByTaskType(db.getSession(), CeTaskTypes.REPORT))
public void hasAnyFailedOrCancelledIssueSyncTask() {
assertThat(underTest.hasAnyFailedOrCancelledIssueSyncTask(db.getSession())).isFalse();
- insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
- insert("TASK_2", REPORT, MAINCOMPONENT_1, FAILED);
+ insert("TASK_1", REPORT, ENTITY_1, SUCCESS);
+ insert("TASK_2", REPORT, ENTITY_1, FAILED);
ProjectDto projectDto1 = db.components().insertPrivateProject(
branchDto -> branchDto.setNeedIssueSync(false), c -> {
return insert(uuid, type, mainComponentUuid, mainComponentUuid, status);
}
- private CeActivityDto insertAndCommit(String uuid, String type, @Nullable String componentUuid, @Nullable String mainComponentUuid, CeActivityDto.Status status) {
- CeActivityDto res = insert(uuid, type, componentUuid, mainComponentUuid, status);
+ private CeActivityDto insertAndCommit(String uuid, String type, @Nullable String componentUuid, @Nullable String entityUuid, CeActivityDto.Status status) {
+ CeActivityDto res = insert(uuid, type, componentUuid, entityUuid, status);
db.commit();
return res;
}
- private CeActivityDto insert(String uuid, String type, @Nullable String componentUuid, @Nullable String mainComponentUuid, CeActivityDto.Status status) {
- CeActivityDto dto = createActivityDto(uuid, type, componentUuid, mainComponentUuid, status);
+ private CeActivityDto insert(String uuid, String type, @Nullable String componentUuid, @Nullable String entityUuid, CeActivityDto.Status status) {
+ CeActivityDto dto = createActivityDto(uuid, type, componentUuid, entityUuid, status);
system2.tick();
underTest.insert(db.getSession(), dto);
return dto;
}
- private CeActivityDto createActivityDto(String uuid, String type, @Nullable String componentUuid, @Nullable String mainComponentUuid, CeActivityDto.Status status) {
+ private CeActivityDto createActivityDto(String uuid, String type, @Nullable String componentUuid, @Nullable String entityUuid, CeActivityDto.Status status) {
CeQueueDto creating = new CeQueueDto();
creating.setUuid(uuid);
creating.setStatus(PENDING);
creating.setTaskType(type);
creating.setComponentUuid(componentUuid);
- creating.setMainComponentUuid(mainComponentUuid);
+ creating.setEntityUuid(entityUuid);
creating.setSubmitterUuid("submitter uuid");
creating.setCreatedAt(system2.now());
private static final long INIT_TIME = 1_450_000_000_000L;
private static final String TASK_UUID_1 = "TASK_1";
private static final String TASK_UUID_2 = "TASK_2";
- private static final String MAIN_COMPONENT_UUID_1 = "PROJECT_1";
- private static final String MAIN_COMPONENT_UUID_2 = "PROJECT_2";
+ private static final String ENTITY_UUID_1 = "PROJECT_1";
+ private static final String ENTITY_UUID_2 = "PROJECT_2";
private static final String COMPONENT_UUID_1 = "BRANCH_1";
private static final String TASK_UUID_3 = "TASK_3";
private static final String SELECT_QUEUE_UUID_AND_STATUS_QUERY = "select uuid,status from ce_queue";
long now = 1_334_333L;
CeQueueDto dto = new CeQueueDto()
.setTaskType(CeTaskTypes.REPORT)
- .setComponentUuid(MAIN_COMPONENT_UUID_1)
+ .setComponentUuid(ENTITY_UUID_1)
.setStatus(PENDING)
.setSubmitterUuid(SUBMITTER_LOGIN);
CeQueueDto saved = underTest.selectByUuid(db.getSession(), uuid).get();
assertThat(saved.getUuid()).isEqualTo(uuid);
assertThat(saved.getTaskType()).isEqualTo(CeTaskTypes.REPORT);
- assertThat(saved.getComponentUuid()).isEqualTo(MAIN_COMPONENT_UUID_1);
+ assertThat(saved.getComponentUuid()).isEqualTo(ENTITY_UUID_1);
assertThat(saved.getStatus()).isEqualTo(PENDING);
assertThat(saved.getSubmitterUuid()).isEqualTo(SUBMITTER_LOGIN);
assertThat(saved.getWorkerUuid()).isNull();
CeQueueDto saved = underTest.selectByUuid(db.getSession(), uuid4).get();
assertThat(saved.getUuid()).isEqualTo(uuid4);
assertThat(saved.getTaskType()).isEqualTo(CeTaskTypes.REPORT);
- assertThat(saved.getComponentUuid()).isEqualTo(MAIN_COMPONENT_UUID_1);
+ assertThat(saved.getComponentUuid()).isEqualTo(ENTITY_UUID_1);
assertThat(saved.getStatus()).isEqualTo(PENDING);
assertThat(saved.getSubmitterUuid()).isEqualTo(SUBMITTER_LOGIN);
assertThat(saved.getWorkerUuid()).isNull();
@Test
public void test_selectByUuid() {
- CeQueueDto ceQueueDto = insertPending(TASK_UUID_1, MAIN_COMPONENT_UUID_1);
+ CeQueueDto ceQueueDto = insertPending(TASK_UUID_1, ENTITY_UUID_1);
assertThat(underTest.selectByUuid(db.getSession(), "TASK_UNKNOWN")).isEmpty();
CeQueueDto saved = underTest.selectByUuid(db.getSession(), TASK_UUID_1).get();
assertThat(saved.getUuid()).isEqualTo(TASK_UUID_1);
assertThat(saved.getTaskType()).isEqualTo(CeTaskTypes.REPORT);
- assertThat(saved.getMainComponentUuid()).isEqualTo(MAIN_COMPONENT_UUID_1);
+ assertThat(saved.getEntityUuid()).isEqualTo(ENTITY_UUID_1);
assertThat(saved.getComponentUuid()).isEqualTo(ceQueueDto.getComponentUuid());
assertThat(saved.getStatus()).isEqualTo(PENDING);
assertThat(saved.getSubmitterUuid()).isEqualTo("henri");
@Test
public void test_selectByMainComponentUuid() {
- insertPending(TASK_UUID_1, MAIN_COMPONENT_UUID_1);
- insertPending(TASK_UUID_2, MAIN_COMPONENT_UUID_1);
+ insertPending(TASK_UUID_1, ENTITY_UUID_1);
+ insertPending(TASK_UUID_2, ENTITY_UUID_1);
insertPending(TASK_UUID_3, "PROJECT_2");
- assertThat(underTest.selectByMainComponentUuid(db.getSession(), "UNKNOWN")).isEmpty();
- assertThat(underTest.selectByMainComponentUuid(db.getSession(), MAIN_COMPONENT_UUID_1)).extracting("uuid").containsOnly(TASK_UUID_1, TASK_UUID_2);
- assertThat(underTest.selectByMainComponentUuid(db.getSession(), "PROJECT_2")).extracting("uuid").containsOnly(TASK_UUID_3);
+ assertThat(underTest.selectByEntityUuid(db.getSession(), "UNKNOWN")).isEmpty();
+ assertThat(underTest.selectByEntityUuid(db.getSession(), ENTITY_UUID_1)).extracting("uuid").containsOnly(TASK_UUID_1, TASK_UUID_2);
+ assertThat(underTest.selectByEntityUuid(db.getSession(), "PROJECT_2")).extracting("uuid").containsOnly(TASK_UUID_3);
}
@Test
public void test_selectAllInAscOrder() {
- insertPending(TASK_UUID_1, MAIN_COMPONENT_UUID_1);
- insertPending(TASK_UUID_2, MAIN_COMPONENT_UUID_1);
+ insertPending(TASK_UUID_1, ENTITY_UUID_1);
+ insertPending(TASK_UUID_2, ENTITY_UUID_1);
insertPending(TASK_UUID_3, "PROJECT_2");
assertThat(underTest.selectAllInAscOrder(db.getSession())).extracting("uuid").containsOnly(TASK_UUID_1, TASK_UUID_2, TASK_UUID_3);
insertPending("p1", dto -> {
dto.setCreatedAt(time);
dto.setUpdatedAt(time + 500);
- dto.setMainComponentUuid("c1");
+ dto.setEntityUuid("c1");
});
insertPending("p2", dto -> {
dto.setCreatedAt(time + 1000);
dto.setUpdatedAt(time + 2000);
- dto.setMainComponentUuid("c2");
+ dto.setEntityUuid("c2");
});
- makeInProgress("w1", alwaysIncreasingSystem2.now(), insertPending("i1", dto -> dto.setMainComponentUuid("c3")));
+ makeInProgress("w1", alwaysIncreasingSystem2.now(), insertPending("i1", dto -> dto.setEntityUuid("c3")));
- assertThat(underTest.selectCreationDateOfOldestPendingByMainComponentUuid(db.getSession(), null))
+ assertThat(underTest.selectCreationDateOfOldestPendingByEntityUuid(db.getSession(), null))
.isEqualTo(Optional.of(time));
}
insertPending("p1", dto -> {
dto.setCreatedAt(time);
dto.setUpdatedAt(time + 500);
- dto.setMainComponentUuid("c2");
+ dto.setEntityUuid("c2");
});
insertPending("p2", dto -> {
dto.setCreatedAt(time + 2000);
dto.setUpdatedAt(time + 3000);
- dto.setMainComponentUuid("c1");
+ dto.setEntityUuid("c1");
});
insertPending("p3", dto -> {
dto.setCreatedAt(time + 4000);
dto.setUpdatedAt(time + 5000);
- dto.setMainComponentUuid("c1");
+ dto.setEntityUuid("c1");
});
- makeInProgress("w1", alwaysIncreasingSystem2.now(), insertPending("i1", dto -> dto.setMainComponentUuid("c1")));
+ makeInProgress("w1", alwaysIncreasingSystem2.now(), insertPending("i1", dto -> dto.setEntityUuid("c1")));
- assertThat(underTest.selectCreationDateOfOldestPendingByMainComponentUuid(db.getSession(), "c1"))
+ assertThat(underTest.selectCreationDateOfOldestPendingByEntityUuid(db.getSession(), "c1"))
.isEqualTo(Optional.of(time + 2000));
}
@Test
public void selectCreationDateOfOldestPendingByMainComponentUuid_returns_empty_when_no_pending_tasks() {
makeInProgress("w1", alwaysIncreasingSystem2.now(), insertPending("i1"));
- assertThat(underTest.selectCreationDateOfOldestPendingByMainComponentUuid(db.getSession(), null))
+ assertThat(underTest.selectCreationDateOfOldestPendingByEntityUuid(db.getSession(), null))
.isEmpty();
}
@Test
public void test_delete() {
- insertPending(TASK_UUID_1, MAIN_COMPONENT_UUID_1);
- insertPending(TASK_UUID_2, MAIN_COMPONENT_UUID_1);
+ insertPending(TASK_UUID_1, ENTITY_UUID_1);
+ insertPending(TASK_UUID_2, ENTITY_UUID_1);
int deletedCount = underTest.deleteByUuid(db.getSession(), "UNKNOWN");
assertThat(deletedCount).isZero();
@Test
public void test_delete_with_expected_status() {
- insertPending(TASK_UUID_1, MAIN_COMPONENT_UUID_1);
+ insertPending(TASK_UUID_1, ENTITY_UUID_1);
insertInProgress(TASK_UUID_2, "workerUuid", System2.INSTANCE.now());
int deletedCount = underTest.deleteByUuid(db.getSession(), "UNKNOWN", null);
public void select_by_query() {
// task status not in query
insertPending(newCeQueueDto(TASK_UUID_1)
- .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+ .setEntityUuid(ENTITY_UUID_1)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));
// too early
insertPending(newCeQueueDto(TASK_UUID_3)
- .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+ .setEntityUuid(ENTITY_UUID_1)
.setStatus(PENDING)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(90_000L));
// task type not in query
insertPending(newCeQueueDto("TASK_4")
- .setMainComponentUuid("PROJECT_2")
+ .setEntityUuid("PROJECT_2")
.setStatus(PENDING)
.setTaskType("ANOTHER_TYPE")
.setCreatedAt(100_000L));
// correct
insertPending(newCeQueueDto(TASK_UUID_2)
- .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+ .setEntityUuid(ENTITY_UUID_1)
.setStatus(PENDING)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));
// correct submitted later
insertPending(newCeQueueDto("TASK_5")
- .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+ .setEntityUuid(ENTITY_UUID_1)
.setStatus(PENDING)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(120_000L));
// select by component uuid, status, task type and minimum submitted at
CeTaskQuery query = new CeTaskQuery()
- .setMainComponentUuids(newArrayList(MAIN_COMPONENT_UUID_1, "PROJECT_2"))
+ .setEntityUuids(newArrayList(ENTITY_UUID_1, "PROJECT_2"))
.setStatuses(singletonList(PENDING.name()))
.setType(CeTaskTypes.REPORT)
.setMinSubmittedAt(100_000L);
@Test
public void select_by_query_returns_empty_list_when_only_current() {
insertPending(newCeQueueDto(TASK_UUID_1)
- .setComponentUuid(MAIN_COMPONENT_UUID_1)
+ .setComponentUuid(ENTITY_UUID_1)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));
@Test
public void select_by_query_returns_empty_list_when_max_submitted_at() {
insertPending(newCeQueueDto(TASK_UUID_1)
- .setComponentUuid(MAIN_COMPONENT_UUID_1)
+ .setComponentUuid(ENTITY_UUID_1)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));
}
@Test
- public void select_by_query_returns_empty_list_when_empty_list_of_main_component_uuid() {
+ public void select_by_query_returns_empty_list_when_empty_list_of_entity_uuid() {
insertPending(newCeQueueDto(TASK_UUID_1)
- .setComponentUuid(MAIN_COMPONENT_UUID_1)
+ .setComponentUuid(ENTITY_UUID_1)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));
- CeTaskQuery query = new CeTaskQuery().setMainComponentUuids(Collections.emptyList());
+ CeTaskQuery query = new CeTaskQuery().setEntityUuids(Collections.emptyList());
List<CeQueueDto> result = underTest.selectByQueryInDescOrder(db.getSession(), query, 1_000);
int total = underTest.countByQuery(db.getSession(), query);
}
@Test
- public void count_by_status_and_main_component_uuid() {
+ public void count_by_status_and_entity_uuid() {
// task retrieved in the queue
insertPending(newCeQueueDto(TASK_UUID_1)
- .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+ .setEntityUuid(ENTITY_UUID_1)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));
// on component uuid 2, not returned
insertPending(newCeQueueDto(TASK_UUID_2)
- .setMainComponentUuid(MAIN_COMPONENT_UUID_2)
+ .setEntityUuid(ENTITY_UUID_2)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));
// pending status, not returned
insertPending(newCeQueueDto(TASK_UUID_3)
- .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+ .setEntityUuid(ENTITY_UUID_1)
.setStatus(PENDING)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));
- assertThat(underTest.countByStatusAndMainComponentUuid(db.getSession(), IN_PROGRESS, MAIN_COMPONENT_UUID_1)).isOne();
+ assertThat(underTest.countByStatusAndEntityUuid(db.getSession(), IN_PROGRESS, ENTITY_UUID_1)).isOne();
assertThat(underTest.countByStatus(db.getSession(), IN_PROGRESS)).isEqualTo(2);
}
@Test
- public void count_by_status_and_main_component_uuids() {
+ public void count_by_status_and_entity_uuids() {
// task retrieved in the queue
insertPending(newCeQueueDto(TASK_UUID_1)
- .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+ .setEntityUuid(ENTITY_UUID_1)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));
// on component uuid 2, not returned
insertPending(newCeQueueDto(TASK_UUID_2)
- .setMainComponentUuid(MAIN_COMPONENT_UUID_2)
+ .setEntityUuid(ENTITY_UUID_2)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));
// pending status, not returned
insertPending(newCeQueueDto(TASK_UUID_3)
- .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+ .setEntityUuid(ENTITY_UUID_1)
.setStatus(PENDING)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(100_000L));
- assertThat(underTest.countByStatusAndMainComponentUuids(db.getSession(), IN_PROGRESS, ImmutableSet.of())).isEmpty();
- assertThat(underTest.countByStatusAndMainComponentUuids(db.getSession(), IN_PROGRESS, ImmutableSet.of("non existing component uuid"))).isEmpty();
- assertThat(underTest.countByStatusAndMainComponentUuids(db.getSession(), IN_PROGRESS, ImmutableSet.of(MAIN_COMPONENT_UUID_1, MAIN_COMPONENT_UUID_2)))
- .containsOnly(entry(MAIN_COMPONENT_UUID_1, 1), entry(MAIN_COMPONENT_UUID_2, 1));
- assertThat(underTest.countByStatusAndMainComponentUuids(db.getSession(), PENDING, ImmutableSet.of(MAIN_COMPONENT_UUID_1, MAIN_COMPONENT_UUID_2)))
- .containsOnly(entry(MAIN_COMPONENT_UUID_1, 1));
+ assertThat(underTest.countByStatusAndEntityUuids(db.getSession(), IN_PROGRESS, ImmutableSet.of())).isEmpty();
+ assertThat(underTest.countByStatusAndEntityUuids(db.getSession(), IN_PROGRESS, ImmutableSet.of("non existing component uuid"))).isEmpty();
+ assertThat(underTest.countByStatusAndEntityUuids(db.getSession(), IN_PROGRESS, ImmutableSet.of(ENTITY_UUID_1, ENTITY_UUID_2)))
+ .containsOnly(entry(ENTITY_UUID_1, 1), entry(ENTITY_UUID_2, 1));
+ assertThat(underTest.countByStatusAndEntityUuids(db.getSession(), PENDING, ImmutableSet.of(ENTITY_UUID_1, ENTITY_UUID_2)))
+ .containsOnly(entry(ENTITY_UUID_1, 1));
assertThat(underTest.countByStatus(db.getSession(), IN_PROGRESS)).isEqualTo(2);
}
assertThat(underTest.hasAnyIssueSyncTaskPendingOrInProgress(db.getSession())).isFalse();
insertPending(newCeQueueDto(TASK_UUID_1)
- .setComponentUuid(MAIN_COMPONENT_UUID_1)
+ .setComponentUuid(ENTITY_UUID_1)
.setStatus(PENDING)
.setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC)
.setCreatedAt(100_000L));
assertThat(underTest.hasAnyIssueSyncTaskPendingOrInProgress(db.getSession())).isFalse();
insertPending(newCeQueueDto(TASK_UUID_1)
- .setComponentUuid(MAIN_COMPONENT_UUID_1)
+ .setComponentUuid(ENTITY_UUID_1)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC)
.setCreatedAt(100_000L));
public void selectOldestPendingPrOrBranch_returns_oldest_100_pr_or_branch_tasks() {
for (int i = 1; i < 110; i++) {
insertPending(newCeQueueDto("task" + i)
- .setComponentUuid(MAIN_COMPONENT_UUID_1).setStatus(PENDING).setTaskType(CeTaskTypes.REPORT).setCreatedAt(i));
+ .setComponentUuid(ENTITY_UUID_1).setStatus(PENDING).setTaskType(CeTaskTypes.REPORT).setCreatedAt(i));
}
for (int i = 1; i < 10; i++) {
insertPending(newCeQueueDto("progress" + i)
- .setComponentUuid(MAIN_COMPONENT_UUID_1).setStatus(IN_PROGRESS).setTaskType(CeTaskTypes.REPORT).setCreatedAt(i));
+ .setComponentUuid(ENTITY_UUID_1).setStatus(IN_PROGRESS).setTaskType(CeTaskTypes.REPORT).setCreatedAt(i));
insertPending(newCeQueueDto("sync" + i)
- .setComponentUuid(MAIN_COMPONENT_UUID_1).setStatus(PENDING).setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC).setCreatedAt(i));
+ .setComponentUuid(ENTITY_UUID_1).setStatus(PENDING).setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC).setCreatedAt(i));
}
List<PrOrBranchTask> prOrBranchTasks = underTest.selectOldestPendingPrOrBranch(db.getSession());
public void selectOldestPendingPrOrBranch_returns_branch_branch_type_if_no_characteristics() {
insertPending(newCeQueueDto(TASK_UUID_1)
.setComponentUuid(COMPONENT_UUID_1)
- .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+ .setEntityUuid(ENTITY_UUID_1)
.setStatus(PENDING)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(123L));
assertThat(prOrBranchTasks).hasSize(1);
assertThat(prOrBranchTasks.get(0))
- .extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getMainComponentUuid, PrOrBranchTask::getTaskType)
- .containsExactly(BRANCH_KEY, COMPONENT_UUID_1, MAIN_COMPONENT_UUID_1, CeTaskTypes.REPORT);
+ .extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getEntityUuid, PrOrBranchTask::getTaskType)
+ .containsExactly(BRANCH_KEY, COMPONENT_UUID_1, ENTITY_UUID_1, CeTaskTypes.REPORT);
}
@Test
public void selectOldestPendingPrOrBranch_returns_branch_branch_type_if_unrelated_characteristics() {
insertPending(newCeQueueDto(TASK_UUID_1)
.setComponentUuid(COMPONENT_UUID_1)
- .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+ .setEntityUuid(ENTITY_UUID_1)
.setStatus(PENDING)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(123L));
assertThat(prOrBranchTasks).hasSize(1);
assertThat(prOrBranchTasks.get(0))
- .extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getMainComponentUuid, PrOrBranchTask::getTaskType)
- .containsExactly(BRANCH_KEY, COMPONENT_UUID_1, MAIN_COMPONENT_UUID_1, CeTaskTypes.REPORT);
+ .extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getEntityUuid, PrOrBranchTask::getTaskType)
+ .containsExactly(BRANCH_KEY, COMPONENT_UUID_1, ENTITY_UUID_1, CeTaskTypes.REPORT);
}
@Test
public void selectOldestPendingPrOrBranch_returns_all_fields() {
insertPending(newCeQueueDto(TASK_UUID_1)
.setComponentUuid(COMPONENT_UUID_1)
- .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+ .setEntityUuid(ENTITY_UUID_1)
.setStatus(PENDING)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(123L));
assertThat(prOrBranchTasks).hasSize(1);
assertThat(prOrBranchTasks.get(0))
- .extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getMainComponentUuid, PrOrBranchTask::getTaskType)
- .containsExactly(PULL_REQUEST, COMPONENT_UUID_1, MAIN_COMPONENT_UUID_1, CeTaskTypes.REPORT);
+ .extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getEntityUuid, PrOrBranchTask::getTaskType)
+ .containsExactly(PULL_REQUEST, COMPONENT_UUID_1, ENTITY_UUID_1, CeTaskTypes.REPORT);
}
@Test
public void selectInProgressWithCharacteristics_returns_all_fields() {
insertPending(newCeQueueDto(TASK_UUID_1)
.setComponentUuid(COMPONENT_UUID_1)
- .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+ .setEntityUuid(ENTITY_UUID_1)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(123L));
assertThat(prOrBranchTasks).hasSize(1);
assertThat(prOrBranchTasks.get(0))
- .extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getMainComponentUuid, PrOrBranchTask::getTaskType)
- .containsExactly(PULL_REQUEST, COMPONENT_UUID_1, MAIN_COMPONENT_UUID_1, CeTaskTypes.REPORT);
+ .extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getEntityUuid, PrOrBranchTask::getTaskType)
+ .containsExactly(PULL_REQUEST, COMPONENT_UUID_1, ENTITY_UUID_1, CeTaskTypes.REPORT);
}
@Test
public void selectInProgressWithCharacteristics_returns_branch_branch_type_if_no_characteristics() {
insertPending(newCeQueueDto(TASK_UUID_1)
.setComponentUuid(COMPONENT_UUID_1)
- .setMainComponentUuid(MAIN_COMPONENT_UUID_1)
+ .setEntityUuid(ENTITY_UUID_1)
.setStatus(IN_PROGRESS)
.setTaskType(CeTaskTypes.REPORT)
.setCreatedAt(123L));
assertThat(prOrBranchTasks).hasSize(1);
assertThat(prOrBranchTasks.get(0))
- .extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getMainComponentUuid, PrOrBranchTask::getTaskType)
- .containsExactly(BRANCH_KEY, COMPONENT_UUID_1, MAIN_COMPONENT_UUID_1, CeTaskTypes.REPORT);
+ .extracting(PrOrBranchTask::getBranchType, PrOrBranchTask::getComponentUuid, PrOrBranchTask::getEntityUuid, PrOrBranchTask::getTaskType)
+ .containsExactly(BRANCH_KEY, COMPONENT_UUID_1, ENTITY_UUID_1, CeTaskTypes.REPORT);
}
private void insertPending(CeQueueDto dto) {
CeQueueDto dto = new CeQueueDto();
dto.setUuid(uuid);
dto.setTaskType(CeTaskTypes.REPORT);
- dto.setMainComponentUuid(mainComponentUuid);
+ dto.setEntityUuid(mainComponentUuid);
dto.setComponentUuid("uuid_" + pendingComponentUuidGenerator++);
dto.setStatus(PENDING);
dto.setSubmitterUuid("henri");
import org.mockito.internal.util.collections.Sets;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ProjectData;
public class LiveMeasureDaoIT {
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
private final LiveMeasureDao underTest = db.getDbClient().liveMeasureDao();
private MetricDto metric;
public void selectForProjectsByMetricUuids() {
MetricDto metric = db.measures().insertMetric();
MetricDto metric2 = db.measures().insertMetric();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
- underTest.insert(db.getSession(), newLiveMeasure(project, metric).setValue(3.14).setData((String) null));
- underTest.insert(db.getSession(), newLiveMeasure(project, metric2).setValue(4.54).setData((String) null));
- underTest.insert(db.getSession(), newLiveMeasure(project2, metric).setValue(99.99).setData((String) null));
+ BranchDto projectBranch = db.components().insertPrivateProject().getMainBranchDto();
+ BranchDto project2Branch = db.components().insertPrivateProject().getMainBranchDto();
+ underTest.insert(db.getSession(), newLiveMeasure(projectBranch, metric).setValue(3.14).setData((String) null));
+ underTest.insert(db.getSession(), newLiveMeasure(projectBranch, metric2).setValue(4.54).setData((String) null));
+ underTest.insert(db.getSession(), newLiveMeasure(project2Branch, metric).setValue(99.99).setData((String) null));
- List<LiveMeasureDto> selected = underTest.selectForProjectsByMetricUuids(db.getSession(), List.of(metric.getUuid(), metric2.getUuid()));
+ List<ProjectMainBranchLiveMeasureDto> selected = underTest.selectForProjectMainBranchesByMetricUuids(db.getSession(), List.of(metric.getUuid(), metric2.getUuid()));
assertThat(selected)
- .extracting(LiveMeasureDto::getComponentUuid, LiveMeasureDto::getProjectUuid, LiveMeasureDto::getMetricUuid, LiveMeasureDto::getValue, LiveMeasureDto::getDataAsString)
+ .extracting(ProjectMainBranchLiveMeasureDto::getProjectUuid, ProjectMainBranchLiveMeasureDto::getMetricUuid,
+ ProjectMainBranchLiveMeasureDto::getValue, ProjectMainBranchLiveMeasureDto::getTextValue)
.containsExactlyInAnyOrder(
- tuple(project.uuid(), project.uuid(), metric.getUuid(), 3.14, null),
- tuple(project.uuid(), project.uuid(), metric2.getUuid(), 4.54, null),
- tuple(project2.uuid(), project2.uuid(), metric.getUuid(), 99.99, null));
+ tuple(projectBranch.getProjectUuid(), metric.getUuid(), 3.14, null),
+ tuple(projectBranch.getProjectUuid(), metric2.getUuid(), 4.54, null),
+ tuple(project2Branch.getProjectUuid(), metric.getUuid(), 99.99, null));
}
@Test
public void selectForProjectsByMetricUuids_whenMetricDoesNotMatch_shouldReturnEmptyList() {
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
underTest.insert(db.getSession(), newLiveMeasure(project, metric).setValue(3.14).setData((String) null));
- List<LiveMeasureDto> selected = underTest.selectForProjectsByMetricUuids(db.getSession(), singletonList("_other_"));
+ List<ProjectMainBranchLiveMeasureDto> selected = underTest.selectForProjectMainBranchesByMetricUuids(db.getSession(), singletonList("_other_"));
assertThat(selected).isEmpty();
}
underTest.insert(db.getSession(), newLiveMeasure(project.getMainBranchComponent(), metric).setValue(4.54).setData((String) null));
underTest.insert(db.getSession(), newLiveMeasure(project2.getMainBranchComponent(), metric).setValue(5.56).setData((String) null));
- List<LiveMeasureDto> selected = underTest.selectForProjectsByMetricUuids(db.getSession(), List.of(metric.getUuid()));
+ List<ProjectMainBranchLiveMeasureDto> selected = underTest.selectForProjectMainBranchesByMetricUuids(db.getSession(), List.of(metric.getUuid()));
assertThat(selected)
- .extracting(LiveMeasureDto::getProjectUuid)
+ .extracting(ProjectMainBranchLiveMeasureDto::getProjectUuid)
.containsExactlyInAnyOrder(project.projectUuid(), project2.projectUuid());
}
LiveMeasureDto result = underTest.selectMeasure(db.getSession(), file.uuid(), metric.getKey()).orElseThrow(() -> new IllegalArgumentException("Measure not found"));
assertThat(result).as("Fail to map fields of %s", result.toString()).extracting(
- LiveMeasureDto::getProjectUuid, LiveMeasureDto::getComponentUuid, LiveMeasureDto::getMetricUuid, LiveMeasureDto::getValue,
- LiveMeasureDto::getDataAsString, LiveMeasureDto::getTextValue)
+ LiveMeasureDto::getProjectUuid, LiveMeasureDto::getComponentUuid, LiveMeasureDto::getMetricUuid, LiveMeasureDto::getValue,
+ LiveMeasureDto::getDataAsString, LiveMeasureDto::getTextValue)
.contains(project.uuid(), file.uuid(), metric.getUuid(), 3.14, "text_value", "text_value");
}
MetricDto ncloc = db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.toString()));
MetricDto lines = db.measures().insertMetric(m -> m.setKey("lines").setValueType(INT.toString()));
- ComponentDto simpleProject = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectData simpleProject = db.components().insertPublicProject();
db.measures().insertLiveMeasure(simpleProject, ncloc, m -> m.setValue(10d));
- ComponentDto projectWithBiggerBranch = db.components().insertPublicProject().getMainBranchComponent();
- ComponentDto bigBranch = db.components().insertProjectBranch(projectWithBiggerBranch, b -> b.setBranchType(BranchType.BRANCH));
+ ProjectData projectWithBiggerBranch = db.components().insertPublicProject();
+ BranchDto bigBranch = db.components().insertProjectBranch(projectWithBiggerBranch.getProjectDto(), b -> b.setBranchType(BranchType.BRANCH));
db.measures().insertLiveMeasure(projectWithBiggerBranch, ncloc, m -> m.setValue(100d));
db.measures().insertLiveMeasure(bigBranch, ncloc, m -> m.setValue(200d));
- ComponentDto projectWithLinesButNoLoc = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectWithLinesButNoLoc = db.components().insertPublicProject();
db.measures().insertLiveMeasure(projectWithLinesButNoLoc, lines, m -> m.setValue(365d));
db.measures().insertLiveMeasure(projectWithLinesButNoLoc, ncloc, m -> m.setValue(0d));
- assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), simpleProject.uuid())).isEqualTo(10L);
- assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), projectWithBiggerBranch.uuid())).isEqualTo(200L);
- assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), projectWithLinesButNoLoc.uuid())).isZero();
+ assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), simpleProject.projectUuid())).isEqualTo(10L);
+ assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), projectWithBiggerBranch.projectUuid())).isEqualTo(200L);
+ assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), projectWithLinesButNoLoc.projectUuid())).isZero();
}
@Test
Map<String, MetricDto> metrics = setupMetrics();
MetricDto ncloc = metrics.get("ncloc");
MetricDto nclocLanguageDistribution = metrics.get("ncloc_language_distribution");
- Map<String, ComponentDto> components = setupProjectsWithLoc(ncloc, nclocLanguageDistribution, metrics.get("lines"));
+ setupProjectsWithLoc(ncloc, nclocLanguageDistribution, metrics.get("lines"));
List<ProjectLocDistributionDto> results = underTest.selectLargestBranchesLocDistribution(db.getSession(), ncloc.getUuid(), nclocLanguageDistribution.getUuid());
assertThat(results)
.containsExactlyInAnyOrder(
- new ProjectLocDistributionDto(components.get("projectWithTieOnBranchSize").uuid(), components.get("projectWithTieOnBranchSize").uuid(), "java=250;js=0"),
- new ProjectLocDistributionDto(components.get("projectWithTieOnOtherBranches").uuid(), components.get("tieBranch1").uuid(), "java=230;js=0"),
- new ProjectLocDistributionDto(components.get("projectWithBranchBiggerThanMaster").uuid(), components.get("notMasterBranch").uuid(), "java=100;js=100"),
- new ProjectLocDistributionDto(components.get("simpleProject").uuid(), components.get("simpleProject").uuid(), "java=10;js=0"),
- new ProjectLocDistributionDto(components.get("projectWithLinesButNoLoc").uuid(), components.get("projectWithLinesButNoLoc").uuid(), "java=0;js=0"));
+ new ProjectLocDistributionDto("projectWithTieOnBranchSize", getMainBranchUuid("projectWithTieOnBranchSize"), "java=250;js=0"),
+ new ProjectLocDistributionDto("projectWithTieOnOtherBranches", getBranchUuid("projectWithTieOnOtherBranches", "tieBranch1"), "java=230;js=0"),
+ new ProjectLocDistributionDto("projectWithBranchBiggerThanMaster", getBranchUuid("projectWithBranchBiggerThanMaster", "notMasterBranch"), "java=100;js=100"),
+ new ProjectLocDistributionDto("simpleProject", getMainBranchUuid("simpleProject"), "java=10;js=0"),
+ new ProjectLocDistributionDto("projectWithLinesButNoLoc", getMainBranchUuid("projectWithLinesButNoLoc"), "java=0;js=0"));
+ }
+
+ private String getBranchUuid(String projectUuid, String branchKey) {
+ return db.getDbClient().branchDao().selectByBranchKey(db.getSession(), projectUuid, branchKey).get().getUuid();
+ }
+
+ private String getMainBranchUuid(String projectUuid) {
+ return db.getDbClient().branchDao().selectMainBranchByProjectUuid(db.getSession(), projectUuid).get().getUuid();
}
@Test
"lines", lines);
}
- private Map<String, ComponentDto> setupProjectsWithLoc(MetricDto ncloc, MetricDto nclocDistribution, MetricDto lines) {
- ComponentDto simpleProject = addProjectWithMeasure("simpleProject", ncloc, 10d);
- addMeasureToComponent(simpleProject, nclocDistribution, "java=10;js=0");
-
- ComponentDto projectWithBranchBiggerThanMaster = addProjectWithMeasure("projectWithBranchBiggerThanMaster", ncloc, 100d);
- addMeasureToComponent(projectWithBranchBiggerThanMaster, nclocDistribution, "java=100;js=0");
+ private void setupProjectsWithLoc(MetricDto ncloc, MetricDto nclocDistribution, MetricDto lines) {
+ ProjectData simpleProject = addProjectWithMeasure("simpleProject", ncloc, 10d);
+ addMeasureToMainBranch(simpleProject, nclocDistribution, "java=10;js=0");
- ComponentDto notMasterBranch = addBranchToProjectWithMeasure(projectWithBranchBiggerThanMaster, "notMasterBranch", ncloc, 200d);
- addMeasureToComponent(notMasterBranch, nclocDistribution, "java=100;js=100");
+ ProjectData projectWithBranchBiggerThanMaster = addProjectWithMeasure("projectWithBranchBiggerThanMaster", ncloc, 100d);
+ addMeasureToMainBranch(projectWithBranchBiggerThanMaster, nclocDistribution, "java=100;js=0");
- ComponentDto projectWithLinesButNoLoc = addProjectWithMeasure("projectWithLinesButNoLoc", lines, 365d);
- addMeasureToComponent(projectWithLinesButNoLoc, nclocDistribution, "java=0;js=0");
- addMeasureToComponent(projectWithLinesButNoLoc, ncloc, 0d, false);
+ BranchDto notMasterBranch = addBranchToProjectWithMeasure(projectWithBranchBiggerThanMaster, "notMasterBranch", ncloc, 200d);
+ addMeasureToBranch(notMasterBranch, nclocDistribution, "java=100;js=100");
- ComponentDto projectWithTieOnBranchSize = addProjectWithMeasure("projectWithTieOnBranchSize", ncloc, 250d);
- addMeasureToComponent(projectWithTieOnBranchSize, nclocDistribution, "java=250;js=0");
- ComponentDto tieBranch = addBranchToProjectWithMeasure(projectWithTieOnBranchSize, "tieBranch", ncloc, 250d);
- addMeasureToComponent(tieBranch, nclocDistribution, "java=250;js=0");
+ ProjectData projectWithLinesButNoLoc = addProjectWithMeasure("projectWithLinesButNoLoc", lines, 365d);
+ addMeasureToMainBranch(projectWithLinesButNoLoc, nclocDistribution, "java=0;js=0");
+ addMeasureToBranch(projectWithLinesButNoLoc.getMainBranchDto(), ncloc, 0d, false);
- ComponentDto projectWithTieOnOtherBranches = addProjectWithMeasure("projectWithTieOnOtherBranches", ncloc, 220d);
- addMeasureToComponent(projectWithTieOnOtherBranches, nclocDistribution, "java=220;js=0");
- ComponentDto tieBranch1 = addBranchToProjectWithMeasure(projectWithTieOnOtherBranches, "tieBranch1", ncloc, 230d);
- addMeasureToComponent(tieBranch1, nclocDistribution, "java=230;js=0");
- ComponentDto tieBranch2 = addBranchToProjectWithMeasure(projectWithTieOnOtherBranches, "tieBranch2", ncloc, 230d);
- addMeasureToComponent(tieBranch2, nclocDistribution, "java=230;js=0");
+ ProjectData projectWithTieOnBranchSize = addProjectWithMeasure("projectWithTieOnBranchSize", ncloc, 250d);
+ addMeasureToMainBranch(projectWithTieOnBranchSize, nclocDistribution, "java=250;js=0");
+ BranchDto tieBranch = addBranchToProjectWithMeasure(projectWithTieOnBranchSize, "tieBranch", ncloc, 250d);
+ addMeasureToBranch(tieBranch, nclocDistribution, "java=250;js=0");
- return Map.of("simpleProject", simpleProject,
- "projectWithBranchBiggerThanMaster", projectWithBranchBiggerThanMaster,
- "notMasterBranch", notMasterBranch,
- "projectWithLinesButNoLoc", projectWithLinesButNoLoc,
- "projectWithTieOnBranchSize", projectWithTieOnBranchSize,
- "tieBranch", tieBranch,
- "projectWithTieOnOtherBranches", projectWithTieOnOtherBranches,
- "tieBranch1", tieBranch1,
- "tieBranch2", tieBranch2);
+ ProjectData projectWithTieOnOtherBranches = addProjectWithMeasure("projectWithTieOnOtherBranches", ncloc, 220d);
+ addMeasureToMainBranch(projectWithTieOnOtherBranches, nclocDistribution, "java=220;js=0");
+ BranchDto tieBranch1 = addBranchToProjectWithMeasure(projectWithTieOnOtherBranches, "tieBranch1", ncloc, 230d);
+ addMeasureToBranch(tieBranch1, nclocDistribution, "java=230;js=0");
+ BranchDto tieBranch2 = addBranchToProjectWithMeasure(projectWithTieOnOtherBranches, "tieBranch2", ncloc, 230d);
+ addMeasureToBranch(tieBranch2, nclocDistribution, "java=230;js=0");
}
- private ComponentDto addProjectWithMeasure(String projectKey, MetricDto metric, double metricValue) {
- ComponentDto project = db.components().insertPublicProject(p -> p.setKey(projectKey)).getMainBranchComponent();
- addMeasureToComponent(project, metric, metricValue, true);
+ private ProjectData addProjectWithMeasure(String projectKey, MetricDto metric, double metricValue) {
+ ProjectData project = db.components().insertPublicProject(projectKey, p -> p.setKey(projectKey));
+ addMeasureToBranch(project.getMainBranchDto(), metric, metricValue, true);
return project;
}
- private void addMeasureToComponent(ComponentDto component, MetricDto metric, double metricValue, boolean addSnapshot) {
+ private void addMeasureToBranch(BranchDto component, MetricDto metric, double metricValue, boolean addSnapshot) {
db.measures().insertLiveMeasure(component, metric, m -> m.setValue(metricValue));
if (addSnapshot) {
db.components().insertSnapshot(component, t -> t.setLast(true));
}
}
- private void addMeasureToComponent(ComponentDto component, MetricDto metric, String metricValue) {
+ private void addMeasureToMainBranch(ProjectData projectData, MetricDto metric, String metricValue) {
+ addMeasureToBranch(projectData.getMainBranchDto(), metric, metricValue);
+ }
+
+ private void addMeasureToBranch(BranchDto component, MetricDto metric, String metricValue) {
db.measures().insertLiveMeasure(component, metric, m -> m.setData(metricValue));
}
- private ComponentDto addBranchToProjectWithMeasure(ComponentDto project, String branchKey, MetricDto metric, double metricValue) {
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH).setKey(branchKey));
- addMeasureToComponent(branch, metric, metricValue, true);
+ private BranchDto addBranchToProjectWithMeasure(ProjectData project, String branchKey, MetricDto metric, double metricValue) {
+ BranchDto branch = db.components()
+ .insertProjectBranch(project.getProjectDto(), b -> b.setBranchType(BranchType.BRANCH).setKey(branchKey));
+ addMeasureToBranch(branch, metric, metricValue, true);
return branch;
}
private MetricDto coverage;
private MetricDto complexity;
private MetricDto ncloc;
- private MetricDto nclocDistribution;
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
- private DbClient dbClient = db.getDbClient();
- private DbSession dbSession = db.getSession();
-
- private MeasureDao underTest = db.getDbClient().measureDao();
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
+ private final DbClient dbClient = db.getDbClient();
+ private final DbSession dbSession = db.getSession();
+ private final MeasureDao underTest = db.getDbClient().measureDao();
@Before
public void before() {
coverage = db.measures().insertMetric(m -> m.setKey("coverage"));
complexity = db.measures().insertMetric(m -> m.setKey("complexity"));
ncloc = db.measures().insertMetric(m -> m.setKey("ncloc"));
- nclocDistribution = db.measures().insertMetric(m -> m.setKey("ncloc_language_distribution"));
+ db.measures().insertMetric(m -> m.setKey("ncloc_language_distribution"));
}
@Test
dbSession.commit();
assertThat(db.countRowsOfTable("ce_queue")).isOne();
- assertThat(db.countSql("select count(*) from ce_queue where main_component_uuid='" + projectToBeDeleted.uuid() + "'")).isZero();
+ assertThat(db.countSql("select count(*) from ce_queue where entity_uuid='" + projectToBeDeleted.uuid() + "'")).isZero();
}
@Test
public void delete_ce_analysis_older_than_180_and_scanner_context_older_than_40_days_of_specified_project_when_purging_project() {
LocalDateTime now = LocalDateTime.now();
ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
- Consumer<CeQueueDto> belongsToProject1 = t -> t.setMainComponentUuid(project1.uuid()).setComponentUuid(project1.uuid());
+ Consumer<CeQueueDto> belongsToProject1 = t -> t.setEntityUuid(project1.uuid()).setComponentUuid(project1.uuid());
ComponentDto project2 = db.components().insertPublicProject().getMainBranchComponent();
- Consumer<CeQueueDto> belongsToProject2 = t -> t.setMainComponentUuid(project2.uuid()).setComponentUuid(project2.uuid());
+ Consumer<CeQueueDto> belongsToProject2 = t -> t.setEntityUuid(project2.uuid()).setComponentUuid(project2.uuid());
insertCeActivityAndChildDataWithDate("VERY_OLD_1", now.minusDays(180).minusMonths(10), belongsToProject1);
insertCeActivityAndChildDataWithDate("JUST_OLD_ENOUGH_1", now.minusDays(180).minusDays(1), belongsToProject1);
LocalDateTime now = LocalDateTime.now();
ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
ComponentDto branch1 = db.components().insertProjectBranch(project1, b -> b.setExcludeFromPurge(true));
- Consumer<CeQueueDto> belongsToProject1 = t -> t.setMainComponentUuid(project1.uuid()).setComponentUuid(project1.uuid());
- Consumer<CeQueueDto> belongsToBranch1 = t -> t.setMainComponentUuid(project1.uuid()).setComponentUuid(branch1.uuid());
+ Consumer<CeQueueDto> belongsToProject1 = t -> t.setEntityUuid(project1.uuid()).setComponentUuid(project1.uuid());
+ Consumer<CeQueueDto> belongsToBranch1 = t -> t.setEntityUuid(project1.uuid()).setComponentUuid(branch1.uuid());
insertCeActivityAndChildDataWithDate("VERY_OLD_1", now.minusDays(180).minusMonths(10), belongsToProject1);
insertCeActivityAndChildDataWithDate("JUST_OLD_ENOUGH_1", now.minusDays(180).minusDays(1), belongsToProject1);
LocalDateTime now = LocalDateTime.now();
ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
ComponentDto branch1 = db.components().insertProjectBranch(project1);
- Consumer<CeQueueDto> belongsToProject1 = t -> t.setMainComponentUuid(project1.uuid()).setComponentUuid(project1.uuid());
- Consumer<CeQueueDto> belongsToBranch1 = t -> t.setMainComponentUuid(project1.uuid()).setComponentUuid(branch1.uuid());
+ Consumer<CeQueueDto> belongsToProject1 = t -> t.setEntityUuid(project1.uuid()).setComponentUuid(project1.uuid());
+ Consumer<CeQueueDto> belongsToBranch1 = t -> t.setEntityUuid(project1.uuid()).setComponentUuid(branch1.uuid());
insertCeActivityAndChildDataWithDate("VERY_OLD_1", now.minusDays(180).minusMonths(10), belongsToProject1);
insertCeActivityAndChildDataWithDate("JUST_OLD_ENOUGH_1", now.minusDays(180).minusDays(1), belongsToProject1);
queueDto.setUuid(Uuids.create());
queueDto.setTaskType(REPORT);
queueDto.setComponentUuid(component.uuid());
- queueDto.setMainComponentUuid(mainBranch);
+ queueDto.setEntityUuid(mainBranch);
queueDto.setSubmitterUuid("submitter uuid");
queueDto.setCreatedAt(1_300_000_000_000L);
queueDto.setStatus(status);
.setUuid(UuidFactoryFast.getInstance().create())
.setTaskType("foo")
.setComponentUuid(component.uuid())
- .setMainComponentUuid(mainBranch)
+ .setEntityUuid(mainBranch)
.setStatus(Status.PENDING)
.setCreatedAt(1_2323_222L)
.setUpdatedAt(1_2323_222L);
private final TestSystem2 system2 = new TestSystem2().setNow(1L);
@Rule
- public DbTester db = DbTester.create(system2);
+ public DbTester db = DbTester.create(system2, true);
private final DbSession session = db.getSession();
private final PushEventDao underTest = db.getDbClient().pushEventDao();
public class ProjectQgateAssociationDaoIT {
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
- private DbSession dbSession = db.getSession();
- private ProjectQgateAssociationDao underTest = db.getDbClient().projectQgateAssociationDao();
+ private final DbSession dbSession = db.getSession();
+ private final ProjectQgateAssociationDao underTest = db.getDbClient().projectQgateAssociationDao();
@Test
public void select_all_projects_by_query() {
QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate();
QualityGateDto qualityGate2 = db.qualityGates().insertQualityGate();
- ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto project3 = db.components().insertPrivateProject().getMainBranchComponent();
- db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project1), qualityGate1);
- db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project2), qualityGate1);
- db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project3), qualityGate2);
+ ProjectDto project1 = db.components().insertPrivateProject().getProjectDto();
+ ProjectDto project2 = db.components().insertPrivateProject().getProjectDto();
+ ProjectDto project3 = db.components().insertPrivateProject().getProjectDto();
+ db.qualityGates().associateProjectToQualityGate(project1, qualityGate1);
+ db.qualityGates().associateProjectToQualityGate(project2, qualityGate1);
+ db.qualityGates().associateProjectToQualityGate(project3, qualityGate2);
List<ProjectQgateAssociationDto> result = underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
.qualityGate(qualityGate1)
assertThat(result)
.extracting(ProjectQgateAssociationDto::getUuid, ProjectQgateAssociationDto::getKey, ProjectQgateAssociationDto::getName, ProjectQgateAssociationDto::getGateUuid)
.containsExactlyInAnyOrder(
- tuple(project1.uuid(), project1.getKey(), project1.name(), qualityGate1.getUuid()),
- tuple(project2.uuid(), project2.getKey(), project2.name(), qualityGate1.getUuid()),
- tuple(project3.uuid(), project3.getKey(), project3.name(), null));
+ tuple(project1.getUuid(), project1.getKey(), project1.getName(), qualityGate1.getUuid()),
+ tuple(project2.getUuid(), project2.getKey(), project2.getName(), qualityGate1.getUuid()),
+ tuple(project3.getUuid(), project3.getKey(), project3.getName(), null));
}
@Test
public void select_all_projects_by_query_should_have_deterministic_order() {
QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate();
- ComponentDto project1 = db.components().insertPrivateProject(d -> d.setName("p1").setKey("key1")).getMainBranchComponent();
- ComponentDto project2 = db.components().insertPrivateProject(d -> d.setName("p1").setKey("key2")).getMainBranchComponent();
- ComponentDto project3 = db.components().insertPrivateProject(d -> d.setName("p2").setKey("key3")).getMainBranchComponent();
- db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project1), qualityGate1);
- db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project2), qualityGate1);
- db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project3), qualityGate1);
+ ProjectDto project1 = db.components().insertPrivateProject(d -> d.setName("p1").setKey("key1")).getProjectDto();
+ ProjectDto project2 = db.components().insertPrivateProject(d -> d.setName("p1").setKey("key2")).getProjectDto();
+ ProjectDto project3 = db.components().insertPrivateProject(d -> d.setName("p2").setKey("key3")).getProjectDto();
+ db.qualityGates().associateProjectToQualityGate(project1, qualityGate1);
+ db.qualityGates().associateProjectToQualityGate(project2, qualityGate1);
+ db.qualityGates().associateProjectToQualityGate(project3, qualityGate1);
List<ProjectQgateAssociationDto> result = underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
.qualityGate(qualityGate1)
assertThat(result)
.extracting(ProjectQgateAssociationDto::getUuid)
- .containsExactlyInAnyOrder(project1.uuid(), project2.uuid(), project3.uuid());
+ .containsExactlyInAnyOrder(project1.getUuid(), project2.getUuid(), project3.getUuid());
}
@Test
public void select_projects_by_query() {
QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
- ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto project3 = db.components().insertPrivateProject().getMainBranchComponent();
- db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project1), qualityGate);
- db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project2), qualityGate);
+ ProjectDto project1 = db.components().insertPrivateProject().getProjectDto();
+ ProjectDto project2 = db.components().insertPrivateProject().getProjectDto();
+ ProjectDto project3 = db.components().insertPrivateProject().getProjectDto();
+ db.qualityGates().associateProjectToQualityGate(project1, qualityGate);
+ db.qualityGates().associateProjectToQualityGate(project2, qualityGate);
assertThat(underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
.qualityGate(qualityGate)
.build()))
.extracting(ProjectQgateAssociationDto::getUuid, ProjectQgateAssociationDto::getName, ProjectQgateAssociationDto::getGateUuid)
.containsExactlyInAnyOrder(
- tuple(project1.uuid(), project1.name(), qualityGate.getUuid()),
- tuple(project2.uuid(), project2.name(), qualityGate.getUuid()));
+ tuple(project1.getUuid(), project1.getName(), qualityGate.getUuid()),
+ tuple(project2.getUuid(), project2.getName(), qualityGate.getUuid()));
assertThat(underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
.qualityGate(qualityGate)
.membership(ProjectQgateAssociationQuery.OUT)
.build()))
.extracting(ProjectQgateAssociationDto::getUuid, ProjectQgateAssociationDto::getName, ProjectQgateAssociationDto::getGateUuid)
- .containsExactlyInAnyOrder(tuple(project3.uuid(), project3.name(), null));
+ .containsExactlyInAnyOrder(tuple(project3.getUuid(), project3.getName(), null));
}
@Test
public void search_by_project_name() {
QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
- ComponentDto project1 = db.components().insertPrivateProject(p -> p.setName("Project One")).getMainBranchComponent();
- ComponentDto project2 = db.components().insertPrivateProject(p -> p.setName("Project Two")).getMainBranchComponent();
- ComponentDto project3 = db.components().insertPrivateProject(p -> p.setName("Project Three")).getMainBranchComponent();
- db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project1), qualityGate);
- db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project2), qualityGate);
+ ProjectDto project1 = db.components().insertPrivateProject(p -> p.setName("Project One")).getProjectDto();
+ ProjectDto project2 = db.components().insertPrivateProject(p -> p.setName("Project Two")).getProjectDto();
+ ProjectDto project3 = db.components().insertPrivateProject(p -> p.setName("Project Three")).getProjectDto();
+ db.qualityGates().associateProjectToQualityGate(project1, qualityGate);
+ db.qualityGates().associateProjectToQualityGate(project2, qualityGate);
assertThat(underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
.qualityGate(qualityGate)
.projectSearch("one")
.build()))
.extracting(ProjectQgateAssociationDto::getUuid)
- .containsExactlyInAnyOrder(project1.uuid());
+ .containsExactlyInAnyOrder(project1.getUuid());
assertThat(underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
.qualityGate(qualityGate)
.projectSearch("project")
.build()))
.extracting(ProjectQgateAssociationDto::getUuid)
- .containsExactlyInAnyOrder(project1.uuid(), project2.uuid(), project3.uuid());
+ .containsExactlyInAnyOrder(project1.getUuid(), project2.getUuid(), project3.getUuid());
}
@Test
public void sorted_by_project_name() {
QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
- ComponentDto project1 = db.components().insertPrivateProject(p -> p.setName("Project One")).getMainBranchComponent();
- ComponentDto project2 = db.components().insertPrivateProject(p -> p.setName("Project Two")).getMainBranchComponent();
- ComponentDto project3 = db.components().insertPrivateProject(p -> p.setName("Project Three")).getMainBranchComponent();
+ ProjectDto project1 = db.components().insertPrivateProject(p -> p.setName("Project One")).getProjectDto();
+ ProjectDto project2 = db.components().insertPrivateProject(p -> p.setName("Project Two")).getProjectDto();
+ ProjectDto project3 = db.components().insertPrivateProject(p -> p.setName("Project Three")).getProjectDto();
assertThat(underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
.qualityGate(qualityGate)
.build()))
.extracting(ProjectQgateAssociationDto::getUuid)
- .containsExactly(project1.uuid(), project3.uuid(), project2.uuid());
+ .containsExactly(project1.getUuid(), project3.getUuid(), project2.getUuid());
}
@Test
QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate();
QualityGateDto qualityGate2 = db.qualityGates().insertQualityGate();
- ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto project3 = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto project4 = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto project5 = db.components().insertPrivateProject().getMainBranchComponent();
- db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project1), qualityGate1);
- db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project2), qualityGate2);
- db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project3), qualityGate1);
- db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project4), qualityGate2);
- db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project5), qualityGate1);
+ ProjectDto project1 = db.components().insertPrivateProject().getProjectDto();
+ ProjectDto project2 = db.components().insertPrivateProject().getProjectDto();
+ ProjectDto project3 = db.components().insertPrivateProject().getProjectDto();
+ ProjectDto project4 = db.components().insertPrivateProject().getProjectDto();
+ ProjectDto project5 = db.components().insertPrivateProject().getProjectDto();
+ db.qualityGates().associateProjectToQualityGate(project1, qualityGate1);
+ db.qualityGates().associateProjectToQualityGate(project2, qualityGate2);
+ db.qualityGates().associateProjectToQualityGate(project3, qualityGate1);
+ db.qualityGates().associateProjectToQualityGate(project4, qualityGate2);
+ db.qualityGates().associateProjectToQualityGate(project5, qualityGate1);
List<ProjectQgateAssociationDto> result = underTest.selectAll(dbSession);
assertThat(result)
.extracting(ProjectQgateAssociationDto::getUuid, ProjectQgateAssociationDto::getGateUuid)
.containsExactlyInAnyOrder(
- tuple(project1.uuid(), qualityGate1.getUuid()),
- tuple(project2.uuid(), qualityGate2.getUuid()),
- tuple(project3.uuid(), qualityGate1.getUuid()),
- tuple(project4.uuid(), qualityGate2.getUuid()),
- tuple(project5.uuid(), qualityGate1.getUuid()));
+ tuple(project1.getUuid(), qualityGate1.getUuid()),
+ tuple(project2.getUuid(), qualityGate2.getUuid()),
+ tuple(project3.getUuid(), qualityGate1.getUuid()),
+ tuple(project4.getUuid(), qualityGate2.getUuid()),
+ tuple(project5.getUuid(), qualityGate1.getUuid()));
}
@Test
public void select_qgate_uuid_is_absent() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPrivateProject().getProjectDto();
- Optional<String> result = underTest.selectQGateUuidByProjectUuid(dbSession, project.uuid());
+ Optional<String> result = underTest.selectQGateUuidByProjectUuid(dbSession, project.getUuid());
assertThat(result).isEmpty();
}
public void select_qgate_uuid() {
QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate();
QualityGateDto qualityGate2 = db.qualityGates().insertQualityGate();
- ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
- db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project1), qualityGate1);
- db.qualityGates().associateProjectToQualityGate(db.components().getProjectDtoByMainBranch(project2), qualityGate2);
+ ProjectDto project1 = db.components().insertPrivateProject().getProjectDto();
+ ProjectDto project2 = db.components().insertPrivateProject().getProjectDto();
+ db.qualityGates().associateProjectToQualityGate(project1, qualityGate1);
+ db.qualityGates().associateProjectToQualityGate(project2, qualityGate2);
- Optional<String> result = underTest.selectQGateUuidByProjectUuid(dbSession, project1.uuid());
+ Optional<String> result = underTest.selectQGateUuidByProjectUuid(dbSession, project1.getUuid());
assertThat(result).contains(qualityGate1.getUuid());
}
underTest.deleteByProjectUuid(dbSession, project.getUuid());
- Optional<String> deletedQualityGate = db.qualityGates().selectQGateUuidByComponentUuid(project.getUuid());
+ Optional<String> deletedQualityGate = db.qualityGates().selectQGateUuidByProjectUuid(project.getUuid());
assertThat(deletedQualityGate).isEmpty();
}
underTest.deleteByQGateUuid(dbSession, qualityGate.getUuid());
- Optional<String> deletedQualityGate = db.qualityGates().selectQGateUuidByComponentUuid(project.getUuid());
+ Optional<String> deletedQualityGate = db.qualityGates().selectQGateUuidByProjectUuid(project.getUuid());
assertThat(deletedQualityGate).isEmpty();
}
underTest.updateProjectQGateAssociation(dbSession, project.getUuid(), secondQualityGate.getUuid());
- Optional<String> updatedQualityGateUuid = db.qualityGates().selectQGateUuidByComponentUuid(project.getUuid());
+ Optional<String> updatedQualityGateUuid = db.qualityGates().selectQGateUuidByProjectUuid(project.getUuid());
assertThat(updatedQualityGateUuid).contains(secondQualityGate.getUuid());
}
public class QualityGateConditionDaoIT {
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
private DbSession dbSession = dbTester.getSession();
private QualityGateConditionDao underTest = dbTester.getDbClient().gateConditionDao();
public class QualityGateDaoIT {
@Rule
- public final DbTester db = DbTester.create(System2.INSTANCE);
+ public final DbTester db = DbTester.create(System2.INSTANCE, true);
private final QualityGateDbTester qualityGateDbTester = new QualityGateDbTester(db);
private final DbSession dbSession = db.getSession();
private final ArgumentCaptor<GroupEditorNewValue> newValueCaptor = ArgumentCaptor.forClass(GroupEditorNewValue.class);
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE, auditPersister);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, auditPersister, true);
private DbSession dbSession = dbTester.getSession();
private QualityGateGroupPermissionsDao underTest = dbTester.getDbClient().qualityGateGroupPermissionsDao();
private final ArgumentCaptor<UserEditorNewValue> newValueCaptor = ArgumentCaptor.forClass(UserEditorNewValue.class);
@Rule
- public final DbTester db = DbTester.create(System2.INSTANCE, auditPersister);
+ public final DbTester db = DbTester.create(System2.INSTANCE, auditPersister, true);
private final DbSession dbSession = db.getSession();
private final UserDbTester userDbTester = new UserDbTester(db);
private System2 system = new TestSystem2().setNow(NOW);
@Rule
- public DbTester db = DbTester.create(system);
+ public DbTester db = DbTester.create(system, true);
private DbSession dbSession = db.getSession();
public class DefaultQProfileDaoIT {
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
private DbSession dbSession = dbTester.getSession();
private System2 system2 = new AlwaysIncreasingSystem2();
@Rule
- public DbTester db = DbTester.create(system2);
+ public DbTester db = DbTester.create(system2, true);
private DbSession dbSession = db.getSession();
private UuidFactory uuidFactory = new SequenceUuidFactory();
private System2 system2 = new TestSystem2().setNow(NOW);
@Rule
- public DbTester db = DbTester.create(system2, auditPersister);
+ public DbTester db = DbTester.create(system2, auditPersister, true);
private QProfileEditGroupsDao underTest = db.getDbClient().qProfileEditGroupsDao();
private final ArgumentCaptor<UserEditorNewValue> newValueCaptor = ArgumentCaptor.forClass(UserEditorNewValue.class);
@Rule
- public DbTester db = DbTester.create(system2, auditPersister);
+ public DbTester db = DbTester.create(system2, auditPersister, true);
private final QProfileEditUsersDao underTest = db.getDbClient().qProfileEditUsersDao();
private final System2 system = mock(System2.class);
@Rule
- public DbTester db = DbTester.create(system);
+ public DbTester db = DbTester.create(system, true);
private final DbSession dbSession = db.getSession();
private final QualityProfileDao underTest = db.getDbClient().qualityProfileDao();
.isEmpty();
}
- @Test
- public void test_selectQProfileUuidsByProjectUuid() {
- ProjectDto project1 = db.components().insertPublicProject().getProjectDto();
- ProjectDto project2 = db.components().insertPublicProject().getProjectDto();
- ProjectDto project3 = db.components().insertPublicProject().getProjectDto();
- QProfileDto javaProfile = db.qualityProfiles().insert(p -> p.setLanguage("java"));
- QProfileDto jsProfile = db.qualityProfiles().insert(p -> p.setLanguage("js"));
- QProfileDto cProfile = db.qualityProfiles().insert(p -> p.setLanguage("c"));
- db.qualityProfiles().associateWithProject(project1, javaProfile, cProfile);
- db.qualityProfiles().associateWithProject(project2, jsProfile);
-
- assertThat(underTest.selectQProfileUuidsByProjectUuid(dbSession, project1.getUuid()))
- .hasSize(2)
- .containsExactly(javaProfile.getKee(), cProfile.getKee());
-
- assertThat(underTest.selectQProfileUuidsByProjectUuid(dbSession, project2.getUuid()))
- .hasSize(1)
- .containsExactly(jsProfile.getKee());
-
- assertThat(underTest.selectQProfileUuidsByProjectUuid(dbSession, project3.getUuid()))
- .isEmpty();
- }
-
@Test
public void test_selectQProfilesByProjectUuid() {
ProjectDto project1 = db.components().insertPublicProject().getProjectDto();
@Test
public void select_selected_projects() {
- ComponentDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name")).getMainBranchComponent();
- ComponentDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name")).getMainBranchComponent();
- ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name")).getMainBranchComponent();
+ ProjectDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name")).getProjectDto();
+ ProjectDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name")).getProjectDto();
+ ProjectDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name")).getProjectDto();
db.components().insertPrivateProject(t -> t.setName("Project4 name")).getMainBranchComponent();
db.components().insertProjectBranch(project1, t -> t.setKey("branch"));
QProfileDto profile1 = newQualityProfileDto();
db.qualityProfiles().insert(profile1);
- db.qualityProfiles().associateWithProject(db.components().getProjectDtoByMainBranch(project1), profile1);
- db.qualityProfiles().associateWithProject(db.components().getProjectDtoByMainBranch(project2), profile1);
+ db.qualityProfiles().associateWithProject(project1, profile1);
+ db.qualityProfiles().associateWithProject(project2, profile1);
QProfileDto profile2 = newQualityProfileDto();
db.qualityProfiles().insert(profile2);
- db.qualityProfiles().associateWithProject(db.components().getProjectDtoByMainBranch(project3), profile2);
+ db.qualityProfiles().associateWithProject(project3, profile2);
QProfileDto profile3 = newQualityProfileDto();
assertThat(underTest.selectSelectedProjects(dbSession, profile1, null))
.extracting("projectUuid", "projectKey", "projectName", "profileKey")
.containsOnly(
- tuple(project1.uuid(), project1.getKey(), project1.name(), profile1.getKee()),
- tuple(project2.uuid(), project2.getKey(), project2.name(), profile1.getKee()));
+ tuple(project1.getUuid(), project1.getKey(), project1.getName(), profile1.getKee()),
+ tuple(project2.getUuid(), project2.getKey(), project2.getName(), profile1.getKee()));
assertThat(underTest.selectSelectedProjects(dbSession, profile1, "ect1")).hasSize(1);
assertThat(underTest.selectSelectedProjects(dbSession, profile3, null)).isEmpty();
@Test
public void select_deselected_projects() {
- ComponentDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name")).getMainBranchComponent();
- ComponentDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name")).getMainBranchComponent();
- ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name")).getMainBranchComponent();
+ ProjectDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name")).getProjectDto();
+ ProjectDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name")).getProjectDto();
+ ProjectDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name")).getProjectDto();
QProfileDto profile1 = newQualityProfileDto();
db.qualityProfiles().insert(profile1);
- db.qualityProfiles().associateWithProject(db.components().getProjectDtoByMainBranch(project1), profile1);
+ db.qualityProfiles().associateWithProject(project1, profile1);
QProfileDto profile2 = newQualityProfileDto();
db.qualityProfiles().insert(profile2);
- db.qualityProfiles().associateWithProject(db.components().getProjectDtoByMainBranch(project2), profile2);
+ db.qualityProfiles().associateWithProject(project2, profile2);
QProfileDto profile3 = newQualityProfileDto();
assertThat(underTest.selectDeselectedProjects(dbSession, profile1, null))
.extracting("projectUuid", "projectKey", "projectName", "profileKey")
.containsExactly(
- tuple(project2.uuid(), project2.getKey(), project2.name(), null),
- tuple(project3.uuid(), project3.getKey(), project3.name(), null));
+ tuple(project2.getUuid(), project2.getKey(), project2.getName(), null),
+ tuple(project3.getUuid(), project3.getKey(), project3.getName(), null));
assertThat(underTest.selectDeselectedProjects(dbSession, profile1, "ect2")).hasSize(1);
assertThat(underTest.selectDeselectedProjects(dbSession, profile3, null)).hasSize(3);
@Test
public void select_project_associations() {
- ComponentDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name")).getMainBranchComponent();
- ComponentDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name")).getMainBranchComponent();
- ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name")).getMainBranchComponent();
+ ProjectDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name")).getProjectDto();
+ ProjectDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name")).getProjectDto();
+ ProjectDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name")).getProjectDto();
db.components().insertProjectBranch(project1, t -> t.setKey("branch"));
QProfileDto profile1 = newQualityProfileDto();
db.qualityProfiles().insert(profile1);
- db.qualityProfiles().associateWithProject(db.components().getProjectDtoByMainBranch(project1), profile1);
+ db.qualityProfiles().associateWithProject(project1, profile1);
QProfileDto profile2 = newQualityProfileDto();
db.qualityProfiles().insert(profile2);
- db.qualityProfiles().associateWithProject(db.components().getProjectDtoByMainBranch(project2), profile2);
+ db.qualityProfiles().associateWithProject(project2, profile2);
QProfileDto profile3 = newQualityProfileDto();
assertThat(underTest.selectProjectAssociations(dbSession, profile1, null))
.extracting("projectUuid", "projectKey", "projectName", "profileKey")
.containsOnly(
- tuple(project1.uuid(), project1.getKey(), project1.name(), profile1.getKee()),
- tuple(project2.uuid(), project2.getKey(), project2.name(), null),
- tuple(project3.uuid(), project3.getKey(), project3.name(), null));
+ tuple(project1.getUuid(), project1.getKey(), project1.getName(), profile1.getKee()),
+ tuple(project2.getUuid(), project2.getKey(), project2.getName(), null),
+ tuple(project3.getUuid(), project3.getKey(), project3.getName(), null));
assertThat(underTest.selectProjectAssociations(dbSession, profile1, "ect2")).hasSize(1);
assertThat(underTest.selectProjectAssociations(dbSession, profile3, null)).hasSize(3);
@Test
public void selectProjectAssociations_shouldFindResult_whenQueryMatchingKey() {
- ComponentDto privateProject = db.components().insertPrivateProject(project -> project.setName("project name"), project -> project.setKey("project_key")).getMainBranchComponent();
+ ProjectDto privateProject = db.components().insertPrivateProject(project -> project.setName("project name"), project -> project.setKey("project_key")).getProjectDto();
QProfileDto qProfileDto = db.qualityProfiles().insert();
List<ProjectQprofileAssociationDto> results = underTest.selectProjectAssociations(dbSession, qProfileDto, "key");
- assertThat(results).extracting(ProjectQprofileAssociationDto::getProjectUuid).containsOnly(privateProject.uuid());
+ assertThat(results).extracting(ProjectQprofileAssociationDto::getProjectUuid).containsOnly(privateProject.getUuid());
}
@Test
public void selectSelectedProjects_shouldFindResult_whenQueryMatchingKey() {
- ComponentDto privateProject = db.components().insertPrivateProject(project -> project.setName("project name"), project -> project.setKey("project_key")).getMainBranchComponent();
+ ProjectDto privateProject = db.components().insertPrivateProject(project -> project.setName("project name"), project -> project.setKey("project_key")).getProjectDto();
QProfileDto qProfileDto = db.qualityProfiles().insert();
- db.qualityProfiles().associateWithProject(db.components().getProjectDtoByMainBranch(privateProject), qProfileDto);
+ db.qualityProfiles().associateWithProject(privateProject, qProfileDto);
List<ProjectQprofileAssociationDto> results = underTest.selectSelectedProjects(dbSession, qProfileDto, "key");
- assertThat(results).extracting(ProjectQprofileAssociationDto::getProjectUuid).containsOnly(privateProject.uuid());
+ assertThat(results).extracting(ProjectQprofileAssociationDto::getProjectUuid).containsOnly(privateProject.getUuid());
}
@Test
public void selectDeselectedProjects_shouldFindResult_whenQueryMatchingKey() {
- ComponentDto privateProject = db.components().insertPrivateProject(project -> project.setName("project name"), project -> project.setKey("project_key")).getMainBranchComponent();
+ ProjectDto privateProject = db.components().insertPrivateProject(project -> project.setName("project name"), project -> project.setKey("project_key")).getProjectDto();
QProfileDto qProfileDto = db.qualityProfiles().insert();
List<ProjectQprofileAssociationDto> results = underTest.selectDeselectedProjects(dbSession, qProfileDto, "key");
- assertThat(results).extracting(ProjectQprofileAssociationDto::getProjectUuid).containsOnly(privateProject.uuid());
+ assertThat(results).extracting(ProjectQprofileAssociationDto::getProjectUuid).containsOnly(privateProject.getUuid());
}
private List<QProfileDto> createSharedData() {
public class QualityProfileExportDaoIT {
@Rule
- public DbTester db = DbTester.create(new AlwaysIncreasingSystem2());
+ public DbTester db = DbTester.create(new AlwaysIncreasingSystem2(), true);
private final DbSession dbSession = db.getSession();
private final QualityProfileExportDao underTest = db.getDbClient().qualityProfileExportDao();
public class FileSourceDaoIT {
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
private final DbSession dbSession = dbTester.getSession();
* Ordered by id desc -> newest to oldest
*/
public List<CeActivityDto> selectByQuery(DbSession dbSession, CeTaskQuery query, Pagination pagination) {
- if (query.isShortCircuitedByMainComponentUuids()) {
+ if (query.isShortCircuitedByEntityUuids()) {
return Collections.emptyList();
}
return mapper(dbSession).countByQuery(query);
}
- public int countLastByStatusAndMainComponentUuid(DbSession dbSession, CeActivityDto.Status status, @Nullable String mainComponentUuid) {
- return mapper(dbSession).countLastByStatusAndMainComponentUuid(status, mainComponentUuid);
+ public int countLastByStatusAndEntityUuid(DbSession dbSession, CeActivityDto.Status status, @Nullable String entityUuid) {
+ return mapper(dbSession).countLastByStatusAndEntityUuid(status, entityUuid);
}
public Optional<CeActivityDto> selectLastByComponentUuidAndTaskType(DbSession dbSession, String componentUuid, String taskType) {
private String uuid;
/**
- * Can be {@code null} when task is not associated to any data in table PROJECTS, but must always be non {@code null}
- * at the same time as {@link #mainComponentUuid}.
+ * Can be {@code null} when task is not associated to any data in table COMPONENTS, but must always be non {@code null}
+ * at the same time as {@link #entityUuid}.
* <p>
- * The component uuid of a any component (project or not) is its own UUID.
+ * The component uuid of any component (project or not) is its own UUID.
*/
private String componentUuid;
/**
- * Can be {@code null} when task is not associated to any data in table PROJECTS, but must always be non {@code null}
+ * Can be {@code null} when task is not associated to any component, but must always be non {@code null}
* at the same time as {@link #componentUuid}.
* <p>
- * The main component uuid of the main branch of project is its own UUID. For other branches of a project, it is the
- * project UUID of the main branch of that project
*/
- private String mainComponentUuid;
+ private String entityUuid;
private String analysisUuid;
private Status status;
private String taskType;
this.uuid = queueDto.getUuid();
this.taskType = queueDto.getTaskType();
this.componentUuid = queueDto.getComponentUuid();
- this.mainComponentUuid = queueDto.getMainComponentUuid();
+ this.entityUuid = queueDto.getEntityUuid();
this.isLastKey = format("%s%s", taskType, Strings.nullToEmpty(componentUuid));
- this.mainIsLastKey = format("%s%s", taskType, Strings.nullToEmpty(mainComponentUuid));
+ this.mainIsLastKey = format("%s%s", taskType, Strings.nullToEmpty(entityUuid));
this.submitterUuid = queueDto.getSubmitterUuid();
this.workerUuid = queueDto.getWorkerUuid();
this.submittedAt = queueDto.getCreatedAt();
}
@CheckForNull
- public String getMainComponentUuid() {
- return mainComponentUuid;
+ public String getEntityUuid() {
+ return entityUuid;
}
- public CeActivityDto setMainComponentUuid(@Nullable String s) {
- validateUuid(s, "MAIN_COMPONENT_UUID");
- this.mainComponentUuid = s;
+ public CeActivityDto setEntityUuid(@Nullable String s) {
+ validateUuid(s, "ENTITY_UUID");
+ this.entityUuid = s;
return this;
}
"uuid='" + uuid + '\'' +
", nodeName='" + nodeName + '\'' +
", componentUuid='" + componentUuid + '\'' +
- ", mainComponentUuid='" + mainComponentUuid + '\'' +
+ ", entityUuid='" + entityUuid + '\'' +
", analysisUuid='" + analysisUuid + '\'' +
", status=" + status +
", taskType='" + taskType + '\'' +
int countByQuery(@Param("query") CeTaskQuery query);
- int countLastByStatusAndMainComponentUuid(@Param("status") CeActivityDto.Status status, @Nullable @Param("mainComponentUuid") String mainComponentUuid);
+ int countLastByStatusAndEntityUuid(@Param("status") CeActivityDto.Status status, @Nullable @Param("entityUuid") String entityUuid);
void insert(CeActivityDto dto);
}
public List<CeQueueDto> selectByQueryInDescOrder(DbSession dbSession, CeTaskQuery query, int page, int pageSize) {
- if (query.isShortCircuitedByMainComponentUuids()
+ if (query.isShortCircuitedByEntityUuids()
|| query.isOnlyCurrents()
|| query.getMaxExecutedAt() != null) {
return emptyList();
}
public int countByQuery(DbSession dbSession, CeTaskQuery query) {
- if (query.isShortCircuitedByMainComponentUuids()
+ if (query.isShortCircuitedByEntityUuids()
|| query.isOnlyCurrents()
|| query.getMaxExecutedAt() != null) {
return 0;
/**
* Ordered by ascending id: oldest to newest
*/
- public List<CeQueueDto> selectByMainComponentUuid(DbSession session, String projectUuid) {
- return mapper(session).selectByMainComponentUuid(projectUuid);
+ public List<CeQueueDto> selectByEntityUuid(DbSession session, String projectUuid) {
+ return mapper(session).selectByEntityUuid(projectUuid);
}
public Optional<CeQueueDto> selectByUuid(DbSession session, String uuid) {
}
public int countByStatus(DbSession dbSession, CeQueueDto.Status status) {
- return mapper(dbSession).countByStatusAndMainComponentUuid(status, null);
+ return mapper(dbSession).countByStatusAndEntityUuid(status, null);
}
- public int countByStatusAndMainComponentUuid(DbSession dbSession, CeQueueDto.Status status, @Nullable String mainComponentUuid) {
- return mapper(dbSession).countByStatusAndMainComponentUuid(status, mainComponentUuid);
+ public int countByStatusAndEntityUuid(DbSession dbSession, CeQueueDto.Status status, @Nullable String entityUuid) {
+ return mapper(dbSession).countByStatusAndEntityUuid(status, entityUuid);
}
- public Optional<Long> selectCreationDateOfOldestPendingByMainComponentUuid(DbSession dbSession, @Nullable String mainComponentUuid) {
- return Optional.ofNullable(mapper(dbSession).selectCreationDateOfOldestPendingByMainComponentUuid(mainComponentUuid));
+ public Optional<Long> selectCreationDateOfOldestPendingByEntityUuid(DbSession dbSession, @Nullable String entityUuid) {
+ return Optional.ofNullable(mapper(dbSession).selectCreationDateOfOldestPendingByEntityUuid(entityUuid));
}
/**
- * Counts entries in the queue with the specified status for each specified main component uuid.
- * The returned map doesn't contain any entry for main component uuids for which there is no entry in the queue (ie.
+ * Counts entries in the queue with the specified status for each specified entity uuid.
+ * The returned map doesn't contain any entry for entity uuids for which there is no entry in the queue (ie.
* all entries have a value >= 0).
*/
- public Map<String, Integer> countByStatusAndMainComponentUuids(DbSession dbSession, CeQueueDto.Status status, Set<String> projectUuids) {
+ public Map<String, Integer> countByStatusAndEntityUuids(DbSession dbSession, CeQueueDto.Status status, Set<String> projectUuids) {
if (projectUuids.isEmpty()) {
return emptyMap();
}
executeLargeUpdates(
projectUuids,
partitionOfProjectUuids -> {
- List<QueueCount> i = mapper(dbSession).countByStatusAndMainComponentUuids(status, partitionOfProjectUuids);
- i.forEach(o -> builder.put(o.getMainComponentUuid(), o.getTotal()));
+ List<QueueCount> i = mapper(dbSession).countByStatusAndEntityUuids(status, partitionOfProjectUuids);
+ i.forEach(o -> builder.put(o.getEntityUuid(), o.getTotal()));
});
return builder.build();
}
private String uuid;
private String taskType;
/**
- * Can be {@code null} when task is not associated to any data in table PROJECTS, but must always be non {@code null}
- * at the same time as {@link #mainComponentUuid}.
+ * Can be {@code null} when task is not associated to any data in the components table, but must always be non {@code null}
+ * at the same time as {@link #entityUuid}.
* <p>
- * The component uuid of a any component (project or not) is its own UUID.
+ * The component uuid of any component is its own UUID.
*/
private String componentUuid;
/**
- * Can be {@code null} when task is not associated to any data in table PROJECTS, but must always be non {@code null}
+ * Can be {@code null} when task is not associated to any entity, but must always be non {@code null}
* at the same time as {@link #componentUuid}.
* <p>
- * The main component uuid of the main branch of project is its own UUID. For other branches of a project, it is the
- * project UUID of the main branch of that project
*/
- private String mainComponentUuid;
+ private String entityUuid;
private Status status;
private String submitterUuid;
/**
}
@CheckForNull
- public String getMainComponentUuid() {
- return mainComponentUuid;
+ public String getEntityUuid() {
+ return entityUuid;
}
- public CeQueueDto setMainComponentUuid(@Nullable String s) {
- checkUuid(s, "MAIN_COMPONENT_UUID");
- this.mainComponentUuid = s;
+ public CeQueueDto setEntityUuid(@Nullable String s) {
+ checkUuid(s, "ENTITY_UUID");
+ this.entityUuid = s;
return this;
}
"uuid='" + uuid + '\'' +
", taskType='" + taskType + '\'' +
", componentUuid='" + componentUuid + '\'' +
- ", mainComponentUuid='" + mainComponentUuid + '\'' +
+ ", entityUuid='" + entityUuid + '\'' +
", status=" + status +
", submitterLogin='" + submitterUuid + '\'' +
", workerUuid='" + workerUuid + '\'' +
public interface CeQueueMapper {
- List<CeQueueDto> selectByMainComponentUuid(@Param("mainComponentUuid") String mainComponentUuid);
+ List<CeQueueDto> selectByEntityUuid(@Param("entityUuid") String entityUuid);
List<CeQueueDto> selectAllInAscOrder();
*/
void resetAllInProgressTasks(@Param("updatedAt") long updatedAt);
- int countByStatusAndMainComponentUuid(@Param("status") CeQueueDto.Status status, @Nullable @Param("mainComponentUuid") String mainComponentUuid);
+ int countByStatusAndEntityUuid(@Param("status") CeQueueDto.Status status, @Nullable @Param("entityUuid") String entityUuid);
@CheckForNull
- Long selectCreationDateOfOldestPendingByMainComponentUuid(@Nullable @Param("mainComponentUuid") String mainComponentUuid);
+ Long selectCreationDateOfOldestPendingByEntityUuid(@Nullable @Param("entityUuid") String entityUuid);
- List<QueueCount> countByStatusAndMainComponentUuids(@Param("status") CeQueueDto.Status status, @Param("mainComponentUuids") List<String> mainComponentUuids);
+ List<QueueCount> countByStatusAndEntityUuids(@Param("status") CeQueueDto.Status status, @Param("entityUuids") List<String> entityUuids);
void insert(CeQueueDto dto);
private boolean onlyCurrents = false;
// SONAR-7681 a public implementation of List must be used in MyBatis - potential concurrency exceptions otherwise
@Nullable
- private ArrayList<String> mainComponentUuids;
+ private ArrayList<String> entityUuids;
@Nullable
private ArrayList<String> statuses;
@Nullable
private ArrayList<String> errorTypes;
@CheckForNull
- public List<String> getMainComponentUuids() {
- return mainComponentUuids;
+ public List<String> getEntityUuids() {
+ return entityUuids;
}
- public CeTaskQuery setMainComponentUuids(@Nullable List<String> l) {
- this.mainComponentUuids = l == null ? null : newArrayList(l);
+ public CeTaskQuery setEntityUuids(@Nullable List<String> l) {
+ this.entityUuids = l == null ? null : newArrayList(l);
return this;
}
- public boolean isShortCircuitedByMainComponentUuids() {
- return mainComponentUuids != null && (mainComponentUuids.isEmpty() || mainComponentUuids.size() > MAX_COMPONENT_UUIDS);
+ public boolean isShortCircuitedByEntityUuids() {
+ return entityUuids != null && (entityUuids.isEmpty() || entityUuids.size() > MAX_COMPONENT_UUIDS);
}
- public CeTaskQuery setMainComponentUuid(@Nullable String s) {
+ public CeTaskQuery setEntityUuid(@Nullable String s) {
if (s == null) {
- this.mainComponentUuids = null;
+ this.entityUuids = null;
} else {
- this.mainComponentUuids = newArrayList(s);
+ this.entityUuids = newArrayList(s);
}
return this;
}
package org.sonar.db.ce;
public class PrOrBranchTask extends CeTaskDtoLight {
- private String mainComponentUuid;
+ private String entityUuid;
private String taskType;
private String branchType;
private String componentUuid;
- public String getMainComponentUuid() {
- return mainComponentUuid;
+ public String getEntityUuid() {
+ return entityUuid;
}
public String getBranchType() {
public class QueueCount {
// set by reflection by MyBatis
- private String mainComponentUuid;
+ private String entityUuid;
private int total;
- public String getMainComponentUuid() {
- return mainComponentUuid;
+ public String getEntityUuid() {
+ return entityUuid;
}
public int getTotal() {
componentUuids -> mapper(dbSession).selectByComponentUuidsAndMetricUuids(componentUuids, metricUuids));
}
- public List<LiveMeasureDto> selectForProjectsByMetricUuids(DbSession dbSession, Collection<String> metricUuids) {
- return mapper(dbSession).selectForProjectsByMetricUuids(metricUuids);
+ public List<ProjectMainBranchLiveMeasureDto> selectForProjectMainBranchesByMetricUuids(DbSession dbSession, Collection<String> metricUuids) {
+ return mapper(dbSession).selectForProjectMainBranchesByMetricUuids(metricUuids);
}
public void scrollSelectByComponentUuidAndMetricKeys(DbSession dbSession, String componentUuid, Collection<String> metricKeys, ResultHandler<LiveMeasureDto> handler) {
@Param("componentUuids") Collection<String> componentUuids,
@Param("metricUuids") Collection<String> metricUuids);
- List<LiveMeasureDto> selectForProjectsByMetricUuids(
+ List<ProjectMainBranchLiveMeasureDto> selectForProjectMainBranchesByMetricUuids(
@Param("metricUuids") Collection<String> metricUuids);
List<LiveMeasureDto> selectByComponentUuidsAndMetricKeys(
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.db.measure;
+
+import javax.annotation.Nullable;
+
+public class ProjectMainBranchLiveMeasureDto {
+ private String projectUuid;
+ private String metricUuid;
+ @Nullable
+ private Double value;
+ @Nullable
+ private String textValue;
+
+ public String getProjectUuid() {
+ return projectUuid;
+ }
+
+ @Nullable
+ public Double getValue() {
+ return value;
+ }
+
+ @Nullable
+ public String getTextValue() {
+ return textValue;
+ }
+
+ public String getMetricUuid() {
+ return metricUuid;
+ }
+}
return mapper(dbSession).selectAssociatedToProjectUuidAndLanguage(project.getUuid(), language);
}
- public List<QProfileDto> selectAssociatedToProjectUuidAndLanguages(DbSession dbSession, String projectUuid, Collection<String> languages) {
- return executeLargeInputs(languages, partition -> mapper(dbSession).selectAssociatedToProjectUuidAndLanguages(projectUuid, partition));
- }
-
public List<QProfileDto> selectAssociatedToProjectAndLanguages(DbSession dbSession, ProjectDto project, Collection<String> languages) {
- return selectAssociatedToProjectUuidAndLanguages(dbSession, project.getUuid(), languages);
- }
-
- public List<String> selectQProfileUuidsByProjectUuid(DbSession dbSession, String projectUuid) {
- return mapper(dbSession).selectQProfileUuidsByProjectUuid(projectUuid);
+ return executeLargeInputs(languages, partition -> mapper(dbSession).selectAssociatedToProjectUuidAndLanguages(project.getUuid(), partition));
}
public List<QProfileDto> selectQProfilesByProjectUuid(DbSession dbSession, String projectUuid) {
@Param("projectUuid") String projectUuid,
@Param("languages") Collection<String> languages);
- List<String> selectQProfileUuidsByProjectUuid(@Param("projectUuid") String projectUuid);
-
List<QProfileDto> selectQProfilesByProjectUuid(@Param("projectUuid") String projectUuid);
void insertProjectProfileAssociation(
ca.node_name as nodeName,
ca.task_type as taskType,
ca.component_uuid as componentUuid,
- ca.main_component_uuid as mainComponentUuid,
+ ca.entity_uuid as entityUuid,
ca.analysis_uuid as analysisUuid,
ca.status as status,
ca.submitter_uuid as submitterUuid,
<if test="query.onlyCurrents">
and ca.main_is_last=${_true}
</if>
- <if test="query.mainComponentUuids != null and query.mainComponentUuids.size()>0">
- and ca.main_component_uuid in
- <foreach collection="query.mainComponentUuids" open="(" close=")" item="cUuid" separator=",">
+ <if test="query.entityUuids != null and query.entityUuids.size()>0">
+ and ca.entity_uuid in
+ <foreach collection="query.entityUuids" open="(" close=")" item="cUuid" separator=",">
#{cUuid,jdbcType=VARCHAR}
</foreach>
</if>
ca.created_at > #{afterDate,jdbcType=BIGINT}
</select>
- <select id="countLastByStatusAndMainComponentUuid" resultType="int">
+ <select id="countLastByStatusAndEntityUuid" resultType="int">
select
count(1)
from
where
main_is_last=${_true}
and status=#{status,jdbcType=VARCHAR}
- <if test="mainComponentUuid!=null">
- and main_component_uuid=#{mainComponentUuid,jdbcType=VARCHAR}
+ <if test="entityUuid!=null">
+ and entity_uuid=#{entityUuid,jdbcType=VARCHAR}
</if>
</select>
uuid,
node_name,
component_uuid,
- main_component_uuid,
+ entity_uuid,
analysis_uuid,
status,
task_type,
#{uuid,jdbcType=VARCHAR},
#{nodeName,jdbcType=VARCHAR},
#{componentUuid,jdbcType=VARCHAR},
- #{mainComponentUuid,jdbcType=VARCHAR},
+ #{entityUuid,jdbcType=VARCHAR},
#{analysisUuid,jdbcType=VARCHAR},
#{status,jdbcType=VARCHAR},
#{taskType,jdbcType=VARCHAR},
cq.uuid,
cq.task_type as taskType,
cq.component_uuid as componentUuid,
- cq.main_component_uuid as mainComponentUuid,
+ cq.entity_uuid as entityUuid,
cq.status as status,
cq.submitter_uuid as submitterUuid,
cq.worker_uuid as workerUuid,
cq.uuid=#{uuid,jdbcType=VARCHAR}
</select>
- <select id="countByStatusAndMainComponentUuid" parameterType="map" resultType="int">
+ <select id="countByStatusAndEntityUuid" parameterType="map" resultType="int">
select
count(1)
from
ce_queue
where
status=#{status,jdbcType=VARCHAR}
- <if test="mainComponentUuid!=null">
- and main_component_uuid=#{mainComponentUuid,jdbcType=VARCHAR}
+ <if test="entityUuid!=null">
+ and entity_uuid=#{entityUuid,jdbcType=VARCHAR}
</if>
</select>
- <select id="selectCreationDateOfOldestPendingByMainComponentUuid" parameterType="map" resultType="Long">
+ <select id="selectCreationDateOfOldestPendingByEntityUuid" parameterType="map" resultType="Long">
select
min(created_at)
from
ce_queue
where
status='PENDING'
- <if test="mainComponentUuid!=null">
- and main_component_uuid=#{mainComponentUuid,jdbcType=VARCHAR}
+ <if test="entityUuid!=null">
+ and entity_uuid=#{entityUuid,jdbcType=VARCHAR}
</if>
</select>
- <select id="countByStatusAndMainComponentUuids" resultType="org.sonar.db.ce.QueueCount">
+ <select id="countByStatusAndEntityUuids" resultType="org.sonar.db.ce.QueueCount">
select
- main_component_uuid as mainComponentUuid,
+ entity_uuid as entityUuid,
count(1) as total
from
ce_queue
where
status=#{status,jdbcType=VARCHAR}
- and main_component_uuid in
- <foreach collection="mainComponentUuids" open="(" close=")" item="mainComponentUuid" separator=",">
- #{mainComponentUuid,jdbcType=VARCHAR}
+ and entity_uuid in
+ <foreach collection="entityUuids" open="(" close=")" item="entityUuid" separator=",">
+ #{entityUuid,jdbcType=VARCHAR}
</foreach>
- group by main_component_uuid
+ group by entity_uuid
</select>
<select id="countAll" resultType="int">
ce_queue
</select>
- <select id="selectByMainComponentUuid" parameterType="String" resultType="org.sonar.db.ce.CeQueueDto">
+ <select id="selectByEntityUuid" parameterType="String" resultType="org.sonar.db.ce.CeQueueDto">
select
<include refid="columns"/>
from
ce_queue cq
where
- cq.main_component_uuid=#{mainComponentUuid,jdbcType=VARCHAR}
+ cq.entity_uuid=#{entityUuid,jdbcType=VARCHAR}
<include refid="orderByDateAndUuid"/>
</select>
from
ce_queue cq
<where>
- <if test="query.mainComponentUuids != null and query.mainComponentUuids.size()>0">
- and cq.main_component_uuid in
- <foreach collection="query.mainComponentUuids" open="(" close=")" item="mainComponentUuid" separator=",">
- #{mainComponentUuid,jdbcType=VARCHAR}
+ <if test="query.entityUuids != null and query.entityUuids.size()>0">
+ and cq.entity_uuid in
+ <foreach collection="query.entityUuids" open="(" close=")" item="entityUuid" separator=",">
+ #{entityUuid,jdbcType=VARCHAR}
</foreach>
</if>
<if test="query.statuses != null">
from
ce_queue cq
<if test="excludeViewRefresh">
- left join components c on c.uuid = cq.main_component_uuid and c.qualifier <> 'VW'
+ left join components c on c.uuid = cq.entity_uuid and c.qualifier <> 'VW'
</if>
- left join ce_queue cq2 on cq.main_component_uuid=cq2.main_component_uuid and cq2.status <>'PENDING'
+ left join ce_queue cq2 on cq.entity_uuid=cq2.entity_uuid and cq2.status <>'PENDING'
where
cq.status='PENDING'
and cq.started_at is null
uuid,
task_type,
component_uuid,
- main_component_uuid,
+ entity_uuid,
status,
submitter_uuid,
worker_uuid,
#{uuid,jdbcType=VARCHAR},
#{taskType,jdbcType=VARCHAR},
#{componentUuid,jdbcType=VARCHAR},
- #{mainComponentUuid,jdbcType=VARCHAR},
+ #{entityUuid,jdbcType=VARCHAR},
#{status,jdbcType=VARCHAR},
#{submitterUuid,jdbcType=VARCHAR},
#{workerUuid,jdbcType=VARCHAR},
<sql id="oldestPendingPrOrBranch">
cq.uuid as ceTaskUuid,
- cq.main_component_uuid as mainComponentUuid,
+ cq.entity_uuid as entityUuid,
cq.component_uuid as componentUuid,
cq.created_at as createdAt,
cq.task_type as taskType,
<select id="selectInProgressWithCharacteristics" resultType="org.sonar.db.ce.PrOrBranchTask">
select
cq.uuid as ceTaskUuid,
- cq.main_component_uuid as mainComponentUuid,
+ cq.entity_uuid as entityUuid,
cq.created_at as createdAt,
coalesce(ctc.kee, 'branch') as branchType,
cq.task_type as taskType,
</foreach>
</select>
- <select id="selectForProjectsByMetricUuids" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto">
- select <include refid="columns"/> from live_measures lm
+ <select id="selectForProjectMainBranchesByMetricUuids" parameterType="map" resultType="org.sonar.db.measure.ProjectMainBranchLiveMeasureDto">
+ select p.uuid as projectUuid, lm.metric_uuid as metricUuid, lm.value as value, lm.text_value as textValue
+ from live_measures lm
+ inner join project_branches pb on pb.uuid = lm.component_uuid
+ inner join projects p on p.uuid = pb.project_uuid
where
lm.metric_uuid in <foreach item="metricUuid" collection="metricUuids" open="(" separator=","
close=")">#{metricUuid, jdbcType=VARCHAR}</foreach>
- and component_uuid in (SELECT
- p.uuid as uuid
- FROM projects p
- where p.qualifier = 'TRK')
+ and p.qualifier = 'TRK'
</select>
<select id="selectByComponentUuidsAndMetricKeys" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto">
select count(1)
from live_measures lm
inner join metrics m on m.uuid = lm.metric_uuid AND m.name = #{metric, jdbcType=VARCHAR}
- inner join projects p on p.uuid = lm.project_uuid and p.qualifier = 'TRK'
+ inner join project_branches pb on pb.uuid = lm.project_uuid
+ inner join projects p on p.uuid = pb.project_uuid and p.qualifier = 'TRK'
+
</select>
<insert id="insert" parameterType="map" useGeneratedKeys="false">
created_at < #{createdAtBefore,jdbcType=BIGINT}
and (
component_uuid=#{rootUuid,jdbcType=VARCHAR}
- or main_component_uuid=#{rootUuid,jdbcType=VARCHAR}
+ or entity_uuid=#{rootUuid,jdbcType=VARCHAR}
)
</when>
<when test="createdAtBefore != null">
</when>
<when test="rootUuid != null">
component_uuid=#{rootUuid,jdbcType=VARCHAR}
- or main_component_uuid=#{rootUuid,jdbcType=VARCHAR}
+ or entity_uuid=#{rootUuid,jdbcType=VARCHAR}
</when>
<!-- safety net when both variables are null to never generate a
delete statement deleting the whole table -->
from ce_queue
where
component_uuid=#{rootUuid,jdbcType=VARCHAR}
- or main_component_uuid=#{rootUuid,jdbcType=VARCHAR}
+ or entity_uuid=#{rootUuid,jdbcType=VARCHAR}
)
</delete>
from ce_queue
where
component_uuid=#{rootUuid,jdbcType=VARCHAR}
- or main_component_uuid=#{rootUuid,jdbcType=VARCHAR}
+ or entity_uuid=#{rootUuid,jdbcType=VARCHAR}
)
</delete>
from ce_queue
where
component_uuid=#{rootUuid,jdbcType=VARCHAR}
- or main_component_uuid=#{rootUuid,jdbcType=VARCHAR}
+ or entity_uuid=#{rootUuid,jdbcType=VARCHAR}
)
</delete>
from ce_queue
where
component_uuid=#{rootUuid,jdbcType=VARCHAR}
- or main_component_uuid=#{rootUuid,jdbcType=VARCHAR}
+ or entity_uuid=#{rootUuid,jdbcType=VARCHAR}
)
</delete>
delete from ce_queue
where
component_uuid=#{rootUuid,jdbcType=VARCHAR}
- or main_component_uuid=#{rootUuid,jdbcType=VARCHAR}
+ or entity_uuid=#{rootUuid,jdbcType=VARCHAR}
</delete>
<delete id="deleteNewCodePeriodsByRootUuid">
and pqp.project_uuid = #{projectUuid, jdbcType=VARCHAR}
</select>
- <select id="selectQProfileUuidsByProjectUuid" parameterType="String" resultType="String">
- SELECT profile_key
- FROM project_qprofiles
- <where>
- AND project_uuid=#{projectUuid}
- </where>
- </select>
-
<select id="selectQProfilesByProjectUuid" parameterType="String" resultType="org.sonar.db.qualityprofile.QProfileDto">
select
<include refid="qProfileColumns"/>
CREATE TABLE "CE_ACTIVITY"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"TASK_TYPE" CHARACTER VARYING(40) NOT NULL,
- "MAIN_COMPONENT_UUID" CHARACTER VARYING(40),
+ "ENTITY_UUID" CHARACTER VARYING(40),
"COMPONENT_UUID" CHARACTER VARYING(40),
"STATUS" CHARACTER VARYING(15) NOT NULL,
"MAIN_IS_LAST" BOOLEAN NOT NULL,
CREATE INDEX "CE_ACTIVITY_COMPONENT" ON "CE_ACTIVITY"("COMPONENT_UUID" NULLS FIRST);
CREATE INDEX "CE_ACTIVITY_ISLAST" ON "CE_ACTIVITY"("IS_LAST" NULLS FIRST, "STATUS" NULLS FIRST);
CREATE INDEX "CE_ACTIVITY_ISLAST_KEY" ON "CE_ACTIVITY"("IS_LAST_KEY" NULLS FIRST);
-CREATE INDEX "CE_ACTIVITY_MAIN_COMPONENT" ON "CE_ACTIVITY"("MAIN_COMPONENT_UUID" NULLS FIRST);
+CREATE INDEX "CE_ACTIVITY_MAIN_COMPONENT" ON "CE_ACTIVITY"("ENTITY_UUID" NULLS FIRST);
CREATE INDEX "CE_ACTIVITY_MAIN_ISLAST" ON "CE_ACTIVITY"("MAIN_IS_LAST" NULLS FIRST, "STATUS" NULLS FIRST);
CREATE INDEX "CE_ACTIVITY_MAIN_ISLAST_KEY" ON "CE_ACTIVITY"("MAIN_IS_LAST_KEY" NULLS FIRST);
CREATE TABLE "CE_QUEUE"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"TASK_TYPE" CHARACTER VARYING(40) NOT NULL,
- "MAIN_COMPONENT_UUID" CHARACTER VARYING(40),
+ "ENTITY_UUID" CHARACTER VARYING(40),
"COMPONENT_UUID" CHARACTER VARYING(40),
"STATUS" CHARACTER VARYING(15),
"SUBMITTER_UUID" CHARACTER VARYING(255),
"UPDATED_AT" BIGINT NOT NULL
);
ALTER TABLE "CE_QUEUE" ADD CONSTRAINT "PK_CE_QUEUE" PRIMARY KEY("UUID");
-CREATE INDEX "CE_QUEUE_MAIN_COMPONENT" ON "CE_QUEUE"("MAIN_COMPONENT_UUID" NULLS FIRST);
+CREATE INDEX "CE_QUEUE_MAIN_COMPONENT" ON "CE_QUEUE"("ENTITY_UUID" NULLS FIRST);
CREATE INDEX "CE_QUEUE_COMPONENT" ON "CE_QUEUE"("COMPONENT_UUID" NULLS FIRST);
CREATE TABLE "CE_SCANNER_CONTEXT"(
.setUuid(randomAlphanumeric(10))
.setTaskType(randomAlphanumeric(11))
.setComponentUuid(randomAlphanumeric(12))
- .setMainComponentUuid(randomAlphanumeric(13))
+ .setEntityUuid(randomAlphanumeric(13))
.setSubmitterUuid(randomAlphanumeric(14))
.setWorkerUuid(randomAlphanumeric(15))
.setCreatedAt(now + 9_999)
assertThat(underTest.getUuid()).isEqualTo(ceQueueDto.getUuid());
assertThat(underTest.getTaskType()).isEqualTo(ceQueueDto.getTaskType());
assertThat(underTest.getComponentUuid()).isEqualTo(ceQueueDto.getComponentUuid());
- assertThat(underTest.getMainComponentUuid()).isEqualTo(ceQueueDto.getMainComponentUuid());
+ assertThat(underTest.getEntityUuid()).isEqualTo(ceQueueDto.getEntityUuid());
assertThat(underTest.getIsLastKey()).isEqualTo(ceQueueDto.getTaskType() + ceQueueDto.getComponentUuid());
assertThat(underTest.getIsLast()).isFalse();
- assertThat(underTest.getMainIsLastKey()).isEqualTo(ceQueueDto.getTaskType() + ceQueueDto.getMainComponentUuid());
+ assertThat(underTest.getMainIsLastKey()).isEqualTo(ceQueueDto.getTaskType() + ceQueueDto.getEntityUuid());
assertThat(underTest.getMainIsLast()).isFalse();
assertThat(underTest.getSubmitterUuid()).isEqualTo(ceQueueDto.getSubmitterUuid());
assertThat(underTest.getWorkerUuid()).isEqualTo(ceQueueDto.getWorkerUuid());
@Test
public void setMainComponentUuid_accepts_null_empty_and_string_40_chars_or_less() {
- underTest.setMainComponentUuid(null);
- underTest.setMainComponentUuid("");
- underTest.setMainComponentUuid("bar");
- underTest.setMainComponentUuid(STR_40_CHARS);
+ underTest.setEntityUuid(null);
+ underTest.setEntityUuid("");
+ underTest.setEntityUuid("bar");
+ underTest.setEntityUuid(STR_40_CHARS);
}
@Test
- public void setMainComponentUuid_throws_IAE_if_value_is_41_chars() {
+ public void seEntityUuid_throws_IAE_if_value_is_41_chars() {
String str_41_chars = STR_40_CHARS + "a";
- assertThatThrownBy(() -> underTest.setMainComponentUuid(str_41_chars))
+ assertThatThrownBy(() -> underTest.setEntityUuid(str_41_chars))
.isInstanceOf(IllegalArgumentException.class)
- .hasMessage("Value is too long for column CE_ACTIVITY.MAIN_COMPONENT_UUID: " + str_41_chars);
+ .hasMessage("Value is too long for column CE_ACTIVITY.ENTITY_UUID: " + str_41_chars);
}
@Test
}
@Test
- public void setMainComponentUuid_accepts_null_empty_and_string_40_chars_or_less() {
- underTest.setMainComponentUuid(null);
- underTest.setMainComponentUuid("");
- underTest.setMainComponentUuid("bar");
- underTest.setMainComponentUuid(STR_40_CHARS);
+ public void setEntityUuid_accepts_null_empty_and_string_40_chars_or_less() {
+ underTest.setEntityUuid(null);
+ underTest.setEntityUuid("");
+ underTest.setEntityUuid("bar");
+ underTest.setEntityUuid(STR_40_CHARS);
}
@Test
- public void setMainComponentUuid_throws_IAE_if_value_is_41_chars() {
+ public void setEntityUuid_throws_IAE_if_value_is_41_chars() {
String str_41_chars = STR_40_CHARS + "a";
- assertThatThrownBy(() -> underTest.setMainComponentUuid(str_41_chars))
+ assertThatThrownBy(() -> underTest.setEntityUuid(str_41_chars))
.isInstanceOf(IllegalArgumentException.class)
- .hasMessage("Value is too long for column CE_QUEUE.MAIN_COMPONENT_UUID: " + str_41_chars);
+ .hasMessage("Value is too long for column CE_QUEUE.ENTITY_UUID: " + str_41_chars);
}
@Test
CeTaskQuery underTest = new CeTaskQuery();
@Test
- public void no_filter_on_component_uuids_by_default() {
- assertThat(underTest.getMainComponentUuids()).isNull();
- assertThat(underTest.isShortCircuitedByMainComponentUuids()).isFalse();
+ public void no_filter_on_entity_uuids_by_default() {
+ assertThat(underTest.getEntityUuids()).isNull();
+ assertThat(underTest.isShortCircuitedByEntityUuids()).isFalse();
}
@Test
- public void filter_on_component_uuid() {
- underTest.setMainComponentUuid("UUID1");
- assertThat(underTest.getMainComponentUuids()).containsOnly("UUID1");
- assertThat(underTest.isShortCircuitedByMainComponentUuids()).isFalse();
+ public void filter_on_entity_uuid() {
+ underTest.setEntityUuid("UUID1");
+ assertThat(underTest.getEntityUuids()).containsOnly("UUID1");
+ assertThat(underTest.isShortCircuitedByEntityUuids()).isFalse();
}
@Test
- public void filter_on_multiple_component_uuids() {
- underTest.setMainComponentUuids(asList("UUID1", "UUID2"));
- assertThat(underTest.getMainComponentUuids()).containsOnly("UUID1", "UUID2");
- assertThat(underTest.isShortCircuitedByMainComponentUuids()).isFalse();
+ public void filter_on_multiple_entity_uuids() {
+ underTest.setEntityUuids(asList("UUID1", "UUID2"));
+ assertThat(underTest.getEntityUuids()).containsOnly("UUID1", "UUID2");
+ assertThat(underTest.isShortCircuitedByEntityUuids()).isFalse();
}
/**
- * componentUuid is not null but is set to empty
+ * entityUuid is not null but is set to empty
* --> no results
*/
@Test
- public void short_circuited_if_empty_component_uuid_filter() {
- underTest.setMainComponentUuids(Collections.emptyList());
- assertThat(underTest.getMainComponentUuids()).isEmpty();
- assertThat(underTest.isShortCircuitedByMainComponentUuids()).isTrue();
+ public void short_circuited_if_empty_entity_uuid_filter() {
+ underTest.setEntityUuids(Collections.emptyList());
+ assertThat(underTest.getEntityUuids()).isEmpty();
+ assertThat(underTest.isShortCircuitedByEntityUuids()).isTrue();
}
/**
- * too many componentUuids for SQL request. Waiting for ES to improve this use-case
+ * too many entityUuids for SQL request. Waiting for ES to improve this use-case
* --> no results
*/
@Test
- public void short_circuited_if_too_many_component_uuid_filters() {
+ public void short_circuited_if_too_many_entity_uuid_filters() {
List<String> uuids = new ArrayList<>();
for (int i = 0; i < CeTaskQuery.MAX_COMPONENT_UUIDS + 2; i++) {
uuids.add(String.valueOf(i));
}
- underTest.setMainComponentUuids(uuids);
- assertThat(underTest.getMainComponentUuids()).hasSize(CeTaskQuery.MAX_COMPONENT_UUIDS + 2);
- assertThat(underTest.isShortCircuitedByMainComponentUuids()).isTrue();
+ underTest.setEntityUuids(uuids);
+ assertThat(underTest.getEntityUuids()).hasSize(CeTaskQuery.MAX_COMPONENT_UUIDS + 2);
+ assertThat(underTest.isShortCircuitedByEntityUuids()).isTrue();
}
@Test
return new CeQueueDto()
.setUuid(uuid)
.setComponentUuid(randomAlphanumeric(40))
- .setMainComponentUuid(randomAlphanumeric(39))
+ .setEntityUuid(randomAlphanumeric(39))
.setStatus(CeQueueDto.Status.PENDING)
.setTaskType(CeTaskTypes.REPORT)
.setSubmitterUuid(randomAlphanumeric(255))
return newFileDto(projectOrBranch, directory, Uuids.createFast(), mainBranchUuid);
}
- public static ComponentDto newFileDto(ComponentDto project, @Nullable ComponentDto directory, String fileUuid) {
- return newFileDto(project, directory, fileUuid, null);
+ public static ComponentDto newFileDto(ComponentDto branch, @Nullable ComponentDto directory, String fileUuid) {
+ return newFileDto(branch, directory, fileUuid, null);
}
- public static ComponentDto newFileDto(ComponentDto project, @Nullable ComponentDto directory, String fileUuid, @Nullable String mainBranchUuid) {
+ public static ComponentDto newFileDto(ComponentDto branch, @Nullable ComponentDto directory, String fileUuid, @Nullable String mainBranchUuid) {
String filename = "NAME_" + fileUuid;
- String path = directory != null ? directory.path() + "/" + filename : project.path() + "/" + filename;
- return newChildComponent(fileUuid, project, directory == null ? project : directory)
+ String path = directory != null ? directory.path() + "/" + filename : branch.path() + "/" + filename;
+ return newChildComponent(fileUuid, branch, directory == null ? branch : directory)
.setKey("FILE_KEY_" + fileUuid)
.setName(filename)
.setLongName(path)
.setScope(Scopes.FILE)
- .setBranchUuid(project.branchUuid())
+ .setBranchUuid(branch.branchUuid())
.setMainBranchProjectUuid(mainBranchUuid)
.setQualifier(Qualifiers.FILE)
.setPath(path)
.setLanguage(null);
}
- public static ComponentDto newChildComponent(String uuid, ComponentDto project, ComponentDto parent) {
- checkArgument(project.isPrivate() == parent.isPrivate(),
- "private flag inconsistent between moduleOrProject (%s) and parent (%s)",
- project.isPrivate(), parent.isPrivate());
+ public static ComponentDto newChildComponent(String uuid, ComponentDto branch, ComponentDto parent) {
+ checkArgument(branch.isPrivate() == parent.isPrivate(),
+ "private flag inconsistent between branch (%s) and parent (%s)",
+ branch.isPrivate(), parent.isPrivate());
return new ComponentDto()
.setUuid(uuid)
.setUuidPath(formatUuidPathFromParent(parent))
.setKey(uuid)
- .setBranchUuid(project.branchUuid())
+ .setBranchUuid(branch.branchUuid())
.setCreatedAt(new Date())
.setEnabled(true)
- .setPrivate(project.isPrivate());
+ .setPrivate(branch.isPrivate());
}
return condition;
}
- public Optional<String> selectQGateUuidByComponentUuid(String componentUuid) {
- return dbClient.projectQgateAssociationDao().selectQGateUuidByProjectUuid(dbSession, componentUuid);
+ public Optional<String> selectQGateUuidByProjectUuid(String projectUuid) {
+ return dbClient.projectQgateAssociationDao().selectQGateUuidByProjectUuid(dbSession, projectUuid);
}
public void addGroupPermission(QualityGateDto qualityGateDto, GroupDto group) {
@Override
public void addSteps(MigrationStepRegistry registry) {
registry.add(10_2_000, "Rename 'component_uuid' in 'user_roles' table to 'entity_uuid'", RenameComponentUuidInUserRoles.class)
- .add(10_2_001, "Rename 'component_uuid' in 'group_roles' table to 'entity_uuid'", RenameComponentUuidInGroupRoles.class);
+ .add(10_2_001, "Rename 'component_uuid' in 'group_roles' table to 'entity_uuid'", RenameComponentUuidInGroupRoles.class)
+ .add(10_2_002, "Rename 'main_component_uuid' in 'ce_activity' table to 'entity_uuid'", RenameMainComponentUuidInCeActivity.class)
+ .add(10_2_003, "Rename 'main_component_uuid' in 'ce_queue' table to 'entity_uuid'", RenameMainComponentUuidInCeQueue.class)
+ ;
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.platform.db.migration.version.v102;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.RenameVarcharColumnChange;
+
+public class RenameMainComponentUuidInCeActivity extends RenameVarcharColumnChange {
+
+ private static final String TABLE_NAME = "ce_activity";
+ private static final String OLD_COLUMN_NAME = "main_component_uuid";
+ private static final String NEW_COLUMN_NAME = "entity_uuid";
+
+ public RenameMainComponentUuidInCeActivity(Database db) {
+ super(db, TABLE_NAME, OLD_COLUMN_NAME, NEW_COLUMN_NAME);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.platform.db.migration.version.v102;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.RenameVarcharColumnChange;
+
+public class RenameMainComponentUuidInCeQueue extends RenameVarcharColumnChange {
+
+ private static final String TABLE_NAME = "ce_queue";
+ private static final String OLD_COLUMN_NAME = "main_component_uuid";
+ private static final String NEW_COLUMN_NAME = "entity_uuid";
+
+ public RenameMainComponentUuidInCeQueue(Database db) {
+ super(db, TABLE_NAME, OLD_COLUMN_NAME, NEW_COLUMN_NAME);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.platform.db.migration.version.v102;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.VARCHAR;
+
+public class RenameMainComponentUuidInCeActivityTest {
+ public static final String TABLE_NAME = "ce_activity";
+ public static final String NEW_COLUMN_NAME = "entity_uuid";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(RenameMainComponentUuidInCeActivityTest.class, "schema.sql");
+
+ private final RenameMainComponentUuidInCeActivity underTest = new RenameMainComponentUuidInCeActivity(db.database());
+
+ @Test
+ public void column_is_renamed() throws SQLException {
+ db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME);
+ underTest.execute();
+ db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true);
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME);
+ underTest.execute();
+ underTest.execute();
+ db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.platform.db.migration.version.v102;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.VARCHAR;
+
+public class RenameMainComponentUuidInCeQueueTest {
+ public static final String TABLE_NAME = "ce_queue";
+ public static final String NEW_COLUMN_NAME = "entity_uuid";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(RenameMainComponentUuidInCeQueueTest.class, "schema.sql");
+
+ private final RenameMainComponentUuidInCeQueue underTest = new RenameMainComponentUuidInCeQueue(db.database());
+
+ @Test
+ public void column_is_renamed() throws SQLException {
+ db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME);
+ underTest.execute();
+ db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true);
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME);
+ underTest.execute();
+ underTest.execute();
+ db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true);
+ }
+}
--- /dev/null
+CREATE TABLE "CE_ACTIVITY"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "TASK_TYPE" CHARACTER VARYING(40) NOT NULL,
+ "MAIN_COMPONENT_UUID" CHARACTER VARYING(40),
+ "COMPONENT_UUID" CHARACTER VARYING(40),
+ "STATUS" CHARACTER VARYING(15) NOT NULL,
+ "MAIN_IS_LAST" BOOLEAN NOT NULL,
+ "MAIN_IS_LAST_KEY" CHARACTER VARYING(55) NOT NULL,
+ "IS_LAST" BOOLEAN NOT NULL,
+ "IS_LAST_KEY" CHARACTER VARYING(55) NOT NULL,
+ "SUBMITTER_UUID" CHARACTER VARYING(255),
+ "SUBMITTED_AT" BIGINT NOT NULL,
+ "STARTED_AT" BIGINT,
+ "EXECUTED_AT" BIGINT,
+ "EXECUTION_COUNT" INTEGER NOT NULL,
+ "EXECUTION_TIME_MS" BIGINT,
+ "ANALYSIS_UUID" CHARACTER VARYING(50),
+ "ERROR_MESSAGE" CHARACTER VARYING(1000),
+ "ERROR_STACKTRACE" CHARACTER LARGE OBJECT,
+ "ERROR_TYPE" CHARACTER VARYING(20),
+ "WORKER_UUID" CHARACTER VARYING(40),
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL,
+ "NODE_NAME" CHARACTER VARYING(100)
+);
+ALTER TABLE "CE_ACTIVITY" ADD CONSTRAINT "PK_CE_ACTIVITY" PRIMARY KEY("UUID");
+CREATE INDEX "CE_ACTIVITY_COMPONENT" ON "CE_ACTIVITY"("COMPONENT_UUID" NULLS FIRST);
+CREATE INDEX "CE_ACTIVITY_ISLAST" ON "CE_ACTIVITY"("IS_LAST" NULLS FIRST, "STATUS" NULLS FIRST);
+CREATE INDEX "CE_ACTIVITY_ISLAST_KEY" ON "CE_ACTIVITY"("IS_LAST_KEY" NULLS FIRST);
+CREATE INDEX "CE_ACTIVITY_MAIN_COMPONENT" ON "CE_ACTIVITY"("MAIN_COMPONENT_UUID" NULLS FIRST);
+CREATE INDEX "CE_ACTIVITY_MAIN_ISLAST" ON "CE_ACTIVITY"("MAIN_IS_LAST" NULLS FIRST, "STATUS" NULLS FIRST);
+CREATE INDEX "CE_ACTIVITY_MAIN_ISLAST_KEY" ON "CE_ACTIVITY"("MAIN_IS_LAST_KEY" NULLS FIRST);
--- /dev/null
+CREATE TABLE "CE_QUEUE"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "TASK_TYPE" CHARACTER VARYING(40) NOT NULL,
+ "MAIN_COMPONENT_UUID" CHARACTER VARYING(40),
+ "COMPONENT_UUID" CHARACTER VARYING(40),
+ "STATUS" CHARACTER VARYING(15),
+ "SUBMITTER_UUID" CHARACTER VARYING(255),
+ "STARTED_AT" BIGINT,
+ "WORKER_UUID" CHARACTER VARYING(40),
+ "EXECUTION_COUNT" INTEGER NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "CE_QUEUE" ADD CONSTRAINT "PK_CE_QUEUE" PRIMARY KEY("UUID");
+CREATE INDEX "CE_QUEUE_MAIN_COMPONENT" ON "CE_QUEUE"("MAIN_COMPONENT_UUID" NULLS FIRST);
+CREATE INDEX "CE_QUEUE_COMPONENT" ON "CE_QUEUE"("COMPONENT_UUID" NULLS FIRST);
public class CeTaskTest {
- private CeTask underTest = new CeTask("A", CeTask.Status.SUCCESS);
+ private final CeTask underTest = new CeTask("A", CeTask.Status.SUCCESS);
@Test
public void constructor_throws_NPE_if_id_is_null() {
}
private void removeExistingIndexationTasksForProject(DbSession dbSession, String projectUuid) {
- Set<String> ceQueueUuidsForProject = dbClient.ceQueueDao().selectByMainComponentUuid(dbSession, projectUuid)
+ Set<String> ceQueueUuidsForProject = dbClient.ceQueueDao().selectByEntityUuid(dbSession, projectUuid)
.stream().filter(p -> p.getTaskType().equals(BRANCH_ISSUE_SYNC))
.map(CeQueueDto::getUuid).collect(Collectors.toSet());
Set<String> ceActivityUuidsForProject = dbClient.ceActivityDao().selectByTaskType(dbSession, BRANCH_ISSUE_SYNC)
.stream()
- .filter(ceActivityDto -> projectUuid.equals(ceActivityDto.getMainComponentUuid()))
+ .filter(ceActivityDto -> projectUuid.equals(ceActivityDto.getEntityUuid()))
.map(CeActivityDto::getUuid).collect(Collectors.toSet());
removeIndexationTasks(dbSession, ceQueueUuidsForProject, ceActivityUuidsForProject);
}
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.db.measure.ProjectLocDistributionDto;
+import org.sonar.db.measure.ProjectMainBranchLiveMeasureDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.db.newcodeperiod.NewCodePeriodDto;
import org.sonar.db.qualitygate.ProjectQgateAssociationDto;
return Collections.emptyMap();
}
- return dbClient.liveMeasureDao().selectForProjectsByMetricUuids(dbSession, metricNamesByUuid.keySet())
+ return dbClient.liveMeasureDao().selectForProjectMainBranchesByMetricUuids(dbSession, metricNamesByUuid.keySet())
.stream()
- .collect(groupingBy(LiveMeasureDto::getProjectUuid,
+ .collect(groupingBy(ProjectMainBranchLiveMeasureDto::getProjectUuid,
toMap(lmDto -> metricNamesByUuid.get(lmDto.getMetricUuid()),
lmDto -> Optional.ofNullable(lmDto.getValue()).orElseGet(() -> Double.valueOf(lmDto.getTextValue())),
(oldValue, newValue) -> newValue, HashMap::new)));
dbTester.components().insertProjectBranch(projectDto, b -> b.setBranchType(BRANCH).setUuid(branchUuid));
CeQueueDto mainBranchTask = new CeQueueDto().setUuid("uuid_2").setTaskType(BRANCH_ISSUE_SYNC)
- .setMainComponentUuid(projectDto.getUuid()).setComponentUuid(projectDto.getUuid());
+ .setEntityUuid(projectDto.getUuid()).setComponentUuid(projectDto.getUuid());
dbClient.ceQueueDao().insert(dbTester.getSession(), mainBranchTask);
CeQueueDto branchTask = new CeQueueDto().setUuid("uuid_3").setTaskType(BRANCH_ISSUE_SYNC)
- .setMainComponentUuid(projectDto.getUuid()).setComponentUuid(branchUuid);
+ .setEntityUuid(projectDto.getUuid()).setComponentUuid(branchUuid);
dbClient.ceQueueDao().insert(dbTester.getSession(), branchTask);
ProjectDto anotherProjectDto = dbTester.components().insertPrivateProject().getProjectDto();
CeQueueDto taskOnAnotherProject = new CeQueueDto().setUuid("uuid_4").setTaskType(BRANCH_ISSUE_SYNC)
- .setMainComponentUuid(anotherProjectDto.getUuid()).setComponentUuid("another-branchUuid");
+ .setEntityUuid(anotherProjectDto.getUuid()).setComponentUuid("another-branchUuid");
CeActivityDto canceledTaskOnAnotherProject = new CeActivityDto(taskOnAnotherProject).setStatus(Status.CANCELED);
dbClient.ceActivityDao().insert(dbTester.getSession(), canceledTaskOnAnotherProject);
// verify that the canceled tasks on anotherProject is still here, and was not removed by the project reindexation
assertThat(dbClient.ceActivityDao().selectByTaskType(dbTester.getSession(), BRANCH_ISSUE_SYNC))
.hasSize(1)
- .extracting(CeActivityDto::getMainComponentUuid)
+ .extracting(CeActivityDto::getEntityUuid)
.containsExactly(anotherProjectDto.getUuid());
assertThat(logTester.logs(Level.INFO))
CeActivityDto dto = new CeActivityDto(queueDto);
dto.setComponentUuid(projectDto.getUuid());
- dto.setMainComponentUuid(projectDto.getUuid());
+ dto.setEntityUuid(projectDto.getUuid());
dto.setStatus(status);
dto.setTaskType(CeTaskTypes.BRANCH_ISSUE_SYNC);
dto.setAnalysisUuid(uuid + "_AA");
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.ce.CeActivityDto;
-import org.sonar.db.component.ComponentDto;
+import org.sonar.db.entity.EntityDto;
import org.sonar.server.monitoring.ServerMonitoringMetrics;
import static java.util.Objects.requireNonNull;
try (DbSession dbSession = dbClient.openSession(false)) {
List<CeActivityDto> recentSuccessfulTasks = getRecentSuccessfulTasks(dbSession);
- Collection<String> componentUuids = recentSuccessfulTasks.stream()
- .map(CeActivityDto::getMainComponentUuid)
+ Collection<String> entityUuids = recentSuccessfulTasks.stream()
+ .map(CeActivityDto::getEntityUuid)
.toList();
- List<ComponentDto> componentDtos = dbClient.componentDao().selectByUuids(dbSession, componentUuids);
- Map<String, String> componentUuidAndKeys = componentDtos.stream()
- .collect(Collectors.toMap(ComponentDto::uuid, ComponentDto::getKey));
+ List<EntityDto> entities = dbClient.entityDao().selectByUuids(dbSession, entityUuids);
+ Map<String, String> entityUuidAndKeys = entities.stream()
+ .collect(Collectors.toMap(EntityDto::getUuid, EntityDto::getKey));
- reportObservedDurationForTasks(recentSuccessfulTasks, componentUuidAndKeys);
+ reportObservedDurationForTasks(recentSuccessfulTasks, entityUuidAndKeys);
}
lastUpdatedTimestamp = system.now();
}
.toList();
}
- private void reportObservedDurationForTasks(List<CeActivityDto> tasks, Map<String, String> componentUuidAndKeys) {
+ private void reportObservedDurationForTasks(List<CeActivityDto> tasks, Map<String, String> entityUuidAndKeys) {
for (CeActivityDto task : tasks) {
- String mainComponentUuid = task.getMainComponentUuid();
+ String mainComponentUuid = task.getEntityUuid();
Long executionTimeMs = task.getExecutionTimeMs();
try {
requireNonNull(mainComponentUuid);
requireNonNull(executionTimeMs);
- String mainComponentKey = componentUuidAndKeys.get(mainComponentUuid);
+ String mainComponentKey = entityUuidAndKeys.get(mainComponentUuid);
requireNonNull(mainComponentKey);
metrics.observeComputeEngineTaskDuration(executionTimeMs, task.getTaskType(), mainComponentKey);
import org.sonar.db.ce.CeActivityDao;
import org.sonar.db.ce.CeActivityDto;
import org.sonar.db.ce.CeQueueDto;
-import org.sonar.db.component.ComponentDao;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.entity.EntityDao;
+import org.sonar.db.entity.EntityDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.server.monitoring.ServerMonitoringMetrics;
import static org.mockito.ArgumentMatchers.any;
private final DbClient dbClient = mock(DbClient.class);
private final CeActivityDao ceActivityDao = mock(CeActivityDao.class);
- private final ComponentDao componentDao = mock(ComponentDao.class);
+ private final EntityDao entityDao = mock(EntityDao.class);
private final ServerMonitoringMetrics metrics = mock(ServerMonitoringMetrics.class);
private final Configuration config = mock(Configuration.class);
private final System2 system = mock(System2.class);
@Before
public void before() {
when(dbClient.ceActivityDao()).thenReturn(ceActivityDao);
- when(dbClient.componentDao()).thenReturn(componentDao);
+ when(dbClient.entityDao()).thenReturn(entityDao);
ComponentDto componentDto = new ComponentDto();
componentDto.setKey("key");
}
RecentTasksDurationTask task = new RecentTasksDurationTask(dbClient, metrics, config, system);
List<CeActivityDto> recentTasks = createTasks(5, 0);
- when(componentDao.selectByUuids(any(), any())).thenReturn(createComponentDtos(5));
+ when(entityDao.selectByUuids(any(), any())).thenReturn(createEntityDtos(5));
when(ceActivityDao.selectNewerThan(any(), anyLong())).thenReturn(recentTasks);
task.run();
RecentTasksDurationTask task = new RecentTasksDurationTask(dbClient, metrics, config, system);
List<CeActivityDto> recentTasks = createTasks(1, 1);
- when(componentDao.selectByUuids(any(), any())).thenReturn(createComponentDtos(1));
+ when(entityDao.selectByUuids(any(), any())).thenReturn(createEntityDtos(1));
when(ceActivityDao.selectNewerThan(any(), anyLong())).thenReturn(recentTasks);
task.run();
List<CeActivityDto> recentTasks = createTasks(1, 0);
recentTasks.get(0).setExecutionTimeMs(null);
- when(componentDao.selectByUuids(any(), any())).thenReturn(createComponentDtos(1));
+ when(entityDao.selectByUuids(any(), any())).thenReturn(createEntityDtos(1));
when(ceActivityDao.selectNewerThan(any(), anyLong())).thenReturn(recentTasks);
task.run();
return dtos;
}
- private List<ComponentDto> createComponentDtos(int number) {
- List<ComponentDto> componentDtos = new ArrayList<>();
+ private List<EntityDto> createEntityDtos(int number) {
+ List<EntityDto> entityDtos = new ArrayList<>();
for(int i=0; i<5; i++) {
- ComponentDto component = new ComponentDto();
- component.setUuid(i + "");
- component.setKey(i + "");
- componentDtos.add(component);
+ ProjectDto entity = new ProjectDto();
+ entity.setUuid(i + "");
+ entity.setKey(i + "");
+ entityDtos.add(entity);
}
- return componentDtos;
+ return entityDtos;
}
private CeActivityDto newCeActivityTask(CeActivityDto.Status status) {
CeActivityDto dto = new CeActivityDto(new CeQueueDto());
dto.setStatus(status);
- dto.setMainComponentUuid("0");
+ dto.setEntityUuid("0");
dto.setExecutionTimeMs(1000L);
return dto;
}
public class ProjectDataLoaderIT {
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
assertThat(ceTask.getType()).isEqualTo(CeTaskTypes.REPORT);
assertThat(ceTask.getComponent()).isPresent();
assertThat(ceTask.getComponent().get().getUuid()).isEqualTo(branch.uuid());
- assertThat(ceTask.getComponent().get().getMainComponentUuid()).isEqualTo(project.uuid());
+ assertThat(ceTask.getComponent().get().getEntityUuid()).isEqualTo(project.uuid());
}
private static BranchSupport.ComponentKey createComponentKeyOfBranch(String projectKey) {
package org.sonar.server.ce.queue;
import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Random;
import java.util.stream.IntStream;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.Configuration;
import org.sonar.api.utils.System2;
import org.sonar.ce.queue.CeQueue;
import org.sonar.ce.queue.CeQueueImpl;
verifyReportIsPersisted(TASK_UUID);
verifyNoInteractions(permissionTemplateService);
verify(queue).submit(argThat(submit -> submit.getType().equals(CeTaskTypes.REPORT)
- && submit.getComponent().filter(cpt -> cpt.getUuid().equals(project.uuid()) && cpt.getMainComponentUuid().equals(project.uuid())).isPresent()
+ && submit.getComponent().filter(cpt -> cpt.getUuid().equals(project.uuid()) && cpt.getEntityUuid().equals(project.uuid())).isPresent()
&& submit.getSubmitterUuid().equals(user.getUuid())
&& submit.getUuid().equals(TASK_UUID)));
}
ComponentDto createdProject = db.getDbClient().componentDao().selectByKey(db.getSession(), PROJECT_KEY).get();
verifyReportIsPersisted(TASK_UUID);
verify(queue).submit(argThat(submit -> submit.getType().equals(CeTaskTypes.REPORT)
- && submit.getComponent().filter(cpt -> cpt.getUuid().equals(createdProject.uuid()) && cpt.getMainComponentUuid().equals(createdProject.uuid())).isPresent()
+ && submit.getComponent().filter(cpt -> cpt.getUuid().equals(createdProject.uuid()) && cpt.getEntityUuid().equals(createdProject.uuid())).isPresent()
&& submit.getUuid().equals(TASK_UUID)));
}
queueDto.setTaskType(CeTaskTypes.REPORT);
if (project != null ) {
queueDto.setComponentUuid(project.uuid());
- queueDto.setMainComponentUuid(project.uuid());
+ queueDto.setEntityUuid(project.uuid());
}
queueDto.setUuid(taskUuid);
queueDto.setStatus(status);
CeQueueDto queueDto = new CeQueueDto();
queueDto.setTaskType(CeTaskTypes.REPORT);
queueDto.setComponentUuid(project.uuid());
- queueDto.setMainComponentUuid(project.uuid());
+ queueDto.setEntityUuid(project.uuid());
queueDto.setUuid(taskUuid);
queueDto.setCreatedAt(EXECUTED_AT);
CeActivityDto activityDto = new CeActivityDto(queueDto);
.setStatus(status);
if(componentDto != null) {
ceQueueDto.setComponentUuid(componentDto.uuid())
- .setMainComponentUuid(componentDto.uuid());
+ .setEntityUuid(componentDto.uuid());
}
if (createdAt != null) {
ceQueueDto.setCreatedAt(createdAt);
private void insertActivity(CeActivityDto.Status status, @Nullable ComponentDto dto) {
CeQueueDto ceQueueDto = newCeQueueDto(Uuids.createFast());
ceQueueDto.setComponentUuid(dto.uuid());
- ceQueueDto.setMainComponentUuid(dto.uuid());
+ ceQueueDto.setEntityUuid(dto.uuid());
dbClient.ceActivityDao().insert(dbSession, new CeActivityDto(ceQueueDto)
.setStatus(status));
db.commit();
CeQueueDto queueDto = new CeQueueDto();
queueDto.setTaskType(taskType);
queueDto.setComponentUuid(branch.getUuid());
- queueDto.setMainComponentUuid(branch.getUuid());
+ queueDto.setEntityUuid(branch.getUuid());
queueDto.setUuid(taskUuid);
CeActivityDto activityDto = new CeActivityDto(queueDto);
activityDto.setStatus(status);
CeQueueDto queueDto = new CeQueueDto();
queueDto.setTaskType(CeTaskTypes.REPORT);
queueDto.setComponentUuid(component.uuid());
- queueDto.setMainComponentUuid(component.uuid());
+ queueDto.setEntityUuid(component.uuid());
queueDto.setUuid(taskUuid);
queueDto.setStatus(status);
db.getDbClient().ceQueueDao().insert(db.getSession(), queueDto);
CeQueueDto queueDto = new CeQueueDto();
queueDto.setTaskType(CeTaskTypes.REPORT);
queueDto.setComponentUuid(component.uuid());
- queueDto.setMainComponentUuid(component.uuid());
+ queueDto.setEntityUuid(component.uuid());
queueDto.setUuid(taskUuid);
CeActivityDto activityDto = new CeActivityDto(queueDto);
activityDto.setStatus(status);
public class LiveMeasureComputerImplIT {
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
private final TestProjectIndexers projectIndexer = new TestProjectIndexers();
private MetricDto metric1;
public class LiveMeasureTreeUpdaterImplIT {
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
private final Configuration config = new MapSettings().setProperty(RATING_GRID, "0.05,0.1,0.2,0.5").asConfig();
private LiveMeasureTreeUpdaterImpl treeUpdater;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
-import org.sonar.server.component.TestComponentFinder;
import org.sonar.server.es.EsTester;
import org.sonar.server.es.ProjectIndexer;
import org.sonar.server.es.TestProjectIndexers;
private final TestProjectIndexers projectIndexers = new TestProjectIndexers();
private final Configuration configuration = mock(Configuration.class);
- private final UpdateVisibilityAction underTest = new UpdateVisibilityAction(dbClient, TestComponentFinder.from(dbTester),
- userSessionRule, projectIndexers, new SequenceUuidFactory(), configuration);
+ private final UpdateVisibilityAction underTest = new UpdateVisibilityAction(dbClient, userSessionRule, projectIndexers, new SequenceUuidFactory(), configuration);
private final WsActionTester ws = new WsActionTester(underTest);
private final Random random = new Random();
public void execute_throws_BadRequestException_if_specified_component_has_pending_tasks() {
ProjectData project = randomPublicOrPrivateProject();
IntStream.range(0, 1 + Math.abs(random.nextInt(5)))
- .forEach(i -> insertPendingTask(project.getMainBranchComponent().uuid()));
+ .forEach(i -> insertPendingTask(project.getMainBranchDto()));
request.setParam(PARAM_PROJECT, project.projectKey())
.setParam(PARAM_VISIBILITY, randomVisibility);
userSessionRule.addProjectPermission(UserRole.ADMIN, project.getProjectDto());
public void execute_throws_BadRequestException_if_main_component_of_specified_component_has_in_progress_tasks() {
ProjectData project = randomPublicOrPrivateProject();
IntStream.range(0, 1 + Math.abs(random.nextInt(5)))
- .forEach(i -> insertInProgressTask(project.getMainBranchComponent().uuid()));
+ .forEach(i -> insertInProgressTask(project.getMainBranchDto()));
request.setParam(PARAM_PROJECT, project.projectKey())
.setParam(PARAM_VISIBILITY, randomVisibility);
userSessionRule.addProjectPermission(UserRole.ADMIN, project.getProjectDto());
.containsAll(permissionService.getAllProjectPermissions());
}
- private void insertPendingTask(String projectUuid) {
- insertCeQueueDto(projectUuid, CeQueueDto.Status.PENDING);
+ private void insertPendingTask(BranchDto branch) {
+ insertCeQueueDto(branch, CeQueueDto.Status.PENDING);
}
- private void insertInProgressTask(String projectUuid) {
- insertCeQueueDto(projectUuid, CeQueueDto.Status.IN_PROGRESS);
+ private void insertInProgressTask(BranchDto branch) {
+ insertCeQueueDto(branch, CeQueueDto.Status.IN_PROGRESS);
}
private int counter = 0;
- private void insertCeQueueDto(String projectUuid, CeQueueDto.Status status) {
+ private void insertCeQueueDto(BranchDto branch, CeQueueDto.Status status) {
dbClient.ceQueueDao().insert(dbTester.getSession(), new CeQueueDto()
.setUuid("pending" + counter++)
- .setComponentUuid(projectUuid)
- .setMainComponentUuid(projectUuid)
+ .setComponentUuid(branch.getUuid())
+ .setEntityUuid(branch.getProjectUuid())
.setTaskType("foo")
.setStatus(status));
dbTester.commit();
.setType(CeTaskTypes.PROJECT_EXPORT)
.setUuid(TASK_ID)
.setComponent(component)
- .setMainComponent(component)
+ .setEntity(component)
.build();
}
}
}
private void assertDeselected(ProjectDto project) {
- Optional<String> qGateUuid = db.qualityGates().selectQGateUuidByComponentUuid(project.getUuid());
+ Optional<String> qGateUuid = db.qualityGates().selectQGateUuidByProjectUuid(project.getUuid());
assertThat(qGateUuid)
.isNotNull()
.isEmpty();
}
private void assertSelected(QualityGateDto qualityGate, ProjectDto project) {
- Optional<String> qGateUuid = db.qualityGates().selectQGateUuidByComponentUuid(project.getUuid());
+ Optional<String> qGateUuid = db.qualityGates().selectQGateUuidByProjectUuid(project.getUuid());
assertThat(qGateUuid)
.isNotNull()
.isNotEmpty()
}
private void assertSelected(QualityGateDto qualityGate, ComponentDto project) {
- Optional<String> qGateUuid = db.qualityGates().selectQGateUuidByComponentUuid(project.uuid());
+ Optional<String> qGateUuid = db.qualityGates().selectQGateUuidByProjectUuid(project.uuid());
assertThat(qGateUuid)
.isNotNull()
.isNotEmpty()
public static final String FILE_UUID = "FILE_UUID";
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
HtmlSourceDecorator htmlDecorator = mock(HtmlSourceDecorator.class);
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
WsActionTester tester = new WsActionTester(
new IndexAction(db.getDbClient(), new SourceService(db.getDbClient(), new HtmlSourceDecorator()), userSession, TestComponentFinder.from(db)));
public class LinesActionIT {
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
@Test
public void hide_scmAuthors() {
ProjectData projectData = db.components().insertPublicProject();
- ComponentDto publicProject = projectData.getMainBranchComponent();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
userSession.registerProjects(projectData.getProjectDto());
+ userSession.addProjectBranchMapping(projectData.projectUuid(), mainBranch);
DbFileSources.Data data = DbFileSources.Data.newBuilder()
.addLines(newLineBuilder().setScmAuthor("isaac@asimov.com"))
.build();
- ComponentDto file = insertFileWithData(data, publicProject);
+ ComponentDto file = insertFileWithData(data, mainBranch);
tester.newRequest()
.setParam("uuid", file.uuid())
@Test
public void show_scmAuthors() {
ProjectData projectData = db.components().insertPublicProject();
- ComponentDto publicProject = projectData.getMainBranchComponent();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
UserDto user = db.users().insertUser();
userSession.logIn(user).registerProjects(projectData.getProjectDto());
+ userSession.addProjectBranchMapping(projectData.projectUuid(), mainBranch);
DbFileSources.Data data = DbFileSources.Data.newBuilder()
.addLines(newLineBuilder().setScmAuthor("isaac@asimov.com"))
.build();
- ComponentDto file = insertFileWithData(data, publicProject);
+ ComponentDto file = insertFileWithData(data, mainBranch);
tester.newRequest()
.setParam("uuid", file.uuid())
private static final String PROJECT_UUID = "PROJECT_A";
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
import static org.sonar.server.branch.ws.ProjectBranchesParameters.PARAM_BRANCH;
import static org.sonar.server.branch.ws.ProjectBranchesParameters.PARAM_PROJECT;
import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional;
-import static org.sonar.server.project.Project.from;
public class DeleteAction implements BranchWsAction {
private final DbClient dbClient;
String componentQuery = request.getQ();
if (entity != null) {
- query.setMainComponentUuid(entity.getUuid());
+ query.setEntityUuid(entity.getUuid());
} else if (componentQuery != null) {
- query.setMainComponentUuids(loadComponents(dbSession, componentQuery).stream()
+ query.setEntityUuids(loadComponents(dbSession, componentQuery).stream()
.map(ComponentDto::uuid)
.collect(toList()));
}
private ActivityStatusWsResponse doHandle(Request request) {
try (DbSession dbSession = dbClient.openSession(false)) {
- Optional<EntityDto> component = searchComponent(dbSession, request);
- String componentUuid = component.map(EntityDto::getUuid).orElse(null);
- checkPermissions(component.orElse(null));
- int pendingCount = dbClient.ceQueueDao().countByStatusAndMainComponentUuid(dbSession, CeQueueDto.Status.PENDING, componentUuid);
- int inProgressCount = dbClient.ceQueueDao().countByStatusAndMainComponentUuid(dbSession, CeQueueDto.Status.IN_PROGRESS, componentUuid);
- int failingCount = dbClient.ceActivityDao().countLastByStatusAndMainComponentUuid(dbSession, CeActivityDto.Status.FAILED, componentUuid);
+ Optional<EntityDto> entity = searchEntity(dbSession, request);
+ String entityUuid = entity.map(EntityDto::getUuid).orElse(null);
+ checkPermissions(entity.orElse(null));
+ int pendingCount = dbClient.ceQueueDao().countByStatusAndEntityUuid(dbSession, CeQueueDto.Status.PENDING, entityUuid);
+ int inProgressCount = dbClient.ceQueueDao().countByStatusAndEntityUuid(dbSession, CeQueueDto.Status.IN_PROGRESS, entityUuid);
+ int failingCount = dbClient.ceActivityDao().countLastByStatusAndEntityUuid(dbSession, CeActivityDto.Status.FAILED, entityUuid);
- Optional<Long> creationDate = dbClient.ceQueueDao().selectCreationDateOfOldestPendingByMainComponentUuid(dbSession, componentUuid);
+ Optional<Long> creationDate = dbClient.ceQueueDao().selectCreationDateOfOldestPendingByEntityUuid(dbSession, entityUuid);
ActivityStatusWsResponse.Builder builder = ActivityStatusWsResponse.newBuilder()
.setPending(pendingCount)
}
}
- private Optional<EntityDto> searchComponent(DbSession dbSession, Request request) {
+ private Optional<EntityDto> searchEntity(DbSession dbSession, Request request) {
EntityDto entity = null;
if (request.getComponentKey() != null) {
entity = componentFinder.getEntityByKey(dbSession, request.getComponentKey());
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto component = loadComponent(dbSession, wsRequest);
userSession.checkComponentPermission(UserRole.USER, component);
- List<CeQueueDto> queueDtos = dbClient.ceQueueDao().selectByMainComponentUuid(dbSession, component.uuid());
+ List<CeQueueDto> queueDtos = dbClient.ceQueueDao().selectByEntityUuid(dbSession, component.uuid());
CeTaskQuery activityQuery = new CeTaskQuery()
- .setMainComponentUuid(component.uuid())
+ .setEntityUuid(component.uuid())
.setOnlyCurrents(true);
List<CeActivityDto> activityDtos = dbClient.ceActivityDao().selectByQuery(dbSession, activityQuery, forPage(1).andSize(1));
return null;
}
- public ComponentDto getRootComponent(DbSession dbSession, ProjectWsRef projectRef) {
- return componentFinder.getRootComponentByUuidOrKey(dbSession, projectRef.uuid(), projectRef.key());
- }
-
public GroupUuidOrAnyone findGroup(DbSession dbSession, Request request) {
String groupName = request.mandatoryParam(PARAM_GROUP_NAME);
return groupWsSupport.findGroupOrAnyone(dbSession, groupName);
import org.sonar.server.user.UserSession;
import static java.util.Collections.singleton;
-import static org.sonar.server.project.Project.from;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_PROJECT;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
-import org.sonar.db.component.ComponentDto;
import org.sonar.db.entity.EntityDto;
import org.sonar.db.permission.GroupPermissionDto;
import org.sonar.db.permission.UserPermissionDto;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserId;
-import org.sonar.server.component.ComponentFinder;
import org.sonar.server.es.ProjectIndexer;
import org.sonar.server.es.ProjectIndexers;
import org.sonar.server.exceptions.BadRequestException;
public class UpdateVisibilityAction implements ProjectsWsAction {
private final DbClient dbClient;
- private final ComponentFinder componentFinder;
private final UserSession userSession;
private final ProjectIndexers projectIndexers;
private final UuidFactory uuidFactory;
private final Configuration configuration;
- public UpdateVisibilityAction(DbClient dbClient, ComponentFinder componentFinder, UserSession userSession,
- ProjectIndexers projectIndexers, UuidFactory uuidFactory, Configuration configuration) {
+ public UpdateVisibilityAction(DbClient dbClient, UserSession userSession, ProjectIndexers projectIndexers, UuidFactory uuidFactory, Configuration configuration) {
this.dbClient = dbClient;
- this.componentFinder = componentFinder;
this.userSession = userSession;
this.projectIndexers = projectIndexers;
this.uuidFactory = uuidFactory;
}
private boolean noPendingTask(DbSession dbSession, String entityKey) {
- ComponentDto componentDto = componentFinder.getByKey(dbSession, entityKey);
- return dbClient.ceQueueDao().selectByMainComponentUuid(dbSession, componentDto.uuid()).isEmpty();
+ EntityDto entityDto = dbClient.entityDao().selectByKey(dbSession, entityKey).orElseThrow(() -> new IllegalStateException("Can't find entity " + entityKey));
+ return dbClient.ceQueueDao().selectByEntityUuid(dbSession, entityDto.getUuid()).isEmpty();
}
private void updatePermissionsToPrivate(DbSession dbSession, EntityDto entity) {
private List<ProjectQgateAssociationDto> keepAuthorizedProjects(DbSession dbSession, List<ProjectQgateAssociationDto> projects) {
List<String> projectUuids = projects.stream().map(ProjectQgateAssociationDto::getUuid).collect(MoreCollectors.toList());
- Collection<String> authorizedProjectIds = dbClient.authorizationDao().keepAuthorizedEntityUuids(dbSession, projectUuids, userSession.getUuid(), UserRole.USER);
- return projects.stream().filter(project -> authorizedProjectIds.contains(project.getUuid())).collect(MoreCollectors.toList());
+ Collection<String> authorizedProjectUuids = dbClient.authorizationDao().keepAuthorizedEntityUuids(dbSession, projectUuids, userSession.getUuid(), UserRole.USER);
+ return projects.stream().filter(project -> authorizedProjectUuids.contains(project.getUuid())).collect(MoreCollectors.toList());
}
}
{
"taskId": "TASK_1",
- "projectId": "PROJECT_1"
+ "projectId": "BRANCH_1"
}
public class SubmitActionTest {
private static final String PROJECT_UUID = "PROJECT_1";
- private static final CeTask.Component COMPONENT = new CeTask.Component(PROJECT_UUID, "KEY_1", "NAME_1");
+ private static final String BRANCH_UUID = "BRANCH_1";
+ private static final CeTask.Component ENTITY = new CeTask.Component(PROJECT_UUID, "KEY_1", "NAME_1");
+ private static final CeTask.Component COMPONENT = new CeTask.Component(BRANCH_UUID, "KEY_1", "NAME_1");
private static final CeTask A_CE_TASK = new CeTask.Builder()
.setUuid("TASK_1")
.setType(CeTaskTypes.REPORT)
.setComponent(COMPONENT)
- .setMainComponent(COMPONENT)
+ .setEntity(ENTITY)
.setSubmitter(new CeTask.User("UUID_1", "LOGIN_1"))
.build();
verify(reportSubmitter).submit(eq("my_project"), eq("My Project"), anyMap(), any());
assertThat(submitResponse.getTaskId()).isEqualTo("TASK_1");
- assertThat(submitResponse.getProjectId()).isEqualTo(PROJECT_UUID);
+ assertThat(submitResponse.getProjectId()).isEqualTo(BRANCH_UUID);
}
@Test
verify(reportSubmitter).submit(eq("my_project"), eq(expectedName), anyMap(), any());
assertThat(submitResponse.getTaskId()).isEqualTo("TASK_1");
- assertThat(submitResponse.getProjectId()).isEqualTo(PROJECT_UUID);
+ assertThat(submitResponse.getProjectId()).isEqualTo(BRANCH_UUID);
}
@Test