KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > network > ForwardingBridgeTest


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.network;
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 import org.apache.activemq.network.ForwardingBridge;
30
31 import junit.framework.Test;
32
33
34 public class ForwardingBridgeTest extends NetworkTestSupport {
35     
36     public ActiveMQDestination destination;
37     public byte destinationType;
38     public int deliveryMode;
39     private ForwardingBridge bridge;
40
41     public void initCombosForTestAddConsumerThenSend() {
42         addCombinationValues( "deliveryMode", new Object JavaDoc[]{
43                 new Integer JavaDoc(DeliveryMode.NON_PERSISTENT),
44                 new Integer JavaDoc(DeliveryMode.PERSISTENT)} );
45         addCombinationValues( "destinationType", new Object JavaDoc[]{
46                 new Byte JavaDoc(ActiveMQDestination.QUEUE_TYPE),
47                 new Byte JavaDoc(ActiveMQDestination.TOPIC_TYPE),
48                 } );
49     }
50     public void testAddConsumerThenSend() throws Exception JavaDoc {
51         // Start a producer on local broker
52
StubConnection connection1 = createConnection();
53         ConnectionInfo connectionInfo1 = createConnectionInfo();
54         SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
55         ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
56         connection1.send(connectionInfo1);
57         connection1.send(sessionInfo1);
58         connection1.send(producerInfo);
59
60         destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
61
62         // Start a consumer on a remote broker
63
StubConnection connection2 = createRemoteConnection();
64         ConnectionInfo connectionInfo2 = createConnectionInfo();
65         SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
66         connection2.send(connectionInfo2);
67         connection2.send(sessionInfo2);
68         ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo2, destination);
69         connection2.send(consumerInfo);
70         Thread.sleep(1000);
71         // Send the message to the local boker.
72
connection1.send(createMessage(producerInfo, destination, deliveryMode));
73         
74         // Make sure the message was delivered via the remote.
75

76         Message m = receiveMessage(connection2);
77         assertNotNull(m);
78     }
79     
80     protected void setUp() throws Exception JavaDoc {
81         super.setUp();
82         bridge = new ForwardingBridge(createTransport(), createRemoteTransport());
83         bridge.setClientId("local-remote-bridge");
84         bridge.setDispatchAsync(false);
85         bridge.start();
86         
87         // PATCH: Give forwarding bridge a chance to finish setting up
88
try {
89             Thread.sleep(1000);
90         } catch (InterruptedException JavaDoc ie) {
91             ie.printStackTrace();
92         }
93     }
94     
95     protected void tearDown() throws Exception JavaDoc {
96         bridge.stop();
97         super.tearDown();
98     }
99     
100     public static Test suite() {
101         return suite(ForwardingBridgeTest.class);
102     }
103     
104     public static void main(String JavaDoc[] args) {
105         junit.textui.TestRunner.run(suite());
106     }
107
108 }
109
Popular Tags