KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > usecases > CreateLotsOfTemporaryQueuesTest


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.usecases;
19
20 import org.apache.activemq.EmbeddedBrokerTestSupport;
21
22 import javax.jms.Connection JavaDoc;
23 import javax.jms.Session JavaDoc;
24 import javax.jms.TemporaryQueue JavaDoc;
25
26 import junit.framework.Test;
27 import junit.framework.TestSuite;
28 import junit.textui.TestRunner;
29
30 /**
31  *
32  * @version $Revision: 1.1 $
33  */

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 JavaDoc[] 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 JavaDoc {
50         log.info("Creating " + numberToCreate + " temporary queue(s)");
51
52         Connection JavaDoc connection = createConnection();
53         connection.start();
54         Session JavaDoc 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 JavaDoc 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 JavaDoc[] args) {
68         if (args.length > 0) {
69             numberToCreate = Integer.parseInt(args[0]);
70         }
71     }
72 }
73
Popular Tags