stevebot
stevebot

Reputation: 24005

Using JDBC in setup for a Jmeter Junit test

I was trying to use the JDBC to connect to my MySQL database in the setup and teardown methods of my Junit tests that are being run through Jmeter. Jmeter will create multiple threads, each of which will run one instance of my test.

The issue that I run into, is if I instantiate my datasource in the setup of my Junit test, then my connection pool runs out of connections. Is there a way to design my test so that this does not happen? I'm trying to avoid increasing my max MySQL connections to solve this issue.

Upvotes: 0

Views: 838

Answers (2)

javamonkey79
javamonkey79

Reputation: 17775

A couple suggestions:

  • If possible use mocks or a mocking framework like mockito.
  • Use connection pooling if you're not already - this might alleviate the overhead of having more connections that you need.

Upvotes: 0

duffymo
duffymo

Reputation: 308763

Yes, make sure that each test closes the connection and returns it to the pool when it's done. Sounds like that's not happening, but I can't be sure.

If that's not the case, I'd recommend tuning your connection and thread pool sizes better so you don't run out.

Upvotes: 1

Related Questions