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 2003-2004 (C) Exoffice Technologies Inc. All Rights Reserved.
42 *
43 * $Id: Send0KTest.java,v 1.6 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.AbstractSendReceiveTestCase;
56 import org.exolab.jmscts.core.SessionHelper;
57 import org.exolab.jmscts.core.MessageCreator;
58 import org.exolab.jmscts.core.MessagePopulator;
59 import org.exolab.jmscts.core.MessageSender;
60 import org.exolab.jmscts.core.TestContext;
61 import org.exolab.jmscts.core.TestCreator;
62 import org.exolab.jmscts.core.TestProperties;
63 import org.exolab.jmscts.core.TestStatistics;
64 import org.exolab.jmscts.core.ThreadedSender;
65 import org.exolab.jmscts.report.types.StatisticType;
66
67
68 /***
69 * Performs a stress test using one producer and empty messages.
70 *
71 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
72 * @version $Revision: 1.6 $
73 * @jmscts.message all
74 * @jmscts.session AUTO_ACKNOWLEDGE
75 * @jmscts.session CLIENT_ACKNOWLEDGE
76 * @jmscts.session DUPS_OK_ACKNOWLEDGE
77 * @jmscts.delivery NON_PERSISTENT, administered
78 * @jmscts.delivery PERSISTENT, administered
79 * @jmscts.delivery NON_PERSISTENT, temporary
80 * @jmscts.delivery PERSISTENT, temporary
81 */
82 public class Send0KTest extends AbstractSendReceiveTestCase {
83
84 /***
85 * The logger
86 */
87 private static final Category log = Category.getInstance(Send0KTest.class);
88
89 /***
90 * The destination used by this test case
91 */
92 private static final String DESTINATION = "Send0KTest";
93
94
95 /***
96 * Construct a <code>Send0KTest</code> for a specific
97 * test case
98 *
99 * @param name the name of test case
100 */
101 public Send0KTest(String name) {
102 super(name);
103 }
104
105 /***
106 * Sets up the test suite
107 *
108 * @return an instance of this class that may be run by
109 * {@link org.exolab.jmscts.core.StressTestRunner}
110 */
111 public static Test suite() {
112 return TestCreator.createSendReceiveTest(Send0KTest.class);
113 }
114
115 /***
116 * Determines if messages should be pre-created and populated for the test.
117 *
118 * @return <code>false</code>
119 */
120 public boolean shouldCreateMessage() {
121 return false;
122 }
123
124 /***
125 * Get the message populator. This implementation returns <code>null</code>
126 *
127 * @return <code>null</code>
128 */
129 public MessagePopulator getMessagePopulator() {
130 return null;
131 }
132
133 /***
134 * Returns the list of destination names used by this test case. These
135 * are used to pre-create destinations prior to running the test case.
136 *
137 * @return the list of destinations used by this test case
138 */
139 public String[] getDestinations() {
140 return new String[]{DESTINATION};
141 }
142
143 /***
144 * Performs a stress test using:
145 * <ul>
146 * <li>a single producer</li>
147 * <li>a single destination</li>
148 * <li>empty messages</li>
149 * </ul>
150 *
151 * @throws Exception for any error
152 */
153 public void test() throws Exception {
154 final int defaultCount = 1000;
155 final int count = TestProperties.getInt(getClass(), "count",
156 defaultCount);
157
158 TestContext context = getContext();
159 Session session = context.getSession();
160 MessageCreator creator = new MessageCreator(session, null);
161 Class messageType = context.getMessageType();
162 Destination destination = getDestination(DESTINATION);
163 MessageSender sender = SessionHelper.createSender(
164 context, destination);
165 TestStatistics stats = context.getStatistics();
166
167 Message message = creator.create(messageType);
168
169 ThreadedSender send = new ThreadedSender(sender, message, count);
170 send.run(); // run the send in the current thread
171
172 if (send.getException() != null) {
173 throw send.getException();
174 }
175
176 stats.log(StatisticType.SEND, count, send.getElapsedTime());
177 }
178
179 }
This page was automatically generated by Maven