1 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 36 37 public class JBossMQReconnectStressTestCase extends JBossTestCase 38 { 39 static String QUEUE_FACTORY = "ConnectionFactory"; 40 41 public JBossMQReconnectStressTestCase(String name) throws Exception 42 { 43 super(name); 44 } 45 46 public void testReconnectStress() throws Throwable 47 { 48 InitialContext ctx = new InitialContext (); 49 QueueConnectionFactory qcf = (QueueConnectionFactory ) 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 66 { 67 public Throwable error; 68 public QueueConnectionFactory qcf; 69 70 public ReconnectThread(QueueConnectionFactory qcf, String name) 71 { 72 super(name); 73 this.qcf = qcf; 74 } 75 76 public void run() 77 { 78 QueueConnection 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 t) 91 { 92 if (c != null) 93 { 94 try 95 { 96 c.close(); 97 } 98 catch (Throwable ignored) 99 { 100 log.warn("Ignored: ", ignored); 101 } 102 } 103 } 104 } 105 } 106 } 107 | Popular Tags |