use of cn.edu.zjnu.acm.judge.support.JudgeData in project judge by zjnu-acm.
the class JudgeRunnerTest method test.
@ParameterizedTest(name = "{index}: {0}")
@MethodSource("data")
public void test(String key, Checker checker, Path path) throws IOException {
Path work = Files.createDirectories(Paths.get("target/work/judgeRunnerTest").resolve(key));
Path[] groovyJars = GroovyHolder.getPaths();
assertThat(groovyJars).isNotEmpty();
for (Path groovyJar : groovyJars) {
Files.copy(groovyJar, work.resolve(groovyJar.getFileName().toString()));
}
String cp = Arrays.stream(groovyJars).map(p -> p.getFileName().toString()).collect(Collectors.joining(File.pathSeparator));
String executeCommand = build("java", "-cp", cp, groovy.ui.GroovyMain.class.getName(), "Main.groovy");
Language groovy = Language.builder().name("groovy").sourceExtension("groovy").executeCommand(executeCommand).executableExtension("groovy").description("").timeFactor(2).build();
log.warn("Language groovy: {}", groovy);
languageMapper.save(groovy);
String extension = getExtension(path);
int languageId = findFirstLanguageByExtension(EXTENSION_MAP.get(extension));
Language language = languageMapper.findOne(languageId);
Objects.requireNonNull(language, "language " + languageId + " not exists");
String source = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
RunRecord runRecord = RunRecord.builder().source(source).timeLimit(timeLimit).memoryLimit(memoryLimit).language(language).build();
RunResult runResult = judgeRunner.run(runRecord, work, judgeData, validator, false);
int expectScore = SPECIAL_SCORE.getOrDefault(key, checker.getScore());
String expectedCaseResult = ResultType.getCaseScoreDescription(checker.getStatus());
Status resultStatus = runResult.getType();
if (resultStatus != null) {
assertThat(resultStatus).describedAs("type will either be null or COMPILATION_ERROR," + " if got other result, please modify this file").isEqualTo(Status.COMPILATION_ERROR);
}
String detail1 = runResult.getDetail();
if (resultStatus == Status.COMPILATION_ERROR) {
assertThat(detail1).describedAs("submission detail").isNull();
} else {
List<SubmissionDetailDTO> details = detail1 != null ? submissionService.parseSubmissionDetail(detail1) : null;
String msg = "%s %s %s";
Object[] param = { key, details, expectedCaseResult };
assertThat(runResult.getScore()).describedAs(msg, param).isEqualTo(expectScore);
assertThat(details).describedAs(msg, param).anyMatch(detail -> expectedCaseResult.equals(detail.getResult()));
}
}
use of cn.edu.zjnu.acm.judge.support.JudgeData 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