001: /*
002: * This software is released under a licence similar to the Apache Software Licence.
003: * See org.logicalcobwebs.proxool.package.html for details.
004: * The latest version is available at http://proxool.sourceforge.net
005: */
006: package org.logicalcobwebs.proxool;
007:
008: import org.apache.commons.logging.Log;
009: import org.apache.commons.logging.LogFactory;
010:
011: import java.sql.DriverManager;
012: import java.sql.SQLException;
013: import java.util.Properties;
014:
015: /**
016: * Test whether we can register and remove a pool in various ways
017: *
018: * @version $Revision: 1.7 $, $Date: 2006/01/18 14:40:06 $
019: * @author bill
020: * @author $Author: billhorsman $ (current maintainer)
021: * @since Proxool 0.8
022: */
023: public class RegistrationTest extends AbstractProxoolTest {
024:
025: private static final Log LOG = LogFactory
026: .getLog(RegistrationTest.class);
027:
028: public RegistrationTest(String alias) {
029: super (alias);
030: }
031:
032: /**
033: * Test whether we can implicitly register a pool by
034: */
035: public void testRegister() throws Exception {
036:
037: String testName = "register";
038: String alias = testName;
039:
040: String url = TestHelper.buildProxoolUrl(alias,
041: TestConstants.HYPERSONIC_DRIVER,
042: TestConstants.HYPERSONIC_TEST_URL);
043: Properties info = new Properties();
044: info.setProperty(ProxoolConstants.USER_PROPERTY,
045: TestConstants.HYPERSONIC_USER);
046: info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
047: TestConstants.HYPERSONIC_PASSWORD);
048:
049: ProxoolFacade.registerConnectionPool(url, info);
050:
051: assertNotNull("snapshot exists", ProxoolFacade
052: .getSnapshot(alias));
053:
054: // TODO check that properties are configured properly
055:
056: }
057:
058: /**
059: * Can we register, remove and then re-register the same pool?
060: */
061: public void testRemove() throws Exception {
062:
063: String testName = "remove";
064: String alias = testName;
065:
066: // Register
067: String url = TestHelper.buildProxoolUrl(alias,
068: TestConstants.HYPERSONIC_DRIVER,
069: TestConstants.HYPERSONIC_TEST_URL);
070: Properties info = new Properties();
071: info.setProperty(ProxoolConstants.USER_PROPERTY,
072: TestConstants.HYPERSONIC_USER);
073: info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
074: TestConstants.HYPERSONIC_PASSWORD);
075: ProxoolFacade.registerConnectionPool(url, info);
076:
077: try {
078: DriverManager.getConnection(url).close();
079: } catch (SQLException e) {
080: fail("Couldn't get connection");
081: }
082:
083: // Remove using alias
084: ProxoolFacade.removeConnectionPool(alias);
085: try {
086: ProxoolFacade.getConnectionPoolDefinition(alias);
087: fail("Didn't expect to get definition of pool that was just removed");
088: } catch (ProxoolException e) {
089: LOG.debug("Ignore expected exception", e);
090: }
091:
092: // Register again
093: ProxoolFacade.registerConnectionPool(url, info);
094: try {
095: DriverManager.getConnection(url).close();
096: } catch (SQLException e) {
097: fail("Couldn't get connection");
098: }
099: // Should only be one served (the earlier one is forgotten)
100: assertEquals("servedCount", 1L, ProxoolFacade
101: .getSnapshot(alias).getServedCount());
102:
103: // Remove using alias
104: ProxoolFacade.removeConnectionPool(alias);
105: try {
106: ProxoolFacade.getConnectionPoolDefinition(alias);
107: fail("Didn't expect to get definition of pool that was just removed");
108: } catch (ProxoolException e) {
109: LOG.debug("Ignore expected exception", e);
110: }
111:
112: // Register again
113: ProxoolFacade.registerConnectionPool(url, info);
114: try {
115: DriverManager.getConnection(url).close();
116: } catch (SQLException e) {
117: fail("Couldn't get connection");
118: }
119: // Should only be one served (the earlier one is forgotten)
120: assertEquals("servedCount", 1L, ProxoolFacade
121: .getSnapshot(alias).getServedCount());
122:
123: }
124:
125: /**
126: * Can we have multiple pools?
127: */
128: public void testMultiple() throws Exception, ClassNotFoundException {
129:
130: String testName = "multiple";
131: String alias1 = testName + "1";
132: String alias2 = testName + "2";
133:
134: // Register
135: String url1 = TestHelper.buildProxoolUrl(alias1,
136: TestConstants.HYPERSONIC_DRIVER,
137: TestConstants.HYPERSONIC_TEST_URL);
138: String url2 = TestHelper.buildProxoolUrl(alias2,
139: TestConstants.HYPERSONIC_DRIVER,
140: TestConstants.HYPERSONIC_TEST_URL);
141: Properties info = new Properties();
142: info.setProperty(ProxoolConstants.USER_PROPERTY,
143: TestConstants.HYPERSONIC_USER);
144: info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
145: TestConstants.HYPERSONIC_PASSWORD);
146: ProxoolFacade.registerConnectionPool(url1, info);
147: ProxoolFacade.registerConnectionPool(url2, info);
148:
149: // Open 2 connections on #1
150: DriverManager.getConnection(url1).close();
151: DriverManager.getConnection(url1).close();
152:
153: // Open 1 connection on #2
154: DriverManager.getConnection(url2).close();
155:
156: assertEquals("connectionsServedCount #1", 2L, ProxoolFacade
157: .getSnapshot(alias1).getServedCount());
158: assertEquals("connectionsServedCount #2", 1L, ProxoolFacade
159: .getSnapshot(alias2).getServedCount());
160:
161: }
162:
163: }
164:
165: /*
166: Revision history:
167: $Log: RegistrationTest.java,v $
168: Revision 1.7 2006/01/18 14:40:06 billhorsman
169: Unbundled Jakarta's Commons Logging.
170:
171: Revision 1.6 2003/03/04 10:58:44 billhorsman
172: checkstyle
173:
174: Revision 1.5 2003/03/04 10:24:40 billhorsman
175: removed try blocks around each test
176:
177: Revision 1.4 2003/03/03 17:09:06 billhorsman
178: all tests now extend AbstractProxoolTest
179:
180: Revision 1.3 2003/03/03 11:12:05 billhorsman
181: fixed licence
182:
183: Revision 1.2 2003/03/01 15:27:24 billhorsman
184: checkstyle
185:
186: Revision 1.1 2003/02/27 18:01:48 billhorsman
187: completely rethought the test structure. it's now
188: more obvious. no new tests yet though.
189:
190: */
|