Search in sources :

Example 6 with Submission

use of cn.edu.zju.acm.onlinejudge.bean.Submission in project zoj by licheng.

the class JudgeClientUnitTest method testRestartServer.

@Test
public void testRestartServer() throws Exception {
    mockServer.addReply(MockClient.ACCEPTED);
    mockServer.addReply(MockClient.COMPILATION_SERVER_ERROR);
    for (int i = 0; i < submissions.length - 1; i++) {
        mockServer.addReply(MockClient.ACCEPTED);
    }
    mockServer.addReply(MockClient.COMPILATION_SERVER_ERROR);
    mockServer.addReply(MockClient.ACCEPTED);
    mockServer.addReply(MockClient.ACCEPTED);
    for (int i = 0; i < submissions.length; i++) {
        queue.add(submissions[i]);
    }
    for (int i = 0; i < submissions.length; i++) {
        for (; ; ) {
            Submission submission = DAOFactory.getSubmissionDAO().getSubmission(i);
            if (submission.getJudgeReply() == JudgeReply.ACCEPTED) {
                break;
            }
            Thread.sleep(10);
        }
    }
    assertEquals(0, mockServer.getReplies().size());
}
Also used : Submission(cn.edu.zju.acm.onlinejudge.bean.Submission) Test(org.junit.Test)

Example 7 with Submission

use of cn.edu.zju.acm.onlinejudge.bean.Submission in project zoj by licheng.

the class JudgeQueueUnitTest method setUp.

@Before
public void setUp() {
    queue = new SubmissionQueueReader();
    for (int i = 0; i < submissions.length; i++) {
        submissions[i] = new Submission();
        submissions[i].setId(i);
    }
}
Also used : Submission(cn.edu.zju.acm.onlinejudge.bean.Submission) Before(org.junit.Before)

Example 8 with Submission

use of cn.edu.zju.acm.onlinejudge.bean.Submission in project zoj by licheng.

the class JudgeQueueUnitTest method testMultiThread.

@Test(timeout = 5000)
public void testMultiThread() throws Exception {
    final Thread[] consumer = new Thread[100];
    final Thread[] provider = new Thread[1000];
    final int submissionPerProvider = 100;
    final int total = provider.length * submissionPerProvider;
    final int[][] count = new int[consumer.length][total];
    submissions = new Submission[total];
    for (int i = 0; i < total; i++) {
        submissions[i] = new Submission();
        submissions[i].setId(i);
        submissions[i].setJudgeReply(JudgeReply.QUEUING);
    }
    for (int i = 0; i < consumer.length; i++) {
        final int k = i;
        final int[] cnt = count[k];
        for (int j = 0; j < cnt.length; j++) {
            cnt[j] = 0;
        }
        consumer[i] = new Thread() {

            public void run() {
                try {
                    for (int i = 0; ; i++) {
                        Submission submission = queue.removeFirst();
                        int id = (int) submission.getId();
                        // System.out.println("poll " + k + " " + id);
                        cnt[id]++;
                        assertEquals(submissions[id], submission);
                        if (id % consumer.length == k) {
                            queue.addFirst(submission);
                        } else {
                            submission.setJudgeReply(JudgeReply.ACCEPTED);
                        }
                        Thread.yield();
                    }
                } catch (InterruptedException e) {
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
    }
    final int[] idGenerator = new int[] { 0 };
    for (int i = 0; i < provider.length; i++) {
        provider[i] = new Thread() {

            public void run() {
                for (int i = 0; i < submissionPerProvider; i++) {
                    synchronized (JudgeQueueUnitTest.this) {
                        int id = idGenerator[0]++;
                        submissions[id].setJudgeReply(JudgeReply.QUEUING);
                        queue.add(submissions[id]);
                    }
                    Thread.yield();
                }
            }
        };
    }
    for (int i = 0; i < consumer.length; i++) {
        consumer[i].start();
    }
    for (int i = 0; i < provider.length; i++) {
        provider[i].start();
    }
    for (int i = 0; i < provider.length; i++) {
        provider[i].join();
    }
    for (int i = 0; i < submissions.length; i++) {
        while (submissions[i].getJudgeReply() != JudgeReply.ACCEPTED) {
            // System.out.println("Wait " + i);
            Thread.sleep(100);
        }
    }
    for (int i = 0; i < consumer.length; i++) {
        consumer[i].interrupt();
        consumer[i].join();
    }
    for (int i = 0; i < total; i++) {
        int sum = 0;
        int max = 0;
        for (int j = 0; j < consumer.length; j++) {
            sum += count[j][i];
            if (count[j][i] > max) {
                max = count[j][i];
            }
        }
        if (sum == 0) {
            fail("" + i);
        }
        if (sum > 1 && max + 1 != sum) {
            fail("" + i + " " + max + " " + sum);
        }
    }
}
Also used : Submission(cn.edu.zju.acm.onlinejudge.bean.Submission) Test(org.junit.Test)

Example 9 with Submission

use of cn.edu.zju.acm.onlinejudge.bean.Submission in project zoj by licheng.

the class JudgingQueueUnitTest method setUp.

@Before
public void setUp() {
    this.queue = new JudgingQueue();
    this.submissions = new Submission[10];
    for (int i = 0; i < this.submissions.length; ++i) {
        this.submissions[i] = new Submission();
        this.submissions[i].setId(i);
    }
}
Also used : Submission(cn.edu.zju.acm.onlinejudge.bean.Submission) Before(org.junit.Before)

Example 10 with Submission

use of cn.edu.zju.acm.onlinejudge.bean.Submission in project zoj by licheng.

the class MockSubmissionDAO method cloneSubmission.

private Submission cloneSubmission(Submission submission) {
    Submission ret = new Submission();
    ret.setJudgeComment(submission.getJudgeComment());
    ret.setContent(submission.getContent());
    ret.setId(submission.getId());
    ret.setLanguage(submission.getLanguage());
    ret.setMemoryConsumption(submission.getMemoryConsumption());
    ret.setProblemId(submission.getProblemId());
    ret.setJudgeReply(submission.getJudgeReply());
    ret.setTimeConsumption(submission.getTimeConsumption());
    return ret;
}
Also used : Submission(cn.edu.zju.acm.onlinejudge.bean.Submission)

Aggregations

Submission (cn.edu.zju.acm.onlinejudge.bean.Submission)33 Test (org.junit.Test)8 ExtendedSubmission (cn.edu.zju.acm.onlinejudge.bean.ExtendedSubmission)7 Language (cn.edu.zju.acm.onlinejudge.bean.enumeration.Language)7 ArrayList (java.util.ArrayList)5 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)4 PersistenceException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)4 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 Date (java.util.Date)4 ActionForward (org.apache.struts.action.ActionForward)4 Before (org.junit.Before)4 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)3 SubmissionPersistence (cn.edu.zju.acm.onlinejudge.persistence.SubmissionPersistence)3 ActionMessages (org.apache.struts.action.ActionMessages)3 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)2 Reference (cn.edu.zju.acm.onlinejudge.bean.Reference)2 List (java.util.List)2