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: CommitTest.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.MessageReceiver;
54 import org.exolab.jmscts.core.MessageSender;
55 import org.exolab.jmscts.core.TestContext;
56 import org.exolab.jmscts.core.TestCreator;
57
58
59 /***
60 * This class tests session commit functionality
61 *
62 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
63 * @version $Revision: 1.9 $
64 * @jmscts.session TRANSACTED
65 * @jmscts.message TextMessage
66 * @jmscts.delivery consumer
67 */
68 public class CommitTest extends AbstractSendReceiveTestCase {
69
70 /***
71 * The destinations to create prior to running the test
72 */
73 private static final String[] DESTINATIONS = {"commit1", "commit2",
74 "commit3"};
75
76 /***
77 * Construct a new <code>CommitTest</code>
78 *
79 * @param name the name of test case
80 */
81 public CommitTest(String name) {
82 super(name);
83 }
84
85 /***
86 * Sets up the test suite.
87 *
88 * @return an instance of this class that may be run by
89 * {@link org.exolab.jmscts.core.JMSTestRunner}
90 */
91 public static Test suite() {
92 return TestCreator.createSendReceiveTest(CommitTest.class);
93 }
94
95 /***
96 * Returns the list of destination names used by this test case. These
97 * are used to pre-administer destinations prior to running the test case.
98 *
99 * @return the list of destinations used by this test case
100 */
101 public String[] getDestinations() {
102 return DESTINATIONS;
103 }
104
105 /***
106 * Verifies session commit behaviour
107 *
108 * @jmscts.requirement session.transactions
109 * @throws Exception for any error
110 */
111 public void testCommit() throws Exception {
112 final int count = 10; // send count messages to each destination
113
114 TestContext context = getContext();
115 Session session = context.getSession();
116 Message message = context.getMessage();
117
118 // create the senders and receivers
119 MessageSender[] senders = createSenders();
120 MessageReceiver[] receivers = createReceivers();
121
122 try {
123 // send the messages
124 send(senders, message, count);
125
126 // verify that the receivers cannot receive the messages until the
127 // session commits
128 receive(receivers, 0);
129
130 // commit the session. The receivers should be able to receive all
131 // messages
132 session.commit();
133
134 receive(receivers, count);
135 } finally {
136 close(senders);
137 close(receivers);
138 }
139 }
140
141 /***
142 * Verifies that messages are sent on commit even if their producer has
143 * been closed, and that consumed messages are acknowledged even if the
144 * consumer that received them has been closed prior to commit
145 *
146 * @jmscts.requirement session.ack.closedconsumer
147 * @throws Exception for any error
148 */
149 public void testCommitForClosedEndpoint() throws Exception {
150 final int count = 10; // send count messages to each destination
151
152 TestContext context = getContext();
153 Session session = context.getSession();
154 Message message = context.getMessage();
155
156 // create the senders and receivers
157 MessageSender[] senders = createSenders();
158 MessageReceiver[] receivers = createReceivers();
159
160 try {
161 // send the messages, and close the producers prior to commit
162 send(senders, message, count);
163 close(senders);
164
165 // commit the session
166 session.commit();
167
168 // receive the messages, close the consumers, and then commit.
169 receive(receivers, count);
170 close(receivers);
171
172 session.commit();
173
174 if (context.isQueueConnectionFactory()) {
175 // for queues, verify that no messages are subsequently
176 // received (i.e, that the session acknowledged messages
177 // for the closed receivers)
178 // TODO - could also perform this test for durable topic
179 // subscribers but there is no infrastructure in place to test
180 // this. This check cannot be performed for non-durable
181 // subscribers
182 receivers = createReceivers();
183 receive(receivers, 0);
184 }
185 } finally {
186 close(senders);
187 close(receivers);
188 }
189 }
190
191 }
This page was automatically generated by Maven