private Queue<CloudProcess> notYetAddedProcessQueue = new LinkedList<CloudProcess>();
@Test(timeout = 600000)
public void daemon() throws InterruptedException { // In main thread
Solver solver = buildSolver();
CloudBalance cloudBalance = buildPlanningProblem();
SolverThread solverThread = new SolverThread(solver, cloudBalance);
solverThread.start();
// Wait for the solver thread to start up
waitForNextStage();
// Give the solver thread a chance to terminate and get into the daemon waiting state
Thread.sleep(500);
for (int i = 0; i < 8; i++) {
CloudProcess process = notYetAddedProcessQueue.poll();
solver.addProblemFactChange(new AddProcessChange(process));
}
// Wait until those AddProcessChanges are processed
waitForNextStage();
// Give the solver thread some time to solve, terminate and get into the daemon waiting state
Thread.sleep(1000);
while (!notYetAddedProcessQueue.isEmpty()) {
CloudProcess process = notYetAddedProcessQueue.poll();
solver.addProblemFactChange(new AddProcessChange(process));
}
// Wait until those AddProcessChanges are processed
waitForNextStage();
solver.terminateEarly();
try {
// Wait until the solver thread dies.
solverThread.join();
} catch (InterruptedException e) {
throw new IllegalStateException("SolverThread did not die.", e);