1   /***
2    * 
3    * Copyright 2004 Protique Ltd
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * 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   **/
18  package org.codehaus.activemq;
19  
20  import javax.jms.Connection;
21  import javax.jms.DeliveryMode;
22  import javax.jms.Session;
23  
24  /***
25   * @version $Revision: 1.18 $
26   */
27  public class JmsTopicSendReceiveWithTwoConnectionsTest extends JmsSendReceiveTestSupport {
28  
29      protected Connection sendConnection;
30      protected Connection receiveConnection;
31      protected Session receiveSession;
32  
33      protected void setUp() throws Exception {
34          super.setUp();
35  
36          connectionFactory = createConnectionFactory();
37  
38          sendConnection = createSendConnection();
39          sendConnection.start();
40  
41          receiveConnection = createReceiveConnection();
42          receiveConnection.start();
43  
44          System.out.println("Created sendConnection: " + sendConnection);
45          System.out.println("Created receiveConnection: " + receiveConnection);
46  
47          session = sendConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
48          receiveSession = receiveConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
49  
50          System.out.println("Created sendSession: " + session);
51          System.out.println("Created receiveSession: " + receiveSession);
52  
53          producer = session.createProducer(null);
54          producer.setDeliveryMode(deliveryMode);
55  
56          System.out.println("Created producer: " + producer + " delivery mode = " +
57                  (deliveryMode == DeliveryMode.PERSISTENT ? "PERSISTENT" : "NON_PERSISTENT"));
58  
59          if (topic) {
60              consumerDestination = session.createTopic(getConsumerSubject());
61              producerDestination = session.createTopic(getProducerSubject());
62          }
63          else {
64              consumerDestination = session.createQueue(getConsumerSubject());
65              producerDestination = session.createQueue(getProducerSubject());
66          }
67  
68          System.out.println("Created  consumer destination: " + consumerDestination + " of type: " + consumerDestination.getClass());
69          System.out.println("Created  producer destination: " + producerDestination + " of type: " + producerDestination.getClass());
70  
71          consumer = receiveSession.createConsumer(consumerDestination);
72          consumer.setMessageListener(this);
73  
74  
75          System.out.println("Started connections");
76      }
77  
78      protected Connection createReceiveConnection() throws Exception {
79          return createConnection();
80      }
81  
82      protected Connection createSendConnection() throws Exception {
83          return createConnection();
84      }
85  
86      protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
87          return new ActiveMQConnectionFactory("vm://localhost");
88      }
89  
90      protected void tearDown() throws Exception {
91          session.close();
92          receiveSession.close();
93          sendConnection.close();
94          receiveConnection.close();
95      }
96  }