1 22 23 24 package com.mchange.v2.c3p0.test.junit; 25 26 import java.sql.*; 27 import java.util.*; 28 import junit.framework.*; 29 30 public final class ConnectionPropertiesResetJUnitTestCase extends C3P0JUnitTestCaseBase 31 { 32 final static Map TM; 33 34 static 35 { 36 Map tmp = new HashMap(); 37 tmp.put("FAKE", SQLData.class); 38 TM = Collections.unmodifiableMap( tmp ); 39 } 40 41 public void testAllConnectionDefaultsReset() 42 { 43 46 cpds.setInitialPoolSize(5); 47 cpds.setMinPoolSize(5); 48 cpds.setMaxPoolSize(5); 49 cpds.setMaxIdleTime(0); 50 cpds.setTestConnectionOnCheckout(false); 51 cpds.setTestConnectionOnCheckin(false); 52 cpds.setIdleConnectionTestPeriod(0); 53 54 String dfltCat; 55 int dflt_txn_isolation; 56 57 try 58 { 59 Connection con = null; 60 try 61 { 62 con = cpds.getConnection(); 63 64 65 dfltCat = con.getCatalog(); 66 dflt_txn_isolation = con.getTransactionIsolation(); 67 68 try { con.setReadOnly(true); } catch (Exception e) { } 69 try { con.setTypeMap(TM); } catch (Exception e) { } 70 try { con.setCatalog("C3P0TestCatalogXXX"); } catch (Exception e) { } 71 try 72 { 73 con.setTransactionIsolation( dflt_txn_isolation == Connection.TRANSACTION_SERIALIZABLE ? 74 Connection.TRANSACTION_READ_COMMITTED : 75 Connection.TRANSACTION_SERIALIZABLE ); 76 } 77 catch (Exception e) { } 78 } 79 finally 80 { 81 try { if (con != null) con.close(); } 82 catch (Exception e) {} 83 } 84 85 Connection[] cons = new Connection[5]; 86 for (int i = 0; i < 5; ++i) 87 { 88 cons[i] = cpds.getConnection(); 89 assertFalse( "Connection from pool should not be readOnly!", cons[i].isReadOnly() ); 90 91 Map typeMap = cons[i].getTypeMap(); 93 assertTrue( "Connection from pool should have an empty type map!", (typeMap == null ? true : typeMap.isEmpty() ) ); 94 95 assertEquals( "Connection from pool should have default catalog set!", dfltCat, cons[i].getCatalog() ); 96 assertEquals( "Connection from pool should have default txn isolation set!", dflt_txn_isolation, cons[i].getTransactionIsolation() ); 97 cons[i].close(); 98 } 99 } 100 catch (Exception e) 101 { 102 e.printStackTrace(); 103 fail( e.getMessage() ); 104 } 105 } 106 } | Popular Tags |