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.Connection ; 13 import java.sql.SQLException ; 14 import java.util.Properties ; 15 16 24 public class UpdateDefinitionTest extends AbstractProxoolTest { 25 26 private static final Log LOG = LogFactory.getLog(UpdateDefinitionTest.class); 27 28 public UpdateDefinitionTest(String alias) { 29 super(alias); 30 } 31 32 35 public void testChangeUrl() throws Exception { 36 37 String testName = "changeUrl"; 38 String alias = testName; 39 40 String url1 = TestHelper.buildProxoolUrl(alias, 41 TestConstants.HYPERSONIC_DRIVER, 42 TestConstants.HYPERSONIC_TEST_URL); 43 44 String url2 = TestHelper.buildProxoolUrl(alias, 45 TestConstants.HYPERSONIC_DRIVER, 46 TestConstants.HYPERSONIC_TEST_URL2); 47 48 Properties info = new Properties (); 49 info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER); 50 info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD); 51 info.setProperty(ProxoolConstants.MINIMUM_CONNECTION_COUNT_PROPERTY, "2"); 52 53 ProxoolFacade.registerConnectionPool(url1, info); 55 56 DriverManager.getConnection(url1).close(); 58 assertEquals("connectionsServedCount", 1L, ProxoolFacade.getSnapshot(alias, false).getServedCount()); 59 60 ProxoolFacade.updateConnectionPool(url2, null); 61 62 DriverManager.getConnection(url2).close(); 64 assertEquals("connectionsServedCount", 2L, ProxoolFacade.getSnapshot(alias, false).getServedCount()); 65 66 ProxoolFacade.updateConnectionPool(url1, null); 67 DriverManager.getConnection(url1).close(); 68 assertEquals("connectionsServedCount", 3L, ProxoolFacade.getSnapshot(alias, false).getServedCount()); 69 70 } 71 72 75 public void testUpdate() throws Exception , ClassNotFoundException { 76 77 String testName = "update"; 78 String alias = testName; 79 80 String url = TestHelper.buildProxoolUrl(alias, 81 TestConstants.HYPERSONIC_DRIVER, 82 TestConstants.HYPERSONIC_TEST_URL); 83 Properties info = new Properties (); 84 info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER); 85 info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD); 86 info.setProperty(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY, "1"); 87 ProxoolFacade.registerConnectionPool(url, info); 88 89 DriverManager.getConnection(url).close(); 91 92 assertEquals("maximumConnectionCount", 1, ProxoolFacade.getConnectionPoolDefinition(alias).getMaximumConnectionCount()); 93 94 info = new Properties (); 96 info.setProperty(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY, "2"); 97 ProxoolFacade.updateConnectionPool(url, info); 98 assertEquals("maximumConnectionCount", 2, ProxoolFacade.getConnectionPoolDefinition(alias).getMaximumConnectionCount()); 99 100 info = new Properties (); 102 info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER); 103 info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD); 104 info.setProperty(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY, "3"); 105 DriverManager.getConnection(url, info).close(); 106 assertEquals("maximumConnectionCount", 3, ProxoolFacade.getConnectionPoolDefinition(alias).getMaximumConnectionCount()); 107 108 } 109 110 114 public void testDefinitionNotChanging() throws SQLException , ProxoolException { 115 116 String testName = "definitionNotChanging"; 117 String alias = testName; 118 119 120 Connection c1 = null; 121 try { 122 String url = TestHelper.buildProxoolUrl(alias, 123 TestConstants.HYPERSONIC_DRIVER, 124 TestConstants.HYPERSONIC_TEST_URL); 125 Properties info = new Properties (); 126 info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER); 127 info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD); 128 info.setProperty(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY, "1"); 129 c1 = DriverManager.getConnection(url, info); 130 assertEquals("id=1", 1L, ProxoolFacade.getId(c1)); 131 } finally { 132 c1.close(); 133 } 134 Connection c2 = null; 136 try { 137 String url = TestHelper.buildProxoolUrl(alias, 138 TestConstants.HYPERSONIC_DRIVER, 139 TestConstants.HYPERSONIC_TEST_URL); 140 Properties info = new Properties (); 141 info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER); 142 info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD); 143 info.setProperty(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY, "1"); 144 c2 = DriverManager.getConnection(url, info); 145 assertEquals("id=1", 1L, ProxoolFacade.getId(c2)); 146 } finally { 147 c2.close(); 148 } 149 assertNotSame("c1!=c2", c1, c2); 151 } 152 153 156 public void testUpdateUsingAPI() throws Exception , ClassNotFoundException { 157 158 String testName = "updateUsingAPI"; 159 String alias = testName; 160 161 String url = ProxoolConstants.PROXOOL 162 + ProxoolConstants.ALIAS_DELIMITER 163 + alias 164 + ProxoolConstants.URL_DELIMITER 165 + TestConstants.HYPERSONIC_DRIVER 166 + ProxoolConstants.URL_DELIMITER 167 + TestConstants.HYPERSONIC_TEST_URL2; 169 170 LOG.debug("Register pool"); 171 Properties info = new Properties (); 172 String checkAlias = ProxoolFacade.registerConnectionPool(url, info); 173 assertEquals(alias, checkAlias); 174 175 LOG.debug("setConfigurationListener"); 176 ProxoolFacade.addConfigurationListener(alias, new ConfigurationListenerIF() { 177 public void definitionUpdated(ConnectionPoolDefinitionIF connectionPoolDefinition, Properties completeInfo, Properties changedInfo) { 178 } 179 }); 180 181 LOG.debug("setStateListener"); 182 ProxoolFacade.addStateListener(alias, new StateListenerIF() { 183 public void upStateChanged(int upState) { 184 } 185 }); 186 187 LOG.debug("Update pool"); 188 ProxoolFacade.updateConnectionPool(url, info); 189 190 } 191 192 } 193 194 195 | Popular Tags |