aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ce-common/src/test
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2018-12-19 22:16:05 +0100
committerSonarTech <sonartech@sonarsource.com>2019-01-09 20:21:07 +0100
commit0c376153dd00a6d06efc2d60fe47801d7a9fae96 (patch)
tree7670d6897ac7b8058ad8ceb2653db27eee433f14 /server/sonar-ce-common/src/test
parente428c8d0491dcc6b0b5cab846156d5a542668708 (diff)
downloadsonarqube-0c376153dd00a6d06efc2d60fe47801d7a9fae96.tar.gz
sonarqube-0c376153dd00a6d06efc2d60fe47801d7a9fae96.zip
SONARCLOUD-310 add WS api/ce/timeout_tasks
Diffstat (limited to 'server/sonar-ce-common/src/test')
-rw-r--r--server/sonar-ce-common/src/test/java/org/sonar/ce/queue/CeQueueImplTest.java33
1 files changed, 31 insertions, 2 deletions
diff --git a/server/sonar-ce-common/src/test/java/org/sonar/ce/queue/CeQueueImplTest.java b/server/sonar-ce-common/src/test/java/org/sonar/ce/queue/CeQueueImplTest.java
index fb557a8293e..6f44b7e42b0 100644
--- a/server/sonar-ce-common/src/test/java/org/sonar/ce/queue/CeQueueImplTest.java
+++ b/server/sonar-ce-common/src/test/java/org/sonar/ce/queue/CeQueueImplTest.java
@@ -52,6 +52,7 @@ import static java.util.Arrays.asList;
import static java.util.Collections.emptyMap;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.catchThrowable;
import static org.assertj.core.api.Assertions.tuple;
import static org.hamcrest.Matchers.startsWith;
import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_MAIN_COMPONENT;
@@ -59,8 +60,9 @@ import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_MAIN_COMP
public class CeQueueImplTest {
private static final String WORKER_UUID = "workerUuid";
+ private static final long NOW = 1_450_000_000_000L;
- private System2 system2 = new TestSystem2().setNow(1_450_000_000_000L);
+ private System2 system2 = new TestSystem2().setNow(NOW);
@Rule
public ExpectedException expectedException = ExpectedException.none();
@@ -72,7 +74,7 @@ public class CeQueueImplTest {
private UuidFactory uuidFactory = UuidFactoryImpl.INSTANCE;
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
- private CeQueue underTest = new CeQueueImpl(db.getDbClient(), uuidFactory, defaultOrganizationProvider);
+ private CeQueue underTest = new CeQueueImpl(system2, db.getDbClient(), uuidFactory, defaultOrganizationProvider);
@Test
public void submit_returns_task_populated_from_CeTaskSubmit_and_creates_CeQueue_row() {
@@ -476,6 +478,33 @@ public class CeQueueImplTest {
assertThat(underTest.getWorkersPauseStatus()).isEqualTo(CeQueue.WorkersPauseStatus.RESUMED);
}
+ @Test
+ public void fail_in_progress_task() {
+ CeTask task = submit(CeTaskTypes.REPORT, newComponent(randomAlphabetic(12)));
+ CeQueueDto queueDto = db.getDbClient().ceQueueDao().peek(db.getSession(), WORKER_UUID).get();
+
+ underTest.fail(db.getSession(), queueDto, "TIMEOUT", "Failed on timeout");
+
+ Optional<CeActivityDto> activity = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), task.getUuid());
+ assertThat(activity.isPresent()).isTrue();
+ assertThat(activity.get().getStatus()).isEqualTo(CeActivityDto.Status.FAILED);
+ assertThat(activity.get().getErrorType()).isEqualTo("TIMEOUT");
+ assertThat(activity.get().getErrorMessage()).isEqualTo("Failed on timeout");
+ assertThat(activity.get().getExecutedAt()).isEqualTo(NOW);
+ assertThat(activity.get().getWorkerUuid()).isEqualTo(WORKER_UUID);
+ }
+
+ @Test
+ public void fail_throws_exception_if_task_is_pending() {
+ CeTask task = submit(CeTaskTypes.REPORT, newComponent(randomAlphabetic(12)));
+ CeQueueDto queueDto = db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), task.getUuid()).get();
+
+ Throwable thrown = catchThrowable(() -> underTest.fail(db.getSession(), queueDto, "TIMEOUT", "Failed on timeout"));
+
+ assertThat(thrown)
+ .isInstanceOf(IllegalStateException.class)
+ .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);