1 22 package org.jboss.test.jbossmessaging.perf; 23 24 import javax.jms.QueueConnection ; 25 import javax.jms.QueueConnectionFactory ; 26 import javax.naming.InitialContext ; 27 28 import org.jboss.test.jbossmessaging.JMSTestCase; 29 30 37 38 public class JMSReconnectStressTestCase extends JMSTestCase 39 { 40 static String QUEUE_FACTORY = "ConnectionFactory"; 41 42 public JMSReconnectStressTestCase(String name) throws Exception 43 { 44 super(name); 45 } 46 47 public void testReconnectStress() throws Throwable 48 { 49 InitialContext ctx = new InitialContext (); 50 QueueConnectionFactory qcf = (QueueConnectionFactory ) 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 67 { 68 public Throwable error; 69 public QueueConnectionFactory qcf; 70 71 public ReconnectThread(QueueConnectionFactory qcf, String name) 72 { 73 super(name); 74 this.qcf = qcf; 75 } 76 77 public void run() 78 { 79 QueueConnection 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 t) 92 { 93 if (c != null) 94 { 95 try 96 { 97 c.close(); 98 } 99 catch (Throwable ignored) 100 { 101 log.warn("Ignored: ", ignored); 102 } 103 } 104 } 105 } 106 } 107 } 108 | Popular Tags |