KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > beanflow > util > ParallelTest


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.util;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.apache.servicemix.beanflow.annotations.Parallel;
22
23 /**
24  *
25  * @version $Revision: $
26  */

27 // START SNIPPET: workflow
28
public class ParallelTest extends ParallelTestCase {
29     private static final Log log = LogFactory.getLog(ParallelBeanWithSyncs.class);
30
31     private boolean methodOneSync1, methodOneSync2, methodTwoSync1, methodTwoSync2;
32
33     @Override JavaDoc
34     public void testParallelMethods() throws Exception JavaDoc {
35         super.testParallelMethods();
36
37         assertTrue("Did not reach sync1 for methodOne", methodOneSync1);
38         assertTrue("Did not reach sync2 for methodOne", methodOneSync2);
39         assertTrue("Did not reach sync1 for methodTwo", methodTwoSync1);
40         assertTrue("Did not reach sync2 for methodTwo", methodTwoSync2);
41     }
42
43     @Parallel
44     public void methodOne() {
45         log.info("Called method one");
46         sync();
47         methodOneSync1 = true;
48         log.info("methodOne: after sync1");
49
50         // simulate a slow thing
51
sleep(1000);
52
53         sync();
54         methodOneSync2 = true;
55         log.info("methodOne: after sync2");
56     }
57
58     @Parallel
59     public void methodTwo() {
60         log.info("Called method two");
61
62         // simulate a slow thing
63
sleep(1000);
64
65         sync();
66         methodTwoSync1 = true;
67         log.info("methodTwo: after sync1");
68
69         sync();
70         methodTwoSync2 = true;
71         log.info("methodTwo: after sync2");
72     }
73
74 }
75 // END SNIPPET: workflow
76
Popular Tags