KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * This software is released under a licence similar to the Apache Software Licence.
3  * See org.logicalcobwebs.proxool.package.html for details.
4  * The latest version is available at http://proxool.sourceforge.net
5  */

6 package org.logicalcobwebs.proxool;
7
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10
11 import java.sql.DriverManager JavaDoc;
12 import java.sql.SQLException JavaDoc;
13 import java.util.Properties JavaDoc;
14
15 /**
16  * Test whether we can register and remove a pool in various ways
17  *
18  * @version $Revision: 1.7 $, $Date: 2006/01/18 14:40:06 $
19  * @author bill
20  * @author $Author: billhorsman $ (current maintainer)
21  * @since Proxool 0.8
22  */

23 public class RegistrationTest extends AbstractProxoolTest {
24
25     private static final Log LOG = LogFactory.getLog(RegistrationTest.class);
26
27     public RegistrationTest(String JavaDoc alias) {
28         super(alias);
29     }
30
31     /**
32      * Test whether we can implicitly register a pool by
33      */

34     public void testRegister() throws Exception JavaDoc {
35
36         String JavaDoc testName = "register";
37         String JavaDoc alias = testName;
38
39
40         String JavaDoc url = TestHelper.buildProxoolUrl(alias,
41                 TestConstants.HYPERSONIC_DRIVER,
42                 TestConstants.HYPERSONIC_TEST_URL);
43         Properties JavaDoc info = new Properties JavaDoc();
44         info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER);
45         info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD);
46
47         ProxoolFacade.registerConnectionPool(url, info);
48
49         assertNotNull("snapshot exists", ProxoolFacade.getSnapshot(alias));
50
51         // TODO check that properties are configured properly
52

53     }
54
55     /**
56      * Can we register, remove and then re-register the same pool?
57      */

58     public void testRemove() throws Exception JavaDoc {
59
60         String JavaDoc testName = "remove";
61         String JavaDoc alias = testName;
62
63
64         // Register
65
String JavaDoc url = TestHelper.buildProxoolUrl(alias,
66                 TestConstants.HYPERSONIC_DRIVER,
67                 TestConstants.HYPERSONIC_TEST_URL);
68         Properties JavaDoc info = new Properties JavaDoc();
69         info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER);
70         info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD);
71         ProxoolFacade.registerConnectionPool(url, info);
72
73         try {
74             DriverManager.getConnection(url).close();
75         } catch (SQLException JavaDoc e) {
76             fail("Couldn't get connection");
77         }
78
79         // Remove using alias
80
ProxoolFacade.removeConnectionPool(alias);
81         try {
82             ProxoolFacade.getConnectionPoolDefinition(alias);
83             fail("Didn't expect to get definition of pool that was just removed");
84         } catch (ProxoolException e) {
85             LOG.debug("Ignore expected exception", e);
86         }
87
88         // Register again
89
ProxoolFacade.registerConnectionPool(url, info);
90         try {
91             DriverManager.getConnection(url).close();
92         } catch (SQLException JavaDoc e) {
93             fail("Couldn't get connection");
94         }
95         // Should only be one served (the earlier one is forgotten)
96
assertEquals("servedCount", 1L, ProxoolFacade.getSnapshot(alias).getServedCount());
97
98         // Remove using alias
99
ProxoolFacade.removeConnectionPool(alias);
100         try {
101             ProxoolFacade.getConnectionPoolDefinition(alias);
102             fail("Didn't expect to get definition of pool that was just removed");
103         } catch (ProxoolException e) {
104             LOG.debug("Ignore expected exception", e);
105         }
106
107         // Register again
108
ProxoolFacade.registerConnectionPool(url, info);
109         try {
110             DriverManager.getConnection(url).close();
111         } catch (SQLException JavaDoc e) {
112             fail("Couldn't get connection");
113         }
114         // Should only be one served (the earlier one is forgotten)
115
assertEquals("servedCount", 1L, ProxoolFacade.getSnapshot(alias).getServedCount());
116
117
118     }
119
120     /**
121      * Can we have multiple pools?
122      */

123     public void testMultiple() throws Exception JavaDoc, ClassNotFoundException JavaDoc {
124
125         String JavaDoc testName = "multiple";
126         String JavaDoc alias1 = testName + "1";
127         String JavaDoc alias2 = testName + "2";
128
129         // Register
130
String JavaDoc url1 = TestHelper.buildProxoolUrl(alias1,
131                 TestConstants.HYPERSONIC_DRIVER,
132                 TestConstants.HYPERSONIC_TEST_URL);
133         String JavaDoc url2 = TestHelper.buildProxoolUrl(alias2,
134                 TestConstants.HYPERSONIC_DRIVER,
135                 TestConstants.HYPERSONIC_TEST_URL);
136         Properties JavaDoc info = new Properties JavaDoc();
137         info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER);
138         info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD);
139         ProxoolFacade.registerConnectionPool(url1, info);
140         ProxoolFacade.registerConnectionPool(url2, info);
141
142         // Open 2 connections on #1
143
DriverManager.getConnection(url1).close();
144         DriverManager.getConnection(url1).close();
145
146         // Open 1 connection on #2
147
DriverManager.getConnection(url2).close();
148
149         assertEquals("connectionsServedCount #1", 2L, ProxoolFacade.getSnapshot(alias1).getServedCount());
150         assertEquals("connectionsServedCount #2", 1L, ProxoolFacade.getSnapshot(alias2).getServedCount());
151
152     }
153
154 }
155
156 /*
157  Revision history:
158  $Log: RegistrationTest.java,v $
159  Revision 1.7 2006/01/18 14:40:06 billhorsman
160  Unbundled Jakarta's Commons Logging.
161
162  Revision 1.6 2003/03/04 10:58:44 billhorsman
163  checkstyle
164
165  Revision 1.5 2003/03/04 10:24:40 billhorsman
166  removed try blocks around each test
167
168  Revision 1.4 2003/03/03 17:09:06 billhorsman
169  all tests now extend AbstractProxoolTest
170
171  Revision 1.3 2003/03/03 11:12:05 billhorsman
172  fixed licence
173
174  Revision 1.2 2003/03/01 15:27:24 billhorsman
175  checkstyle
176
177  Revision 1.1 2003/02/27 18:01:48 billhorsman
178  completely rethought the test structure. it's now
179  more obvious. no new tests yet though.
180
181  */
Popular Tags