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 org.junit.Test;
19 import org.kuali.rice.ksb.messaging.MessageServiceInvoker;
20 import org.kuali.rice.ksb.messaging.PersistedMessageBO;
21
22 import java.sql.Timestamp;
23
24 import static org.junit.Assert.assertEquals;
25
26
27
28
29
30
31
32
33
34 public class PriorityBlockingQueuePersistedMessageComparatorTest {
35
36 @Test public void testSortingByPriorityAndDate() throws Exception {
37 PersistedMessageBO message1 = new PersistedMessageBO();
38 message1.setQueuePriority(1);
39 message1.setQueueDate(new Timestamp(System.currentTimeMillis()));
40
41 PersistedMessageBO message2 = new PersistedMessageBO();
42 message2.setQueuePriority(5);
43 message2.setQueueDate(new Timestamp(System.currentTimeMillis()));
44
45 PersistedMessageBO message3 = new PersistedMessageBO();
46 message3.setQueuePriority(5);
47 message3.setQueueDate(new Timestamp(System.currentTimeMillis() + 5));
48
49 assertEquals(PriorityBlockingQueuePersistedMessageComparator.class.getName() + " is sorting incorrectly", -1, new PriorityBlockingQueuePersistedMessageComparator().compare(new MessageServiceInvoker(message1), new MessageServiceInvoker(message2)));
50 assertEquals(PriorityBlockingQueuePersistedMessageComparator.class.getName() + " is sorting incorrectly", 1, new PriorityBlockingQueuePersistedMessageComparator().compare(new MessageServiceInvoker(message2), new MessageServiceInvoker(message1)));
51 assertEquals(PriorityBlockingQueuePersistedMessageComparator.class.getName() + " is sorting incorrectly", -1, new PriorityBlockingQueuePersistedMessageComparator().compare(new MessageServiceInvoker(message2), new MessageServiceInvoker(message3)));
52 }
53 }