KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > nmr > flow > MultipleFlowsTest


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

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 JavaDoc {
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 JavaDoc {
60         context.close();
61     }
62     
63     public void test() throws Exception JavaDoc {
64         // Local
65
localSender.sendMessages(messageCount);
66         localReceiver.getMessageList().assertMessagesReceived(messageCount);
67
68         // Remote
69
remoteSender.sendMessages(messageCount);
70         remoteReceiver.getMessageList().assertMessagesReceived(messageCount);
71
72         // Clustered
73
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