use of cn.edu.zjnu.acm.judge.domain.Problem in project judge by zjnu-acm.
the class ProblemStatusControllerTest method testStatus.
/**
* Test of status method, of class ProblemStatusController.
*
* {@link ProblemStatusController#status(HttpServletRequest, long, Integer, Pageable)}
*/
@Test
public void testStatus() throws Exception {
log.info("status");
Problem problem = Problem.builder().contests(new long[] { 0 }).timeLimit(1000L).memoryLimit(65536L).build();
problemService.save(problem);
long problemId = problem.getId();
MvcResult result = mvc.perform(get("/problemstatus").param("problem_id", Long.toString(problemId))).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML)).andReturn();
}
use of cn.edu.zjnu.acm.judge.domain.Problem in project judge by zjnu-acm.
the class ProblemControllerTest method test.
/**
* {@link ProblemController#save(Problem)}
* {@link ProblemController#findOne(long, String)}
* {@link ProblemController#update(long, Problem, String)}
* {@link ProblemController#delete(long)}
*/
@Test
public void test() throws Exception {
Problem problem = mockDataService.problem(false);
Long id = objectMapper.readValue(mvc.perform(post("/api/problems?_format=json").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsBytes(problem))).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)).andReturn().getResponse().getContentAsString(), Problem.class).getId();
assertThat(id).describedAs("problem id").isNotNull();
assertFalse(findOne(id).getDisabled());
mvc.perform(patch("/api/problems/{id}?_format=json", id).content("{\"disabled\":true}").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isNoContent());
assertTrue(findOne(id).getDisabled());
mvc.perform(patch("/api/problems/{id}?_format=json", id).content("{\"disabled\":false}").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isNoContent());
assertFalse(findOne(id).getDisabled());
mvc.perform(delete("/api/problems/{id}?_format=json", id)).andExpect(status().isNoContent());
BusinessCode code = assertThrows(BusinessException.class, () -> problemService.findOne(id)).getCode();
assertThat(code).isEqualTo(BusinessCode.PROBLEM_NOT_FOUND);
mvc.perform(get("/api/problems/{id}?_format=json", id)).andExpect(status().isNotFound());
mvc.perform(delete("/api/problems/{id}?_format=json", id)).andExpect(status().isNotFound());
mvc.perform(patch("/api/problems/{id}?_format=json", id).content("{}").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isNotFound());
}
use of cn.edu.zjnu.acm.judge.domain.Problem in project judge by zjnu-acm.
the class SubmitControllerTest method testContestSubmitPage.
/**
* Test of contestSubmitPage method, of class SubmitController.
*
* {@link SubmitController#contestSubmitPage(Model, Long, long)}
*/
@Test
public void testContestSubmitPage() throws Exception {
log.info("contestSubmitPage");
User user = mockDataService.user();
Problem problem = mockDataService.problem();
{
mvc.perform(get("/problems/{problemId}/submit", problem.getId()).with(anonymous())).andExpect(forwardedUrl("/unauthorized"));
mvc.perform(get("/problems/{problemId}/submit", problem.getId()).with(user(user.getId()))).andExpect(status().isOk()).andReturn();
}
{
Contest contest = mockDataService.contest();
long problemId = problem.getId();
long contestId = contest.getId();
mvc.perform(get("/contests/{contestId}/problems/{problemId}/submit", contestId, problemId).with(user(user.getId()))).andExpect(status().isOk()).andReturn();
}
}
use of cn.edu.zjnu.acm.judge.domain.Problem in project judge by zjnu-acm.
the class ProblemStatusController method status.
@GetMapping("problemstatus")
@SuppressWarnings("AssignmentToMethodParameter")
public String status(HttpServletRequest request, @RequestParam("problem_id") long id, @RequestParam(value = "language", required = false) Integer language, @PageableDefault(size = 20, sort = { "time", "memory", "code_length" }) Pageable pageable) {
log.debug("{}", pageable);
if (pageable.getPageSize() > 500) {
pageable = PageRequest.of(pageable.getPageNumber(), 500, pageable.getSort());
}
Problem problem = problemService.findOneNoI18n(id);
List<ScoreCount> list = submissionMapper.groupByScore(null, id);
ArrayList<String> scores = new ArrayList<>(list.size());
ArrayList<Long> counts = new ArrayList<>(list.size());
ArrayList<String> urls = new ArrayList<>(list.size());
for (ScoreCount scoreCount : list) {
int score = scoreCount.getScore();
scores.add(ResultType.getShowSourceString(score));
counts.add(scoreCount.getCount());
urls.add(request.getContextPath() + "/status?problem_id=" + id + "&score=" + score);
}
BestSubmissionForm form = BestSubmissionForm.builder().problemId(id).language(language).build();
Page<Submission> page = submissionService.bestSubmission(form, pageable, problem.getSubmitUser());
boolean isAdmin = UserDetailsServiceImpl.isAdministrator(request);
boolean isSourceBrowser = UserDetailsServiceImpl.isSourceBrowser(request);
boolean canView = isAdmin || isSourceBrowser;
request.setAttribute("page", page);
request.setAttribute("sa", Arrays.asList(counts, scores, urls));
request.setAttribute("problem", problem);
request.setAttribute("url", URIBuilder.fromRequest(request).replaceQueryParam("page").toString());
request.setAttribute("canView", canView);
request.setAttribute("currentUserId", SecurityUtils.getUserId());
return "problems/status";
}
use of cn.edu.zjnu.acm.judge.domain.Problem in project judge by zjnu-acm.
the class JudgeServiceImpl method execute.
@Override
public void execute(long submissionId) {
Submission submission = submissionMapper.findOne(submissionId);
if (submission == null) {
throw new BusinessException(BusinessCode.SUBMISSION_NOT_FOUND, submissionId);
}
long problemId = submission.getProblem();
Problem problem = problemService.findOneNoI18n(problemId);
try {
RunRecord runRecord = RunRecord.builder().language(languageService.getAvailableLanguage(submission.getLanguage())).source(submissionDetailMapper.findSourceById(submissionId)).memoryLimit(problem.getMemoryLimit()).timeLimit(problem.getTimeLimit()).build();
Path dataDirectory = systemService.getDataDirectory(problemId);
JudgeData judgeData = JudgeData.parse(dataDirectory);
Path specialFile = systemService.getSpecialJudgeExecutable(problemId);
boolean isSpecial = systemService.isSpecialJudge(problemId);
// 建立临时文件
Path work = systemService.getWorkDirectory(submissionId);
final Validator validator = isSpecial ? new SpecialValidator(specialFile.toString(), work) : SimpleValidator.PE_AS_AC;
boolean deleteTempFile = systemService.isDeleteTempFile();
RunResult runResult = judgeRunner.run(runRecord, work, judgeData, validator, deleteTempFile);
SubmissionDetail detail = SubmissionDetail.builder().id(submissionId).compileInfo(runResult.getCompileInfo()).detail(runResult.getDetail()).systemInfo(runResult.getSystemInfo()).build();
if (runResult.getType() == Status.COMPILATION_ERROR) {
submissionMapper.updateResult(submissionId, ResultType.COMPILE_ERROR, 0, 0);
} else {
int score = runResult.getScore();
long time = runResult.getTime();
long memory = runResult.getMemory();
submissionMapper.updateResult(submissionId, score, time, memory);
}
// TODO return value not handled, we can do nothing for the record not exists in the table now.
submissionDetailMapper.update(detail);
updateSubmissionStatus(submission.getUser(), problemId);
} catch (ThreadDeath | VirtualMachineError error) {
throw error;
} catch (JudgeException | IOException | Error ex) {
log.error("got an exception when judging submission {}", submissionId, ex);
submissionMapper.updateResult(submissionId, ResultType.SYSTEM_ERROR, 0, 0);
StringWriter sw = new StringWriter();
try (PrintWriter pw = new PrintWriter(sw)) {
ex.printStackTrace(pw);
}
submissionDetailMapper.update(SubmissionDetail.builder().id(submissionId).systemInfo(sw.toString()).build());
}
}
Aggregations