1
2
3
4
5
6
7
8
9
10
11
12
13 package org.kuali.rice.ksb.messaging;
14
15 import java.util.List;
16
17 import javax.xml.namespace.QName;
18
19 import org.junit.Test;
20 import org.kuali.rice.core.config.ConfigContext;
21 import org.kuali.rice.ksb.messaging.GlobalCallbackRegistry;
22 import org.kuali.rice.ksb.messaging.PersistedMessage;
23 import org.kuali.rice.ksb.messaging.remotedservices.TesetHarnessExplodingQueue;
24 import org.kuali.rice.ksb.messaging.service.KSBJavaService;
25 import org.kuali.rice.ksb.service.KSBServiceLocator;
26 import org.kuali.rice.ksb.test.KSBTestCase;
27 import org.kuali.rice.ksb.util.KSBConstants;
28 import org.kuali.rice.test.TestUtilities;
29
30
31
32
33
34
35
36
37 public class ExceptionRetryCountTest extends KSBTestCase {
38
39
40 private QName retryCountServiceName = new QName("KEW", "testExplodingRetryCount");
41 private TestCallback callback = new TestCallback();
42
43 @Override
44 public void setUp() throws Exception {
45 System.setProperty(KSBConstants.ROUTE_QUEUE_TIME_INCREMENT_KEY, "500");
46 System.setProperty(KSBConstants.ROUTE_QUEUE_MAX_RETRY_ATTEMPTS_KEY, "2");
47 super.setUp();
48 GlobalCallbackRegistry.getCallbacks().clear();
49 GlobalCallbackRegistry.getCallbacks().add(this.callback);
50 TestCallback.clearCallbacks();
51 TesetHarnessExplodingQueue.NUM_CALLS = 0;
52 }
53
54 @Override
55 public void tearDown() throws Exception {
56 try {
57 KSBServiceLocator.getScheduler().shutdown();
58 } finally {
59 super.tearDown();
60 }
61 }
62
63
64
65
66
67
68 @Test
69 public void testRetryCount() throws Exception {
70
71
72 ConfigContext.getCurrentContextConfig().putProperty(KSBConstants.ROUTE_QUEUE_TIME_INCREMENT_KEY, "100");
73
74 KSBJavaService explodingQueue = (KSBJavaService) KSBServiceLocator.getMessageHelper().getServiceAsynchronously(
75 this.retryCountServiceName);
76 explodingQueue.invoke("");
77 TestUtilities.waitForExceptionRouting();
78
79 this.callback.pauseUntilNumberCallbacksUsingStaticCounter(3, this.retryCountServiceName);
80
81
82 int i = 0;
83 while (i++ < 30) {
84 List<PersistedMessage> queuedItems = KSBServiceLocator.getRouteQueueService().findAll();
85 if (queuedItems.size() != 1) {
86 fail("test setup wrong should have a single item in the queue.");
87 }
88 PersistedMessage message = queuedItems.get(0);
89 if (message.getQueueStatus().equals("E")) {
90 break;
91 }
92 System.out.println("Message not saved to queue in 'E' status. Sleeping 1 sec.");
93 Thread.sleep(1000);
94 }
95
96 assertEquals("Service should have been called 3 times", 3, TesetHarnessExplodingQueue.NUM_CALLS);
97
98 List<PersistedMessage> messagesQueued = KSBServiceLocator.getRouteQueueService().findByServiceName(
99 this.retryCountServiceName, "invoke");
100 PersistedMessage message = messagesQueued.get(0);
101 assertEquals("Message should be in exception status", KSBConstants.ROUTE_QUEUE_EXCEPTION, message.getQueueStatus());
102 assertEquals("Message retry count not what was configured", new Integer(2), message.getRetryCount());
103 }
104
105 }