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.util.Properties;
013:
014: /**
015: * Tests {@link ProxoolFacade#getConnectionInfos}
016: *
017: * @version $Revision: 1.8 $, $Date: 2006/01/18 14:40:06 $
018: * @author bill
019: * @author $Author: billhorsman $ (current maintainer)
020: * @since Proxool 0.8
021: */
022: public class ConnectionInfoTest extends AbstractProxoolTest {
023:
024: private static final Log LOG = LogFactory
025: .getLog(ConnectionInfoTest.class);
026:
027: public ConnectionInfoTest(String alias) {
028: super (alias);
029: }
030:
031: /**
032: * If we ask for more simultaneous connections then we have allowed we should gracefully
033: * refuse them.
034: */
035: public void testConnectionInfo() throws Exception {
036:
037: String testName = "connectionInfo";
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: ProxoolFacade.registerConnectionPool(url, info);
049:
050: DriverManager.getConnection(url);
051: assertEquals("connectionInfo count", 1, ProxoolFacade
052: .getSnapshot(alias, true).getConnectionInfos().length);
053:
054: DriverManager.getConnection(url);
055: assertEquals("connectionInfo count", 2, ProxoolFacade
056: .getSnapshot(alias, true).getConnectionInfos().length);
057:
058: DriverManager.getConnection(url).close();
059: assertEquals("connectionInfo count", 3, ProxoolFacade
060: .getSnapshot(alias, true).getConnectionInfos().length);
061:
062: ConnectionInfoIF[] connectionInfos = ProxoolFacade.getSnapshot(
063: alias, true).getConnectionInfos();
064: assertEquals("activeCount", 2, getCount(connectionInfos,
065: ConnectionInfoIF.STATUS_ACTIVE));
066: assertEquals("availableCount", 1, getCount(connectionInfos,
067: ConnectionInfoIF.STATUS_AVAILABLE));
068:
069: }
070:
071: private int getCount(ConnectionInfoIF[] connectionInfos, int status) {
072: int count = 0;
073: for (int i = 0; i < connectionInfos.length; i++) {
074: ConnectionInfoIF connectionInfo = connectionInfos[i];
075: if (connectionInfo.getStatus() == status) {
076: count++;
077: }
078: }
079: return count;
080: }
081:
082: }
083:
084: /*
085: Revision history:
086: $Log: ConnectionInfoTest.java,v $
087: Revision 1.8 2006/01/18 14:40:06 billhorsman
088: Unbundled Jakarta's Commons Logging.
089:
090: Revision 1.7 2003/04/28 20:02:43 billhorsman
091: changed from deprecated getConnectionInfos to Snapshot
092:
093: Revision 1.6 2003/03/11 00:38:41 billhorsman
094: allowed for connections in different order
095:
096: Revision 1.5 2003/03/04 10:24:40 billhorsman
097: removed try blocks around each test
098:
099: Revision 1.4 2003/03/03 17:08:55 billhorsman
100: all tests now extend AbstractProxoolTest
101:
102: Revision 1.3 2003/03/03 11:12:04 billhorsman
103: fixed licence
104:
105: Revision 1.2 2003/03/01 15:27:24 billhorsman
106: checkstyle
107:
108: Revision 1.1 2003/02/27 18:01:47 billhorsman
109: completely rethought the test structure. it's now
110: more obvious. no new tests yet though.
111:
112: */
|