Source:
<code>public void testGetBestSolution() throws Exception { SolverInstance instance = new SolverInstance(); instance.setSolverConfigFile( SOLVER_1_CONFIG ); assertSuccess( client.createContainer( CONTAINER_1_ID, new KieContainerResource( CONTAINER_1_ID, kjar1 ) ) ); assertSuccess( solverClient.createSolver( CONTAINER_1_ID, SOLVER_1_ID, instance ) ); instance.setStatus( SolverInstance.SolverStatus.SOLVING ); instance.setPlanningProblem( loadPlanningProblem( 10, 30 ) ); ServiceResponse<SolverInstance> response = solverClient.updateSolverState( CONTAINER_1_ID, SOLVER_1_ID, instance ); assertSuccess( response ); assertEquals( SolverInstance.SolverStatus.SOLVING, response.getResult().getStatus() ); <START> Thread.sleep(5000); <END> ServiceResponse<SolverInstance> solutionResponse = solverClient.getSolverBestSolution(CONTAINER_1_ID, SOLVER_1_ID); assertSuccess(solutionResponse); Solution solution = solutionResponse.getResult().getBestSolution(); assertTrue(solution.getScore() != null); List<?> computerList = (List<?>) valueOf(solution, "computerList"); assertEquals(10, computerList.size()); List<?> processList = (List<?>) valueOf(solution, "processList"); assertEquals(30, processList.size()); for(Object process : processList) { Object computer = valueOf(process, "computer"); assertNotNull(computer); } assertSuccess( solverClient.disposeSolver( CONTAINER_1_ID, SOLVER_1_ID ) ); }</code><technical_language>5000ms is little. a fast machine unnecessarily slows test 5 seconds (that's a lot, 3 formats 15secodns - if other tests this philosophy, long run tests, runs tests committing). slow machines, fail a false negative. original code is intended 1000ms a fast machine 15000ms a slow (and I increase loop 60, slow machine 60000ms is acceptable - infinite loop set a @Test.timeout of 60 seconds - I 'll send a PR later) fact this change fixes problem, means is adhering contract. contract states solution.getScore() is null long solution initialized. Furthermore, I solution is null if solver started yet. I suspect **the race condition is solution of previous run, if solver started yet, instead of null.**</technical_language>

Target:
public void testGetBestSolution() throws Exception { SolverInstance instance = new SolverInstance(); instance.setSolverConfigFile( SOLVER_1_CONFIG ); assertSuccess( client.createContainer( CONTAINER_1_ID, new KieContainerResource( CONTAINER_1_ID, kjar1 ) ) ); assertSuccess( solverClient.createSolver( CONTAINER_1_ID, SOLVER_1_ID, instance ) ); instance.setStatus( SolverInstance.SolverStatus.SOLVING ); instance.setPlanningProblem( loadPlanningProblem( 10, 30 ) ); ServiceResponse<SolverInstance> response = solverClient.updateSolverState( CONTAINER_1_ID, SOLVER_1_ID, instance ); assertSuccess( response ); assertEquals( SolverInstance.SolverStatus.SOLVING, response.getResult().getStatus() ); Solution solution = null; while (!Thread.currentThread().isInterrupted()) { ServiceResponse<SolverInstance> solutionResponse = solverClient.getSolverBestSolution(CONTAINER_1_ID, SOLVER_1_ID); assertSuccess(solutionResponse); solution = solutionResponse.getResult().getBestSolution(); if (solution != null && solution.getScore() != null) { break; } Thread.sleep(1000); } assertTrue(solution.getScore() != null); List<?> computerList = (List<?>) valueOf(solution, "computerList"); assertEquals(10, computerList.size()); List<?> processList = (List<?>) valueOf(solution, "processList"); assertEquals(30, processList.size()); for(Object process : processList) { Object computer = valueOf(process, "computer"); assertNotNull(computer); } assertSuccess( solverClient.disposeSolver( CONTAINER_1_ID, SOLVER_1_ID ) ); }