KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > proxy > ProxyConnectorTest


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

18 package org.apache.activemq.proxy;
19
20 import javax.jms.DeliveryMode JavaDoc;
21
22 import org.apache.activemq.broker.StubConnection;
23 import org.apache.activemq.command.ActiveMQDestination;
24 import org.apache.activemq.command.ConnectionInfo;
25 import org.apache.activemq.command.ConsumerInfo;
26 import org.apache.activemq.command.Message;
27 import org.apache.activemq.command.ProducerInfo;
28 import org.apache.activemq.command.SessionInfo;
29
30 import junit.framework.Test;
31
32
33 public class ProxyConnectorTest extends ProxyTestSupport {
34     
35     public static Test suite() {
36         return suite(ProxyConnectorTest.class);
37     }
38     
39     public static void main(String JavaDoc[] args) {
40         junit.textui.TestRunner.run(suite());
41     }
42
43     public ActiveMQDestination destination;
44     public byte destinationType;
45     public int deliveryMode;
46
47     public void setUp() throws Exception JavaDoc {
48         super.setAutoFail(true);
49         super.setUp();
50     }
51
52     public void initCombosForTestSendAndConsume() {
53         addCombinationValues( "deliveryMode", new Object JavaDoc[]{
54                 new Integer JavaDoc(DeliveryMode.NON_PERSISTENT),
55                 new Integer JavaDoc(DeliveryMode.PERSISTENT)
56                 } );
57         addCombinationValues( "destinationType", new Object JavaDoc[]{
58                 new Byte JavaDoc(ActiveMQDestination.TOPIC_TYPE),
59                 } );
60     }
61     public void testSendAndConsume() throws Exception JavaDoc {
62         
63         // Start a producer on local broker using the proxy
64
StubConnection connection1 = createProxyConnection();
65         ConnectionInfo connectionInfo1 = createConnectionInfo();
66         SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
67         ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
68         connection1.send(connectionInfo1);
69         connection1.send(sessionInfo1);
70         connection1.send(producerInfo);
71
72         destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
73         ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
74         connection1.send(consumerInfo1);
75
76         // Start a consumer on a remote broker using a proxy connection.
77
StubConnection connection2 = createRemoteProxyConnection();
78         ConnectionInfo connectionInfo2 = createConnectionInfo();
79         SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
80         connection2.send(connectionInfo2);
81         connection2.send(sessionInfo2);
82
83         ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
84         connection2.send(consumerInfo2);
85         
86         // Give broker enough time to receive and register the consumer info
87
// Either that or make consumer retroactive
88
try {
89             Thread.sleep(1000);
90         } catch (Exception JavaDoc e) {
91             e.printStackTrace();
92         }
93
94         // Send the message to the local broker.
95
connection1.request(createMessage(producerInfo, destination, deliveryMode));
96                 
97         // Verify that the message Was sent to the remote broker and the local broker.
98
Message m;
99         m = receiveMessage(connection1);
100         assertNotNull(m);
101         assertNoMessagesLeft(connection1);
102
103         m = receiveMessage(connection2);
104         assertNotNull(m);
105         assertNoMessagesLeft(connection2);
106
107     }
108
109    
110 }
111
Popular Tags