1 6 package org.logicalcobwebs.proxool.admin; 7 8 import org.apache.commons.logging.Log; 9 import org.apache.commons.logging.LogFactory; 10 import org.logicalcobwebs.proxool.AbstractProxoolTest; 11 import org.logicalcobwebs.proxool.ConnectionPoolDefinitionIF; 12 import org.logicalcobwebs.proxool.ProxoolConstants; 13 import org.logicalcobwebs.proxool.ProxoolFacade; 14 import org.logicalcobwebs.proxool.ResultMonitor; 15 import org.logicalcobwebs.proxool.TestConstants; 16 import org.logicalcobwebs.proxool.TestHelper; 17 18 import java.sql.DriverManager ; 19 import java.text.DecimalFormat ; 20 import java.util.Properties ; 21 22 30 public class StatisticsTest extends AbstractProxoolTest { 31 32 private static final Log LOG = LogFactory.getLog(StatisticsTest.class); 33 34 private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat ("0.00"); 35 36 39 public StatisticsTest(String s) { 40 super(s); 41 } 42 43 46 public void testStatistics() throws Exception { 47 48 String testName = "statistics"; 49 String alias = testName; 50 51 String url = TestHelper.buildProxoolUrl(alias, 52 TestConstants.HYPERSONIC_DRIVER, 53 TestConstants.HYPERSONIC_TEST_URL); 54 Properties info = new Properties (); 55 info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER); 56 info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD); 57 info.setProperty(ProxoolConstants.STATISTICS_PROPERTY, "10s,15s"); 58 info.setProperty(ProxoolConstants.MINIMUM_CONNECTION_COUNT_PROPERTY, "1"); 59 info.setProperty(ProxoolConstants.VERBOSE_PROPERTY, "true"); 60 61 info.setProperty(ProxoolConstants.STATISTICS_LOG_LEVEL_PROPERTY, ProxoolConstants.STATISTICS_LOG_LEVEL_DEBUG); 63 64 ProxoolFacade.registerConnectionPool(url, info); 66 67 StatisticsResultMonitor srm = new StatisticsResultMonitor(alias, "10s"); 70 assertEquals("Timeout", ResultMonitor.SUCCESS, srm.getResult()); 71 srm.getStatistics(); 72 73 74 DriverManager.getConnection(url).close(); 75 76 srm = new StatisticsResultMonitor(alias, "10s") { 77 protected boolean check(StatisticsIF statistics) { 78 return (statistics.getServedCount() == 1); 79 } 80 }; 81 assertEquals("Timeout", ResultMonitor.SUCCESS, srm.getResult()); 82 StatisticsIF statistics = srm.getStatistics(); 83 84 assertEquals("servedCount", 1L, statistics.getServedCount()); 85 assertEquals("servedPerSecond", 0.09, 0.11, statistics.getServedPerSecond()); 86 assertEquals("refusedCount", 0L, statistics.getRefusedCount()); 87 88 } 89 90 public void testOverhead() throws Exception { 91 String testName = "overhead"; 92 String alias = testName; 93 String url = TestHelper.buildProxoolUrl(alias, 94 TestConstants.HYPERSONIC_DRIVER, 95 TestConstants.HYPERSONIC_TEST_URL); 96 Properties info = new Properties (); 97 info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER); 98 info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD); 99 info.setProperty(ProxoolConstants.STATISTICS_PROPERTY, "10s"); 100 info.setProperty(ProxoolConstants.MINIMUM_CONNECTION_COUNT_PROPERTY, "1"); 101 102 info.setProperty(ProxoolConstants.STATISTICS_LOG_LEVEL_PROPERTY, ProxoolConstants.STATISTICS_LOG_LEVEL_DEBUG); 104 105 ProxoolFacade.registerConnectionPool(url, info); 107 108 ConnectionPoolDefinitionIF cpd = ProxoolFacade.getConnectionPoolDefinition(alias); 109 Admin admin = new Admin(cpd); 110 111 final int loops = 100000; 112 long start = System.currentTimeMillis(); 113 for (int i = 0; i < loops; i++) { 114 admin.connectionReturned(10); 115 } 116 double avg = (double) (System.currentTimeMillis() - start) / (double) loops; 117 LOG.info("Statistics take " + DECIMAL_FORMAT.format(avg * 1000) + " microseconds"); 118 119 } 120 121 } 122 123 205 | Popular Tags |