1 18 package org.apache.activemq; 19 20 import javax.jms.Connection ; 21 import javax.jms.Destination ; 22 import javax.jms.Message ; 23 import javax.jms.MessageConsumer ; 24 import javax.jms.MessageProducer ; 25 import javax.jms.Session ; 26 import javax.jms.TextMessage ; 27 import javax.jms.Topic ; 28 29 import org.apache.activemq.test.JmsTopicSendReceiveTest; 30 31 34 public class JmsDurableTopicSendReceiveTest extends JmsTopicSendReceiveTest { 35 private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory 36 .getLog(JmsDurableTopicSendReceiveTest.class); 37 38 protected Connection connection2; 39 protected Session session2; 40 protected Session consumeSession2; 41 protected MessageConsumer consumer2; 42 protected MessageProducer producer2; 43 protected Destination consumerDestination2; 44 protected Destination producerDestination2; 45 50 protected void setUp() throws Exception { 51 this.durable = true; 52 super.setUp(); 53 } 54 55 60 public void testSendWhileClosed() throws Exception { 61 connection2 = createConnection(); 62 connection2.setClientID("test"); 63 connection2.start(); 64 session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE); 65 producer2 = session2.createProducer(null); 66 producer2.setDeliveryMode(deliveryMode); 67 producerDestination2 = session2.createTopic(getProducerSubject()+"2"); 68 Thread.sleep(1000); 69 70 consumeSession2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE); 71 consumerDestination2 = session2.createTopic(getConsumerSubject()+"2"); 72 consumer2 = consumeSession2.createDurableSubscriber((Topic )consumerDestination2, getName()); 73 Thread.sleep(1000); 74 consumer2.close(); 75 TextMessage message = session2.createTextMessage("test"); 76 message.setStringProperty("test","test"); 77 message.setJMSType("test"); 78 producer2.send(producerDestination2, message); 79 log.info("Creating durable consumer"); 80 consumer2 = consumeSession2.createDurableSubscriber((Topic )consumerDestination2, getName()); 81 Message msg = consumer2.receive(1000); 82 assertNotNull(msg); 83 assertEquals(((TextMessage ) msg).getText(), "test"); 84 assertEquals(msg.getJMSType(), "test"); 85 assertEquals(msg.getStringProperty("test"), "test"); 86 connection2.stop(); 87 connection2.close(); 88 } 89 } 90 | Popular Tags |