KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > broker > virtual > VirtualTopicPubSubTest


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

17 package org.apache.activemq.broker.virtual;
18
19 import org.apache.activemq.EmbeddedBrokerTestSupport;
20 import org.apache.activemq.command.ActiveMQQueue;
21 import org.apache.activemq.command.ActiveMQTopic;
22 import org.apache.activemq.spring.ConsumerBean;
23
24 import javax.jms.Connection JavaDoc;
25 import javax.jms.MessageConsumer JavaDoc;
26 import javax.jms.MessageProducer JavaDoc;
27 import javax.jms.Session JavaDoc;
28
29 /**
30  *
31  * @version $Revision: $
32  */

33 public class VirtualTopicPubSubTest extends EmbeddedBrokerTestSupport {
34
35     private Connection JavaDoc connection;
36
37     public void testVirtualTopicCreation() throws Exception JavaDoc {
38         if (connection == null) {
39             connection = createConnection();
40         }
41         connection.start();
42
43         ConsumerBean messageList = new ConsumerBean();
44         messageList.setVerbose(true);
45         
46         String JavaDoc queueAName = getVirtualTopicConsumerName();
47         // create consumer 'cluster'
48
ActiveMQQueue queue1 = new ActiveMQQueue(queueAName);
49         ActiveMQQueue queue2 = new ActiveMQQueue(queueAName);
50
51         Session JavaDoc session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
52         MessageConsumer JavaDoc c1 = session.createConsumer(queue1);
53         MessageConsumer JavaDoc c2 = session.createConsumer(queue2);
54
55         c1.setMessageListener(messageList);
56         c2.setMessageListener(messageList);
57
58         // create topic producer
59
MessageProducer JavaDoc producer = session.createProducer(new ActiveMQTopic(getVirtualTopicName()));
60         assertNotNull(producer);
61
62         int total = 10;
63         for (int i = 0; i < total; i++) {
64             producer.send(session.createTextMessage("message: " + i));
65         }
66         
67         messageList.assertMessagesArrived(total);
68     }
69
70
71     protected String JavaDoc getVirtualTopicName() {
72         return "VirtualTopic.TEST";
73     }
74
75
76     protected String JavaDoc getVirtualTopicConsumerName() {
77         return "Consumer.A.VirtualTopic.TEST";
78     }
79
80
81     protected void tearDown() throws Exception JavaDoc {
82         if (connection != null) {
83             connection.close();
84         }
85         super.tearDown();
86     }
87 }
88
Popular Tags