KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jbossmessaging > perf > JMSReconnectStressTestCase


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.jbossmessaging.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.jbossmessaging.JMSTestCase;
29
30 /**
31  * Reconnect stress
32  *
33  * @author <a HREF="mailto:richard.achmatowicz@jboss.com">Richard Achmatowicz</a>
34  * @author
35  * @version
36  */

37
38 public class JMSReconnectStressTestCase extends JMSTestCase
39 {
40    static String JavaDoc QUEUE_FACTORY = "ConnectionFactory";
41
42    public JMSReconnectStressTestCase(String JavaDoc name) throws Exception JavaDoc
43    {
44       super(name);
45    }
46
47    public void testReconnectStress() throws Throwable JavaDoc
48    {
49       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
50       QueueConnectionFactory JavaDoc qcf = (QueueConnectionFactory JavaDoc) ctx.lookup(QUEUE_FACTORY);
51       
52       ReconnectThread[] threads = new ReconnectThread[getThreadCount()];
53       for (int i = 0; i < threads.length; ++i)
54          threads[i] = new ReconnectThread(qcf, "Reconnect-"+i);
55       for (int i = 0; i < threads.length; ++i)
56          threads[i].start();
57       for (int i = 0; i < threads.length; ++i)
58          threads[i].join();
59       for (int i = 0; i < threads.length; ++i)
60       {
61          if (threads[i].error != null)
62             throw threads[i].error;
63       }
64    }
65    
66    public class ReconnectThread extends Thread JavaDoc
67    {
68       public Throwable JavaDoc error;
69       public QueueConnectionFactory JavaDoc qcf;
70       
71       public ReconnectThread(QueueConnectionFactory JavaDoc qcf, String JavaDoc name)
72       {
73          super(name);
74          this.qcf = qcf;
75       }
76       
77       public void run()
78       {
79          QueueConnection JavaDoc c = null;
80          try
81          {
82             for (int i = 0; i < getIterationCount(); ++i)
83             {
84                log.info(Thread.currentThread() + " connect " + i);
85                c = qcf.createQueueConnection();
86                log.info(Thread.currentThread() + " close " + i);
87                c.close();
88                c = null;
89             }
90          }
91          catch (Throwable JavaDoc t)
92          {
93             if (c != null)
94             {
95                try
96                {
97                   c.close();
98                }
99                catch (Throwable JavaDoc ignored)
100                {
101                   log.warn("Ignored: ", ignored);
102                }
103             }
104          }
105       }
106    }
107 }
108
Popular Tags