You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2020/11/10 10:40:20 UTC

[sling-org-apache-sling-adapter-annotations] branch master updated: SLING-2938 - check multiple paths for readiness

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

bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-adapter-annotations.git


The following commit(s) were added to refs/heads/master by this push:
     new a4bb0b3  SLING-2938 - check multiple paths for readiness
a4bb0b3 is described below

commit a4bb0b3d126b078ec8872f41ff15bc5a809c8018
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue Nov 10 11:37:31 2020 +0100

    SLING-2938 - check multiple paths for readiness
---
 .../adapter/annotations/util/AppSlingClient.java   | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/it/annotations-it/src/test/java/org/apache/sling/adapter/annotations/util/AppSlingClient.java b/src/it/annotations-it/src/test/java/org/apache/sling/adapter/annotations/util/AppSlingClient.java
index 1982973..ad5309d 100644
--- a/src/it/annotations-it/src/test/java/org/apache/sling/adapter/annotations/util/AppSlingClient.java
+++ b/src/it/annotations-it/src/test/java/org/apache/sling/adapter/annotations/util/AppSlingClient.java
@@ -29,13 +29,20 @@ import java.util.concurrent.TimeoutException;
 public class AppSlingClient {
     private static boolean bundleInstalledAndStarted;
 
+    private static final String [] READINESS_PATHS = {
+        "/starter.html",
+        "/system/console/status-adapters.txt",
+        "/system/console/components",
+        "/system/console/services"
+    };
+
     @SuppressWarnings("squid:S2095") // Caller will close the client
     public static SlingClient newSlingClient() throws URISyntaxException, ClientException, TimeoutException, InterruptedException {
         final SlingClient client = new SlingClient(new URI(System.getProperty("baseUrl")), "admin", "admin");
 
         // client.waitExists() adds ".json" to the path, which is not desired, since that requests the Sling Default GET Servlet instead of Sling Starter HTML
-        new Polling(() -> client.doGet("/starter.html").getStatusLine().getStatusCode() == 200)
-                .poll(60_000, 500);
+        new Polling(() -> allPathsOk(client, READINESS_PATHS, 200))
+            .poll(60_000, 500);
 
         if (!bundleInstalledAndStarted) {
             final OsgiConsoleClient osgiConsoleClient = client.adaptTo(OsgiConsoleClient.class);
@@ -45,4 +52,15 @@ public class AppSlingClient {
         }
         return client;
     }
+
+    /** @return true if all paths return expected status */
+    private static boolean allPathsOk(SlingClient client, String [] paths, int expectedStatus) throws ClientException, InterruptedException {
+        for(String path : paths) {
+            final int actualStatus = client.doGet(path).getStatusLine().getStatusCode();
+            if(actualStatus != expectedStatus) {
+                throw new ClientException("Expected status " + expectedStatus + " but got " + actualStatus + " for " + path);
+            }
+        }
+        return true;
+    }
 }