HHH-5838 - Proxool connection pool should only close pools it opened

This commit is contained in:
Sanne Grinovero 2011-01-13 18:34:48 +00:00
parent 90bb8634df
commit af81f187b4
5 changed files with 99 additions and 1 deletions

View File

@ -4,4 +4,5 @@ dependencies {
compile( project( ':hibernate-core' ) )
compile( [group: 'proxool', name: 'proxool', version: '0.8.3'] )
testCompile( project(':hibernate-core').sourceSets.test.classes )
testRuntime( libraries.h2 )
}

View File

@ -202,8 +202,13 @@ public class ProxoolConnectionProvider implements ConnectionProvider {
// We have created the pool ourselves, so shut it down
try {
if ( ProxoolFacade.getAliases().length == 1 ) {
ProxoolFacade.shutdown( 0 );
}
else {
ProxoolFacade.removeConnectionPool(proxoolAlias.substring(PROXOOL_JDBC_STEM.length()));
}
}
catch (Exception e) {
// If you're closing down the ConnectionProvider chances are an
// is not a real big deal, just warn

View File

@ -0,0 +1,78 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat, Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.service.jdbc.connections.internal;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import org.hibernate.cfg.Environment;
import org.logicalcobwebs.proxool.ProxoolFacade;
import junit.framework.TestCase;
/**
* Test to verify connection pools are closed, and that only the managed one is closed.
* @author Sanne Grinovero
*/
public class ProxoolConnectionProviderTest extends TestCase {
public void testPoolsClosed() {
assertDefinedPools(); // zero-length-vararg used as parameter
ProxoolConnectionProvider providerOne = new ProxoolConnectionProvider();
providerOne.configure( getPoolConfigurarion( "pool-one" ) );
assertDefinedPools( "pool-one" );
ProxoolConnectionProvider providerTwo = new ProxoolConnectionProvider();
providerTwo.configure( getPoolConfigurarion( "pool-two" ) );
assertDefinedPools( "pool-one", "pool-two" );
providerOne.close();
assertDefinedPools( "pool-two" );
providerTwo.close();
assertDefinedPools();
}
private void assertDefinedPools(String... expectedPoolNames) {
List<String> aliases = Arrays.asList( ProxoolFacade.getAliases() );
assertEquals( expectedPoolNames.length, aliases.size() );
for (String poolName : expectedPoolNames) {
assertTrue( "pool named " + poolName + " missing", aliases.contains( poolName ) );
}
}
/**
* @param pool name
* @return his configuration - see src/tests/resources for matches
*/
private Properties getPoolConfigurarion(String poolName) {
Properties cfg = new Properties();
cfg.setProperty( Environment.PROXOOL_POOL_ALIAS, poolName );
cfg.setProperty( Environment.PROXOOL_PROPERTIES, poolName + ".properties" );
return cfg;
}
}

View File

@ -0,0 +1,7 @@
jdbc-0.proxool.alias=pool-one
jdbc-0.proxool.driver-url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE
jdbc-0.proxool.driver-class=org.h2.Driver
jdbc-0.user=sa
jdbc-0.password=
jdbc-0.proxool.maximum-connection-count=2
jdbc-0.proxool.house-keeping-test-sql=select CURRENT_DATE

View File

@ -0,0 +1,7 @@
jdbc-0.proxool.alias=pool-two
jdbc-0.proxool.driver-url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE
jdbc-0.proxool.driver-class=org.h2.Driver
jdbc-0.user=sa
jdbc-0.password=
jdbc-0.proxool.maximum-connection-count=2
jdbc-0.proxool.house-keeping-test-sql=select CURRENT_DATE