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.exceptionhandling;
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.GlobalCallbackRegistry;
030: import edu.iu.uis.eden.messaging.KEWJavaService;
031: import edu.iu.uis.eden.messaging.PersistedMessage;
032: import edu.iu.uis.eden.messaging.TestCallback;
033: import edu.iu.uis.eden.messaging.remotedservices.TesetHarnessExplodingQueue;
034:
035: /**
036: * Tests various exception messaging cases
037: *
038: * Millis to live - that a message with no home is still sending messages while it's time to live hasn't expired
039: * Retry count - that a message configured with a retry count will send x number of messages before being marked exception
040: * Being marked as exception - that a message in exception is in the route log and marked with a status of 'E'
041: * Defuault retry count - that a message configured with no retry or time to live is retry the default number of times as
042: * noted in an app constant and a class default if that constant is not a number or doesn't exist
043: * App Constant to determine the default time increment works (we need this to effectively test anyway)
044: * Things work without the timeincrement constant in place
045: *
046: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
047: *
048: */
049: public class ExceptionMessagingTest extends KSBTestCase {
050:
051: private QName queueTimeToLiveServiceName = new QName("KEW",
052: "explodingQueueTimeLimit");
053: private QName retryCountServiceName = new QName("KEW",
054: "testExplodingRetryCount");
055: private TestCallback callback = new TestCallback();
056:
057: @Override
058: public void setUp() throws Exception {
059: System.setProperty(
060: RiceConstants.ROUTE_QUEUE_TIME_INCREMENT_KEY, "500");
061: System.setProperty(
062: RiceConstants.ROUTE_QUEUE_MAX_RETRY_ATTEMPTS_KEY, "5");
063: // System.setProperty(RiceConstants.IMMEDIATE_EXCEPTION_ROUTING, "false");
064: super .setUp();
065: GlobalCallbackRegistry.getCallbacks().clear();
066: GlobalCallbackRegistry.getCallbacks().add(this .callback);
067: TestCallback.clearCallbacks();
068: TesetHarnessExplodingQueue.NUM_CALLS = 0;
069: }
070:
071: @Override
072: public void tearDown() throws Exception {
073: KSBServiceLocator.getScheduler().shutdown();
074: super .tearDown();
075: }
076:
077: /**
078: * test that service is in queue marked 'E' when the time to live is expired.
079: * @throws Exception
080: */
081: @Test
082: public void testTimeToLive() throws Exception {
083:
084: KEWJavaService explodingQueue = (KEWJavaService) KSBServiceLocator
085: .getMessageHelper().getServiceAsynchronously(
086: this .queueTimeToLiveServiceName);
087: explodingQueue.invoke("");
088: TestUtilities.waitForExceptionRouting();
089: //this service is on a 3 second wait the queue is on a 1 sec.
090: Thread.sleep(10000);
091:
092: //verify the entry is in exception routing
093: List<PersistedMessage> messagesQueued = KSBServiceLocator
094: .getRouteQueueService().findByServiceName(
095: this .queueTimeToLiveServiceName, "invoke");
096: PersistedMessage message = messagesQueued.get(0);
097: assertEquals("Message should be in exception status",
098: RiceConstants.ROUTE_QUEUE_EXCEPTION, message
099: .getQueueStatus());
100: assertTrue(
101: "Message expiration date should be equal to or earlier than last queue date",
102: message.getExpirationDate().getTime() <= message
103: .getQueueDate().getTime());
104: }
105:
106: }
|