KickJava   Java API By Example, From Geeks To Geeks.

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


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 JoinQuorumTest 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         JoinQuorum flow = new JoinQuorum(child1, child2, child3);
33         startActivity(flow, timeout);
34
35         child1.stop();
36         assertStarted(flow);
37
38         child2.stop();
39         assertStopped(flow);
40
41         // lets check things are still fine when the quorum is complete
42
child3.stop();
43         assertStopped(flow);
44     }
45
46     public void testJoinQuorumTerminatesWhenTooManyClientsFail() throws Exception JavaDoc {
47         JoinQuorum flow = new JoinQuorum(child1, child2, child3);
48         startActivity(flow, timeout);
49
50         child3.fail("Test case error simulation");
51         assertStarted(flow);
52
53         child2.fail("Test case error simulation");
54         assertFailed(flow);
55     }
56
57     public void testJoinQuorumFailsIfChildrenDoNotCompleteInTime() throws Exception JavaDoc {
58         JoinQuorum flow = new JoinQuorum(child1, child2, child3);
59         startActivity(flow, timeout);
60
61         child1.stop();
62         assertStarted(flow);
63
64         // lets force a timeout failure
65
Thread.sleep(timeout * 2);
66
67         assertFailed(flow);
68
69         // lets check that completing the final child flow keeps the join failed
70
child2.stop();
71         assertFailed(flow);
72
73         child3.stop();
74         assertFailed(flow);
75     }
76 }
77
Popular Tags