This is an automated email from the ASF dual-hosted git repository.

dulvac pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-clients.git


The following commit(s) were added to refs/heads/master by this push:
     new 798e726  SLING-11609: Provide doGetWithRetry methods in Sling Testing 
Clients (#38)
798e726 is described below

commit 798e726537e459c5af1fd8360b39b3c0dce7b77d
Author: Nicola Scendoni <[email protected]>
AuthorDate: Mon Jan 15 09:47:25 2024 +0100

    SLING-11609: Provide doGetWithRetry methods in Sling Testing Clients (#38)
    
    * SLING-11609: Provide doGetWithRetry methods in Sling Testing Clients
    * Added How to retry HTTP Requests in Readme
---
 README.md | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/README.md b/README.md
index c6e5b72..088e0b5 100644
--- a/README.md
+++ b/README.md
@@ -151,6 +151,24 @@ public class MyClient extends SlingClient {
     }
 }
 ```
+## <a name="builder"></a> How to retry HTTP Requests
+In several situations during IT Tests development, HTTP requests must be 
retried until some assertions are verified.
+In such cases, a good approach is to use the `Awaitility` library. For example:
+```java
+    public void testDoGetWithRetry() throws ClientException, 
InterruptedException, TimeoutException {
+        SlingClient c = new SlingClient(httpServer.getURI(), "user", "pass");
+
+        Awaitility.await("doGet until expectedStatus and Assertions are 
satisfied")
+            .atMost(Duration.ofSeconds(1000))
+            .pollInterval(Duration.ofMillis(100))
+            .ignoreExceptionsInstanceOf(ClientException.class)
+            .until(() -> {
+                SlingHttpResponse response = c.doGet("/", 200);
+                return SUCCESS_RESPONSE.equals(response.getContent());
+            });
+    }
+    
+```
 
 ## FAQ
 ##### How can I change the server url of an existing client?

Reply via email to