KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > nmr > flow > jms > MultipleJMSFlowTest


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.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 JavaDoc {
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 JavaDoc {
43         super.tearDown();
44         broker.stop();
45     }
46     
47     public void test() throws Exception JavaDoc {
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 JavaDoc 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