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);
}
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());
}
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);
}
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);
}
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);
}
Aggregations