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

commit 09b429d7e4b1f69cccba9de1e7a1a25d0358a0dd
Author: Andrei Dulvac <[email protected]>
AuthorDate: Wed Sep 18 11:55:53 2019 +0200

    SLING-8710 refactor with java 8 streams and other cleanup
---
 .../testing/clients/indexing/IndexingClient.java   | 65 ++++++++++------------
 .../clients/indexing/IndexingClientTest.java       |  2 +-
 2 files changed, 31 insertions(+), 36 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/testing/clients/indexing/IndexingClient.java 
b/src/main/java/org/apache/sling/testing/clients/indexing/IndexingClient.java
index 5368e78..2bbea26 100644
--- 
a/src/main/java/org/apache/sling/testing/clients/indexing/IndexingClient.java
+++ 
b/src/main/java/org/apache/sling/testing/clients/indexing/IndexingClient.java
@@ -30,14 +30,14 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.net.URI;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
-import java.util.concurrent.Callable;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicLong;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import static java.util.UUID.randomUUID;
 import static org.apache.http.HttpStatus.SC_OK;
@@ -146,6 +146,7 @@ public class IndexingClient extends SlingClient {
 
     /** Global counter for how much time was spent in total waiting for async 
indexing */
     private static final AtomicLong totalWaited = new AtomicLong();
+    public static final String ASYNC_INDEXER_CONFIG = 
"org.apache.jackrabbit.oak.plugins.index.AsyncIndexerService";
 
     /**
      * Constructor used by Builders and adaptTo(). <b>Should never be called 
directly from the code.</b>
@@ -197,24 +198,11 @@ public class IndexingClient extends SlingClient {
             return configuredLanes;
         }
 
-        try {
-            Object asyncConfigs = adaptTo(OsgiConsoleClient.class)
-                    
.getConfiguration("org.apache.jackrabbit.oak.plugins.index.AsyncIndexerService")
-                    .get("asyncConfigs");
-
-            if (asyncConfigs instanceof String[]) {
-                String[] configs = (String[]) asyncConfigs;  // ugly, we 
should refactor OsgiConsoleClient
-
-                List<String> lanes = new ArrayList<>(configs.length);
-                for (String asyncConfig : configs) {
-                    lanes.add(asyncConfig.split(":")[0]);
-                }
-                return lanes;
-            } else {
-                throw new ClientException("Cannot retrieve config from 
AsyncIndexerService, asyncConfigs is not a String[]");
-            }
-        } catch (Exception e) {
-            throw new ClientException("Failed to retrieve lanes", e);
+        Object configs = 
adaptTo(OsgiConsoleClient.class).getConfiguration(ASYNC_INDEXER_CONFIG).get("asyncConfigs");
+        if (configs instanceof String[]) {
+            return Stream.of((String[]) configs).map(e -> 
e.split(":")[0]).collect(Collectors.toList());
+        } else {
+            throw new ClientException("Cannot retrieve config from 
AsyncIndexerService, asyncConfigs is not a String[]");
         }
     }
 
@@ -223,13 +211,8 @@ public class IndexingClient extends SlingClient {
         if (configLanesCsv == null) {
             return Collections.emptyList();
         }
-
-        String[] configLanesArr = configLanesCsv.split(",");
-        for (int i = 0; i < configLanesArr.length; i++) {
-            configLanesArr[i] = configLanesArr[i].trim();
-        }
-
-        return Collections.unmodifiableList(Arrays.asList(configLanesArr));
+        return 
Collections.unmodifiableList(Stream.of(configLanesCsv.split(","))
+                .map(e -> e.trim()).collect(Collectors.toList()));
     }
 
     /**
@@ -261,12 +244,7 @@ public class IndexingClient extends SlingClient {
         final String uniqueValue = randomUUID().toString();  // to be added in 
all the content nodes
         final List<String> lanes = getLaneNames();  // dynamically detect 
which lanes to wait for
 
-        Polling p = new Polling(new Callable<Boolean>() {
-            @Override
-            public Boolean call() throws Exception {
-                return searchContent(lanes, uniqueValue);
-            }
-        });
+        Polling p = new Polling(() -> searchContent(lanes, uniqueValue));
 
         try {
             createContent(lanes, uniqueValue);
@@ -319,7 +297,7 @@ public class IndexingClient extends SlingClient {
             String indexName = getIndexName(lane);
             String indexDefinition = replacePlaceholders(INDEX_DEFINITION, 
lane, null);
             LOG.info("Creating index {} in {}", indexName, INDEX_PATH);
-            LOG.debug(indexDefinition);
+            LOG.debug("Index definition: {}", indexDefinition);
             importContent(INDEX_PATH, "json", indexDefinition);
             // Trigger reindex to make sure the complete index definition is 
used
             setPropertyString(INDEX_PATH + "/" + indexName, "reindex", "true");
@@ -332,10 +310,27 @@ public class IndexingClient extends SlingClient {
      * <p>User must manually call this if needed, as opposed to {@link 
#install()}, which is called
      * automatically.</p>
      *
+     * @deprecated Use #uninstallWithRetry
      * @throws ClientException if the cleanup failed
      */
     public void uninstall() throws ClientException {
-        deletePath(WAIT_FOR_ASYNC_INDEXING_ROOT, SC_OK);
+        this.deletePath(WAIT_FOR_ASYNC_INDEXING_ROOT, SC_OK);
+    }
+
+    /**
+     * <p>Retries cleaning all the data generated by {@link #install()} and 
{@link #waitForAsyncIndexing(long, long)}.</p>
+     *
+     * <p>User must manually call this if needed, as opposed to {@link 
#install()}, which is called
+     * automatically.</p>
+     *
+     * @throws TimeoutException if retry operation times out and the path 
still exists
+     * @throws InterruptedException if the retry operation was interrupted by 
the user
+     */
+    public void uninstallWithRetry() throws TimeoutException, 
InterruptedException {
+        new Polling(() -> {
+            this.deletePath(WAIT_FOR_ASYNC_INDEXING_ROOT, SC_OK);
+            return this.exists(WAIT_FOR_ASYNC_INDEXING_ROOT);
+        }).poll(5000, 500);
     }
 
     /**
diff --git 
a/src/test/java/org/apache/sling/testing/clients/indexing/IndexingClientTest.java
 
b/src/test/java/org/apache/sling/testing/clients/indexing/IndexingClientTest.java
index b97812a..6346afc 100644
--- 
a/src/test/java/org/apache/sling/testing/clients/indexing/IndexingClientTest.java
+++ 
b/src/test/java/org/apache/sling/testing/clients/indexing/IndexingClientTest.java
@@ -208,7 +208,7 @@ public class IndexingClientTest {
     }
 
     @Test
-    public void testWaitForAsyncIndexing_ConfiguredLanes() throws 
ClientException, TimeoutException, InterruptedException {
+    public void testWaitForAsyncIndexingConfiguredLanes() throws 
ClientException, TimeoutException, InterruptedException {
         client.setLaneNames(PRE_DEFINED_INDEXING_LANES);
         client.waitForAsyncIndexing();
 

Reply via email to