KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Properties JavaDoc;
13
14 /**
15  * Tests {@link ProxoolFacade#getConnectionInfos}
16  *
17  * @version $Revision: 1.8 $, $Date: 2006/01/18 14:40:06 $
18  * @author bill
19  * @author $Author: billhorsman $ (current maintainer)
20  * @since Proxool 0.8
21  */

22 public class ConnectionInfoTest extends AbstractProxoolTest {
23
24     private static final Log LOG = LogFactory.getLog(ConnectionInfoTest.class);
25
26     public ConnectionInfoTest(String JavaDoc alias) {
27         super(alias);
28     }
29
30     /**
31      * If we ask for more simultaneous connections then we have allowed we should gracefully
32      * refuse them.
33      */

34     public void testConnectionInfo() throws Exception JavaDoc {
35
36         String JavaDoc testName = "connectionInfo";
37         String JavaDoc alias = testName;
38
39         String JavaDoc url = TestHelper.buildProxoolUrl(alias,
40                 TestConstants.HYPERSONIC_DRIVER,
41                 TestConstants.HYPERSONIC_TEST_URL);
42         Properties JavaDoc info = new Properties JavaDoc();
43         info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER);
44         info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD);
45         ProxoolFacade.registerConnectionPool(url, info);
46
47         DriverManager.getConnection(url);
48         assertEquals("connectionInfo count", 1, ProxoolFacade.getSnapshot(alias, true).getConnectionInfos().length);
49
50         DriverManager.getConnection(url);
51         assertEquals("connectionInfo count", 2, ProxoolFacade.getSnapshot(alias, true).getConnectionInfos().length);
52
53         DriverManager.getConnection(url).close();
54         assertEquals("connectionInfo count", 3, ProxoolFacade.getSnapshot(alias, true).getConnectionInfos().length);
55
56         ConnectionInfoIF[] connectionInfos = ProxoolFacade.getSnapshot(alias, true).getConnectionInfos();
57         assertEquals("activeCount", 2, getCount(connectionInfos, ConnectionInfoIF.STATUS_ACTIVE));
58         assertEquals("availableCount", 1, getCount(connectionInfos, ConnectionInfoIF.STATUS_AVAILABLE));
59
60     }
61
62     private int getCount(ConnectionInfoIF[] connectionInfos, int status) {
63         int count = 0;
64         for (int i = 0; i < connectionInfos.length; i++) {
65             ConnectionInfoIF connectionInfo = connectionInfos[i];
66             if (connectionInfo.getStatus() == status) {
67                 count++;
68             }
69         }
70         return count;
71     }
72
73
74 }
75
76
77 /*
78  Revision history:
79  $Log: ConnectionInfoTest.java,v $
80  Revision 1.8 2006/01/18 14:40:06 billhorsman
81  Unbundled Jakarta's Commons Logging.
82
83  Revision 1.7 2003/04/28 20:02:43 billhorsman
84  changed from deprecated getConnectionInfos to Snapshot
85
86  Revision 1.6 2003/03/11 00:38:41 billhorsman
87  allowed for connections in different order
88
89  Revision 1.5 2003/03/04 10:24:40 billhorsman
90  removed try blocks around each test
91
92  Revision 1.4 2003/03/03 17:08:55 billhorsman
93  all tests now extend AbstractProxoolTest
94
95  Revision 1.3 2003/03/03 11:12:04 billhorsman
96  fixed licence
97
98  Revision 1.2 2003/03/01 15:27:24 billhorsman
99  checkstyle
100
101  Revision 1.1 2003/02/27 18:01:47 billhorsman
102  completely rethought the test structure. it's now
103  more obvious. no new tests yet though.
104
105  */
Popular Tags