use of org.acme.schooltimetabling.message.SolverResponse in project optaplanner-quickstarts by kiegroup.
the class TimeTableMessagingHandlerTest method solve.
@Test
@Timeout(TEST_TIMEOUT_SECONDS)
void solve() {
long problemId = 1L;
TimeTable unsolvedTimeTable = createTestTimeTable();
sendSolverRequest(new SolverRequest(problemId, unsolvedTimeTable));
SolverResponse solverResponse = receiveSolverResponse(MESSAGE_RECEIVE_TIMEOUT_SECONDS);
assertThat(SolverResponse.ResponseStatus.SUCCESS == solverResponse.getResponseStatus());
assertThat(problemId == solverResponse.getProblemId());
assertThat(solverResponse.getTimeTable().getLessonList()).hasSameSizeAs(unsolvedTimeTable.getLessonList());
assertThat(solverResponse.getTimeTable().getScore().isFeasible()).isTrue();
}
use of org.acme.schooltimetabling.message.SolverResponse in project optaplanner-quickstarts by kiegroup.
the class TimeTableResource method process.
@Incoming("solver_response")
@Acknowledgment(Acknowledgment.Strategy.POST_PROCESSING)
public void process(String solverResponseMessage) {
SolverResponse solverResponse;
try {
solverResponse = objectMapper.readValue(solverResponseMessage, SolverResponse.class);
} catch (JsonProcessingException ex) {
throw new IllegalStateException("Unable to deserialize the solver response.", ex);
}
if (solverResponse.isSuccess()) {
TimeTable timeTable = solverResponse.getTimeTable();
timeTable.setSolverStatus(SolverStatus.NOT_SOLVING);
timeTableRepository.update(timeTable);
} else {
timeTableRepository.get().setSolverStatus(SolverStatus.NOT_SOLVING);
throw new IllegalStateException("Solving failed with exception class (" + solverResponse.getErrorInfo().getExceptionClassName() + ") and message (" + solverResponse.getErrorInfo().getExceptionMessage() + ").");
}
}
use of org.acme.schooltimetabling.message.SolverResponse in project optaplanner-quickstarts by kiegroup.
the class TimeTableResourceTest method solveAndRetrieve.
@Test
@Timeout(60L)
void solveAndRetrieve() throws JsonProcessingException {
timeTableResource.solve();
await().timeout(AWAIT_TIMEOUT).until(solverRequestSink::received, messages -> messages.size() == 1);
Message<String> solverRequestMessage = solverRequestSink.received().get(0);
SolverRequest solverRequest = objectMapper.readValue(solverRequestMessage.getPayload(), SolverRequest.class);
// Assign one lesson to simulate solving.
TimeTable requestTimeTable = solverRequest.getTimeTable();
Lesson firstLesson = requestTimeTable.getLessonList().get(0);
firstLesson.setRoom(requestTimeTable.getRoomList().get(0));
firstLesson.setTimeslot(requestTimeTable.getTimeslotList().get(0));
SolverResponse solverResponse = new SolverResponse(solverRequest.getProblemId(), requestTimeTable);
solverResponseSource.send(objectMapper.writeValueAsString(solverResponse));
// Wait until the client receives the message and saves the new timetable to a database.
await().timeout(AWAIT_TIMEOUT).until(timeTableResource::getTimeTable, timeTable -> timeTable.getLessonList().get(0).getRoom() != null);
Lesson solvedFirstLesson = timeTableResource.getTimeTable().getLessonList().get(0);
assertThat(solvedFirstLesson.getRoom()).isNotNull();
assertThat(solvedFirstLesson.getTimeslot()).isNotNull();
}
use of org.acme.schooltimetabling.message.SolverResponse in project optaplanner-quickstarts by kiegroup.
the class TimeTableMessagingHandler method replyFailure.
private void replyFailure(Message<String> solverRequestMessage, Long problemId, Throwable throwable) {
SolverResponse solverResponse = new SolverResponse(problemId, new SolverResponse.ErrorInfo(throwable.getClass().getName(), throwable.getMessage()));
reply(solverRequestMessage, solverResponse, serializationException -> {
throw new IllegalStateException("Unable to serialize error response.", serializationException);
});
}
use of org.acme.schooltimetabling.message.SolverResponse in project optaplanner-quickstarts by kiegroup.
the class TimeTableMessagingHandler method replySuccess.
private void replySuccess(Message<String> solverRequestMessage, Long problemId, TimeTable solution) {
SolverResponse solverResponse = new SolverResponse(problemId, solution);
reply(solverRequestMessage, solverResponse, exception -> replyFailure(solverRequestMessage, problemId, exception));
}
Aggregations