1 17 package org.apache.servicemix.jbi.nmr.flow; 18 19 import junit.framework.TestCase; 20 21 import org.apache.servicemix.jbi.container.SpringJBIContainer; 22 import org.apache.servicemix.tck.Receiver; 23 import org.apache.servicemix.tck.Sender; 24 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext; 25 import org.springframework.context.support.AbstractXmlApplicationContext; 26 27 public class MultipleFlowsTest extends TestCase { 28 29 private SpringJBIContainer localContainer; 30 private SpringJBIContainer remoteContainer; 31 32 private Sender localSender; 33 private Sender remoteSender; 34 private Sender clusteredSender; 35 36 private Receiver localReceiver; 37 private Receiver remoteReceiver; 38 private Receiver clusteredReceiver1; 39 private Receiver clusteredReceiver2; 40 41 private AbstractXmlApplicationContext context; 42 43 private int messageCount = 100; 44 45 protected void setUp() throws Exception { 46 context = new ClassPathXmlApplicationContext("org/apache/servicemix/jbi/nmr/flow/multiple-flows.xml"); 47 localContainer = (SpringJBIContainer) context.getBean("local"); 48 remoteContainer = (SpringJBIContainer) context.getBean("remote"); 49 localSender = (Sender) localContainer.getBean("localSender"); 50 remoteSender = (Sender) localContainer.getBean("remoteSender"); 51 clusteredSender = (Sender) localContainer.getBean("clusteredSender"); 52 localReceiver = (Receiver) localContainer.getBean("localReceiver"); 53 remoteReceiver = (Receiver) remoteContainer.getBean("remoteReceiver"); 54 clusteredReceiver1 = (Receiver) localContainer.getBean("clusteredReceiver"); 55 clusteredReceiver2 = (Receiver) remoteContainer.getBean("clusteredReceiver"); 56 Thread.sleep(5000); 57 } 58 59 protected void tearDown() throws Exception { 60 context.close(); 61 } 62 63 public void test() throws Exception { 64 localSender.sendMessages(messageCount); 66 localReceiver.getMessageList().assertMessagesReceived(messageCount); 67 68 remoteSender.sendMessages(messageCount); 70 remoteReceiver.getMessageList().assertMessagesReceived(messageCount); 71 72 clusteredSender.sendMessages(messageCount); 74 long t0 = System.currentTimeMillis(); 75 int n1 = 0; 76 int n2 = 0; 77 while (System.currentTimeMillis() - t0 < 10000) { 78 n1 = clusteredReceiver1.getMessageList().getMessageCount(); 79 n2 = clusteredReceiver2.getMessageList().getMessageCount(); 80 if (n1 + n2 == messageCount) { 81 break; 82 } 83 } 84 assertEquals(messageCount, n1 + n2); 85 assertTrue(n1 > 0); 86 assertTrue(n2 > 0); 87 } 88 89 } 90 | Popular Tags |