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.sql.SQLException ; 13 import java.util.Properties ; 14 15 23 public class RegistrationTest extends AbstractProxoolTest { 24 25 private static final Log LOG = LogFactory.getLog(RegistrationTest.class); 26 27 public RegistrationTest(String alias) { 28 super(alias); 29 } 30 31 34 public void testRegister() throws Exception { 35 36 String testName = "register"; 37 String alias = testName; 38 39 40 String url = TestHelper.buildProxoolUrl(alias, 41 TestConstants.HYPERSONIC_DRIVER, 42 TestConstants.HYPERSONIC_TEST_URL); 43 Properties info = new Properties (); 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 53 } 54 55 58 public void testRemove() throws Exception { 59 60 String testName = "remove"; 61 String alias = testName; 62 63 64 String url = TestHelper.buildProxoolUrl(alias, 66 TestConstants.HYPERSONIC_DRIVER, 67 TestConstants.HYPERSONIC_TEST_URL); 68 Properties info = new Properties (); 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 e) { 76 fail("Couldn't get connection"); 77 } 78 79 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 ProxoolFacade.registerConnectionPool(url, info); 90 try { 91 DriverManager.getConnection(url).close(); 92 } catch (SQLException e) { 93 fail("Couldn't get connection"); 94 } 95 assertEquals("servedCount", 1L, ProxoolFacade.getSnapshot(alias).getServedCount()); 97 98 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 ProxoolFacade.registerConnectionPool(url, info); 109 try { 110 DriverManager.getConnection(url).close(); 111 } catch (SQLException e) { 112 fail("Couldn't get connection"); 113 } 114 assertEquals("servedCount", 1L, ProxoolFacade.getSnapshot(alias).getServedCount()); 116 117 118 } 119 120 123 public void testMultiple() throws Exception , ClassNotFoundException { 124 125 String testName = "multiple"; 126 String alias1 = testName + "1"; 127 String alias2 = testName + "2"; 128 129 String url1 = TestHelper.buildProxoolUrl(alias1, 131 TestConstants.HYPERSONIC_DRIVER, 132 TestConstants.HYPERSONIC_TEST_URL); 133 String url2 = TestHelper.buildProxoolUrl(alias2, 134 TestConstants.HYPERSONIC_DRIVER, 135 TestConstants.HYPERSONIC_TEST_URL); 136 Properties info = new Properties (); 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 DriverManager.getConnection(url1).close(); 144 DriverManager.getConnection(url1).close(); 145 146 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 | Popular Tags |