01: /*
02: * Copyright 2007 The Kuali Foundation
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package edu.iu.uis.eden.messaging.threadpool;
17:
18: import java.sql.Timestamp;
19:
20: import junit.framework.TestCase;
21:
22: import org.junit.Test;
23:
24: import edu.iu.uis.eden.messaging.MessageServiceInvoker;
25: import edu.iu.uis.eden.messaging.PersistedMessage;
26:
27: /**
28: * Tests that the {@link PriorityBlockingQueuePersistedMessageComparator} is sorting by
29: * priority and date.
30: *
31: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
32: *
33: */
34: public class PriorityBlockingQueuePersistedMessageComparatorTest extends
35: TestCase {
36:
37: @Test
38: public void testSortingByPriorityAndDate() throws Exception {
39: PersistedMessage message1 = new PersistedMessage();
40: message1.setQueuePriority(1);
41: message1
42: .setQueueDate(new Timestamp(System.currentTimeMillis()));
43:
44: PersistedMessage message2 = new PersistedMessage();
45: message2.setQueuePriority(5);
46: message2
47: .setQueueDate(new Timestamp(System.currentTimeMillis()));
48:
49: PersistedMessage message3 = new PersistedMessage();
50: message3.setQueuePriority(5);
51: message3.setQueueDate(new Timestamp(
52: System.currentTimeMillis() + 5));
53:
54: assertEquals(
55: PriorityBlockingQueuePersistedMessageComparator.class
56: .getName()
57: + " is sorting incorrectly", -1,
58: new PriorityBlockingQueuePersistedMessageComparator()
59: .compare(new MessageServiceInvoker(message1),
60: new MessageServiceInvoker(message2)));
61: assertEquals(
62: PriorityBlockingQueuePersistedMessageComparator.class
63: .getName()
64: + " is sorting incorrectly", 1,
65: new PriorityBlockingQueuePersistedMessageComparator()
66: .compare(new MessageServiceInvoker(message2),
67: new MessageServiceInvoker(message1)));
68: assertEquals(
69: PriorityBlockingQueuePersistedMessageComparator.class
70: .getName()
71: + " is sorting incorrectly", -1,
72: new PriorityBlockingQueuePersistedMessageComparator()
73: .compare(new MessageServiceInvoker(message2),
74: new MessageServiceInvoker(message3)));
75: }
76: }
|