use of org.kie.server.api.model.instance.SolverInstance in project droolsjbpm-integration by kiegroup.
the class SolverClientIntegrationTest method getSolverStatus.
private SolverInstance.SolverStatus getSolverStatus() {
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;
return solverInstance.getStatus();
}
use of org.kie.server.api.model.instance.SolverInstance in project droolsjbpm-integration by kiegroup.
the class OptaPlannerJmsResponseHandlerIntegrationTest method testSolverWithAsyncResponseHandler.
@Test
public void testSolverWithAsyncResponseHandler() throws Exception {
Marshaller marshaller = MarshallerFactory.getMarshaller(new HashSet<>(extraClasses.values()), configuration.getMarshallingFormat(), client.getClassLoader());
ResponseCallback responseCallback = new BlockingResponseCallback(marshaller);
ResponseHandler asyncResponseHandler = new AsyncResponseHandler(responseCallback);
solverClient.setResponseHandler(asyncResponseHandler);
SolverInstance response = solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
assertThat(response).isNull();
SolverInstance solver = responseCallback.get(SolverInstance.class);
assertThat(solver).isNotNull();
assertThat(solver.getContainerId()).isEqualTo(CONTAINER_1_ID);
assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
List<SolverInstance> solverInstanceList = solverClient.getSolvers(CONTAINER_1_ID);
assertThat(solverInstanceList).isNull();
SolverInstanceList solverList = responseCallback.get(SolverInstanceList.class);
assertThat(solverList).isNotNull();
assertThat(solverList.getContainers()).isNotNull().isNotEmpty().hasSize(1);
solver = solverList.getContainers().get(0);
assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
assertThat(solver.getStatus()).isEqualTo(SolverInstance.SolverStatus.NOT_SOLVING);
solverClient.solvePlanningProblem(CONTAINER_1_ID, SOLVER_1_ID, loadPlanningProblem(5, 15));
// Make sure the service call result is consumed
responseCallback.get(Void.class);
response = solverClient.getSolver(CONTAINER_1_ID, SOLVER_1_ID);
assertThat(response).isNull();
solver = responseCallback.get(SolverInstance.class);
assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
assertThat(solver.getStatus()).isEqualTo(SolverInstance.SolverStatus.SOLVING);
solverClient.terminateSolverEarly(CONTAINER_1_ID, SOLVER_1_ID);
// Make sure the service call result is consumed
responseCallback.get(Void.class);
response = solverClient.getSolver(CONTAINER_1_ID, SOLVER_1_ID);
assertThat(response).isNull();
solver = responseCallback.get(SolverInstance.class);
assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
assertThat(solver.getStatus()).isIn(SolverInstance.SolverStatus.TERMINATING_EARLY, SolverInstance.SolverStatus.NOT_SOLVING);
solverClient.disposeSolver(CONTAINER_1_ID, SOLVER_1_ID);
// Make sure the service call result is consumed
responseCallback.get(Void.class);
solverClient.getSolvers(CONTAINER_1_ID);
assertThat(response).isNull();
solverList = responseCallback.get(SolverInstanceList.class);
assertThat(solverList).isNotNull();
assertThat(solverList.getContainers()).isNullOrEmpty();
}
use of org.kie.server.api.model.instance.SolverInstance in project droolsjbpm-integration by kiegroup.
the class OptaplannerIntegrationTest method testTerminateEarly.
@Test
public void testTerminateEarly() throws Exception {
solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
// start solver
solverClient.solvePlanningProblem(CONTAINER_1_ID, SOLVER_1_ID, loadPlanningProblem(50, 150));
SolverInstance instance = solverClient.getSolver(CONTAINER_1_ID, SOLVER_1_ID);
assertEquals(SolverInstance.SolverStatus.SOLVING, instance.getStatus());
// and then terminate it
solverClient.terminateSolverEarly(CONTAINER_1_ID, SOLVER_1_ID);
instance = solverClient.getSolver(CONTAINER_1_ID, SOLVER_1_ID);
assertTrue(instance.getStatus() == SolverInstance.SolverStatus.TERMINATING_EARLY || instance.getStatus() == SolverInstance.SolverStatus.NOT_SOLVING);
solverClient.disposeSolver(CONTAINER_1_ID, SOLVER_1_ID);
}
use of org.kie.server.api.model.instance.SolverInstance in project droolsjbpm-integration by kiegroup.
the class OptaplannerIntegrationTest method testCreateDuplicitSolver.
@Test
public void testCreateDuplicitSolver() {
SolverInstance solverInstance = solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
assertNotNull(solverInstance);
try {
solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
fail("A KieServicesException should have been thrown by now.");
} catch (KieServicesException e) {
KieServerAssert.assertResultContainsStringRegex(e.getMessage(), ".*Failed to create solver. Solver .* already exists for container .*");
}
}
use of org.kie.server.api.model.instance.SolverInstance in project droolsjbpm-integration by kiegroup.
the class OptaplannerIntegrationTest method verifySolverAndGetBestSolution.
private Object verifySolverAndGetBestSolution() {
SolverInstance solver = solverClient.getSolverWithBestSolution(CONTAINER_1_ID, SOLVER_1_ID);
assertEquals(SolverInstance.SolverStatus.SOLVING, solver.getStatus());
Object bestSolution = solver.getBestSolution();
assertEquals(bestSolution.getClass().getName(), CLASS_CLOUD_BALANCE);
return bestSolution;
}
Aggregations