KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > logicalcobwebs > proxool > AbstractProxoolTest


1 /**
2  * Clever Little Trader
3  *
4  * Jubilee Group and Logical Cobwebs, 2002
5  */

6 package org.logicalcobwebs.proxool;
7
8 import junit.framework.TestCase;
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11 import org.logicalcobwebs.concurrent.ReaderPreferenceReadWriteLock;
12
13 import java.util.Stack JavaDoc;
14
15 /**
16  * Provides common code for all Proxool tests
17  * @version $Revision: 1.6 $, $Date: 2006/01/18 14:40:06 $
18  * @author bill
19  * @author $Author: billhorsman $ (current maintainer)
20  * @since Proxool 0.8
21  */

22 public abstract class AbstractProxoolTest extends TestCase {
23
24     private static final Log LOG = LogFactory.getLog(AbstractProxoolTest.class);
25
26     private String JavaDoc alias;
27
28     private static ReaderPreferenceReadWriteLock testLock = new ReaderPreferenceReadWriteLock();
29
30     private Stack JavaDoc threadNames = new Stack JavaDoc();
31
32     public AbstractProxoolTest(String JavaDoc alias) {
33         super(alias);
34         this.alias = alias;
35     }
36
37     /**
38      * @see TestCase#setUp()
39      */

40     protected void setUp() throws Exception JavaDoc {
41         GlobalTest.globalSetup();
42         threadNames.push(Thread.currentThread().getName());
43         LOG.debug("Thread '" + Thread.currentThread().getName() + "' -> '" + alias + "'");
44         Thread.currentThread().setName(alias);
45         testLock.writeLock().acquire();
46     }
47
48     /**
49      * @see TestCase#tearDown()
50      */

51     protected void tearDown() throws Exception JavaDoc {
52         try {
53             GlobalTest.globalTeardown(alias);
54             Thread.currentThread().setName((String JavaDoc) threadNames.pop());
55             LOG.debug("Thread '" + alias + "' -> '" + Thread.currentThread().getName() + "'");
56         } finally {
57             testLock.writeLock().release();
58         }
59     }
60
61 }
62
63
64 /*
65  Revision history:
66  $Log: AbstractProxoolTest.java,v $
67  Revision 1.6 2006/01/18 14:40:06 billhorsman
68  Unbundled Jakarta's Commons Logging.
69
70  Revision 1.5 2004/03/26 16:00:23 billhorsman
71  Make sure we release lock on tearDown. I don't think this was a problem, but it was unrobust.
72
73  Revision 1.4 2003/09/30 19:09:46 billhorsman
74  Now uses a readwrite lock to make sure that each test runs sequentially. This should be true all the time, but sometimes
75  tests fail and it is always because of some timing issue that is very hard to track down. This is an attempt to
76  fix that.
77
78  Revision 1.3 2003/03/04 10:11:09 billhorsman
79  actually made abstract
80
81  Revision 1.2 2003/03/03 17:38:47 billhorsman
82  leave shutdown to AbstractProxoolTest
83
84  Revision 1.1 2003/03/03 17:08:54 billhorsman
85  all tests now extend AbstractProxoolTest
86
87  */
Popular Tags