import java.util.List;
import java.util.Optional;
import java.util.Set;
+import java.util.stream.StreamSupport;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.api.resources.Qualifiers;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
+import static java.util.stream.Collectors.toSet;
import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
import static org.sonar.api.utils.DateUtils.parseEndingDateOrDateTime;
import static org.sonar.api.utils.DateUtils.parseStartingDateOrDateTime;
private static ActivityResponse buildResponse(Iterable<Ce.Task> queuedTasks, Iterable<Ce.Task> pastTasks, int pageSize) {
Ce.ActivityResponse.Builder wsResponseBuilder = Ce.ActivityResponse.newBuilder();
+ Set<String> pastIds = StreamSupport
+ .stream(pastTasks.spliterator(), false)
+ .map(Ce.Task::getId)
+ .collect(toSet());
+
int nbInsertedTasks = 0;
for (Ce.Task queuedTask : queuedTasks) {
- if (nbInsertedTasks < pageSize) {
+ if (nbInsertedTasks < pageSize && !pastIds.contains(queuedTask.getId())) {
wsResponseBuilder.addTasks(queuedTask);
nbInsertedTasks++;
}
import org.junit.rules.ExpectedException;
import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.utils.System2;
+import org.sonar.api.utils.log.LogTester;
+import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.api.web.UserRole;
import org.sonar.ce.task.taskprocessor.CeTaskProcessor;
import org.sonar.core.util.Uuids;
.setParam(PARAM_TYPE, CeTaskTypes.REPORT)
.setParam(PARAM_STATUS, "SUCCESS,FAILED,CANCELED,IN_PROGRESS,PENDING"));
- assertThat(result.getTasksCount()).isEqualTo(2);
+ assertThat(result.getTasksCount()).isEqualTo(1);
}
@Test
JsonAssert.assertJson(wsResponse.getInput()).isSimilarTo("{\"tasks\":[]}");
}
+ @Test
+ public void filter_out_duplicate_tasks_in_progress_and_success(){
+ logInAsSystemAdministrator();
+ ComponentDto project1 = db.components().insertPrivateProject();
+ ComponentDto project2 = db.components().insertPrivateProject();
+ ComponentDto project3 = db.components().insertPrivateProject();
+ insertQueue("T2", project2, IN_PROGRESS);
+ insertQueue("T3", project3, IN_PROGRESS);
+ insertActivity("T1", project1, SUCCESS);
+ insertActivity("T2", project2, SUCCESS);
+
+ ActivityResponse response = ws.newRequest().setParam("status", "FAILED,IN_PROGRESS,SUCCESS").executeProtobuf(ActivityResponse.class);
+
+ assertThat(response.getTasksList())
+ .extracting(Task::getId)
+ .containsExactlyInAnyOrder("T1","T2","T3");
+ }
+
private void logInAsSystemAdministrator() {
userSession.logIn().setSystemAdministrator();
}