@Override public List<TaskExecutionDetails> list(Status status) { return idToExecutionDetails.values() .stream() .filter(details -> details.getStatus().equals(status)) .collect(Guavate.toImmutableList()); }
public static Status fromString(String value) { return Arrays.stream(values()) .filter(status -> status.value.equalsIgnoreCase(value)) .findFirst() .orElseThrow(() -> new IllegalArgumentException( String.format("Unknown status value '%s'", value))); }
@Test void mergingMailboxTaskShouldBeInformative() { MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, ALICE, MailboxConstants.INBOX); String taskId = fixGhostMailboxes(newAliceInbox); with() .spec(webadminSpecification) .basePath(TasksRoutes.BASE) .when() .get(taskId + "/await") .then() .body("status", is(TaskManager.Status.COMPLETED.getValue())) .body("taskId", is(taskId)) .body("additionalInformation.oldMailboxId", is(aliceGhostInboxId.serialize())) .body("additionalInformation.newMailboxId", is(newAliceInbox.serialize())) .body("additionalInformation.totalMessageCount", is(1)) .body("additionalInformation.messageMovedCount", is(1)) .body("additionalInformation.messageFailedCount", is(0)) .body("type", is(MailboxMergingTask.MAILBOX_MERGING)) .body("submitDate", is(not(nullValue()))) .body("startedDate", is(not(nullValue()))) .body("completedDate", is(not(nullValue()))); }
@Test public void listShouldListTaskWhenStatusFilter() throws Exception { CountDownLatch inProgressLatch = new CountDownLatch(1); TaskId taskId = taskManager.submit(() -> { inProgressLatch.countDown(); await(); return Task.Result.COMPLETED; }); inProgressLatch.await(); given() .param("status", TaskManager.Status.IN_PROGRESS.getValue()) .when() .get() .then() .statusCode(HttpStatus.OK_200) .body("", hasSize(1)) .body("[0].status", is(TaskManager.Status.IN_PROGRESS.getValue())) .body("[0].taskId", is(taskId.getValue().toString())) .body("[0].type", is(Task.UNKNOWN)); }
@Test public void listShouldListTaskWhenStatusFilter() throws Exception { CountDownLatch inProgressLatch = new CountDownLatch(1); TaskId taskId = taskManager.submit(() -> { inProgressLatch.countDown(); await(); return Task.Result.COMPLETED; }); inProgressLatch.await(); given() .param("status", TaskManager.Status.IN_PROGRESS.getValue()) .when() .get() .then() .statusCode(HttpStatus.OK_200) .body("", hasSize(1)) .body("[0].status", is(TaskManager.Status.IN_PROGRESS.getValue())) .body("[0].taskId", is(taskId.getValue().toString())) .body("[0].type", is(Task.UNKNOWN)); }
@Test public void listShouldReturnEmptyWhenNonMatchingStatusFilter() throws Exception { CountDownLatch inProgressLatch = new CountDownLatch(1); taskManager.submit(() -> { inProgressLatch.countDown(); await(); return Task.Result.COMPLETED; }); inProgressLatch.await(); given() .param("status", TaskManager.Status.WAITING.getValue()) .when() .get() .then() .statusCode(HttpStatus.OK_200) .body("", hasSize(0)); }
@Test public void listShouldReturnTaskDetailsWhenTaskInProgress() throws Exception { CountDownLatch taskInProgressLatch = new CountDownLatch(1); TaskId taskId = taskManager.submit(() -> { taskInProgressLatch.countDown(); await(); return Task.Result.COMPLETED; }); taskInProgressLatch.await(); when() .get() .then() .statusCode(HttpStatus.OK_200) .body("", hasSize(1)) .body("[0].status", is(TaskManager.Status.IN_PROGRESS.getValue())) .body("[0].taskId", is(taskId.getValue().toString())) .body("[0].class", is(not(empty()))); }
@Test public void listShouldReturnTaskDetailsWhenTaskInProgress() throws Exception { CountDownLatch taskInProgressLatch = new CountDownLatch(1); TaskId taskId = taskManager.submit(() -> { taskInProgressLatch.countDown(); await(); return Task.Result.COMPLETED; }); taskInProgressLatch.await(); when() .get() .then() .statusCode(HttpStatus.OK_200) .body("", hasSize(1)) .body("[0].status", is(TaskManager.Status.IN_PROGRESS.getValue())) .body("[0].taskId", is(taskId.getValue().toString())) .body("[0].class", is(not(empty()))); }
@Test public void listShouldReturnEmptyWhenNonMatchingStatusFilter() throws Exception { CountDownLatch inProgressLatch = new CountDownLatch(1); taskManager.submit(() -> { inProgressLatch.countDown(); await(); return Task.Result.COMPLETED; }); inProgressLatch.await(); given() .param("status", TaskManager.Status.WAITING.getValue()) .when() .get() .then() .statusCode(HttpStatus.OK_200) .body("", hasSize(0)); }
public String getStatus() { return executionDetails.getStatus().getValue(); }