Testing HTTP errors and retrial

If you call a remote REST service, you perhaps want to retry automatically upon recoverable errors. Make sure to test that code - so that you won't end up surprised that it is completely broken, as I was :-) What follows is a few simple tips for simulating some common recoverable failures.

  • java.net.ConnectException - use http://localhost:<port where nothing runs>
  • java.net.SocketTimeoutException - run nc -lk 5432 to listen but not respond and connect to "http://localhost:5432"
  • HTTP 5xx - use "https://httpbin.org/status/500" (or any other 5xx number)
  • Other - use Toxiproxy, a TCP proxy to simulate network and system conditions for chaos and resiliency testing