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: ClientAcknowledgeTest.java,v 1.10 2004/02/03 21:52:12 tanderson Exp $
44 */
45 package org.exolab.jmscts.test.session.clientack;
46
47 import java.util.List;
48
49 import javax.jms.Message;
50 import javax.jms.Session;
51
52 import org.apache.log4j.Category;
53
54 import junit.framework.Test;
55
56 import org.exolab.jmscts.core.MessageReceiver;
57 import org.exolab.jmscts.core.TestContext;
58 import org.exolab.jmscts.core.TestCreator;
59
60
61 /***
62 * This class tests the behaviour of sessions created with the
63 * <code>Session.CLIENT_ACKNOWLEDGE</code> message acknowledgment mode.
64 *
65 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
66 * @version $Revision: 1.10 $
67 * @jmscts.session CLIENT_ACKNOWLEDGE
68 * @jmscts.message TextMessage
69 * @jmscts.delivery consumer
70 */
71 public class ClientAcknowledgeTest extends ClientAcknowledgeTestCase {
72
73 /***
74 * The destinations to create prior to running the test
75 */
76 private static final String[] DESTINATIONS = {"clientack1", "clientack2",
77 "clientack3"};
78
79 /***
80 * The logger
81 */
82 private static final Category log =
83 Category.getInstance(ClientAcknowledgeTest.class);
84
85
86 /***
87 * Construct a new <code>ClientAcknowledgeTest</code>
88 *
89 * @param name the name of test case
90 */
91 public ClientAcknowledgeTest(String name) {
92 super(name);
93 }
94
95 /***
96 * Sets up the test suite.
97 *
98 * @return an instance of this class that may be run by
99 * {@link org.exolab.jmscts.core.JMSTestRunner}
100 */
101 public static Test suite() {
102 return TestCreator.createSendReceiveTest(ClientAcknowledgeTest.class);
103 }
104
105 /***
106 * Returns the list of destination names used by this test case. These
107 * are used to pre-administer destinations prior to running the test case.
108 *
109 * @return the list of destinations used by this test case
110 */
111 public String[] getDestinations() {
112 return DESTINATIONS;
113 }
114
115 /***
116 * Verifies client acknowledgement functionality. For each destination,
117 * send n messages, and then receive them. Acknowledge the last message
118 * received, recover the session, and verify that no other messages are
119 * received.
120
121 * @jmscts.requirement session.CLIENT_ACKNOWLEDGE
122 * @jmscts.requirement session.recover
123 * @throws Exception for any error
124 */
125 public void testClientAcknowledge() throws Exception {
126 final int count = 10; // send count messages to each destination
127
128 TestContext context = getContext();
129 Session session = context.getSession();
130
131 // create the receivers prior to sending any messages
132 MessageReceiver[] receivers = createReceivers();
133
134 try {
135 // send the messages, assigning the JMSXGroupSeq and JMSXGroupID
136 // properties to each message
137 send(count);
138
139 // acknowledge the last message received by the session, and
140 // verify no other messages are received
141 Message last = receive(receivers, count, 1, false);
142 last.acknowledge();
143 receive(receivers, 0);
144
145 // recover the session and verify no messages are received
146 session.recover();
147 receive(receivers, 0);
148 } finally {
149 close(receivers);
150 }
151 }
152
153 /***
154 * Verifies client acknowledgement functionality. For each destination,
155 * send n messages, and then receive them. Acknowledge the middle message
156 * received for each destination, recover the session, and verify that
157 * the messages can be received again.
158 * The messages received after recovery should have their JMSRedelivered
159 * flag set to true.
160 *
161 * @jmscts.requirement session.CLIENT_ACKNOWLEDGE
162 * @jmscts.requirement session.recover
163 * @jmscts.requirement message.redelivered.receive
164 * @throws Exception for any error
165 */
166 public void testPartialClientAcknowledge() throws Exception {
167 final int count = 10; // send count messages to each destination
168
169 TestContext context = getContext();
170 Session session = context.getSession();
171
172 // create the receivers prior to sending any messages
173 MessageReceiver[] receivers = createReceivers();
174
175 try {
176 // send the messages, assigning the JMSXGroupSeq and JMSXGroupID
177 // properties to each message
178 send(count);
179
180 // for each destination, receive all messages, verify they
181 // have the correct sequence, and acknowledge the first half.
182 // The session needs to be recovered each time to avoid
183 // acknowledging messages received from the other destinations.
184 for (int i = 0; i < receivers.length; ++i) {
185 List result = receive(receivers[i], count);
186
187 // verify that each message has the correct properties
188 String name = getDestinations()[i];
189 checkProperties(result, name, 1, false);
190
191 // Acknowledge the middle message. This should
192 // acknowledge all prior messages as well.
193 Message received = (Message) result.get((count / 2) - 1);
194 received.acknowledge();
195
196 log.debug("Recovering session to receive "
197 + "unacknowledged messages");
198 session.recover();
199 }
200
201 // now receive the remaining messages, and acknowledge the last one
202 int remaining = count - (count / 2);
203 int sequence = count - remaining + 1;
204 Message last = receive(receivers, remaining, sequence, true);
205 last.acknowledge();
206
207 // verify that no further messages are received
208 receive(receivers, 0);
209 session.recover();
210 receive(receivers, 0);
211 } finally {
212 close(receivers);
213 }
214 }
215
216 /***
217 * Verifies session recovery behaviour. For each destination,
218 * send n messages, and then receive them. Recover the session, and
219 * verify that the messages can be received again.
220 * The messages received after recovery should have their JMSRedelivered
221 * flag set to true.
222 *
223 * @jmscts.requirement session.recover
224 * @jmscts.requirement message.redelivered.receive
225 * @throws Exception for any error
226 */
227 public void testRecover() throws Exception {
228 final int count = 10; // send count messages to each destination
229
230 TestContext context = getContext();
231 Session session = context.getSession();
232
233 // create the receivers prior to sending any messages
234 MessageReceiver[] receivers = createReceivers();
235
236 try {
237 send(count);
238 receive(receivers, count, 1, false);
239 session.recover();
240 receive(receivers, count, 1, true);
241 } finally {
242 close(receivers);
243 }
244 }
245
246 }
This page was automatically generated by Maven