Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate slow HTTP connect for Java integration test?

is it possible to simulate a slow HTTP connect in a Java integration test, so that I can define how long the server should wait until he confirms the connection? A solution which also supports a JAX-WS webservice would be perfect.

Background: I have to integration test a central timeout configurator. The configurator itself must be technology-independent. At first it supports JAX-WS webservices, therefore the attribute com.sun.xml.ws.connect.timeout will be set in request context.

(I'll try to convince them, that it is part of JAX-WS and thus we don't need to test it, but this question is my backup plan.)

P.S.: There are other questions which ask about simulating a slow connection in general. This is different because I cannot use external tools in an unit test and I must be able to define a specific connection time.

like image 448
Christian Strempfer Avatar asked May 30 '26 23:05

Christian Strempfer


1 Answers

In one of my unit test, I used NanoHTTPd https://github.com/NanoHttpd/nanohttpd which is a pure Java. It is only one class.

like image 192
Pu Gong Avatar answered Jun 02 '26 20:06

Pu Gong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!