I'm working on some legacy code that stores files to a remote server. I'd like to use Apache's DefaultHttpRequestRetryHandler to implement a retry logic. A simplified version of the implementation is shown below. How do I test my retry logic?
I was able to manually test it by overriding retryRequest() in the DefaultHttpRequestRetryHandler class but an automated way would be nice. (I'm using Spock to test.)
private CloseableHttpClient getHttpClient() {
DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler();
CloseableHttpClient httpClient = HttpClients.custom().setRetryHandler(retryHandler).build();
return httpClient;
}
public CloseableHttpResponse uploadFile(){
CloseableHttpClient httpClient = getHttpClient();
CloseableHttpResponse response = null;
try {
response = httpClient.execute(post, getHttpContext());
} catch (Exception ex) {
//handle exception
}
return response;
}
Aucun commentaire:
Enregistrer un commentaire