KickJava   Java API By Example, From Geeks To Geeks.

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


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

14 package org.apache.activemq.perf;
15
16 import java.io.File JavaDoc;
17 import java.net.URI JavaDoc;
18 import javax.jms.Connection JavaDoc;
19 import javax.jms.Destination JavaDoc;
20 import javax.jms.JMSException JavaDoc;
21 import javax.jms.MapMessage JavaDoc;
22 import javax.jms.Message JavaDoc;
23 import javax.jms.MessageProducer JavaDoc;
24 import javax.jms.Session JavaDoc;
25 import javax.jms.Topic JavaDoc;
26 import javax.jms.TopicSubscriber JavaDoc;
27 import junit.framework.AssertionFailedError;
28 import junit.framework.TestCase;
29 import org.apache.activemq.ActiveMQConnectionFactory;
30 import org.apache.activemq.broker.BrokerFactory;
31 import org.apache.activemq.broker.BrokerService;
32 import org.apache.activemq.store.journal.JournalPersistenceAdapterFactory;
33 import org.apache.activemq.store.kahadaptor.KahaPersistenceAdapter;
34 /**
35  * @version $Revision: 454471 $
36  */

37 public class InactiveQueueTest extends TestCase{
38     private static final int MESSAGE_COUNT = 0;
39     private static final String JavaDoc DEFAULT_PASSWORD="";
40     private static final String JavaDoc USERNAME="testuser";
41     private static final String JavaDoc CLIENTID="mytestclient";
42     private static final String JavaDoc QUEUE_NAME="testevent";
43     private static final int deliveryMode=javax.jms.DeliveryMode.PERSISTENT;
44     private static final int deliveryPriority=javax.jms.Message.DEFAULT_PRIORITY;
45     private Connection JavaDoc connection=null;
46     private MessageProducer JavaDoc publisher=null;
47     private TopicSubscriber JavaDoc subscriber=null;
48     private Destination JavaDoc destination=null;
49     private Session JavaDoc session=null;
50     ActiveMQConnectionFactory connectionFactory=null;
51     BrokerService broker;
52
53     protected void setUp() throws Exception JavaDoc{
54         super.setUp();
55         broker=new BrokerService();
56         
57         //broker.setPersistenceAdapter(new KahaPersistenceAdapter(new File ("TEST_STUFD")));
58
/*
59         JournalPersistenceAdapterFactory factory = new JournalPersistenceAdapterFactory();
60         factory.setDataDirectoryFile(broker.getDataDirectory());
61         factory.setTaskRunnerFactory(broker.getTaskRunnerFactory());
62         factory.setUseJournal(false);
63         broker.setPersistenceFactory(factory);
64         */

65         broker.addConnector(ActiveMQConnectionFactory.DEFAULT_BROKER_URL);
66         broker.start();
67         connectionFactory=new ActiveMQConnectionFactory(ActiveMQConnectionFactory.DEFAULT_BROKER_URL);
68         /*
69          * Doesn't matter if you enable or disable these, so just leaving them out for this test case
70          * connectionFactory.setAlwaysSessionAsync(true); connectionFactory.setAsyncDispatch(true);
71          */

72         connectionFactory.setUseAsyncSend(true);
73     }
74
75     protected void tearDown() throws Exception JavaDoc{
76         super.tearDown();
77         broker.stop();
78     }
79
80     public void testNoSubscribers() throws Exception JavaDoc{
81         connection=connectionFactory.createConnection(USERNAME,DEFAULT_PASSWORD);
82         assertNotNull(connection);
83         connection.start();
84         session=connection.createSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);
85         assertNotNull(session);
86         destination=session.createQueue(QUEUE_NAME);
87         assertNotNull(destination);
88         publisher=session.createProducer(destination);
89         assertNotNull(publisher);
90         MapMessage JavaDoc msg=session.createMapMessage();
91         assertNotNull(msg);
92         msg.setString("key1","value1");
93         int loop;
94         for(loop=0;loop<MESSAGE_COUNT;loop++){
95             msg.setInt("key2",loop);
96             publisher.send(msg,deliveryMode,deliveryPriority,Message.DEFAULT_TIME_TO_LIVE);
97             if (loop%500==0){
98                 System.out.println("Sent " + loop + " messages");
99             }
100         }
101         Thread.sleep(1000000);
102         this.assertEquals(loop,MESSAGE_COUNT);
103         publisher.close();
104         session.close();
105         connection.stop();
106         connection.stop();
107     }
108
109     
110 }
111
Popular Tags