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());
}
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);
}
}
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);
}
}
}
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);
}
}
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;
}
Aggregations