View Javadoc

1   /*
2    * Copyright 2007-2008 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
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 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   * Tests that the {@link PriorityBlockingQueuePersistedMessageComparator} is sorting by 
30   * priority and date. 
31   * 
32   * @author Kuali Rice Team (rice.collab@kuali.org)
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  }