Search in sources :

Example 1 with DataEvent

use of org.kie.kogito.taskassigning.service.event.DataEvent in project kogito-apps by kiegroup.

the class EventUtilTest method filterNewestSolutionUpdatedOnBackgroundEvent.

@Test
void filterNewestSolutionUpdatedOnBackgroundEvent() {
    List<DataEvent<?>> eventList = Arrays.asList(SOLUTION_UPDATED_DATA_EVENT_2, SOLUTION_UPDATED_DATA_EVENT_3, SOLUTION_UPDATED_DATA_EVENT_1);
    SolutionUpdatedOnBackgroundDataEvent result = EventUtil.filterNewestSolutionUpdatedOnBackgroundEvent(eventList);
    assertThat(result).isSameAs(SOLUTION_UPDATED_DATA_EVENT_3);
}
Also used : TaskDataEvent(org.kie.kogito.taskassigning.service.event.TaskDataEvent) DataEvent(org.kie.kogito.taskassigning.service.event.DataEvent) UserDataEvent(org.kie.kogito.taskassigning.service.event.UserDataEvent) SolutionUpdatedOnBackgroundDataEvent(org.kie.kogito.taskassigning.service.event.SolutionUpdatedOnBackgroundDataEvent) SolutionUpdatedOnBackgroundDataEvent(org.kie.kogito.taskassigning.service.event.SolutionUpdatedOnBackgroundDataEvent) Test(org.junit.jupiter.api.Test)

Example 2 with DataEvent

use of org.kie.kogito.taskassigning.service.event.DataEvent in project kogito-apps by kiegroup.

the class EventUtilTest method filterNewestTaskEventsInContext.

@Test
void filterNewestTaskEventsInContext() {
    TaskAssigningServiceContext context = new TaskAssigningServiceContext();
    context.setTaskLastEventTime(TASK_2, TASK_2_EVENT_1.getEventTime());
    context.setTaskLastEventTime(TASK_3, TASK_3_EVENT_2.getEventTime());
    context.setTaskLastEventTime(TASK_4, TASK_4_EVENT_3.getEventTime());
    List<DataEvent<?>> eventList = buildDataEvents();
    List<TaskDataEvent> result = EventUtil.filterNewestTaskEventsInContext(context, eventList);
    assertThat(result).hasSize(3).contains(TASK_1_EVENT_3, TASK_2_EVENT_3, TASK_3_EVENT_3);
    assertThat(context.getTaskLastEventTime(TASK_1)).isEqualTo(TASK_1_EVENT_3.getEventTime());
    assertThat(context.getTaskLastEventTime(TASK_2)).isEqualTo(TASK_2_EVENT_3.getEventTime());
    assertThat(context.getTaskLastEventTime(TASK_3)).isEqualTo(TASK_3_EVENT_3.getEventTime());
    assertThat(context.getTaskLastEventTime(TASK_4)).isEqualTo(TASK_4_EVENT_3.getEventTime());
}
Also used : TaskDataEvent(org.kie.kogito.taskassigning.service.event.TaskDataEvent) TaskDataEvent(org.kie.kogito.taskassigning.service.event.TaskDataEvent) DataEvent(org.kie.kogito.taskassigning.service.event.DataEvent) UserDataEvent(org.kie.kogito.taskassigning.service.event.UserDataEvent) SolutionUpdatedOnBackgroundDataEvent(org.kie.kogito.taskassigning.service.event.SolutionUpdatedOnBackgroundDataEvent) TaskAssigningServiceContext(org.kie.kogito.taskassigning.service.TaskAssigningServiceContext) Test(org.junit.jupiter.api.Test)

Example 3 with DataEvent

use of org.kie.kogito.taskassigning.service.event.DataEvent in project kogito-apps by kiegroup.

the class TaskAssigningServiceTest method onSolutionChangeWhenApplyingPlanningExecutionResult.

@Test
void onSolutionChangeWhenApplyingPlanningExecutionResult() throws Exception {
    prepareStart();
    TaskAssigningSolution initialSolution = buildSolution();
    context.setTaskPublished(TASK_1_ID, false);
    context.setTaskPublished(TASK_2_ID, true);
    context.setTaskPublished(TASK_3_ID, true);
    context.setTaskPublished(TASK_4_ID, true);
    taskAssigningService.onBestSolutionChange(mockEvent(initialSolution, true, true));
    verify(managedExecutor).runAsync(managedExecutorCaptor.capture());
    managedExecutorCaptor.getValue().run();
    verify(planningExecutor).start(planningCaptor.capture(), any());
    assertThat(planningCaptor.getValue()).isNotNull().hasSize(1);
    PlanningItem planningItem = new PlanningItem(Task.newBuilder().id(TASK_1_ID).build(), USER_1_ID);
    PlanningExecutionResult executionResult = new PlanningExecutionResult(Collections.singletonList(new PlanningExecutionResultItem(planningItem)));
    taskAssigningService.onPlanningExecuted(executionResult);
    List<DataEvent<?>> eventList = Arrays.asList(mockTaskDataEvent(TASK_1_ID, TaskState.COMPLETED.value(), TASK_1_LAST_UPDATE.plusSeconds(1)), mockTaskDataEvent(TASK_2_ID, TaskState.ABORTED.value(), TASK_2_LAST_UPDATE.plusSeconds(1)));
    doReturn(eventList).when(serviceEventConsumer).pollEvents();
    TaskAssigningSolution newSolution = buildSolution();
    context.setCurrentChangeSetId(context.nextChangeSetId());
    taskAssigningService.onBestSolutionChange(mockEvent(newSolution, true, true));
    verify(managedExecutor, times(2)).runAsync(managedExecutorCaptor.capture());
    managedExecutorCaptor.getValue().run();
    verify(solverExecutor, times(2)).addProblemFactChanges(problemFactChangesCaptor.capture());
    List<ProblemFactChange<TaskAssigningSolution>> changes = problemFactChangesCaptor.getAllValues().get(1);
    assertHasRemoveTaskChangeForTask(changes, TASK_1_ID);
    assertHasRemoveTaskChangeForTask(changes, TASK_2_ID);
}
Also used : TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) TaskDataEvent(org.kie.kogito.taskassigning.service.event.TaskDataEvent) UserDataEvent(org.kie.kogito.taskassigning.service.event.UserDataEvent) SolutionUpdatedOnBackgroundDataEvent(org.kie.kogito.taskassigning.service.event.SolutionUpdatedOnBackgroundDataEvent) DataEvent(org.kie.kogito.taskassigning.service.event.DataEvent) AssignTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange) ProblemFactChange(org.optaplanner.core.api.solver.ProblemFactChange) AddUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AddUserProblemFactChange) RemoveTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange) AddTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange) Test(org.junit.jupiter.api.Test)

