Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create network errors for testing a distributed system

I am developing a Java library for communication via HTTP, and I want to test its reliability and performance in case of network problems such as packet loss, high latency, low bandwidth, and congestion. I'm using Apache's httpclient library for doing connections from client side, and Java's own com.sun.net.httpserver.HttpServer for starting up HTTP servers.

Are there libraries available that do that kind of thing, or should I roll my own? I guess I could try to plug my own org.apache.http.conn.scheme.SchemeSocketFactory into the client side, and simulate several of the problems mentioned above with that, but I'd prefer to use something that works already :-)

This is similar to question Creating TCP network errors for unit testing, but I'm looking for solutions involving Java on Linux. I've looked at click, which was suggested for that question, but I'm not sure it can provide what I'm looking for.

like image 573
daniel kullmann Avatar asked Oct 21 '11 11:10

daniel kullmann


1 Answers

Since Java API's do not have access to the low level network API's, emulating it would be challenging.

Alternatively The Apache HTTP Core components library may have something to help you simulate latency and data loss and possibly bandwidth issues. The library has the feature to inject your own session input and output buffers. You can find the documentation at Advanced Features of HTTP Core

By injecting your own buffer

  • Latency can be a small delay injected into the read and writes
  • Data loss is some bytes thrown away. It is not packet loss in the true sense, since there is no resending of duplicates.
  • Bandwidth can be limited by tuning the read/write and flush operations.
  • Traffic is hard to simulate except as an over all slowdown of reading and writing to the buffer.

You can also look at TCPProxy available in the Grinder project. I haven't looked at it in detail. The documentation shows EchoFilter as an example but I believe it should be possible to extend the filters to delay the sending and receiving of bytes within the stream. But it makes sense to use a proxy to simulate network issues. This way your client and server remain blissfully ignorant of the testing going on.

In both cases simulation of the network issues seems to be the best effort possible in Java. Or else you can setup a local firewall and have it configured to intercept and play with the packets it receives.

Hope this was helpfull.

like image 97
akhilss Avatar answered Oct 05 '22 06:10

akhilss