(no commit message)
[utils] / support / test / org / wamblee / concurrency / JvmLockTest.java
1 /*
2  * Copyright 2005 the original author or authors.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.wamblee.concurrency;
18
19 import org.wamblee.test.EventTracker;
20 import org.wamblee.test.TimingUtils;
21
22 import junit.framework.TestCase;
23
24 /**
25  * Tests for the JVMLock.
26  */
27 public class JvmLockTest extends AbstractLockTestCase {
28
29     private JvmLock _lock;
30     
31     /*
32      * (non-Javadoc)
33      * 
34      * @see junit.framework.TestCase#setUp()
35      */
36     @Override
37     protected void setUp() throws Exception {
38         super.setUp();
39         _lock = new JvmLock();
40     }
41
42     protected Thread runThread() {
43         Thread t = new Thread(new Runnable() {
44             public void run() {
45                 getTracker().eventOccurred(STARTED);
46                 _lock.acquire();
47                 getTracker().eventOccurred(ACQUIRED);
48                 TimingUtils.sleep(SLEEP_TIME);
49                 _lock.release();
50                 getTracker().eventOccurred(RELEASED);
51             };
52         });
53         t.start();
54         return t;
55     }
56 }