View Javadoc
1 /*** 2 * Redistribution and use of this software and associated documentation 3 * ("Software"), with or without modification, are permitted provided 4 * that the following conditions are met: 5 * 6 * 1. Redistributions of source code must retain copyright 7 * statements and notices. Redistributions must also contain a 8 * copy of this document. 9 * 10 * 2. Redistributions in binary form must reproduce the 11 * above copyright notice, this list of conditions and the 12 * following disclaimer in the documentation and/or other 13 * materials provided with the distribution. 14 * 15 * 3. The name "Exolab" must not be used to endorse or promote 16 * products derived from this Software without prior written 17 * permission of Exoffice Technologies. For written permission, 18 * please contact tma@netspace.net.au. 19 * 20 * 4. Products derived from this Software may not be called "Exolab" 21 * nor may "Exolab" appear in their names without prior written 22 * permission of Exoffice Technologies. Exolab is a registered 23 * trademark of Exoffice Technologies. 24 * 25 * 5. Due credit should be given to the Exolab Project 26 * (http://www.exolab.org/). 27 * 28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS 29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 39 * OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 * Copyright 2004 (C) Exoffice Technologies Inc. All Rights Reserved. 42 * 43 * $Id: SubscriberRedeliveredTest.java,v 1.1 2004/02/02 05:38:07 tanderson Exp $ 44 */ 45 package org.exolab.jmscts.test.session.clientack; 46 47 import java.util.Iterator; 48 import java.util.List; 49 50 import javax.jms.Message; 51 import javax.jms.Session; 52 53 import org.apache.log4j.Category; 54 55 import junit.framework.Test; 56 57 import org.exolab.jmscts.core.AckTypes; 58 import org.exolab.jmscts.core.AbstractSendReceiveTestCase; 59 import org.exolab.jmscts.core.JMSTestRunner; 60 import org.exolab.jmscts.core.MessageReceiver; 61 import org.exolab.jmscts.core.TestContext; 62 import org.exolab.jmscts.core.TestContextHelper; 63 import org.exolab.jmscts.core.TestCreator; 64 65 66 /*** 67 * This class tests the behaviour of the JMSRedelivered flag when 68 * multiple topic subscribers subscribe to the same topic, and 69 * one of the CLIENT_ACKNOWLEDGE sessions is recovered. 70 * 71 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 72 * @version $Revision: 1.1 $ 73 * @jmscts.factory TopicConnectionFactory 74 * @jmscts.factory XATopicConnectionFactory 75 * @jmscts.message ObjectMessage 76 */ 77 public class SubscriberRedeliveredTest extends AbstractSendReceiveTestCase { 78 79 /*** 80 * The destination used by this test case 81 */ 82 private static final String DESTINATION = "SubscriberRedeliveredTest"; 83 84 /*** 85 * The logger 86 */ 87 private static final Category log = 88 Category.getInstance(SubscriberRedeliveredTest.class); 89 90 91 /*** 92 * Construct an instance of this class for a specific test case. 93 * The test will be run against the CLIENT_ACKNOWLEGE acknowledgement type, 94 * all consumer messaging behaviours, and using TextMessage messages 95 * 96 * @param name the name of test case 97 */ 98 public SubscriberRedeliveredTest(String name) { 99 super(name); 100 } 101 102 /*** 103 * The main line used to execute this test 104 * 105 * @param args the command line arguments 106 */ 107 public static void main(String[] args) { 108 JMSTestRunner test = new JMSTestRunner(suite(), args); 109 junit.textui.TestRunner.run(test); 110 } 111 112 /*** 113 * Sets up the test suite. 114 * 115 * @return the test suite 116 */ 117 public static Test suite() { 118 return TestCreator.createSendReceiveTest( 119 SubscriberRedeliveredTest.class); 120 } 121 122 /*** 123 * Returns the list of destination names used by this test case. These 124 * are used to pre-administer destinations prior to running the test case. 125 * 126 * @return the list of destinations used by this test case 127 */ 128 public String[] getDestinations() { 129 return new String[]{DESTINATION}; 130 } 131 132 /*** 133 * Verifies that messages received after 134 * <code>TopicSession.recover()</code> have their JMSRedelivered flag set 135 * to <code>true</code>, and that the same messages received via 136 * another TopicSession have their JMSRedelivered flag set to 137 * <code>false</code>. 138 * 139 * @jmscts.requirement message.redelivered.receive 140 * @throws Exception for any error 141 */ 142 public void testJMSRedelivered() throws Exception { 143 final int count = 10; // send count messages 144 145 TestContext context = getContext(); 146 Session session = context.getSession(); 147 148 // set up a client ack session 149 TestContext clientAckContext = TestContextHelper.createSessionContext( 150 context, AckTypes.CLIENT_ACKNOWLEDGE); 151 Session clientAckSession = clientAckContext.getSession(); 152 153 MessageReceiver subscriber1 = null; 154 MessageReceiver subscriber2 = null; 155 156 try { 157 // create the subscribers prior to sending any messages 158 subscriber1 = createReceiver(context, DESTINATION); 159 subscriber2 = createReceiver(clientAckContext, DESTINATION); 160 161 send(context, DESTINATION, count); 162 163 // receive messages via the CLIENT_ACKNOWLEDGE session 164 List messages = receive(clientAckContext, subscriber2, count); 165 checkJMSRedelivered(messages, false); 166 clientAckSession.recover(); 167 messages = receive(clientAckContext, subscriber2, count); 168 checkJMSRedelivered(messages, true); 169 170 // messages received by subscriber1 shouldn't have their 171 // JMSRedelivered set 172 messages = receive(context, subscriber1, count); 173 checkJMSRedelivered(messages, false); 174 } finally { 175 close(subscriber1); 176 close(subscriber2); 177 } 178 } 179 180 /*** 181 * Verifies that the JMSRedelivered property matches that expected 182 * 183 * @param messages the list of messages to verify 184 * @param redelivered the expected value of JMSRedelivered 185 * @throws Exception for any error 186 */ 187 protected void checkJMSRedelivered(List messages, boolean redelivered) 188 throws Exception { 189 Iterator iter = messages.iterator(); 190 while (iter.hasNext()) { 191 Message message = (Message) iter.next(); 192 if (message.getJMSRedelivered() != redelivered) { 193 fail("Expected message to have JMSRedelivered=" 194 + redelivered + ", but got JMSRedelivered=" 195 + message.getJMSRedelivered()); 196 } 197 } 198 } 199 200 } 201

This page was automatically generated by Maven