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