1 6 package org.logicalcobwebs.proxool; 7 8 import org.apache.commons.logging.Log; 9 import org.apache.commons.logging.LogFactory; 10 import org.logicalcobwebs.proxool.admin.SnapshotIF; 11 import org.logicalcobwebs.proxool.admin.SnapshotResultMonitor; 12 13 import java.sql.Connection ; 14 import java.sql.DriverManager ; 15 import java.util.Properties ; 16 17 25 public class PrototyperTest extends AbstractProxoolTest { 26 27 private static final Log LOG = LogFactory.getLog(PrototyperTest.class); 28 29 public PrototyperTest(String alias) { 30 super(alias); 31 } 32 33 36 public void testPrototypeCount() throws Exception { 37 38 final String testName = "prototypeCount"; 39 final String alias = testName; 40 41 Properties info = new Properties (); 42 info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER); 43 info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD); 44 info.setProperty(ProxoolConstants.VERBOSE_PROPERTY, Boolean.TRUE.toString()); 45 info.setProperty(ProxoolConstants.MINIMUM_CONNECTION_COUNT_PROPERTY, "0"); 46 info.setProperty(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY, "5"); 47 info.setProperty(ProxoolConstants.PROTOTYPE_COUNT_PROPERTY, "2"); 48 info.setProperty(ProxoolConstants.HOUSE_KEEPING_SLEEP_TIME_PROPERTY, "1000"); 49 info.setProperty(ProxoolConstants.HOUSE_KEEPING_TEST_SQL_PROPERTY, TestConstants.HYPERSONIC_TEST_SQL); 50 51 String url = ProxoolConstants.PROXOOL 52 + ProxoolConstants.ALIAS_DELIMITER 53 + alias 54 + ProxoolConstants.URL_DELIMITER 55 + TestConstants.HYPERSONIC_DRIVER 56 + ProxoolConstants.URL_DELIMITER 57 + TestConstants.HYPERSONIC_TEST_URL; 58 ProxoolFacade.registerConnectionPool(url, info); 59 60 Connection [] connections = new Connection [6]; 61 62 SnapshotResultMonitor srm = new SnapshotResultMonitor(alias) { 63 public boolean check(SnapshotIF snapshot) throws Exception { 64 SnapshotIF s = ProxoolFacade.getSnapshot(alias); 65 return (s.getActiveConnectionCount() == 0 66 && s.getAvailableConnectionCount() >= 2); 67 } 68 }; 69 assertEquals("Timeout", ResultMonitor.SUCCESS, srm.getResult()); 70 assertEquals("activeConnectionCount", 0, srm.getSnapshot().getActiveConnectionCount()); 71 assertEquals("availableConnectionCount", 2, srm.getSnapshot().getAvailableConnectionCount()); 72 73 connections[0] = DriverManager.getConnection(url); 74 75 srm = new SnapshotResultMonitor(alias) { 76 public boolean check(SnapshotIF snapshot) throws Exception { 77 SnapshotIF s = ProxoolFacade.getSnapshot(alias); 78 return (s.getActiveConnectionCount() == 1 79 && s.getAvailableConnectionCount() >= 2); 80 } 81 }; 82 assertEquals("Timeout", ResultMonitor.SUCCESS, srm.getResult()); 83 assertEquals("activeConnectionCount", 1, srm.getSnapshot().getActiveConnectionCount()); 84 assertEquals("availableConnectionCount", 2, srm.getSnapshot().getAvailableConnectionCount()); 85 86 connections[1] = DriverManager.getConnection(url); 87 connections[2] = DriverManager.getConnection(url); 88 connections[3] = DriverManager.getConnection(url); 89 90 srm = new SnapshotResultMonitor(alias) { 91 public boolean check(SnapshotIF snapshot) throws Exception { 92 SnapshotIF s = ProxoolFacade.getSnapshot(alias); 93 return (s.getActiveConnectionCount() == 4 94 && s.getAvailableConnectionCount() == 1); 95 } 96 }; 97 assertEquals("Timeout", ResultMonitor.SUCCESS, srm.getResult()); 98 assertEquals("activeConnectionCount", 4, srm.getSnapshot().getActiveConnectionCount()); 99 assertEquals("availableConnectionCount", 1, srm.getSnapshot().getAvailableConnectionCount()); 100 101 } 102 103 106 public void testMinimumConnectionCount() throws Exception { 107 108 String testName = "miniumumConnectionCount"; 109 final String alias = testName; 110 111 Properties info = new Properties (); 112 info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER); 113 info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD); 114 info.setProperty(ProxoolConstants.VERBOSE_PROPERTY, Boolean.TRUE.toString()); 115 info.setProperty(ProxoolConstants.MINIMUM_CONNECTION_COUNT_PROPERTY, "2"); 116 info.setProperty(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY, "5"); 117 info.setProperty(ProxoolConstants.PROTOTYPE_COUNT_PROPERTY, "0"); 118 info.setProperty(ProxoolConstants.HOUSE_KEEPING_SLEEP_TIME_PROPERTY, "1000"); 119 info.setProperty(ProxoolConstants.HOUSE_KEEPING_TEST_SQL_PROPERTY, TestConstants.HYPERSONIC_TEST_SQL); 120 String url = TestHelper.buildProxoolUrl(alias, TestConstants.HYPERSONIC_DRIVER, TestConstants.HYPERSONIC_TEST_URL); 121 ProxoolFacade.registerConnectionPool(url, info); 122 123 ResultMonitor srm = new SnapshotResultMonitor(alias) { 124 public boolean check(SnapshotIF snapshot) throws Exception { 125 SnapshotIF s = ProxoolFacade.getSnapshot(alias); 126 return (s.getAvailableConnectionCount() == 2); 127 } 128 }; 129 assertEquals("Timeout", ResultMonitor.SUCCESS, srm.getResult()); 130 131 assertEquals("availableConnectionCount", 2, ProxoolFacade.getSnapshot(alias, false).getAvailableConnectionCount()); 132 133 } 134 135 } 136 137 138 | Popular Tags |