KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > beanflow > JoinAllTest


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.beanflow;
18
19 import org.apache.servicemix.beanflow.util.ActivityTestSupport;
20
21 /**
22  *
23  * @version $Revision: $
24  */

25 public class JoinAllTest extends ActivityTestSupport {
26
27     protected Activity child1 = new TimeoutActivity();
28     protected Activity child2 = new TimeoutActivity();
29     protected Activity child3 = new TimeoutActivity();
30
31     public void testJoinAllWhenEachChildFlowCompletes() throws Exception JavaDoc {
32         // START SNIPPET: example
33
// lets create a join on a number of child flows completing
34
JoinAll flow = new JoinAll(child1, child2, child3);
35         flow.startWithTimeout(timer, timeout);
36
37         // now lets test the flow
38
child1.stop();
39         assertStarted(flow);
40
41         child2.stop();
42         assertStarted(flow);
43
44         child3.stop();
45         assertStopped(flow);
46         // END SNIPPET: example
47
}
48
49     public void testJoinAllTerminatesWhenAClientFails() throws Exception JavaDoc {
50         JoinAll flow = new JoinAll(child1, child2, child3);
51         startActivity(flow, timeout);
52
53         child3.fail("Test case error simulation");
54         assertStarted(flow);
55
56         child2.stop();
57         assertStarted(flow);
58
59         child1.stop();
60         assertFailed(flow);
61     }
62
63     public void testJoinAllTerminatesAsSoonAsOneChildFails() throws Exception JavaDoc {
64         JoinAll flow = new JoinAll(child1, child2, child3);
65         flow.setFailFast(true);
66         startActivity(flow, timeout);
67
68         child1.fail("Test case error simulation");
69         assertFailed(flow);
70     }
71
72     public void testJoinAllFailsIfChildrenDoNotCompleteInTime() throws Exception JavaDoc {
73         JoinAll flow = new JoinAll(child1, child2, child3);
74         startActivity(flow, timeout);
75
76         child1.stop();
77         assertStarted(flow);
78
79         child2.stop();
80         assertStarted(flow);
81
82         // lets force a timeout failure
83
Thread.sleep(timeout * 2);
84
85         assertFailed(flow);
86
87         // lets check that completing the final child flow keeps the join failed
88
child3.stop();
89         assertFailed(flow);
90     }
91 }
92
Popular Tags