1 18 package org.apache.activemq.usecases; 19 20 import org.apache.activemq.EmbeddedBrokerTestSupport; 21 22 import javax.jms.Connection ; 23 import javax.jms.Session ; 24 import javax.jms.TemporaryQueue ; 25 26 import junit.framework.Test; 27 import junit.framework.TestSuite; 28 import junit.textui.TestRunner; 29 30 34 public class CreateLotsOfTemporaryQueuesTest extends EmbeddedBrokerTestSupport { 35 36 private static int numberToCreate = 500; 37 private static long sleep = 20; 38 39 40 public static void main(String [] args) { 41 configure(args); 42 TestRunner.run(suite()); 43 } 44 45 public static Test suite() { 46 return new TestSuite(CreateLotsOfTemporaryQueuesTest.class); 47 } 48 49 public void testCreateLotsOfTemporaryQueues() throws Exception { 50 log.info("Creating " + numberToCreate + " temporary queue(s)"); 51 52 Connection connection = createConnection(); 53 connection.start(); 54 Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE); 55 for (int i = 0; i < numberToCreate; i++) { 56 if (i % 1000 == 0) { 57 log.info("attempt " + i); 58 } 59 TemporaryQueue temporaryQueue = session.createTemporaryQueue(); 60 temporaryQueue.delete(); 61 Thread.sleep(sleep ); 62 } 63 log.info("Created " + numberToCreate + " temporary queue(s)"); 64 connection.close(); 65 } 66 67 public static void configure(String [] args) { 68 if (args.length > 0) { 69 numberToCreate = Integer.parseInt(args[0]); 70 } 71 } 72 } 73 | Popular Tags |