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.
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 2003-2004 (C) Exoffice Technologies Inc. All Rights Reserved.
42   *
43   * $Id: ReceiveSize0KTest.java,v 1.4 2004/02/03 21:52:08 tanderson Exp $
44   */
45  package org.exolab.jmscts.stress;
46  
47  import javax.jms.Destination;
48  import javax.jms.Message;
49  import javax.jms.Session;
50  
51  import org.apache.log4j.Category;
52  
53  import junit.framework.Test;
54  
55  import org.exolab.jmscts.core.AckType;
56  import org.exolab.jmscts.core.AbstractSendReceiveTestCase;
57  import org.exolab.jmscts.core.CountingListener;
58  import org.exolab.jmscts.core.SessionHelper;
59  import org.exolab.jmscts.core.MessageCreator;
60  import org.exolab.jmscts.core.MessagePopulator;
61  import org.exolab.jmscts.core.MessageReceiver;
62  import org.exolab.jmscts.core.MessageSender;
63  import org.exolab.jmscts.core.TestContext;
64  import org.exolab.jmscts.core.TestCreator;
65  import org.exolab.jmscts.core.TestProperties;
66  import org.exolab.jmscts.core.TestStatistics;
67  import org.exolab.jmscts.core.ThreadedReceiver;
68  import org.exolab.jmscts.core.ThreadedSender;
69  import org.exolab.jmscts.report.types.StatisticType;
70  
71  
72  /***
73   * Performs a stress test using one producer, one consumer and empty
74   * messages.
75   *
76   * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
77   * @version $Revision: 1.4 $
78   * @jmscts.message all
79   * @jmscts.session AUTO_ACKNOWLEDGE
80   * @jmscts.session CLIENT_ACKNOWLEDGE
81   * @jmscts.session DUPS_OK_ACKNOWLEDGE
82   * @jmscts.delivery consumer
83   */
84  public class ReceiveSize0KTest extends AbstractSendReceiveTestCase {
85  
86      /***
87       * The logger
88       */
89      private static final Category LOG = Category.getInstance(
90          ReceiveSize0KTest.class);
91  
92      /***
93       * The destination used by this test case
94       */
95      private static final String DESTINATION = "ReceiveSize0KTest";
96  
97  
98      /***
99       * Construct a <code>ReceiveSize0KTest</code> for a specific
100      * test case
101      *
102      * @param name the name of test case
103      */
104     public ReceiveSize0KTest(String name) {
105         super(name);
106     }
107 
108     /***
109      * Sets up the test suite
110      *
111      * @return an instance of this class that may be run by
112      * {@link org.exolab.jmscts.core.StressTestRunner}
113      */
114     public static Test suite() {
115         return TestCreator.createSendReceiveTest(ReceiveSize0KTest.class);
116     }
117 
118     /***
119      * Determines if messages should be pre-created and populated for the test.
120      *
121      * @return <code>false</code>
122      */
123     public boolean shouldCreateMessage() {
124         return false;
125     }
126 
127     /***
128      * Get the message populator. This implementation returns <code>null</code>
129      *
130      * @return <code>null</code>
131      */
132     public MessagePopulator getMessagePopulator() {
133         return null;
134     }
135 
136     /***
137      * Returns the list of destination names used by this test case. These
138      * are used to pre-create destinations prior to running the test case.
139      *
140      * @return the list of destinations used by this test case
141      */
142     public String[] getDestinations() {
143         return new String[]{DESTINATION};
144     }
145 
146     /***
147      * Performs a stress test using:
148      * <ul>
149      *   <li>a single consumer</li>
150      *   <li>empty messages</li>
151      * </ul>
152      * For <em>CLIENT_ACKNOWLEDGE</em> sessions, each message is acknowledged.
153      *
154      * @throws Exception for any error
155      */
156     public void test() throws Exception {
157         final int defaultCount = 1000;
158         final int count = TestProperties.getInt(getClass(), "count",
159                                                 defaultCount);
160 
161         TestContext context = getContext();
162 
163         Session session = context.getSession();
164         MessageCreator creator = new MessageCreator(session, null);
165         Class messageType = context.getMessageType();
166         Destination destination = getDestination(DESTINATION);
167         MessageSender sender = SessionHelper.createSender(
168             context, destination);
169         MessageReceiver receiver = SessionHelper.createReceiver(
170             context, destination);
171 
172         CountingListener listener;
173         AckType ack = context.getAckType();
174         if (ack.getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE) {
175             listener = new AckingListener(count);
176         } else {
177             listener = new CountingListener(count);
178         }
179 
180         TestStatistics stats = context.getStatistics();
181 
182         Message message = creator.create(messageType);
183 
184         ThreadedSender send = new ThreadedSender(sender, message, count);
185         ThreadedReceiver receive = new ThreadedReceiver(
186             receiver, 0, listener);
187 
188         send.run();      // run the send in the current thread
189 
190         if (send.getException() != null) {
191             throw send.getException();
192         }
193 
194         receive.run();   // run the receive after the send has completed
195 
196         if (receive.getException() != null) {
197             throw receive.getException();
198         }
199 
200         int received = listener.getReceived();
201         assertEquals("Expected " + count + " messages to be received, but got "
202                      + received, count, received);
203 
204         stats.log(StatisticType.RECEIVE, count, receive.getElapsedTime());
205 
206         receiver.remove();
207     }
208 
209 }
This page was automatically generated by Maven