1 22 package org.jboss.ejb3.test.strictpool.unit; 23 24 import javax.jms.*; 25 import javax.naming.InitialContext ; 26 import org.jboss.ejb3.test.strictpool.MDBInvoker; 27 import org.jboss.ejb3.test.strictpool.SessionInvoker; 28 import org.jboss.ejb3.test.strictpool.StrictlyPooledSession; 29 import org.jboss.ejb3.test.strictpool.Counter; 30 import org.jboss.test.JBossTestCase; 31 import EDU.oswego.cs.dl.util.concurrent.CountDown; 32 import junit.framework.Test; 33 34 35 41 public class StrictPoolUnitTestCase 42 extends JBossTestCase 43 { 44 static final int MAX_SIZE = 20; 45 static String QUEUE_FACTORY = "ConnectionFactory"; 46 47 48 public StrictPoolUnitTestCase(String name) 49 { 50 super(name); 51 } 52 public void testSession() throws Exception 53 { 54 System.out.println("*** testSession"); 55 CountDown done = new CountDown(MAX_SIZE); 56 InitialContext ctx = new InitialContext (); 57 StrictlyPooledSession session =(StrictlyPooledSession)ctx.lookup("StrictlyPooledSessionBean/remote"); 58 SessionInvoker[] threads = new SessionInvoker[MAX_SIZE]; 59 for(int n = 0; n < MAX_SIZE; n ++) 60 { 61 SessionInvoker t = new SessionInvoker(n, done, session); 62 threads[n] = t; 63 t.start(); 64 } 65 boolean ok = done.attempt(1500 * MAX_SIZE); 66 super.assertTrue("Acquired done, remaining="+done.currentCount(), ok); 67 68 for(int n = 0; n < MAX_SIZE; n ++) 69 { 70 SessionInvoker t = threads[n]; 71 if( t.runEx != null ) 72 { 73 t.runEx.printStackTrace(); 74 System.err.println("SessionInvoker.runEx != null"); 75 t.runEx.printStackTrace(); 76 fail("SessionInvoker.runEx != null"); 77 } 78 } 79 } 80 81 public void testMessageDriven() throws Exception 82 { 83 System.out.println("*** testMessageDriven"); 84 CountDown done = new CountDown(MAX_SIZE); 85 InitialContext ctx = new InitialContext (); 86 QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup(QUEUE_FACTORY); 87 QueueConnection queConn = factory.createQueueConnection(); 88 QueueSession session = queConn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); 89 Queue queueA = (Queue) ctx.lookup("queue/queueA"); 90 Queue queueB = (Queue) ctx.lookup("queue/queueB"); 91 queConn.start(); 92 MDBInvoker[] threads = new MDBInvoker[MAX_SIZE]; 93 for(int n = 0; n < MAX_SIZE; n ++) 94 { 95 MDBInvoker t = new MDBInvoker(session, queueA, queueB, n, done); 96 threads[n] = t; 97 t.start(); 98 } 99 assertTrue("Acquired done", done.attempt(1500 * MAX_SIZE)); 100 session.close(); 101 queConn.close(); 102 103 for(int n = 0; n < MAX_SIZE; n ++) 104 { 105 MDBInvoker t = threads[n]; 106 if( t.runEx != null ) 107 { 108 t.runEx.printStackTrace(); 109 fail("Inovker.runEx != null, msg="+t.runEx.getMessage()); 110 } 111 } 112 } 113 public void testPoolTimeout() throws Exception 114 { 115 InitialContext ctx = new InitialContext (); 116 ConnectionFactory factory = (ConnectionFactory)ctx.lookup("ConnectionFactory"); 117 Connection conn = factory.createConnection(); 118 Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); 119 Queue queueC = (Queue)ctx.lookup("queue/queueC"); 120 conn.start(); 121 MessageProducer sender = session.createProducer(queueC); 122 TextMessage msg = session.createTextMessage("hello world"); 123 msg.setIntProperty("JMS_JBOSS_REDELIVERY_LIMIT", 20); 124 sender.send(msg); 125 TextMessage msg2 = session.createTextMessage("hello world 2"); 127 msg2.setIntProperty("JMS_JBOSS_REDELIVERY_LIMIT", 20); 128 sender.send(msg2); 129 130 Thread.sleep(5000); 131 Counter counter = (Counter)ctx.lookup("CounterBean/remote"); 132 assertEquals(1, counter.getCount()); 133 134 } 135 136 public static Test suite() throws Exception 137 { 138 return getDeploySetup(StrictPoolUnitTestCase.class, "strictpool_mdbtest-service.xml, strictpool-test.jar"); 139 140 } 141 142 } 143 | Popular Tags |