users@jersey.java.net

Tests eating up too many connections

From: Gary Moore <gary.moore_at_gmail.com>
Date: Thu, 19 Aug 2010 11:24:15 -0400

Hey all,

Been stumped on this for a couple of weeks. I have a problem where my
container tests, when run all together as a suite (or mvn test) eat up
too many connections to the database. Eventually the DB runs out of
connections and starts refusing.

This isn't a Hibernate pooling problem. We've tested the app under
load when deployed to an external container. Connection levels are
reasonable there.

Usually see something like this for each method in each test

INFO: Starting the Grizzly Web Container...
Aug 19, 2010 11:01:46 AM com.sun.grizzly.http.servlet.ServletContextImpl log
INFO: Initializing Spring root WebApplicationContext
171414 [main] INFO
org.hibernate.connection.DriverManagerConnectionProvider - Using
Hibernate built-in connection pool (not for production use!)
171414 [main] INFO
org.hibernate.connection.DriverManagerConnectionProvider - Hibernate
connection pool size: 20
171414 [main] INFO
org.hibernate.connection.DriverManagerConnectionProvider - autocommit
mode: true
171414 [main] INFO
org.hibernate.connection.DriverManagerConnectionProvider - using
driver: com.mysql.jdbc.Driver at URL:
jdbc:mysql://localhost/ATHENA-Tix
171414 [main] INFO
org.hibernate.connection.DriverManagerConnectionProvider - connection
properties: {user=root, password=****, autocommit=true,
release_mode=auto}
(snip...)
Aug 19, 2010 11:01:40 AM
com.sun.jersey.test.framework.spi.container.grizzly.web.GrizzlyWebTestContainerFactory$GrizzlyWebTestContainer
stop
INFO: Stopping the Grizzly Web Container...
Aug 19, 2010 11:01:41 AM com.sun.grizzly.http.servlet.ServletContextImpl log
INFO: Closing Spring root WebApplicationContext
164441 [main] INFO org.hibernate.impl.SessionFactoryImpl - closing
164441 [main] INFO
org.hibernate.connection.DriverManagerConnectionProvider - cleaning up
connection pool: jdbc:mysql://localhost/ATHENA-Tix

This looks to me like it is initializing a new connection pool in each
method and somehow they aren't getting cleaned up properly.

I've tried running the tests with

mvn test -Dtest.containerFactory=com.sun.jersey.test.framework.spi.container.external.EmbeddedGlassFishTestContainerFactory

which didn't appear to work. The tests still used Grizzly.

Our project is open source, you can find the code on Github.

Pom: http://github.com/fracturedatlas/parakeet/blob/master/pom.xml
persistence.xml:
http://github.com/fracturedatlas/parakeet/blob/master/src/main/resources/META-INF/persistence.xml
Our test setup:
http://github.com/fracturedatlas/parakeet/blob/master/src/test/java/org/fracturedatlas/athena/tix/util/BaseTixContainerTest.java
Sample test: http://github.com/fracturedatlas/parakeet/blob/master/src/test/java/org/fracturedatlas/athena/tix/resource/container/SaveTicketContainerTest.java

Any suggestions?

Thanks much,
Gary

-- 
Gary Moore
http://www.gmoore.net