• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring - Connection Problem in some Unit Tests

 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi mates

If I run all(31) the unit test together, I get following connection error in 2 - 3 unit tests, however if I run those tests indvidually, the run successfully. Can you please guide me on this strange behaviour. I am using Spring 3.0.6, Spring batch 2.1.7 and orcale XE database.

below is the error

 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are your tests closing the dataSource? calling the close() method. It looks like after running a few of the tests and those past tests shutdown Spring container but not closing the connections in the datasources, therefore the backend database has all these connections being used and is probably then reaching its max connections and can't create any new ones for the later tests.

Basically you can configure your datasource to have a <bean … destroy-method="close"/>

How are you creating your Spring ApplicationContext are you using the annotation @ContextConfiguration and @RunWith? Or are you creating it yourself in the setup method?

Mark
 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark

I am using @ContextConfiguration and @RunWith in the tests. I am not calling close() method of DataSource. My understanding was that all the connection handling is taken care by Spring itself. I have tested it by adding the close() call but of no gain. Below is my datasource config
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How many connections does your database allow. Can you post some of your test code? The cause network connection could not be made would be either because the network went down, but I doubt that, or that you are trying to create too many connections than the server/database can start up. So it isn't exactly a Spring or Unit Test problem as a configuration for your database.

What database are you using?

Mark
 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In addition to what Mark said, consider providing the following information

1. Does the exception happen on the same test when you run all 31 test cases?
2. Does it happen each and every time you run the 31 test cases?
3. Do all the 31 cases try to connect to the database?

31 test cases (unit test) connecting to the database? How many steps does your batch job have? Do you really need so many to connect to the Database?
 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:How many connections does your database allow. Can you post some of your test code? The cause network connection could not be made would be either because the network went down, but I doubt that, or that you are trying to create too many connections than the server/database can start up. So it isn't exactly a Spring or Unit Test problem as a configuration for your database.

What database are you using?

Mark



I am using Orcale XE database installed on my local machine(No network db call). I am not sure how I should check the connection allowed by the db. Please guide me on this. It is the case of connection exhausting but I am not sure where is the problem. I my unit test I am get simpleJdbcTemplate injected. My unit test are calling Spring Batch Job. The job reads table containting 100 reacords, call some transformation logic and write them back in new table.
 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I run unit test from maven, they work fine. The problems only seems with tests run from eclipse.

Any idea ?
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Amirr Rafique wrote:If I run unit test from maven, they work fine. The problems only seems with tests run from eclipse.

Any idea ?



Yeah, Eclipse. ;) You have managed to reduce the possibilities to one place. Eclipse.

Also, the latest you post you wrote sounds like a different question. I am going to split that into its own thread here.


Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Amirr Rafique,
Your post was moved to a new topic.
 
today's feeble attempt to support the empire
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic