1 17 package org.apache.servicemix.jbi.nmr.flow.jms; 18 19 import org.apache.activemq.broker.BrokerService; 20 import org.apache.activemq.xbean.BrokerFactoryBean; 21 import org.apache.servicemix.jbi.container.JBIContainer; 22 import org.apache.servicemix.jbi.nmr.flow.Flow; 23 import org.apache.servicemix.jbi.nmr.flow.jms.JMSFlow; 24 import org.apache.servicemix.tck.ReceiverComponent; 25 import org.apache.servicemix.tck.SenderComponent; 26 import org.springframework.core.io.ClassPathResource; 27 28 import junit.framework.TestCase; 29 30 public class MultipleJMSFlowTest extends TestCase { 31 32 protected BrokerService broker; 33 34 protected void setUp() throws Exception { 35 BrokerFactoryBean bfb = new BrokerFactoryBean(new ClassPathResource("org/apache/servicemix/jbi/nmr/flow/jca/broker.xml")); 36 bfb.afterPropertiesSet(); 37 broker = bfb.getBroker(); 38 broker.start(); 39 super.setUp(); 40 } 41 42 protected void tearDown() throws Exception { 43 super.tearDown(); 44 broker.stop(); 45 } 46 47 public void test() throws Exception { 48 JBIContainer[] containers = new JBIContainer[4]; 49 for (int i = 0; i < containers.length; i++) { 50 containers[i] = new JBIContainer(); 51 containers[i].setName("container" + i); 52 containers[i].setFlow(createFlow()); 53 containers[i].setEmbedded(true); 54 containers[i].setMonitorInstallationDirectory(false); 55 containers[i].setUseMBeanServer(false); 56 containers[i].setCreateMBeanServer(false); 57 containers[i].init(); 58 } 59 long t0 = System.currentTimeMillis(); 60 printNodes(containers); 61 for (int i = 0; i < containers.length; i++) { 62 containers[i].start(); 63 printNodes(containers); 64 } 65 long t1 = System.currentTimeMillis(); 66 System.err.println(t1 - t0); 67 for (int i = 0; i < containers.length; i++) { 68 containers[i].activateComponent(new ReceiverComponent(), "receiver"); 69 } 70 for (int i = 0; i < containers.length; i++) { 71 containers[i].stop(); 72 printNodes(containers); 73 } 74 for (int i = 0; i < containers.length; i++) { 75 containers[i].start(); 76 printNodes(containers); 77 } 78 for (int i = 0; i < containers.length; i++) { 79 containers[i].stop(); 80 printNodes(containers); 81 } 82 for (int i = 0; i < containers.length; i++) { 83 containers[i].shutDown(); 84 printNodes(containers); 85 } 86 } 87 88 protected void printNodes(JBIContainer[] containers) { 89 String msg = "Nodes: "; 90 for (int j = 0; j < containers.length; j++) { 91 if (j > 0) msg += ", "; 92 msg += ((JMSFlow) containers[j].getFlow()).numberInNetwork(); 93 } 94 System.err.println(msg); 95 } 96 97 protected Flow createFlow() { 98 JMSFlow flow = new JMSFlow(); 99 flow.setJmsURL("tcp://localhost:61216"); 100 return flow; 101 } 102 103 } 104 | Popular Tags |