1 package org.logicalcobwebs.proxool; 2 3 import org.apache.commons.logging.Log; 4 import org.apache.commons.logging.LogFactory; 5 6 import java.sql.Connection ; 7 import java.sql.DriverManager ; 8 import java.sql.SQLException ; 9 import java.util.Properties ; 10 11 18 public class TestHelper { 19 20 private static final Log LOG = LogFactory.getLog(TestHelper.class); 21 22 27 public static Properties buildCompleteAlternativeProperties() { 28 Properties properties = new Properties (); 29 properties.setProperty("user", "sa"); 30 properties.setProperty("password", ""); 31 properties.setProperty(ProxoolConstants.HOUSE_KEEPING_SLEEP_TIME_PROPERTY, "40000"); 32 properties.setProperty(ProxoolConstants.HOUSE_KEEPING_TEST_SQL_PROPERTY, TestConstants.HYPERSONIC_TEST_SQL); 33 properties.setProperty(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY, "10"); 34 properties.setProperty(ProxoolConstants.MINIMUM_CONNECTION_COUNT_PROPERTY, "3"); 35 properties.setProperty(ProxoolConstants.MAXIMUM_CONNECTION_LIFETIME_PROPERTY, "18000000"); 36 properties.setProperty(ProxoolConstants.SIMULTANEOUS_BUILD_THROTTLE_PROPERTY, "5"); 37 properties.setProperty(ProxoolConstants.RECENTLY_STARTED_THRESHOLD_PROPERTY, "40000"); 38 properties.setProperty(ProxoolConstants.OVERLOAD_WITHOUT_REFUSAL_LIFETIME_PROPERTY, "50000"); 39 properties.setProperty(ProxoolConstants.MAXIMUM_ACTIVE_TIME_PROPERTY, "60000"); 40 properties.setProperty(ProxoolConstants.VERBOSE_PROPERTY, "true"); 41 properties.setProperty(ProxoolConstants.TRACE_PROPERTY, "true"); 42 properties.setProperty(ProxoolConstants.FATAL_SQL_EXCEPTION_PROPERTY, "Fatal error"); 43 properties.setProperty(ProxoolConstants.PROTOTYPE_COUNT_PROPERTY, "2"); 44 return properties; 45 } 46 47 53 public static void equalsCompleteAlternativeProperties(ConnectionPoolDefinitionIF connectionPoolDefinition) 54 throws ProxoolException { 55 checkProperty("user", "sa", connectionPoolDefinition.getDelegateProperties().getProperty("user")); 56 checkProperty("password", "", connectionPoolDefinition.getDelegateProperties().getProperty("password")); 57 checkProperty(ProxoolConstants.HOUSE_KEEPING_SLEEP_TIME, 40000, 58 connectionPoolDefinition.getHouseKeepingSleepTime()); 59 checkProperty(ProxoolConstants.HOUSE_KEEPING_TEST_SQL, "select CURRENT_DATE", 60 connectionPoolDefinition.getHouseKeepingTestSql()); 61 checkProperty(ProxoolConstants.MAXIMUM_CONNECTION_COUNT, 10, 62 connectionPoolDefinition.getMaximumConnectionCount()); 63 checkProperty(ProxoolConstants.MINIMUM_CONNECTION_COUNT, 3, 64 connectionPoolDefinition.getMinimumConnectionCount()); 65 checkProperty(ProxoolConstants.MAXIMUM_CONNECTION_LIFETIME, 18000000, 66 connectionPoolDefinition.getMaximumConnectionLifetime()); 67 checkProperty(ProxoolConstants.SIMULTANEOUS_BUILD_THROTTLE, 5, 68 connectionPoolDefinition.getSimultaneousBuildThrottle()); 69 checkProperty(ProxoolConstants.RECENTLY_STARTED_THRESHOLD, 40000, 70 connectionPoolDefinition.getRecentlyStartedThreshold()); 71 checkProperty(ProxoolConstants.OVERLOAD_WITHOUT_REFUSAL_LIFETIME, 50000, 72 connectionPoolDefinition.getOverloadWithoutRefusalLifetime()); 73 checkProperty(ProxoolConstants.MAXIMUM_ACTIVE_TIME, 60000, 74 connectionPoolDefinition.getMaximumActiveTime()); 75 checkProperty(ProxoolConstants.VERBOSE, "true", 76 new Boolean (connectionPoolDefinition.isVerbose()).toString()); 77 checkProperty(ProxoolConstants.TRACE, "true", 78 new Boolean (connectionPoolDefinition.isTrace() == true).toString()); 79 checkProperty(ProxoolConstants.FATAL_SQL_EXCEPTION, "Fatal error", 80 connectionPoolDefinition.getFatalSqlExceptions().iterator().next().toString()); 81 checkProperty(ProxoolConstants.PROTOTYPE_COUNT, 2, 82 connectionPoolDefinition.getPrototypeCount()); 83 } 84 85 private static void checkProperty(String name, String correctValue, String candidateValue) throws ProxoolException { 86 if (candidateValue == null) { 87 throw new ProxoolException(name + " was null."); 88 } else if (!candidateValue.equals(correctValue)) { 89 throw new ProxoolException("Expected value for " + name + " was " + correctValue + " but the value was " 90 + candidateValue + "."); 91 } 92 } 93 94 private static void checkProperty(String name, int correctValue, int candidateValue) throws ProxoolException { 95 checkProperty(name, String.valueOf(correctValue), String.valueOf(candidateValue)); 96 } 97 98 105 public static String buildProxoolUrl(String alias, String driver, String delegateUrl) { 106 String url = ProxoolConstants.PROXOOL 107 + ProxoolConstants.ALIAS_DELIMITER 108 + alias 109 + ProxoolConstants.URL_DELIMITER 110 + driver 111 + ProxoolConstants.URL_DELIMITER 112 + delegateUrl; 113 return url; 114 } 115 116 121 public static String buildProxoolUrl(String alias) { 122 String url = ProxoolConstants.PROXOOL 123 + ProxoolConstants.ALIAS_DELIMITER 124 + alias; 125 return url; 126 } 127 128 public static Connection getDirectConnection() throws ClassNotFoundException , SQLException { 129 Connection connection = null; 130 Class.forName(TestConstants.HYPERSONIC_DRIVER); 131 Properties info = new Properties (); 132 info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER); 133 info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD); 134 connection = DriverManager.getConnection(TestConstants.HYPERSONIC_TEST_URL, info); 135 return connection; 136 } 137 138 } 139 140 | Popular Tags |