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.Connection ; 12 import java.sql.DriverManager ; 13 import java.util.Properties ; 14 15 23 public class ConnectionResetterTest extends AbstractProxoolTest { 24 25 private static final Log LOG = LogFactory.getLog(ConnectionResetterTest.class); 26 27 30 public ConnectionResetterTest(String s) { 31 super(s); 32 } 33 34 38 public void testAutoCommit() throws Exception { 39 40 String testName = "autoCommit"; 41 String alias = testName; 42 43 String url = TestHelper.buildProxoolUrl(alias, 44 TestConstants.HYPERSONIC_DRIVER, 45 TestConstants.HYPERSONIC_TEST_URL); 46 Properties info = new Properties (); 47 info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER); 48 info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD); 49 ProxoolFacade.registerConnectionPool(url, info); 50 51 Connection c1 = DriverManager.getConnection(url); 52 53 Connection c2 = DriverManager.getConnection(url); 54 55 56 c1.setAutoCommit(false); 57 c1.close(); 58 59 c1 = DriverManager.getConnection(url); 60 assertTrue("c1.getAutoCommit", c1.getAutoCommit()); 61 62 c2.close(); 63 c1.close(); 64 assertEquals("connectionCount", 2, ProxoolFacade.getSnapshot(alias).getConnectionCount()); 65 66 } 67 68 71 public void testFailedReset() throws Exception { 72 73 try { 74 ConnectionResetter.setTriggerResetException(true); 76 77 String testName = "failedReset"; 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 ProxoolFacade.registerConnectionPool(url, info); 87 88 Connection c1 = DriverManager.getConnection(url); 89 c1.setAutoCommit(false); 90 c1.close(); 91 92 assertEquals("connectionCount", 0, ProxoolFacade.getSnapshot(alias).getConnectionCount()); 93 } finally { 94 ConnectionResetter.setTriggerResetException(false); 96 } 97 98 } 99 100 104 public void testReadOnly() throws Exception { 105 106 String testName = "readOnly"; 107 String alias = testName; 108 109 String url = TestHelper.buildProxoolUrl(alias, 110 TestConstants.HYPERSONIC_DRIVER, 111 TestConstants.HYPERSONIC_TEST_URL); 112 Properties info = new Properties (); 113 info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER); 114 info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD); 115 info.setProperty(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY, "2"); 116 ProxoolFacade.registerConnectionPool(url, info); 117 118 Connection c1 = DriverManager.getConnection(url); 119 ; 120 Connection c2 = DriverManager.getConnection(url); 121 ; 122 123 boolean originalReadOnly = c1.isReadOnly(); 124 c1.setReadOnly(true); 125 c1.close(); 126 127 c1 = DriverManager.getConnection(url); 128 ; 129 assertTrue("readOnly", c1.isReadOnly() == originalReadOnly); 130 131 c2.close(); 132 c1.close(); 133 134 } 135 136 } 137 138 195 | Popular Tags |