1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.messaging.exceptionhandling;
17
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertTrue;
20
21 import java.util.List;
22
23 import javax.xml.namespace.QName;
24
25 import org.junit.Test;
26 import org.kuali.rice.ksb.api.KsbApiServiceLocator;
27 import org.kuali.rice.ksb.messaging.GlobalCallbackRegistry;
28 import org.kuali.rice.ksb.messaging.PersistedMessageBO;
29 import org.kuali.rice.ksb.messaging.TestCallback;
30 import org.kuali.rice.ksb.messaging.remotedservices.TesetHarnessExplodingQueue;
31 import org.kuali.rice.ksb.messaging.service.KSBJavaService;
32 import org.kuali.rice.ksb.service.KSBServiceLocator;
33 import org.kuali.rice.ksb.test.KSBTestCase;
34 import org.kuali.rice.ksb.util.KSBConstants;
35 import org.kuali.rice.test.TestUtilities;
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 public class ExceptionMessagingTest extends KSBTestCase {
53
54
55 private QName queueTimeToLiveServiceName = new QName("KEW", "explodingQueueTimeLimit");
56 private TestCallback callback = new TestCallback();
57
58 @Override
59 public void setUp() throws Exception {
60 System.setProperty(KSBConstants.Config.ROUTE_QUEUE_TIME_INCREMENT_KEY, "500");
61 System.setProperty(KSBConstants.Config.ROUTE_QUEUE_MAX_RETRY_ATTEMPTS_KEY, "5");
62 super.setUp();
63 GlobalCallbackRegistry.getCallbacks().clear();
64 GlobalCallbackRegistry.getCallbacks().add(this.callback);
65 TestCallback.clearCallbacks();
66 TesetHarnessExplodingQueue.NUM_CALLS = 0;
67 }
68
69 @Override
70 public void tearDown() throws Exception {
71 try {
72 KSBServiceLocator.getScheduler().shutdown();
73 } finally {
74 super.tearDown();
75 }
76 }
77
78
79
80
81
82
83
84 @Test public void testTimeToLive() throws Exception {
85
86 KSBJavaService explodingQueue = (KSBJavaService) KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(this.queueTimeToLiveServiceName);
87 explodingQueue.invoke("");
88 TestUtilities.waitForExceptionRouting();
89
90 Thread.sleep(10000);
91
92
93 List<PersistedMessageBO> messagesQueued = KSBServiceLocator.getMessageQueueService().findByServiceName(this.queueTimeToLiveServiceName, "invoke");
94 PersistedMessageBO message = messagesQueued.get(0);
95 assertEquals("Message should be in exception status", KSBConstants.ROUTE_QUEUE_EXCEPTION, message.getQueueStatus());
96 assertTrue("Message expiration date should be equal to or earlier than last queue date", message.getExpirationDate().getTime() <= message.getQueueDate().getTime());
97 }
98
99
100 }