开发者

Making a reliable web service unreliable, but in a controlled way?

I have a 开发者_如何学CJava 6 based web service client using the standard Java 6 annotation based approach (i.e. no Axis or other third party web service library), which works very well. So does the web service I am calling, which is nice, but now I need to write error handling code, and I need to be able to make the existing web service unreliable in a controlled way.

There are many mock frameworks, and they may be helpful, but I don't need right now to be able to mock out the service with prerecorded answers or anything, just introduce unreliability causing the web service library to fail so I can handle the situation gracefully. This would probably be a proxy server running locally.

I work with Eclipse Java EE 3.6, but Netbeans, IntelliJ and JDeveloper are also options.

What would be the best way to do this?


Tcpmon, http://ws.apache.org/commons/tcpmon/index.html can be set up to act as a proxy and even simulate slow connections. That would give you a chance to simulate both "sorry, not here" and "yes, we are here but we time out".


Any introduced instability is likely to lead to operation avenues of instability being missed. Aim to cover all potential error vectors in your code rather than trying to mitigate for specifics.


Since You've not disclosed enough details of your setup, maybe throwing Exception here and there would be enough?

Seriously, for integration tests like this I'd suggest running some subset of a real web service container.

Based on service's logic it may behave unreliably because of:

  • external system it is using is misbehaving - try to mock the external system and throw faults - different types - from it
  • database access problem - try mocking DAO layer and throw Exception from there
  • general hardware problem - depends :) try to stress your code as you see fit


I think rather than introducing unreliability to a running-instance of the web service application, you are better off simulating error conditions in your unit/integration tests and asserting that your top-layer of the service responds the way that you would like.

For example:

  1. How does the service entry-point respond to a request if the data layer reports that it cannot communicate with the backend (if the data layer throws exceptions, or however it indicates failure)
  2. How does the service entry-point behave if other required components are throwing "unavailable"-like exceptions?
  3. Do you have any timeout logic in place, i.e. the service returns an error if it takes more than X seconds to process the request? If so, this can be simulated in a mock test as well.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