I have a couple of methods that send HTTP requests to upload an input stream to S3. If the request to S3 fails, there is a retry strategy to attempt to send the request again on certain status codes. Since we cannot guarantee that the input stream has not been partially read from a previous request, we must provide a new input stream when retrying.
The object class containing the input stream looks something like this:
public class CustomRequest {
private InputStream stream;
private InputStreamProvider inputStreamProvider;
}
where InputStreamProvider is a functional interface created for the purpose of supplying a brand new input stream in the case of a retry and looks something like this:
public interface InputStreamProvider {
InputStream getInputStream();
}
Each CustomRequest can either have an InputStream which means we do not support retrying OR an InputStreamProvider for which we do support retries.
My question is how would I unit test to ensure I am in fact providing a new input stream when retrying with InputStreamProvider.getInputStream()?