1 18 package org.apache.activemq.network; 19 20 import javax.jms.DeliveryMode ; 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 []{ 43 new Integer (DeliveryMode.NON_PERSISTENT), 44 new Integer (DeliveryMode.PERSISTENT)} ); 45 addCombinationValues( "destinationType", new Object []{ 46 new Byte (ActiveMQDestination.QUEUE_TYPE), 47 new Byte (ActiveMQDestination.TOPIC_TYPE), 48 } ); 49 } 50 public void testAddConsumerThenSend() throws Exception { 51 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 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 connection1.send(createMessage(producerInfo, destination, deliveryMode)); 73 74 76 Message m = receiveMessage(connection2); 77 assertNotNull(m); 78 } 79 80 protected void setUp() throws Exception { 81 super.setUp(); 82 bridge = new ForwardingBridge(createTransport(), createRemoteTransport()); 83 bridge.setClientId("local-remote-bridge"); 84 bridge.setDispatchAsync(false); 85 bridge.start(); 86 87 try { 89 Thread.sleep(1000); 90 } catch (InterruptedException ie) { 91 ie.printStackTrace(); 92 } 93 } 94 95 protected void tearDown() throws Exception { 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 [] args) { 105 junit.textui.TestRunner.run(suite()); 106 } 107 108 } 109 | Popular Tags |