Search in sources :

Example 16 with TaskInfo

use of com.enonic.xp.task.TaskInfo in project xp by enonic.

the class ClusteredTaskManagerImplTest method getAllTasks_collect_data_from_all_members.

@Test
void getAllTasks_collect_data_from_all_members() {
    final TaskId taskId1 = TaskId.from("someTask1");
    final TaskId taskId2 = TaskId.from("someTask2");
    final Member member1 = mock(Member.class);
    final Member member2 = mock(Member.class);
    when(executorService.submitToAllMembers(any(TasksReporterCallable.class))).thenReturn(Map.of(member1, CompletableFuture.completedFuture(List.of(TaskInfo.create().id(taskId1).build())), member2, CompletableFuture.completedFuture(List.of(TaskInfo.create().id(taskId2).build()))));
    final List<TaskInfo> taskInfos = clusteredTaskManager.getAllTasks();
    assertNotNull(taskInfos);
    assertEquals(taskInfos.stream().map(TaskInfo::getId).collect(Collectors.toSet()), Set.of(taskId1, taskId2));
}
Also used : TaskInfo(com.enonic.xp.task.TaskInfo) TaskId(com.enonic.xp.task.TaskId) TasksReporterCallable(com.enonic.xp.impl.task.distributed.TasksReporterCallable) Member(com.hazelcast.core.Member) Test(org.junit.jupiter.api.Test)

Example 17 with TaskInfo

use of com.enonic.xp.task.TaskInfo in project xp by enonic.

the class ClusteredTaskManagerImplTest method getRunningTasks_collect_data_from_all_members.

@Test
void getRunningTasks_collect_data_from_all_members() {
    final TaskId taskId1 = TaskId.from("someTask1");
    final TaskId taskId2 = TaskId.from("someTask2");
    final Member member1 = mock(Member.class);
    final Member member2 = mock(Member.class);
    when(executorService.submitToAllMembers(any(TasksReporterCallable.class))).thenReturn(Map.of(member1, CompletableFuture.completedFuture(List.of(TaskInfo.create().id(taskId1).build())), member2, CompletableFuture.completedFuture(List.of(TaskInfo.create().id(taskId2).build()))));
    final List<TaskInfo> taskInfos = clusteredTaskManager.getRunningTasks();
    assertNotNull(taskInfos);
    assertEquals(taskInfos.stream().map(TaskInfo::getId).collect(Collectors.toSet()), Set.of(taskId1, taskId2));
}
Also used : TaskInfo(com.enonic.xp.task.TaskInfo) TaskId(com.enonic.xp.task.TaskId) TasksReporterCallable(com.enonic.xp.impl.task.distributed.TasksReporterCallable) Member(com.hazelcast.core.Member) Test(org.junit.jupiter.api.Test)

Example 18 with TaskInfo

use of com.enonic.xp.task.TaskInfo in project xp by enonic.

the class TaskEventsTest method removed.

@Test
public void removed() {
    TaskInfo taskInfo = TaskInfo.create().id(TaskId.from("task1")).name("name1").description("Task1 description").application(ApplicationKey.from("com.enonic.myapp")).user(PrincipalKey.from("user:store:me")).startTime(Instant.parse("2017-10-01T09:00:00Z")).state(TaskState.FINISHED).build();
    final Event event = TaskEvents.removed(taskInfo);
    assertEquals(TaskEvents.TASK_REMOVED_EVENT, event.getType());
    assertEquals("task1", event.getValueAs(String.class, "id").get());
    assertEquals("name1", event.getValueAs(String.class, "name").get());
    assertEquals("Task1 description", event.getValueAs(String.class, "description").get());
    assertEquals("FINISHED", event.getValueAs(String.class, "state").get());
    assertEquals("com.enonic.myapp", event.getValueAs(String.class, "application").get());
    assertEquals("user:store:me", event.getValueAs(String.class, "user").get());
    assertEquals("2017-10-01T09:00:00Z", event.getValueAs(String.class, "startTime").get());
}
Also used : TaskInfo(com.enonic.xp.task.TaskInfo) Event(com.enonic.xp.event.Event) Test(org.junit.jupiter.api.Test)

