1 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 ; 12 import java.util.Properties ; 13 14 22 public class ConnectionInfoTest extends AbstractProxoolTest { 23 24 private static final Log LOG = LogFactory.getLog(ConnectionInfoTest.class); 25 26 public ConnectionInfoTest(String alias) { 27 super(alias); 28 } 29 30 34 public void testConnectionInfo() throws Exception { 35 36 String testName = "connectionInfo"; 37 String alias = testName; 38 39 String url = TestHelper.buildProxoolUrl(alias, 40 TestConstants.HYPERSONIC_DRIVER, 41 TestConstants.HYPERSONIC_TEST_URL); 42 Properties info = new Properties (); 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 | Popular Tags |