use of org.kie.server.services.taskassigning.core.model.TaskAssigningSolution in project droolsjbpm-integration by kiegroup.
the class SolverHandlerTest method onSolutionSynchronizedWithUnchangedPeriodTimeoutAndDifferentScoreBestSolution.
@Test
public void onSolutionSynchronizedWithUnchangedPeriodTimeoutAndDifferentScoreBestSolution() {
TaskAssigningSolution initialSolution = prepareStartAndASolutionProduced();
BestSolutionChangedEvent<TaskAssigningSolution> event = mockEvent(true, true);
TaskAssigningSolution nextBestSolution = event.getNewBestSolution();
BendableLongScore initialSolutionScore = initialSolution.getScore();
BendableLongScore modifiedScore = initialSolutionScore.multiply(123);
doReturn(modifiedScore).when(nextBestSolution).getScore();
listenerCaptor.getValue().bestSolutionChanged(event);
SolutionSynchronizer.Result result = SolutionSynchronizer.Result.forUnchangedPeriodTimeout();
synchronizerConsumerCaptor.getValue().accept(result);
verify(solverExecutor, never()).addProblemFactChanges(any(List.class));
verify(solutionProcessor).process(nextBestSolution);
verify(solutionSynchronizer, never()).synchronizeSolution(any(TaskAssigningSolution.class), any(LocalDateTime.class));
}
use of org.kie.server.services.taskassigning.core.model.TaskAssigningSolution in project droolsjbpm-integration by kiegroup.
the class SolverHandlerTest method mockEvent.
@SuppressWarnings("unchecked")
private BestSolutionChangedEvent<TaskAssigningSolution> mockEvent(boolean allChangesProcessed, boolean solutionInitialized) {
BestSolutionChangedEvent<TaskAssigningSolution> event = mock(BestSolutionChangedEvent.class);
doReturn(allChangesProcessed).when(event).isEveryProblemFactChangeProcessed();
TaskAssigningSolution solution = mock(TaskAssigningSolution.class);
BendableLongScore score = BendableLongScore.zero(1, 1).withInitScore(solutionInitialized ? 1 : -1);
doReturn(score).when(solution).getScore();
doReturn(solution).when(event).getNewBestSolution();
return event;
}
use of org.kie.server.services.taskassigning.core.model.TaskAssigningSolution in project droolsjbpm-integration by kiegroup.
the class SolutionProcessorTest method process.
@Test(timeout = TEST_TIMEOUT)
public void process() throws Exception {
CompletableFuture future = startRunnableBase();
doReturn(result).when(delegate).executePlanning(generatedPlan, TARGET_USER_ID);
TaskAssigningSolution solution = new TaskAssigningSolution(-1, new ArrayList<>(), new ArrayList<>());
runnableBase.process(solution);
// wait until the processing has finished
processingFinished.await();
verify(delegate).executePlanning(generatedPlan, TARGET_USER_ID);
assertEquals(result, capturedResult.getExecutionResult());
runnableBase.destroy();
future.get();
assertTrue(runnableBase.isDestroyed());
}
use of org.kie.server.services.taskassigning.core.model.TaskAssigningSolution in project droolsjbpm-integration by kiegroup.
the class SolutionProcessorTest method processWithDelegateError.
@Test(timeout = TEST_TIMEOUT)
public void processWithDelegateError() throws Exception {
CompletableFuture future = startRunnableBase();
TaskAssigningSolution solution = new TaskAssigningSolution(-1, new ArrayList<>(), new ArrayList<>());
RuntimeException generatedError = new RuntimeException("Emulate a service invocation error.");
doThrow(generatedError).when(delegate).executePlanning(generatedPlan, TARGET_USER_ID);
runnableBase.process(solution);
// wait until the processing has finished
processingFinished.await();
assertEquals(generatedError, capturedResult.getException());
runnableBase.destroy();
future.get();
assertTrue(runnableBase.isDestroyed());
}
use of org.kie.server.services.taskassigning.core.model.TaskAssigningSolution in project droolsjbpm-integration by kiegroup.
the class SolutionProcessorTest method processWithInvalidStatusFailure.
@Test
public void processWithInvalidStatusFailure() {
TaskAssigningSolution solution = new TaskAssigningSolution(-1, new ArrayList<>(), new ArrayList<>());
runnableBase.process(solution);
Assertions.assertThatThrownBy(() -> runnableBase.process(solution)).hasMessage("SolutionProcessor process method can only be invoked when the status is STOPPED");
}
Aggregations