I would like to simulate a socket connection going bad in order to test my application. The goal is to verify whether my Java code behaves the way it expected to, when a long standing socket connection to a remote server gets reset at runtime or server becomes unavailable.
I tried creating a firewall rule in Windows Firewall. However, enabling the rule does not seem to affect a socket connection that is already open. Pulling the network cable is not an option because I have to perform these tests over a remote desktop connection to the server that is running my code.
I realize that this isn't directly under Windows, but considering the nature of Java, it may still work.
There is a program called Netem under Linux, which considering your code is java, may run. I've never used it, so I can't attest to its abilities or use, but there are some examples for use here. You can fairly trivially run Linux inside a VM (like the free (as in beer, or as in the kind of free speech you enjoy in Britain) VirtualBox) and hopefully your Java app inside that.
May not be perfect, and sorry about a general lack of know-how, but it might work for what you need
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With