Reputation: 559
I'm currently writting an integration test for a persistent object that is connected to a Tcp socket.
What I got to do now is to test its reconnection feature: network goes down, it emits the 'disconnected' event and start trying to reconnect and reauthenticate the socket.
I decided that, instead of mocking the socket, it would be brilliant if the the test could shutdown connectivity, check the events, the attempts and finally, bring it back up and assert that the component is up and running again.
In .NET it's a piece of cake. Couldn't find how to do it in Java though.
Any ideas? Many thanks!
Upvotes: 0
Views: 111
Reputation: 201409
Java doesn't give you access to the underlying hardware, it runs in a Virtual Machine. You could potentially use JNA to access native routines to do that, or use a ProcessBuilder
to run
ipconfig /release
and then (when ready to bring networking back up)
ipconfig /renew
Upvotes: 1