Removed DOCUMENT ME comments that were generated and applied source code
[utils] / support / spring / src / test / java / org / wamblee / concurrency / spring / LockAdviceTest.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 package org.wamblee.concurrency.spring;
17
18 import org.springframework.aop.framework.ProxyFactoryBean;
19
20 import org.wamblee.concurrency.AbstractLockTestCase;
21 import org.wamblee.concurrency.JvmLock;
22 import org.wamblee.concurrency.spring.LockAdvice;
23
24 import org.wamblee.test.TimingUtils;
25
26 /**
27  * 
28  * @author Erik Brakkee
29  */
30 public class LockAdviceTest extends AbstractLockTestCase {
31     private Runnable target;
32
33     /*
34      * (non-Javadoc)
35      * 
36      * @see org.wamblee.concurrency.AbstractLockTestCase#setUp()
37      */
38     @Override
39     protected void setUp() throws Exception {
40         super.setUp();
41
42         Runner runner = new Runner();
43         LockAdvice advice = new LockAdvice(new JvmLock());
44
45         ProxyFactoryBean support = new ProxyFactoryBean();
46         support.setInterfaces(new Class[] { Runnable.class });
47         support.setTarget(runner);
48         support.addAdvice(advice);
49         target = (Runnable) support.getObject();
50     }
51
52     /*
53      * (non-Javadoc)
54      * 
55      * @see org.wamblee.concurrency.AbstractLockTestCase#runThread()
56      */
57     @Override
58     protected Thread runThread() {
59         Thread t = new Thread(new Runnable() {
60             public void run() {
61                 try {
62                     getTracker().eventOccurred(STARTED);
63                     target.run();
64                     getTracker().eventOccurred(RELEASED);
65                 } catch (Throwable e) {
66                     throw new RuntimeException(e);
67                 }
68             };
69         });
70         t.start();
71
72         return t;
73     }
74
75     private class Runner implements Runnable {
76         public void run() {
77             LockAdviceTest.this.getTracker().eventOccurred(ACQUIRED);
78             TimingUtils.sleep(SLEEP_TIME);
79         }
80     }
81 }