0

I'm looking for a way to test if my application can survive if the database it connects to goes down and back up again. In which case the expected behaviour of the application would be to first throw an exception and then reconnect successfully once the database is up.

I would like to do so in an automated integration test (so manually powering off/on the database and see how the app behaves is out of question).

Connecting to an in-memory database is an option but this will devalue the test somewhat since the prod code and test code wont run against exactly the same db and drivers, so not ideal.

Another option would be for the test to trigger a process which would cutoff the connection between the database and the app for a few seconds (not sure how to do that).

Any other ideas ?

Technical stack is Java with Spring (jdbc templates).

Eleco
  • 3,194
  • 9
  • 31
  • 40

2 Answers2

0

I think you can try to supply with incorrect db log in information to simulate the connection loss

sotondolphin
  • 223
  • 1
  • 10
0

If you are looking at killing the connection, depending on your setup you could create a batch script to disable your network adapter, and another switch it back on again once you are ready

This might help How can I write a batch file to toggle my network adapters?

and you can use this to call the script How do I run a batch file from my Java Application?

Community
  • 1
  • 1
LordSquall
  • 161
  • 7