Example 4 with DataEvent

use of org.kie.kogito.taskassigning.service.event.DataEvent in project kogito-apps by kiegroup.

the class TaskAssigningServiceTest method prepareOnSolutionUpdatedOnBackground.

@SuppressWarnings("unchecked")
private void prepareOnSolutionUpdatedOnBackground(BendableLongScore initialSolutionScore, TaskAssigningSolution newBestSolution) throws Exception {
    prepareStart();
    TaskAssigningSolution initialSolution = buildSolutionWithScore(initialSolutionScore);
    context.setTaskPublished(TASK_1_ID, true);
    context.setTaskPublished(TASK_2_ID, true);
    context.setTaskPublished(TASK_3_ID, true);
    context.setTaskPublished(TASK_4_ID, true);
    doReturn(IMPROVE_SOLUTION_ON_BACKGROUND_DURATION).when(config).getImproveSolutionOnBackgroundDuration();
    doReturn(TIMER_ID).when(vertx).setTimer(eq(IMPROVE_SOLUTION_ON_BACKGROUND_DURATION.toMillis()), any(Handler.class));
    taskAssigningService.onBestSolutionChange(mockEvent(initialSolution));
    verify(managedExecutor).runAsync(managedExecutorCaptor.capture());
    managedExecutorCaptor.getValue().run();
    taskAssigningService.onBestSolutionChange(mockEvent(newBestSolution));
    List<DataEvent<?>> eventList = Collections.singletonList(new SolutionUpdatedOnBackgroundDataEvent(TIMER_ID, ZonedDateTime.now()));
    dataEventsConsumerCaptor.getValue().accept(eventList);
    verify(managedExecutor, times(2)).runAsync(managedExecutorCaptor.capture());
    managedExecutorCaptor.getValue().run();
    verify(taskAssigningService).executeSolutionChange(initialSolution);
}
Also used : TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) Handler(io.vertx.core.Handler) TaskDataEvent(org.kie.kogito.taskassigning.service.event.TaskDataEvent) UserDataEvent(org.kie.kogito.taskassigning.service.event.UserDataEvent) SolutionUpdatedOnBackgroundDataEvent(org.kie.kogito.taskassigning.service.event.SolutionUpdatedOnBackgroundDataEvent) DataEvent(org.kie.kogito.taskassigning.service.event.DataEvent) SolutionUpdatedOnBackgroundDataEvent(org.kie.kogito.taskassigning.service.event.SolutionUpdatedOnBackgroundDataEvent)

Example 5 with DataEvent

use of org.kie.kogito.taskassigning.service.event.DataEvent in project kogito-apps by kiegroup.

the class EventUtilTest method filterNewestUserEvent.

@Test
void filterNewestUserEvent() {
    List<DataEvent<?>> eventList = buildDataEvents();
    UserDataEvent result = EventUtil.filterNewestUserEvent(eventList);
    assertThat(result).isSameAs(USER_DATA_EVENT_3);
}
Also used : TaskDataEvent(org.kie.kogito.taskassigning.service.event.TaskDataEvent) DataEvent(org.kie.kogito.taskassigning.service.event.DataEvent) UserDataEvent(org.kie.kogito.taskassigning.service.event.UserDataEvent) SolutionUpdatedOnBackgroundDataEvent(org.kie.kogito.taskassigning.service.event.SolutionUpdatedOnBackgroundDataEvent) UserDataEvent(org.kie.kogito.taskassigning.service.event.UserDataEvent) Test(org.junit.jupiter.api.Test)

Aggregations

DataEvent (org.kie.kogito.taskassigning.service.event.DataEvent)6 SolutionUpdatedOnBackgroundDataEvent (org.kie.kogito.taskassigning.service.event.SolutionUpdatedOnBackgroundDataEvent)6 TaskDataEvent (org.kie.kogito.taskassigning.service.event.TaskDataEvent)6 UserDataEvent (org.kie.kogito.taskassigning.service.event.UserDataEvent)6 Test (org.junit.jupiter.api.Test)4 TaskAssigningSolution (org.kie.kogito.taskassigning.core.model.TaskAssigningSolution)2 AssignTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange)2 ProblemFactChange (org.optaplanner.core.api.solver.ProblemFactChange)2 Handler (io.vertx.core.Handler)1 AddTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange)1 AddUserProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AddUserProblemFactChange)1 RemoveTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange)1 TaskAssigningServiceContext (org.kie.kogito.taskassigning.service.TaskAssigningServiceContext)1