use of com.enonic.xp.task.RunnableTask in project xp by enonic.
the class LocalTaskManagerImplTest method submitTaskWithError.
@Test
public void submitTaskWithError() {
final RunnableTask runnableTask = (id, progressReporter) -> {
throw new RuntimeException("Some error");
};
assertEquals(0, taskMan.getAllTasks().size());
assertEquals(0, taskMan.getRunningTasks().size());
assertNull(taskMan.getTaskInfo(TaskId.from("1")));
final DescribedTaskImpl describedTask = new DescribedTaskImpl(runnableTask, "task 1", TEST_TASK_CONTEXT);
taskMan.submitTask(describedTask);
assertNotNull(taskMan.getTaskInfo(describedTask.getTaskId()));
assertEquals(1, taskMan.getAllTasks().size());
assertEquals(0, taskMan.getRunningTasks().size());
assertEquals(TaskState.FAILED, taskMan.getTaskInfo(describedTask.getTaskId()).getState());
assertEquals(4, eventsPublished.size());
assertEquals("task.submitted , task.updated , task.updated , task.failed", eventTypes());
}
use of com.enonic.xp.task.RunnableTask in project xp by enonic.
the class LocalTaskManagerImplTest method testRemoveExpiredTasks.
@Test
public void testRemoveExpiredTasks() throws InterruptedException {
Instant initTime = Instant.now();
taskMan.setClock(Clock.fixed(initTime, ZoneId.systemDefault()));
CountDownLatch latch = new CountDownLatch(1);
RunnableTask runnableTask = (id, progressReporter) -> {
latch.countDown();
};
final DescribedTaskImpl describedTask = new DescribedTaskImpl(runnableTask, "task 1", TEST_TASK_CONTEXT);
taskMan.submitTask(describedTask);
cleanupScheduler.rerun();
assertNotNull(taskMan.getTaskInfo(describedTask.getTaskId()));
assertEquals(1, taskMan.getAllTasks().size());
assertTrue(taskMan.getRunningTasks().size() <= 1);
latch.await();
Instant laterTime = initTime.plus(LocalTaskManagerImpl.KEEP_COMPLETED_MAX_TIME_SEC + 1, ChronoUnit.SECONDS);
taskMan.setClock(Clock.fixed(laterTime, ZoneId.systemDefault()));
cleanupScheduler.rerun();
assertNull(taskMan.getTaskInfo(describedTask.getTaskId()));
assertEquals(0, taskMan.getAllTasks().size());
assertEquals(0, taskMan.getRunningTasks().size());
assertEquals(4, eventsPublished.size());
assertEquals("task.submitted , task.updated , task.finished , task.removed", eventTypes());
}
use of com.enonic.xp.task.RunnableTask in project xp by enonic.
the class LocalTaskManagerImplTest method submitTask.
@Test
public void submitTask() {
final RunnableTask runnableTask = (id, progressReporter) -> {
for (int i = 0; i < 5; i++) {
progressReporter.progress(1, 10);
progressReporter.info("Step " + i);
}
};
assertEquals(0, taskMan.getAllTasks().size());
assertEquals(0, taskMan.getRunningTasks().size());
assertNull(taskMan.getTaskInfo(TaskId.from("1")));
final DescribedTaskImpl describedTask = new DescribedTaskImpl(runnableTask, "task 1", TEST_TASK_CONTEXT);
taskMan.submitTask(describedTask);
assertNotNull(taskMan.getTaskInfo(describedTask.getTaskId()));
for (int i = 0; i < 25; i++) {
final TaskInfo taskInfo = taskMan.getTaskInfo(describedTask.getTaskId());
System.out.printf("Task %s, details: %s\r\n", describedTask.getTaskId(), taskInfo);
System.out.flush();
}
assertEquals(1, taskMan.getAllTasks().size());
assertEquals(0, taskMan.getRunningTasks().size());
assertNotNull(taskMan.getTaskInfo(describedTask.getTaskId()));
assertEquals(13, eventsPublished.size());
assertEquals("task.submitted , task.updated , task.updated , task.updated , task.updated , task.updated , " + "task.updated , task.updated , task.updated , task.updated , task.updated , task.updated , task.finished", eventTypes());
}
use of com.enonic.xp.task.RunnableTask in project xp by enonic.
the class NamedTaskFactoryImplTest method createExisting.
@Test
void createExisting() {
final DescriptorKey descriptorKey = DescriptorKey.from("myapplication:mytask");
final TaskDescriptor descriptor = TaskDescriptor.create().key(descriptorKey).build();
when(taskDescriptorService.getTask(descriptorKey)).thenReturn(descriptor);
final RunnableTask runnableTask = namedTaskScriptFactory.create(descriptor, new PropertyTree());
assertNotNull(runnableTask);
runnableTask.run(TaskId.from("123"), null);
}
Aggregations