01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.test.jbossmq.perf;
23:
24: import javax.jms.QueueConnection;
25: import javax.jms.QueueConnectionFactory;
26: import javax.naming.InitialContext;
27:
28: import org.jboss.test.JBossTestCase;
29:
30: /**
31: * Reconnect stress
32: *
33: * @author
34: * @version
35: */
36:
37: public class JBossMQReconnectStressTestCase extends JBossTestCase {
38: static String QUEUE_FACTORY = "ConnectionFactory";
39:
40: public JBossMQReconnectStressTestCase(String name) throws Exception {
41: super (name);
42: }
43:
44: public void testReconnectStress() throws Throwable {
45: InitialContext ctx = new InitialContext();
46: QueueConnectionFactory qcf = (QueueConnectionFactory) ctx
47: .lookup(QUEUE_FACTORY);
48:
49: ReconnectThread[] threads = new ReconnectThread[getThreadCount()];
50: for (int i = 0; i < threads.length; ++i)
51: threads[i] = new ReconnectThread(qcf, "Reconnect-" + i);
52: for (int i = 0; i < threads.length; ++i)
53: threads[i].start();
54: for (int i = 0; i < threads.length; ++i)
55: threads[i].join();
56: for (int i = 0; i < threads.length; ++i) {
57: if (threads[i].error != null)
58: throw threads[i].error;
59: }
60: }
61:
62: public class ReconnectThread extends Thread {
63: public Throwable error;
64: public QueueConnectionFactory qcf;
65:
66: public ReconnectThread(QueueConnectionFactory qcf, String name) {
67: super (name);
68: this .qcf = qcf;
69: }
70:
71: public void run() {
72: QueueConnection c = null;
73: try {
74: for (int i = 0; i < getIterationCount(); ++i) {
75: log.info(Thread.currentThread() + " connect " + i);
76: c = qcf.createQueueConnection();
77: log.info(Thread.currentThread() + " close " + i);
78: c.close();
79: c = null;
80: }
81: } catch (Throwable t) {
82: if (c != null) {
83: try {
84: c.close();
85: } catch (Throwable ignored) {
86: log.warn("Ignored: ", ignored);
87: }
88: }
89: }
90: }
91: }
92: }
|