1 22 package org.jboss.test.cts.test; 23 24 25 import javax.jms.Queue ; 26 import javax.jms.QueueConnection ; 27 import javax.jms.QueueConnectionFactory ; 28 import javax.jms.QueueSession ; 29 import javax.naming.InitialContext ; 30 31 import EDU.oswego.cs.dl.util.concurrent.CountDown; 32 import junit.framework.Test; 33 import org.jboss.test.JBossTestCase; 34 35 40 public class MDBUnitTestCase 41 extends JBossTestCase 42 { 43 static final int MAX_SIZE = 20; 44 static String QUEUE_FACTORY = "ConnectionFactory"; 45 46 public MDBUnitTestCase (String name) 47 { 48 super(name); 49 } 50 51 public void testPooling() throws Exception 52 { 53 CountDown done = new CountDown(MAX_SIZE); 54 InitialContext ctx = new InitialContext (); 55 QueueConnectionFactory factory = (QueueConnectionFactory ) ctx.lookup(QUEUE_FACTORY); 56 QueueConnection queConn = factory.createQueueConnection(); 57 QueueSession session = queConn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); 58 Queue queueA = (Queue ) ctx.lookup("queue/A"); 59 Queue queueB = (Queue ) ctx.lookup("queue/B"); 60 queConn.start(); 61 MDBInvoker[] threads = new MDBInvoker[MAX_SIZE]; 62 for(int n = 0; n < MAX_SIZE; n ++) 63 { 64 MDBInvoker t = new MDBInvoker(session, queueA, queueB, n, done, getLog()); 65 threads[n] = t; 66 t.start(); 67 } 68 assertTrue("Acquired done", done.attempt(1500 * MAX_SIZE)); 69 session.close(); 70 queConn.close(); 71 72 for(int n = 0; n < MAX_SIZE; n ++) 73 { 74 MDBInvoker t = threads[n]; 75 if( t.runEx != null ) 76 { 77 t.runEx.printStackTrace(); 78 fail("Inovker.runEx != null, msg="+t.runEx.getMessage()); 79 } 80 } 81 } 82 83 public static Test suite() throws Exception 84 { 85 return getDeploySetup(MDBUnitTestCase.class, "cts.jar"); 86 } 87 88 } 89 | Popular Tags |