Example #1
0
  @Override
  public SubmissionResult checkSubmission()
      throws CloudCoderAuthenticationException, SubmissionException {
    // Make sure user is authenticated
    User user =
        ServletUtil.checkClientIsAuthenticated(getThreadLocalRequest(), RunServiceImpl.class);

    HttpSession session = getThreadLocalRequest().getSession();

    // Retrieve session objects for submission
    IFutureSubmissionResult future =
        (IFutureSubmissionResult)
            session.getAttribute(SessionAttributeKeys.FUTURE_SUBMISSION_RESULT_KEY);

    if (future == null) {
      throw new SubmissionException("No pending submission in session");
    }

    // See if the SubmissionResult is ready
    SubmissionResult result;
    try {
      result = future.waitFor(IFutureSubmissionResult.STANDARD_POLL_WAIT_MS);
    } catch (SubmissionException e) {
      // If poll() throws an exception, the submission completed
      // with an error, but it did complete, so clear the session objects.
      session.removeAttribute(SessionAttributeKeys.FUTURE_SUBMISSION_RESULT_KEY);
      throw e;
    } catch (InterruptedException e) {
      logger.error("checkSubmission interrupted unexpectedly", e);
      return null;
    }
    if (result == null) {
      // submission result not ready yet
      return null;
    }

    // Re-number the test results
    // The Builder thinks it is returning database keys
    // which it doesn't know so it sets everything to -1
    int i = 1;
    for (TestResult r : result.getTestResults()) {
      r.setId(i);
      i++;
    }

    // We are just trusting that the submission result is for the
    // correct problem...

    // TODO Put results into DB once we have a meta-file system set up
    //        SubmissionReceipt receipt = createSubmissionReceipt(fullTextChange, result, user,
    // problem);
    //        Database.getInstance().insertSubmissionReceipt(receipt, result.getTestResults());
    //
    //        int numResult=0;
    //        if (result!=null && result.getTestResults()!=null) {
    //            numResult=result.getTestResults().length;
    //        }
    //        logger.info("Compilation "+result.getCompilationResult()+", received " +numResult+"
    // TestResults");
    //
    //        // Clear session objects for submission
    //        session.removeAttribute(SessionAttributeKeys.FUTURE_SUBMISSION_RESULT_KEY);
    return result;
  }
Example #2
0
  private void testOne(ProblemAndTestCaseList problemWithTestCases, String fileName)
      throws IOException, SubmissionException, InterruptedException {
    String programText = readProgram(fileName);

    OOPBuildServiceSubmission future =
        new OOPBuildServiceSubmission(
            new Submission(
                problemWithTestCases.getProblem(),
                Arrays.asList(problemWithTestCases.getTestCaseList()),
                programText));

    serverTask.submit(future);

    SubmissionResult result;
    while (true) {
      result = future.poll();
      if (result != null) {
        break;
      }
      Thread.sleep(200L);
    }

    if (fileName.startsWith("./")) {
      fileName = fileName.substring(2);
    }

    System.out.println("program: " + fileName);
    if (result.getCompilationResult().getOutcome() != CompilationOutcome.SUCCESS) {
      System.out.println("compiled: false");
      return;
    }
    System.out.println("compiled: true");

    for (int i = 0; i < problemWithTestCases.getTestCaseList().length; i++) {
      TestCase testCase = problemWithTestCases.getTestCaseList()[i];
      TestResult testResult = result.getTestResults()[i];

      String outcome;
      switch (testResult.getOutcome()) {
        case PASSED:
          outcome = "passed";
          break;
        case FAILED_WITH_EXCEPTION:
          outcome = "crashed";
          break;
        case FAILED_FROM_TIMEOUT:
          outcome = "timeout";
          break;
        default:
          outcome = "failed";
          break;
      }
      System.out.println("test " + testCase.getTestCaseName() + ":" + outcome);
      if (testResult.getOutcome() != TestOutcome.PASSED) {
        String output = testResult.getStdout();
        if (!output.endsWith("\n")) {
          output = output + "\n";
        }
        System.out.print(output);
      }
    }
  }