Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
2 commits merged into from
Jan 14, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions connection-proxool/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,10 @@
<artifactId>proxool</artifactId>
<version>0.8.3</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,12 @@ public void close() throws HibernateException {

// We have created the pool ourselves, so shut it down
try {
ProxoolFacade.shutdown(0);
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.connection;

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;
}

}
7 changes: 7 additions & 0 deletions connection-proxool/src/test/resources/pool-one.properties
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions connection-proxool/src/test/resources/pool-two.properties
Original file line number Diff line number Diff line change
@@ -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