1 18 package org.apache.activemq; 19 20 import javax.jms.DeliveryMode ; 21 import javax.jms.Session ; 22 import javax.jms.Message ; 23 import javax.jms.MessageConsumer ; 24 import javax.jms.TextMessage ; 25 import javax.jms.Destination ; 26 import javax.jms.JMSException ; 27 import javax.jms.MessageProducer ; 28 29 import org.apache.activemq.command.ActiveMQDestination; 30 import org.apache.activemq.test.JmsTopicSendReceiveTest; 31 32 33 36 public class JmsQueueWildcardSendReceiveTest extends JmsTopicSendReceiveTest { 37 38 private String destination1String = "TEST.ONE.ONE" ; 39 private String destination2String = "TEST.ONE.ONE.ONE" ; 40 private String destination3String = "TEST.ONE.TWO" ; 41 private String destination4String = "TEST.TWO.ONE" ; 42 43 48 protected void setUp() throws Exception { 49 topic = false; 50 deliveryMode = DeliveryMode.NON_PERSISTENT; 51 super.setUp(); 52 } 53 54 60 protected String getConsumerSubject(){ 61 return "FOO.>"; 62 } 63 64 70 protected String getProducerSubject(){ 71 return "FOO.BAR.HUMBUG"; 72 } 73 74 public void testReceiveWildcardQueueEndAsterisk() throws Exception { 75 connection.start(); 76 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 77 78 ActiveMQDestination destination1 = (ActiveMQDestination) session.createQueue(destination1String); 79 ActiveMQDestination destination3 = (ActiveMQDestination) session.createQueue(destination3String); 80 81 Message m = null; 82 MessageConsumer consumer = null; 83 String text = null; 84 85 sendMessage(session,destination1,destination1String); 86 sendMessage(session,destination3,destination3String); 87 ActiveMQDestination destination6 = (ActiveMQDestination) session.createQueue("TEST.ONE.*"); 88 consumer = session.createConsumer(destination6); 89 m = consumer.receive(1000); 90 assertNotNull(m); 91 text = ((TextMessage )m).getText(); 92 if(!(text.equals(destination1String) || text.equals(destination3String))) { 93 fail("unexpected message:" + text); 94 } 95 m = consumer.receive(1000); 96 assertNotNull(m); 97 text = ((TextMessage )m).getText(); 98 if(!(text.equals(destination1String) || text.equals(destination3String))) { 99 fail("unexpected message:" + text); 100 } 101 assertNull(consumer.receiveNoWait()); 102 } 103 104 public void testReceiveWildcardQueueEndGreaterThan() throws Exception { 105 connection.start(); 106 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 107 108 ActiveMQDestination destination1 = (ActiveMQDestination) session.createQueue(destination1String); 109 ActiveMQDestination destination2 = (ActiveMQDestination) session.createQueue(destination2String); 110 ActiveMQDestination destination3 = (ActiveMQDestination) session.createQueue(destination3String); 111 112 Message m = null; 113 MessageConsumer consumer = null; 114 String text = null; 115 116 sendMessage(session,destination1,destination1String); 117 sendMessage(session,destination2,destination2String); 118 sendMessage(session,destination3,destination3String); 119 ActiveMQDestination destination7 = (ActiveMQDestination) session.createQueue("TEST.ONE.>"); 120 consumer = session.createConsumer(destination7); 121 m = consumer.receive(1000); 122 assertNotNull(m); 123 text = ((TextMessage )m).getText(); 124 if(!(text.equals(destination1String) || text.equals(destination2String) || text.equals(destination3String))) { 125 fail("unexpected message:" + text); 126 } 127 m = consumer.receive(1000); 128 assertNotNull(m); 129 if(!(text.equals(destination1String) || text.equals(destination2String) || text.equals(destination3String))) { 130 fail("unexpected message:" + text); 131 } 132 m = consumer.receive(1000); 133 assertNotNull(m); 134 if(!(text.equals(destination1String) || text.equals(destination2String) || text.equals(destination3String))) { 135 fail("unexpected message:" + text); 136 } 137 assertNull(consumer.receiveNoWait()); 138 } 139 140 public void testReceiveWildcardQueueMidAsterisk() throws Exception { 141 connection.start(); 142 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 143 144 ActiveMQDestination destination1 = (ActiveMQDestination) session.createQueue(destination1String); 145 ActiveMQDestination destination4 = (ActiveMQDestination) session.createQueue(destination4String); 146 147 Message m = null; 148 MessageConsumer consumer = null; 149 String text = null; 150 151 sendMessage(session,destination1,destination1String); 152 sendMessage(session,destination4,destination4String); 153 ActiveMQDestination destination8 = (ActiveMQDestination) session.createQueue("TEST.*.ONE"); 154 consumer = session.createConsumer(destination8); 155 m = consumer.receive(1000); 156 assertNotNull(m); 157 text = ((TextMessage )m).getText(); 158 if(!(text.equals(destination1String) || text.equals(destination4String))) { 159 fail("unexpected message:" + text); 160 } 161 m = consumer.receive(1000); 162 assertNotNull(m); 163 text = ((TextMessage )m).getText(); 164 if(!(text.equals(destination1String) || text.equals(destination4String))) { 165 fail("unexpected message:" + text); 166 } 167 assertNull(consumer.receiveNoWait()); 168 169 } 170 171 private void sendMessage(Session session, Destination destination, String text) throws JMSException { 172 MessageProducer producer = session.createProducer(destination); 173 producer.send(session.createTextMessage(text)); 174 producer.close(); 175 } 176 } 177 | Popular Tags |