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: CloseTest.java,v 1.9 2004/02/03 21:52:12 tanderson Exp $ 44 */ 45 package org.exolab.jmscts.test.session.transacted; 46 47 import javax.jms.Message; 48 import javax.jms.Session; 49 50 import junit.framework.Test; 51 52 import org.exolab.jmscts.core.AbstractSendReceiveTestCase; 53 import org.exolab.jmscts.core.ConnectionHelper; 54 import org.exolab.jmscts.core.MessageReceiver; 55 import org.exolab.jmscts.core.MessageSender; 56 import org.exolab.jmscts.core.TestContext; 57 import org.exolab.jmscts.core.TestContextHelper; 58 import org.exolab.jmscts.core.TestCreator; 59 60 61 /*** 62 * This class tests session rollback functionality. 63 * 64 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 65 * @version $Revision: 1.9 $ 66 * @jmscts.session TRANSACTED 67 * @jmscts.message MapMessage 68 * @jmscts.delivery administered-consumer 69 */ 70 public class CloseTest extends AbstractSendReceiveTestCase { 71 72 /*** 73 * The destinations to create prior to running the test 74 */ 75 private static final String[] DESTINATIONS = {"rollback1", "rollback2", 76 "rollback3"}; 77 78 /*** 79 * Construct a new <code>CloseTest</code> 80 * 81 * @param name the name of test case 82 */ 83 public CloseTest(String name) { 84 super(name); 85 } 86 87 /*** 88 * Sets up the test suite. 89 * 90 * @return an instance of this class that may be run by 91 * {@link org.exolab.jmscts.core.JMSTestRunner} 92 */ 93 public static Test suite() { 94 return TestCreator.createSendReceiveTest(CloseTest.class); 95 } 96 97 /*** 98 * Returns the list of destination names used by this test case. These 99 * are used to pre-administer destinations prior to running the test case. 100 * 101 * @return the list of destinations used by this test case 102 */ 103 public String[] getDestinations() { 104 return DESTINATIONS; 105 } 106 107 /*** 108 * Verifies that closing a session rolls back the transaction in progress 109 * 110 * @jmscts.requirement session.close.transacted 111 * @throws Exception for any error 112 */ 113 public void testRollbackForClosedSession() throws Exception { 114 final int count = 10; // send count messages to each destination 115 TestContext context = getContext(); 116 Message message = context.getMessage(); 117 118 // create a new session context 119 Session session = ConnectionHelper.createSession(context); 120 TestContext tmp = new TestContext(context, session, 121 context.getAckType()); 122 TestContext local = new TestContext(tmp, context.getMessage(), 123 context.getMessagingBehaviour()); 124 125 // create the senders and receivers 126 MessageSender[] senders = createSenders(local); 127 MessageReceiver[] receivers = createReceivers(context); 128 129 try { 130 // send the messages, and close the session 131 send(senders, message, count); 132 session.close(); 133 134 // verify that the session rolled back, by ensuring that the 135 // receivers cannot receive any messages 136 receive(receivers, 0); 137 } finally { 138 close(senders); 139 close(receivers); 140 // close of receivers should be ignored as the connection is closed 141 } 142 } 143 144 /*** 145 * Verifies that closing a connection rolls back the transactions in 146 * progress on its transacted sessions. 147 * 148 * @jmscts.requirement connection.close.session.transacted 149 * @throws Exception for any error 150 */ 151 public void testRollbackForClosedConnection() throws Exception { 152 final int count = 10; // send count messages to each destination 153 TestContext context = getContext(); 154 Message message = context.getMessage(); 155 156 // create a new connection and session 157 TestContext local = TestContextHelper.createSendReceiveContext( 158 context); 159 160 // create the senders and receivers 161 MessageSender[] senders = createSenders(local); 162 MessageReceiver[] receivers = createReceivers(context); 163 164 try { 165 // send the messages, and close the connection 166 send(senders, message, count); 167 local.getConnection().close(); 168 169 // verify that the session rolled back, by ensuring that the 170 // receivers cannot receive any messages 171 receive(receivers, 0); 172 } finally { 173 close(senders); 174 close(receivers); 175 // close of receivers should be ignored as the connection is closed 176 } 177 } 178 179 }

This page was automatically generated by Maven