You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by du...@apache.org on 2019/09/16 19:57:23 UTC

[sling-org-apache-sling-testing-clients] branch master updated (d85300a -> 4f59360)

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

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


    from d85300a  [maven-release-plugin] prepare for next development iteration
     new a04c813  SLING-8710: IndexingClient should have configurable lanes
     new da31a12  SLING-8710: IndexingClient should have configurable lanes
     new 6db2a0e  SLING-8710: IndexingClient should have configurable lanes
     new 4f59360  SLING-8710: IndexingClient should have configurable lanes

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../testing/clients/indexing/IndexingClient.java   | 38 +++++++++++++++++++++-
 .../testing/clients/indexing/package-info.java     |  2 +-
 .../clients/indexing/IndexingClientTest.java       | 20 ++++++++++++
 3 files changed, 58 insertions(+), 2 deletions(-)


[sling-org-apache-sling-testing-clients] 01/04: SLING-8710: IndexingClient should have configurable lanes

Posted by du...@apache.org.
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 a04c8139fd6a232f67583a019c71b9f66d63f96b
Author: Vikas Saurabh <vs...@adobe.com>
AuthorDate: Mon Sep 16 18:48:21 2019 +0530

    SLING-8710: IndexingClient should have configurable lanes
---
 .../testing/clients/indexing/IndexingClient.java   | 25 ++++++++++++++++++++++
 .../testing/clients/indexing/package-info.java     |  2 +-
 .../clients/indexing/IndexingClientTest.java       | 18 ++++++++++++++++
 3 files changed, 44 insertions(+), 1 deletion(-)

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 de1782b..62cf14d 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
@@ -32,6 +32,7 @@ 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;
@@ -58,6 +59,11 @@ import static org.apache.http.HttpStatus.SC_OK;
 public class IndexingClient extends SlingClient {
     private static final Logger LOG = LoggerFactory.getLogger(IndexingClient.class);
 
+    /** Configuration name in {@link SlingClientConfig} to be used to initialize pre-defined index lanes
+     *  Configured value, if any, is supposed to be an array of lane names
+     */
+    public static final String INDEX_LANES_CSV_CONFIG_NAME = "indexLanesCsv";
+
     /** Root of all the data created by this tool. Its presence marks that it was already installed */
     private static final String WAIT_FOR_ASYNC_INDEXING_ROOT = "/tmp/testing/waitForAsyncIndexing";
 
@@ -175,6 +181,11 @@ public class IndexingClient extends SlingClient {
      * @throws ClientException if the request fails
      */
     public List<String> getLaneNames() throws ClientException {
+        List<String> configuredLanes = getConfiguredLaneNames();
+        if (configuredLanes != null) {
+            return configuredLanes;
+        }
+
         try {
             Object asyncConfigs = adaptTo(OsgiConsoleClient.class)
                     .getConfiguration("org.apache.jackrabbit.oak.plugins.index.AsyncIndexerService")
@@ -196,6 +207,20 @@ public class IndexingClient extends SlingClient {
         }
     }
 
+    private List<String> getConfiguredLaneNames() {
+        String configLanesCsv = getValue(INDEX_LANES_CSV_CONFIG_NAME);
+        if (configLanesCsv == null) {
+            return null;
+        }
+
+        String[] configLanesArr = configLanesCsv.split(",");
+        for (int i = 0; i < configLanesArr.length; i++) {
+            configLanesArr[i] = configLanesArr[i].trim();
+        }
+
+        return Collections.unmodifiableList(Arrays.asList(configLanesArr));
+    }
+
     /**
      * <p>Blocks until all the async indices are up to date, to guarantee that the susequent queries return
      * all the results.</p>
diff --git a/src/main/java/org/apache/sling/testing/clients/indexing/package-info.java b/src/main/java/org/apache/sling/testing/clients/indexing/package-info.java
index 385a674..f6ae230 100644
--- a/src/main/java/org/apache/sling/testing/clients/indexing/package-info.java
+++ b/src/main/java/org/apache/sling/testing/clients/indexing/package-info.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-@Version("0.1.0")
+@Version("0.2.0")
 package org.apache.sling.testing.clients.indexing;
 
 import org.osgi.annotation.versioning.Version;
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 0fde485..f409204 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
@@ -27,6 +27,7 @@ import org.apache.http.protocol.HttpRequestHandler;
 import org.apache.sling.testing.clients.ClientException;
 import org.apache.sling.testing.clients.HttpServerRule;
 import org.apache.sling.testing.clients.query.servlet.QueryServlet;
+import org.junit.Assert;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -37,6 +38,7 @@ import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicInteger;
 
 public class IndexingClientTest {
     private static final Logger LOG = LoggerFactory.getLogger(IndexingClientTest.class);
@@ -44,6 +46,10 @@ public class IndexingClientTest {
     private static final String EXPLAIN_RESPONSE = "{\"plan\": \"random plan with testIndexingLane-async and testIndexingLane-fulltext-async\",\"time\": 1}";
     private static final String QUERY_RESPONSE = "{\"total\": 1234,\"time\": 1}";
 
+    private static final String PRE_DEFINED_INDEXING_LANES_CSV = "async, fulltext-async";
+
+    private static final AtomicInteger NUM_INDEXING_LANE_CONSOLE_CALLS = new AtomicInteger();
+
     @ClassRule
     public static HttpServerRule httpServer = new HttpServerRule() {
         HttpRequestHandler okHandler =  new HttpRequestHandler() {
@@ -124,6 +130,7 @@ public class IndexingClientTest {
                         @Override
                         public void handle(HttpRequest request, HttpResponse response, HttpContext context)
                                 throws HttpException, IOException {
+                            NUM_INDEXING_LANE_CONSOLE_CALLS.incrementAndGet();
                             response.setStatusCode(200);
                             response.setEntity(new StringEntity("{\"properties\":{" +
                                     "\"asyncConfigs\":{\"values\":[\"async:5\",\"fulltext-async:5\"]}}}"));
@@ -180,6 +187,7 @@ public class IndexingClientTest {
     private IndexingClient client;
 
     public IndexingClientTest() throws ClientException {
+        NUM_INDEXING_LANE_CONSOLE_CALLS.set(0);
         client = new IndexingClient(httpServer.getURI(), "admin", "admin");
         //client = new IndexingClient(java.net.URI.create("http://localhost:4502"), "admin", "admin");
     }
@@ -199,6 +207,16 @@ public class IndexingClientTest {
         client.waitForAsyncIndexing();
     }
 
+    @Test
+    public void testWaitForAsyncIndexing_ConfiguredLanes() throws ClientException, TimeoutException, InterruptedException {
+        client.getValues().put(IndexingClient.INDEX_LANES_CSV_CONFIG_NAME, PRE_DEFINED_INDEXING_LANES_CSV);
+
+        client.waitForAsyncIndexing();
+
+        Assert.assertEquals("Must not get indexing lanes from /system/console",
+                0, NUM_INDEXING_LANE_CONSOLE_CALLS.get());
+    }
+
     private static List<NameValuePair> extractParameters(HttpRequest request) {
         if (request instanceof HttpEntityEnclosingRequest) {
             HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();


[sling-org-apache-sling-testing-clients] 02/04: SLING-8710: IndexingClient should have configurable lanes

Posted by du...@apache.org.
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 da31a123d56b007971a6d46a9b56ae2756934895
Author: Vikas Saurabh <vs...@adobe.com>
AuthorDate: Mon Sep 16 19:09:54 2019 +0530

    SLING-8710: IndexingClient should have configurable lanes
    
    Fix sonar's complain of code smell
---
 .../org/apache/sling/testing/clients/indexing/IndexingClient.java     | 4 ++--
 1 file changed, 2 insertions(+), 2 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 62cf14d..8c6d57c 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
@@ -182,7 +182,7 @@ public class IndexingClient extends SlingClient {
      */
     public List<String> getLaneNames() throws ClientException {
         List<String> configuredLanes = getConfiguredLaneNames();
-        if (configuredLanes != null) {
+        if (!configuredLanes.isEmpty()) {
             return configuredLanes;
         }
 
@@ -210,7 +210,7 @@ public class IndexingClient extends SlingClient {
     private List<String> getConfiguredLaneNames() {
         String configLanesCsv = getValue(INDEX_LANES_CSV_CONFIG_NAME);
         if (configLanesCsv == null) {
-            return null;
+            return Collections.emptyList();
         }
 
         String[] configLanesArr = configLanesCsv.split(",");


[sling-org-apache-sling-testing-clients] 03/04: SLING-8710: IndexingClient should have configurable lanes

Posted by du...@apache.org.
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 6db2a0e74c722cc4b0579b0b001fb615b1c0caec
Author: Vikas Saurabh <vs...@adobe.com>
AuthorDate: Mon Sep 16 19:43:24 2019 +0530

    SLING-8710: IndexingClient should have configurable lanes
    
    Implement comment from apache/sling-org-apache-sling-testing-clients#10
    to not expose config map property name but expose a setLanes method.
---
 .../org/apache/sling/testing/clients/indexing/IndexingClient.java | 6 +++++-
 .../apache/sling/testing/clients/indexing/IndexingClientTest.java | 8 +++++---
 2 files changed, 10 insertions(+), 4 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 8c6d57c..be9a159 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
@@ -62,7 +62,7 @@ public class IndexingClient extends SlingClient {
     /** Configuration name in {@link SlingClientConfig} to be used to initialize pre-defined index lanes
      *  Configured value, if any, is supposed to be an array of lane names
      */
-    public static final String INDEX_LANES_CSV_CONFIG_NAME = "indexLanesCsv";
+    private static final String INDEX_LANES_CSV_CONFIG_NAME = "indexLanesCsv";
 
     /** Root of all the data created by this tool. Its presence marks that it was already installed */
     private static final String WAIT_FOR_ASYNC_INDEXING_ROOT = "/tmp/testing/waitForAsyncIndexing";
@@ -174,6 +174,10 @@ public class IndexingClient extends SlingClient {
         super(url, user, password);
     }
 
+    public void setLaneNames(String ... laneNames) {
+        getValues().put(INDEX_LANES_CSV_CONFIG_NAME, StringUtils.join(laneNames));
+    }
+
     /**
      * Retrieves the list of indexing lanes configured on the instance
      *
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 f409204..b97812a 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
@@ -46,7 +46,7 @@ public class IndexingClientTest {
     private static final String EXPLAIN_RESPONSE = "{\"plan\": \"random plan with testIndexingLane-async and testIndexingLane-fulltext-async\",\"time\": 1}";
     private static final String QUERY_RESPONSE = "{\"total\": 1234,\"time\": 1}";
 
-    private static final String PRE_DEFINED_INDEXING_LANES_CSV = "async, fulltext-async";
+    private static final String [] PRE_DEFINED_INDEXING_LANES = new String[]{"async, fulltext-async"};
 
     private static final AtomicInteger NUM_INDEXING_LANE_CONSOLE_CALLS = new AtomicInteger();
 
@@ -209,10 +209,12 @@ public class IndexingClientTest {
 
     @Test
     public void testWaitForAsyncIndexing_ConfiguredLanes() throws ClientException, TimeoutException, InterruptedException {
-        client.getValues().put(IndexingClient.INDEX_LANES_CSV_CONFIG_NAME, PRE_DEFINED_INDEXING_LANES_CSV);
-
+        client.setLaneNames(PRE_DEFINED_INDEXING_LANES);
         client.waitForAsyncIndexing();
 
+        IndexingClient otherClient = client.adaptTo(IndexingClient.class);
+        otherClient.waitForAsyncIndexing();
+
         Assert.assertEquals("Must not get indexing lanes from /system/console",
                 0, NUM_INDEXING_LANE_CONSOLE_CALLS.get());
     }


[sling-org-apache-sling-testing-clients] 04/04: SLING-8710: IndexingClient should have configurable lanes

Posted by du...@apache.org.
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 4f59360890ec126fbfaf7f946fb1f19249345f15
Author: Vikas Saurabh <vs...@adobe.com>
AuthorDate: Mon Sep 16 19:50:47 2019 +0530

    SLING-8710: IndexingClient should have configurable lanes
    
    Fix javadoc
---
 .../apache/sling/testing/clients/indexing/IndexingClient.java    | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

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 be9a159..5368e78 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
@@ -174,12 +174,19 @@ public class IndexingClient extends SlingClient {
         super(url, user, password);
     }
 
+    /**
+     * Set provided {@code laneNames} to config map. This allows for subsequent initializations
+     * using {@code adaptTo} that shard the same config map to not require further configuration
+     * of lane names
+     * @param laneNames lane names to work on
+     */
     public void setLaneNames(String ... laneNames) {
         getValues().put(INDEX_LANES_CSV_CONFIG_NAME, StringUtils.join(laneNames));
     }
 
     /**
-     * Retrieves the list of indexing lanes configured on the instance
+     * Return the list of indexing lanes configured by {@link #setLaneNames}, if any.
+     * Else, retrieves configured lanes on the instance
      *
      * @return list of lane names
      * @throws ClientException if the request fails