use of org.kie.server.api.model.instance.SolverInstance in project droolsjbpm-integration by kiegroup.
the class SolverClientIntegrationTest method cleanUpSolvers.
@After
public void cleanUpSolvers() {
final Map<String, Object> parameters = new HashMap<>();
parameters.put("containerId", CONTAINER_ID);
final ExecutionServerCommand executionServerCommand = new ExecutionServerCommand();
executionServerCommand.setClient("solver");
executionServerCommand.setOperation("getSolvers");
executionServerCommand.setParameters(parameters);
final Object response = runOnExecutionServer(executionServerCommand);
final List<SolverInstance> solverInstances = (List<SolverInstance>) response;
for (SolverInstance solverInstance : solverInstances) {
disposeSolver(solverInstance.getSolverId());
}
}
use of org.kie.server.api.model.instance.SolverInstance in project droolsjbpm-integration by kiegroup.
the class SolverClientIntegrationTest method testGetSolver.
@Test
public void testGetSolver() {
final Map<String, Object> parameters = new HashMap<>();
parameters.put("containerId", CONTAINER_ID);
parameters.put("solverId", CLOUD_BALANCE_SOLVER_ID);
final ExecutionServerCommand executionServerCommand = new ExecutionServerCommand();
executionServerCommand.setClient("solver");
executionServerCommand.setOperation("getSolver");
executionServerCommand.setParameters(parameters);
final Object response = runOnExecutionServer(executionServerCommand);
Assertions.assertThat(response).isNotNull();
Assertions.assertThat(response).isInstanceOf(SolverInstance.class);
final SolverInstance solverInstance = (SolverInstance) response;
Assertions.assertThat(solverInstance.getContainerId()).isEqualTo(CONTAINER_ID);
Assertions.assertThat(solverInstance.getSolverId()).isEqualTo(CLOUD_BALANCE_SOLVER_ID);
}
use of org.kie.server.api.model.instance.SolverInstance in project droolsjbpm-integration by kiegroup.
the class OptaPlannerJmsResponseHandlerIntegrationTest method testSolverWithFireAndForgetResponseHandler.
@Test
public void testSolverWithFireAndForgetResponseHandler() throws Exception {
solverClient.setResponseHandler(new FireAndForgetResponseHandler());
SolverInstance solverInstance = solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
assertThat(solverInstance).isNull();
solverClient.setResponseHandler(new RequestReplyResponseHandler());
KieServerSynchronization.waitForSolver(solverClient, CONTAINER_1_ID, SOLVER_1_ID);
solverClient.setResponseHandler(new FireAndForgetResponseHandler());
solverClient.solvePlanningProblem(CONTAINER_1_ID, SOLVER_1_ID, loadPlanningProblem(5, 15));
solverClient.setResponseHandler(new RequestReplyResponseHandler());
KieServerSynchronization.waitForSolverStatus(solverClient, CONTAINER_1_ID, SOLVER_1_ID, SolverInstance.SolverStatus.SOLVING);
solverClient.setResponseHandler(new FireAndForgetResponseHandler());
solverClient.terminateSolverEarly(CONTAINER_1_ID, SOLVER_1_ID);
solverClient.setResponseHandler(new RequestReplyResponseHandler());
KieServerSynchronization.waitForSolverStatus(solverClient, CONTAINER_1_ID, SOLVER_1_ID, SolverInstance.SolverStatus.NOT_SOLVING);
solverClient.setResponseHandler(new FireAndForgetResponseHandler());
solverClient.disposeSolver(CONTAINER_1_ID, SOLVER_1_ID);
solverClient.setResponseHandler(new RequestReplyResponseHandler());
KieServerSynchronization.waitForSolverDispose(solverClient, CONTAINER_1_ID, SOLVER_1_ID);
List<SolverInstance> solverInstanceList = solverClient.getSolvers(CONTAINER_1_ID);
assertThat(solverInstanceList).isNullOrEmpty();
}
use of org.kie.server.api.model.instance.SolverInstance in project droolsjbpm-integration by kiegroup.
the class OptaplannerIntegrationTest method testGetSolverState.
@Test
public void testGetSolverState() {
SolverInstance solverInstance = solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
assertNotNull(solverInstance);
solverInstance = solverClient.getSolver(CONTAINER_1_ID, SOLVER_1_ID);
assertNotNull(solverInstance);
assertEquals(CONTAINER_1_ID, solverInstance.getContainerId());
assertEquals(SOLVER_1_CONFIG, solverInstance.getSolverConfigFile());
assertEquals(SOLVER_1_ID, solverInstance.getSolverId());
assertEquals(SolverInstance.getSolverInstanceKey(CONTAINER_1_ID, SOLVER_1_ID), solverInstance.getSolverInstanceKey());
assertEquals(SolverInstance.SolverStatus.NOT_SOLVING, solverInstance.getStatus());
assertNotNull(solverInstance.getScoreWrapper());
assertNull(solverInstance.getScoreWrapper().toScore());
}
use of org.kie.server.api.model.instance.SolverInstance in project droolsjbpm-integration by kiegroup.
the class OptaplannerIntegrationTest method testGetBestSolution.
@Test(timeout = 60000)
public void testGetBestSolution() throws Exception {
SolverInstance solverInstance = solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
// Start the solver
Object planningProblem = loadPlanningProblem(10, 30);
solverClient.solvePlanningProblem(CONTAINER_1_ID, SOLVER_1_ID, planningProblem);
Object solution = null;
HardSoftScore score = null;
// The test timeout will interrupt this thread if it takes too long
while (!Thread.currentThread().isInterrupted()) {
solverInstance = solverClient.getSolverWithBestSolution(CONTAINER_1_ID, SOLVER_1_ID);
assertNotNull(solverInstance);
solution = solverInstance.getBestSolution();
ScoreWrapper scoreWrapper = solverInstance.getScoreWrapper();
assertNotNull(scoreWrapper);
if (scoreWrapper.toScore() != null) {
assertEquals(HardSoftScore.class, scoreWrapper.getScoreClass());
score = (HardSoftScore) scoreWrapper.toScore();
}
// Wait until the solver finished initializing the solution
if (solution != null && score != null && score.isSolutionInitialized()) {
break;
}
Thread.sleep(1000);
}
assertNotNull(score);
assertTrue(score.isSolutionInitialized());
assertTrue(score.getHardScore() <= 0);
// A soft score of 0 is impossible because we'll always need at least 1 computer
assertTrue(score.getSoftScore() < 0);
List<?> computerList = (List<?>) KieServerReflections.valueOf(solution, "computerList");
assertEquals(10, computerList.size());
List<?> processList = (List<?>) KieServerReflections.valueOf(solution, "processList");
assertEquals(30, processList.size());
for (Object process : processList) {
Object computer = KieServerReflections.valueOf(process, "computer");
assertNotNull(computer);
// TODO: Change to identity comparation after @XmlID is implemented
assertTrue(computerList.contains(computer));
}
solverClient.disposeSolver(CONTAINER_1_ID, SOLVER_1_ID);
}
Aggregations