1 14 package org.apache.activemq.perf; 15 16 import java.io.File ; 17 import java.net.URI ; 18 import javax.jms.Connection ; 19 import javax.jms.Destination ; 20 import javax.jms.JMSException ; 21 import javax.jms.MapMessage ; 22 import javax.jms.Message ; 23 import javax.jms.MessageProducer ; 24 import javax.jms.Session ; 25 import javax.jms.Topic ; 26 import javax.jms.TopicSubscriber ; 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 37 public class InactiveQueueTest extends TestCase{ 38 private static final int MESSAGE_COUNT = 0; 39 private static final String DEFAULT_PASSWORD=""; 40 private static final String USERNAME="testuser"; 41 private static final String CLIENTID="mytestclient"; 42 private static final String 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 connection=null; 46 private MessageProducer publisher=null; 47 private TopicSubscriber subscriber=null; 48 private Destination destination=null; 49 private Session session=null; 50 ActiveMQConnectionFactory connectionFactory=null; 51 BrokerService broker; 52 53 protected void setUp() throws Exception { 54 super.setUp(); 55 broker=new BrokerService(); 56 57 65 broker.addConnector(ActiveMQConnectionFactory.DEFAULT_BROKER_URL); 66 broker.start(); 67 connectionFactory=new ActiveMQConnectionFactory(ActiveMQConnectionFactory.DEFAULT_BROKER_URL); 68 72 connectionFactory.setUseAsyncSend(true); 73 } 74 75 protected void tearDown() throws Exception { 76 super.tearDown(); 77 broker.stop(); 78 } 79 80 public void testNoSubscribers() throws Exception { 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 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 |