KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > perf > QueueConnectionMemoryTest


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.perf;
19
20 import javax.jms.Connection JavaDoc;
21 import javax.jms.Destination JavaDoc;
22 import javax.jms.JMSException JavaDoc;
23 import javax.jms.MessageConsumer JavaDoc;
24 import javax.jms.Session JavaDoc;
25 import org.apache.activemq.broker.BrokerService;
26 import org.apache.activemq.store.kahadaptor.KahaPersistenceAdapter;
27 /**
28  * @version $Revision: 1.3 $
29  */

30 public class QueueConnectionMemoryTest extends SimpleQueueTest{
31     
32     protected void setUp() throws Exception JavaDoc{
33     }
34     
35     protected void tearDown() throws Exception JavaDoc{
36         
37     }
38     
39     protected Destination JavaDoc createDestination(Session JavaDoc s,String JavaDoc destinationName) throws JMSException JavaDoc{
40         return s.createTemporaryQueue();
41     }
42     
43     
44     
45     public void testPerformance() throws JMSException JavaDoc{
46         //just cancel super class test
47
}
48     
49     protected void configureBroker(BrokerService answer) throws Exception JavaDoc{
50         KahaPersistenceAdapter adaptor = new KahaPersistenceAdapter();
51         answer.setPersistenceAdapter(adaptor);
52         answer.addConnector(bindAddress);
53         answer.setDeleteAllMessagesOnStartup(true);
54     }
55     
56     public void testMemory() throws Exception JavaDoc{
57         if(broker==null){
58             broker=createBroker();
59         }
60         factory=createConnectionFactory();
61         Connection JavaDoc con=factory.createConnection();
62         Session JavaDoc session=con.createSession(false,Session.AUTO_ACKNOWLEDGE);
63         destination=createDestination(session,DESTINATION_NAME);
64         con.close();
65         for (int i =0; i < 3;i++) {
66             Connection JavaDoc connection=factory.createConnection();
67             connection.start();
68             Session JavaDoc s=connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
69             Destination JavaDoc dest = s.createTemporaryQueue();
70             MessageConsumer JavaDoc consumer=s.createConsumer(dest);
71             System.out.println("Created connnection: " + i);
72             Thread.sleep(1000);
73         }
74         
75         Thread.sleep(Integer.MAX_VALUE);
76     }
77 }
78
Popular Tags