001: /*
002: * Copyright 2007 The Kuali Foundation
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package edu.iu.uis.eden.messaging;
017:
018: import java.util.List;
019:
020: import javax.xml.namespace.QName;
021:
022: import org.junit.Test;
023: import org.kuali.bus.services.KSBServiceLocator;
024: import org.kuali.bus.test.KSBTestCase;
025: import org.kuali.rice.RiceConstants;
026: import org.kuali.rice.core.Core;
027: import org.kuali.rice.test.TestUtilities;
028:
029: import edu.iu.uis.eden.messaging.remotedservices.TesetHarnessExplodingQueue;
030:
031: /**
032: * This is a description of what this class does - rkirkend don't forget to fill this in.
033: *
034: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
035: *
036: */
037: public class ExceptionRetryCountTest extends KSBTestCase {
038:
039: private QName retryCountServiceName = new QName("KEW",
040: "testExplodingRetryCount");
041: private TestCallback callback = new TestCallback();
042:
043: @Override
044: public void setUp() throws Exception {
045: System.setProperty(
046: RiceConstants.ROUTE_QUEUE_TIME_INCREMENT_KEY, "500");
047: System.setProperty(
048: RiceConstants.ROUTE_QUEUE_MAX_RETRY_ATTEMPTS_KEY, "2");
049: // System.setProperty(RiceConstants.IMMEDIATE_EXCEPTION_ROUTING, "false");
050: super .setUp();
051: GlobalCallbackRegistry.getCallbacks().clear();
052: GlobalCallbackRegistry.getCallbacks().add(this .callback);
053: TestCallback.clearCallbacks();
054: TesetHarnessExplodingQueue.NUM_CALLS = 0;
055: }
056:
057: @Override
058: public void tearDown() throws Exception {
059: try {
060: KSBServiceLocator.getScheduler().shutdown();
061: } finally {
062: super .tearDown();
063: }
064: }
065:
066: /**
067: * Test that a message with retry count gets retried that many times.
068: *
069: * @throws Exception
070: */
071: @Test
072: public void testRetryCount() throws Exception {
073: //Turn the requeue up very high so the message will go through all it's requeues immediately
074:
075: Core.getCurrentContextConfig().overrideProperty(
076: RiceConstants.ROUTE_QUEUE_TIME_INCREMENT_KEY, "100");
077:
078: KEWJavaService explodingQueue = (KEWJavaService) KSBServiceLocator
079: .getMessageHelper().getServiceAsynchronously(
080: this .retryCountServiceName);
081: explodingQueue.invoke("");
082: TestUtilities.waitForExceptionRouting();
083:
084: this .callback.pauseUntilNumberCallbacksUsingStaticCounter(3,
085: this .retryCountServiceName);
086: //pause to let save to queue in status 'E' happen
087: int i = 0;
088: while (i++ < 30) {
089: List<PersistedMessage> queuedItems = KSBServiceLocator
090: .getRouteQueueService().findAll();
091: if (queuedItems.size() != 1) {
092: fail("test setup wrong should have a single item in the queue.");
093: }
094: PersistedMessage message = queuedItems.get(0);
095: if (message.getQueueStatus().equals("E")) {
096: break;
097: }
098: System.out
099: .println("Message not saved to queue in 'E' status. Sleeping 1 sec.");
100: Thread.sleep(1000);
101: }
102:
103: assertEquals("Service should have been called 3 times", 3,
104: TesetHarnessExplodingQueue.NUM_CALLS);
105:
106: List<PersistedMessage> messagesQueued = KSBServiceLocator
107: .getRouteQueueService().findByServiceName(
108: this .retryCountServiceName, "invoke");
109: PersistedMessage message = messagesQueued.get(0);
110: assertEquals("Message should be in exception status",
111: RiceConstants.ROUTE_QUEUE_EXCEPTION, message
112: .getQueueStatus());
113: assertEquals("Message retry count not what was configured",
114: new Integer(2), message.getRetryCount());
115: }
116:
117: }
|