Example 19 with TaskInfo

use of com.enonic.xp.task.TaskInfo in project xp by enonic.

the class TaskEventsTest method submitted.

@Test
public void submitted() {
    TaskInfo taskInfo = TaskInfo.create().id(TaskId.from("task1")).name("name1").description("Task1 description").application(ApplicationKey.from("com.enonic.myapp")).user(PrincipalKey.from("user:store:me")).startTime(Instant.parse("2017-10-01T09:00:00Z")).progress(TaskProgress.create().current(2).total(42).info("Processing").build()).build();
    final Event event = TaskEvents.submitted(taskInfo);
    assertEquals(TaskEvents.TASK_SUBMITTED_EVENT, event.getType());
    assertEquals("task1", event.getValueAs(String.class, "id").get());
    assertEquals("name1", event.getValueAs(String.class, "name").get());
    assertEquals("Task1 description", event.getValueAs(String.class, "description").get());
    assertEquals("WAITING", event.getValueAs(String.class, "state").get());
    assertEquals("com.enonic.myapp", event.getValueAs(String.class, "application").get());
    assertEquals("user:store:me", event.getValueAs(String.class, "user").get());
    assertEquals("2017-10-01T09:00:00Z", event.getValueAs(String.class, "startTime").get());
    Map<?, ?> progress = event.getValueAs(Map.class, "progress").get();
    assertEquals(2, progress.get("current"));
    assertEquals(42, progress.get("total"));
    assertEquals("Processing", progress.get("info"));
}
Also used : TaskInfo(com.enonic.xp.task.TaskInfo) Event(com.enonic.xp.event.Event) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 20 with TaskInfo

use of com.enonic.xp.task.TaskInfo in project xp by enonic.

the class TaskEventsTest method failed.

@Test
public void failed() {
    TaskInfo taskInfo = TaskInfo.create().id(TaskId.from("task1")).name("name1").description("Task1 description").application(ApplicationKey.from("com.enonic.myapp")).user(PrincipalKey.from("user:store:me")).startTime(Instant.parse("2017-10-01T09:00:00Z")).state(TaskState.FAILED).build();
    final Event event = TaskEvents.failed(taskInfo);
    assertEquals(TaskEvents.TASK_FAILED_EVENT, event.getType());
    assertEquals("task1", event.getValueAs(String.class, "id").get());
    assertEquals("name1", event.getValueAs(String.class, "name").get());
    assertEquals("Task1 description", event.getValueAs(String.class, "description").get());
    assertEquals("FAILED", event.getValueAs(String.class, "state").get());
    assertEquals("com.enonic.myapp", event.getValueAs(String.class, "application").get());
    assertEquals("user:store:me", event.getValueAs(String.class, "user").get());
    assertEquals("2017-10-01T09:00:00Z", event.getValueAs(String.class, "startTime").get());
}
Also used : TaskInfo(com.enonic.xp.task.TaskInfo) Event(com.enonic.xp.event.Event) Test(org.junit.jupiter.api.Test)

Aggregations

TaskInfo (com.enonic.xp.task.TaskInfo)25 Test (org.junit.jupiter.api.Test)15 TaskId (com.enonic.xp.task.TaskId)9 Event (com.enonic.xp.event.Event)6 TasksReporterCallable (com.enonic.xp.impl.task.distributed.TasksReporterCallable)5 Member (com.hazelcast.core.Member)4 Instant (java.time.Instant)3 List (java.util.List)3 TaskProgress (com.enonic.xp.task.TaskProgress)2 TaskService (com.enonic.xp.task.TaskService)2 TaskState (com.enonic.xp.task.TaskState)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 Branch (com.enonic.xp.branch.Branch)1 RecurringJob (com.enonic.xp.core.internal.concurrent.RecurringJob)1 OsgiSupportMock (com.enonic.xp.core.internal.osgi.OsgiSupportMock)1 AllTasksReporter (com.enonic.xp.impl.task.distributed.AllTasksReporter)1 DescribedTask (com.enonic.xp.impl.task.distributed.DescribedTask)1