1 6 package org.logicalcobwebs.proxool; 7 8 import java.util.Properties ; 9 import java.sql.Connection ; 10 import java.sql.DriverManager ; 11 12 19 public class KillTest extends AbstractProxoolTest { 20 private static final boolean MERCIFUL = true; 21 private static final boolean MERCILESS = false; 22 private static final boolean DETAILED = true; 23 24 27 public KillTest(String alias) { 28 super(alias); 29 } 30 31 34 public void testKillAllMercifully() throws Exception { 35 String alias = "killAllMercifully"; 36 String url = TestHelper.buildProxoolUrl(alias, 37 TestConstants.HYPERSONIC_DRIVER, 38 TestConstants.HYPERSONIC_TEST_URL); 39 Properties info = new Properties (); 40 info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER); 41 info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD); 42 info.setProperty(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY, "2"); 43 Connection c1 = DriverManager.getConnection(url, info); 44 Connection c2 = DriverManager.getConnection(url, info); 45 c1.close(); 46 c2.close(); 47 assertEquals("Connection count", 2, ProxoolFacade.getSnapshot(alias, DETAILED).getConnectionInfos().length); 49 ProxoolFacade.killAllConnections(alias, "testing", MERCIFUL); 50 assertEquals("Connection count", 0, ProxoolFacade.getSnapshot(alias, DETAILED).getConnectionInfos().length); 52 } 53 54 57 public void testKillAllMercilessly() throws Exception { 58 String alias = "killAllMercilessly"; 59 String url = TestHelper.buildProxoolUrl(alias, 60 TestConstants.HYPERSONIC_DRIVER, 61 TestConstants.HYPERSONIC_TEST_URL); 62 Properties info = new Properties (); 63 info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER); 64 info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD); 65 info.setProperty(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY, "2"); 66 Connection c1 = DriverManager.getConnection(url, info); 67 Connection c2 = DriverManager.getConnection(url, info); 68 assertEquals("Connection count", 2, ProxoolFacade.getSnapshot(alias, DETAILED).getConnectionInfos().length); 70 ProxoolFacade.killAllConnections(alias, "testing", MERCILESS); 71 assertEquals("Connection count", 0, ProxoolFacade.getSnapshot(alias, DETAILED).getConnectionInfos().length); 73 c1.close(); 74 c2.close(); 75 } 76 77 80 public void testKillOneById() throws Exception { 81 String alias = "killOneById"; 82 String url = TestHelper.buildProxoolUrl(alias, 83 TestConstants.HYPERSONIC_DRIVER, 84 TestConstants.HYPERSONIC_TEST_URL); 85 Properties info = new Properties (); 86 info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER); 87 info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD); 88 info.setProperty(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY, "2"); 89 Connection c1 = DriverManager.getConnection(url, info); 90 Connection c2 = DriverManager.getConnection(url, info); 91 c1.close(); 92 c2.close(); 93 assertEquals("Connection count", 2, ProxoolFacade.getSnapshot(alias, DETAILED).getConnectionInfos().length); 95 long id1 = ProxoolFacade.getId(c1); 96 long id2 = ProxoolFacade.getId(c2); 97 ProxoolFacade.killConnecton(alias, id1, MERCIFUL); 98 assertEquals("Connection count", 1, ProxoolFacade.getSnapshot(alias, DETAILED).getConnectionInfos().length); 100 assertEquals("Active count", 0, ProxoolFacade.getSnapshot(alias, DETAILED).getActiveConnectionCount()); 101 Connection c3 = DriverManager.getConnection(url, info); 102 assertEquals("Active count", 1, ProxoolFacade.getSnapshot(alias, DETAILED).getActiveConnectionCount()); 103 long id3 = ProxoolFacade.getId(c3); 104 Connection c4 = DriverManager.getConnection(url, info); 105 assertEquals("Active count", 2, ProxoolFacade.getSnapshot(alias, DETAILED).getActiveConnectionCount()); 106 long id4 = ProxoolFacade.getId(c4); 107 c3.close(); 108 c4.close(); 109 assertTrue("Killed ID served", id3 != id1); 110 assertTrue("Killed ID served", id4 != id1); 111 } 112 115 public void testKillOneByConnection() throws Exception { 116 String alias = "killOneByConnection"; 117 String url = TestHelper.buildProxoolUrl(alias, 118 TestConstants.HYPERSONIC_DRIVER, 119 TestConstants.HYPERSONIC_TEST_URL); 120 Properties info = new Properties (); 121 info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER); 122 info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD); 123 info.setProperty(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY, "2"); 124 Connection c1 = DriverManager.getConnection(url, info); 125 Connection c2 = DriverManager.getConnection(url, info); 126 c1.close(); 127 c2.close(); 128 assertEquals("Connection count", 2, ProxoolFacade.getSnapshot(alias, DETAILED).getConnectionInfos().length); 130 long id1 = ProxoolFacade.getId(c1); 131 long id2 = ProxoolFacade.getId(c2); 132 ProxoolFacade.killConnecton(c1, MERCIFUL); 133 assertEquals("Connection count", 1, ProxoolFacade.getSnapshot(alias, DETAILED).getConnectionInfos().length); 135 Connection c3 = DriverManager.getConnection(url, info); 136 long id3 = ProxoolFacade.getId(c3); 137 Connection c4 = DriverManager.getConnection(url, info); 138 long id4 = ProxoolFacade.getId(c4); 139 c3.close(); 140 c4.close(); 141 assertTrue("Killed ID served", id3 != id1); 142 assertTrue("Killed ID served", id4 != id1); 143 } 144 145 } 146 | Popular Tags |