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 2001-2004 (C) Exoffice Technologies Inc. All Rights Reserved. 42 * 43 * $Id: DuplicateDurableSubscriberTest.java,v 1.6 2004/02/03 21:52:12 tanderson Exp $ 44 */ 45 package org.exolab.jmscts.test.topic; 46 47 import javax.jms.JMSException; 48 import javax.jms.Topic; 49 import javax.jms.TopicSession; 50 import javax.jms.TopicSubscriber; 51 52 import junit.framework.Test; 53 54 import org.exolab.jmscts.core.AbstractSessionTestCase; 55 import org.exolab.jmscts.core.ConnectionHelper; 56 import org.exolab.jmscts.core.DestinationHelper; 57 import org.exolab.jmscts.core.TestCreator; 58 import org.exolab.jmscts.core.TestContext; 59 60 61 /*** 62 * This class tests the behaviour of durable TopicSubscribers<br/> 63 * @todo - test duplicate durable subscriber in another JVM 64 * @todo - needs to be modified when OpenJMS supports clientId 65 * 66 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 67 * @version $Revision: 1.6 $ 68 * @see AbstractSessionTestCase 69 * @jmscts.factory TopicConnectionFactory 70 * @jmscts.factory XATopicConnectionFactory 71 */ 72 public class DuplicateDurableSubscriberTest extends AbstractSessionTestCase { 73 74 /*** 75 * The destination to create prior to running the test 76 */ 77 private static final String DESTINATION = "DuplicateDurableSubscriberTest"; 78 79 /*** 80 * Construct a new <code>DupublicDurableSubscriberTest</code> 81 * 82 * @param name the name of test case 83 */ 84 public DuplicateDurableSubscriberTest(String name) { 85 super(name); 86 } 87 88 /*** 89 * Sets up the test suite 90 * 91 * @return an instance of this class that may be run by 92 * {@link org.exolab.jmscts.core.JMSTestRunner} 93 */ 94 public static Test suite() { 95 return TestCreator.createSessionTest( 96 DuplicateDurableSubscriberTest.class); 97 } 98 99 /*** 100 * Verifies that creating a duplicate durable subscriber in the same 101 * session throws JMSException 102 * 103 * @jmscts.requirement subscriber.durable.unique 104 * @throws Exception for any error 105 */ 106 public void testDuplicateSubscriberPerSession() throws Exception { 107 final String name = "duplicate"; 108 TestContext context = getContext(); 109 TopicSession session = (TopicSession) context.getSession(); 110 DestinationHelper.destroy(DESTINATION, context.getAdministrator()); 111 Topic topic = (Topic) DestinationHelper.create(context, DESTINATION); 112 TopicSubscriber subscriber1 = session.createDurableSubscriber( 113 topic, name); 114 try { 115 TopicSubscriber subscriber2 = session.createDurableSubscriber( 116 topic, name); 117 subscriber2.close(); 118 fail("Managed to create a duplicate durable subscriber in the " 119 + "same session"); 120 } catch (JMSException expected) { 121 // the expected behaviour 122 } finally { 123 subscriber1.close(); 124 session.unsubscribe(name); 125 } 126 } 127 128 /*** 129 * Verifies that creating a duplicate subscriber in a different session 130 * but same connection throws JMSException 131 * 132 * @jmscts.requirement subscriber.durable.unique 133 * @throws Exception for any error 134 */ 135 public void testDuplicateSubscriber() throws Exception { 136 final String name = "duplicate"; 137 TestContext context = getContext(); 138 TopicSession session1 = (TopicSession) context.getSession(); 139 DestinationHelper.destroy(DESTINATION, context.getAdministrator()); 140 Topic topic = (Topic) DestinationHelper.create(context, DESTINATION); 141 TopicSubscriber subscriber1 = session1.createDurableSubscriber( 142 topic, name); 143 TopicSession session2 = 144 (TopicSession) ConnectionHelper.createSession(context); 145 try { 146 TopicSubscriber subscriber2 = session2.createDurableSubscriber( 147 topic, name); 148 subscriber2.close(); 149 fail("Managed to create a duplicate durable subscriber in " 150 + "another session, sharing the same connection"); 151 } catch (JMSException expected) { 152 // the expected behaviour 153 } finally { 154 subscriber1.close(); 155 session1.unsubscribe(name); 156 session2.close(); 157 } 158 } 159 160 }

This page was automatically generated by Maven