1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.messaging.threadpool;
17
18 import java.sql.Timestamp;
19
20 import junit.framework.TestCase;
21
22 import org.junit.Test;
23 import org.kuali.rice.ksb.messaging.MessageServiceInvoker;
24 import org.kuali.rice.ksb.messaging.PersistedMessage;
25 import org.kuali.rice.ksb.messaging.threadpool.PriorityBlockingQueuePersistedMessageComparator;
26
27
28
29
30
31
32
33
34
35 public class PriorityBlockingQueuePersistedMessageComparatorTest extends TestCase {
36
37 @Test public void testSortingByPriorityAndDate() throws Exception {
38 PersistedMessage message1 = new PersistedMessage();
39 message1.setQueuePriority(1);
40 message1.setQueueDate(new Timestamp(System.currentTimeMillis()));
41
42 PersistedMessage message2 = new PersistedMessage();
43 message2.setQueuePriority(5);
44 message2.setQueueDate(new Timestamp(System.currentTimeMillis()));
45
46 PersistedMessage message3 = new PersistedMessage();
47 message3.setQueuePriority(5);
48 message3.setQueueDate(new Timestamp(System.currentTimeMillis() + 5));
49
50 assertEquals(PriorityBlockingQueuePersistedMessageComparator.class.getName() + " is sorting incorrectly", -1, new PriorityBlockingQueuePersistedMessageComparator().compare(new MessageServiceInvoker(message1), new MessageServiceInvoker(message2)));
51 assertEquals(PriorityBlockingQueuePersistedMessageComparator.class.getName() + " is sorting incorrectly", 1, new PriorityBlockingQueuePersistedMessageComparator().compare(new MessageServiceInvoker(message2), new MessageServiceInvoker(message1)));
52 assertEquals(PriorityBlockingQueuePersistedMessageComparator.class.getName() + " is sorting incorrectly", -1, new PriorityBlockingQueuePersistedMessageComparator().compare(new MessageServiceInvoker(message2), new MessageServiceInvoker(message3)));
53 }
54 }