KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jbossmq > perf > JBossMQReconnectStressTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * 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 JavaDoc;
25 import javax.jms.QueueConnectionFactory JavaDoc;
26 import javax.naming.InitialContext JavaDoc;
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 {
39    static String JavaDoc QUEUE_FACTORY = "ConnectionFactory";
40
41    public JBossMQReconnectStressTestCase(String JavaDoc name) throws Exception JavaDoc
42    {
43       super(name);
44    }
45
46    public void testReconnectStress() throws Throwable JavaDoc
47    {
48       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
49       QueueConnectionFactory JavaDoc qcf = (QueueConnectionFactory JavaDoc) ctx.lookup(QUEUE_FACTORY);
50       
51       ReconnectThread[] threads = new ReconnectThread[getThreadCount()];
52       for (int i = 0; i < threads.length; ++i)
53          threads[i] = new ReconnectThread(qcf, "Reconnect-"+i);
54       for (int i = 0; i < threads.length; ++i)
55          threads[i].start();
56       for (int i = 0; i < threads.length; ++i)
57          threads[i].join();
58       for (int i = 0; i < threads.length; ++i)
59       {
60          if (threads[i].error != null)
61             throw threads[i].error;
62       }
63    }
64    
65    public class ReconnectThread extends Thread JavaDoc
66    {
67       public Throwable JavaDoc error;
68       public QueueConnectionFactory JavaDoc qcf;
69       
70       public ReconnectThread(QueueConnectionFactory JavaDoc qcf, String JavaDoc name)
71       {
72          super(name);
73          this.qcf = qcf;
74       }
75       
76       public void run()
77       {
78          QueueConnection JavaDoc c = null;
79          try
80          {
81             for (int i = 0; i < getIterationCount(); ++i)
82             {
83                log.info(Thread.currentThread() + " connect " + i);
84                c = qcf.createQueueConnection();
85                log.info(Thread.currentThread() + " close " + i);
86                c.close();
87                c = null;
88             }
89          }
90          catch (Throwable JavaDoc t)
91          {
92             if (c != null)
93             {
94                try
95                {
96                   c.close();
97                }
98                catch (Throwable JavaDoc ignored)
99                {
100                   log.warn("Ignored: ", ignored);
101                }
102             }
103          }
104       }
105    }
106 }
107
Popular Tags