Class IndexingClient

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, org.apache.http.client.HttpClient

    public class IndexingClient
    extends SlingClient

    Interface to the oak indexing mechanism

    Exposes waitForAsyncIndexing(long, long) for waiting all the indexing lanes to finish indexing and to guarantee all the indices are up to date

    For using waitForAsyncIndexing(long, long), the user must have access rights to:

    • read/write in /tmp
    • install bundles via OsgiConsoleClient (if the query servlet was not previously installed)

    In short, it requires administrative rights.

    • Field Detail

      • ASYNC_INDEXER_CONFIG

        public static final java.lang.String ASYNC_INDEXER_CONFIG
        See Also:
        Constant Field Values
    • Constructor Detail

      • IndexingClient

        public IndexingClient​(org.apache.http.impl.client.CloseableHttpClient http,
                              SlingClientConfig config)
                       throws ClientException
        Constructor used by Builders and adaptTo(). Should never be called directly from the code.
        Parameters:
        http - the underlying HttpClient to be used
        config - sling specific configs
        Throws:
        ClientException - if the client could not be created
      • IndexingClient

        public IndexingClient​(java.net.URI url,
                              java.lang.String user,
                              java.lang.String password)
                       throws ClientException

        Handy constructor easy to use in simple tests. Creates a client that uses basic authentication.

        For constructing clients with complex configurations, use a SlingClient.InternalBuilder

        For constructing clients with the same configuration, but a different class, use AbstractSlingClient.adaptTo(Class)

        Parameters:
        url - url of the server (including context path)
        user - username for basic authentication
        password - password for basic authentication
        Throws:
        ClientException - never, kept for uniformity with the other constructors
    • Method Detail

      • setLaneNames

        public void setLaneNames​(java.lang.String... laneNames)
        Set provided laneNames to config map. This allows for subsequent initializations using adaptTo that shard the same config map to not require further configuration of lane names
        Parameters:
        laneNames - lane names to work on
      • waitForAsyncIndexing

        public void waitForAsyncIndexing​(long timeout,
                                         long delay)
                                  throws java.util.concurrent.TimeoutException,
                                         java.lang.InterruptedException,
                                         ClientException

        Blocks until all the async indices are up to date, to guarantee that the susequent queries return all the results.

        Works by creating a custom index for each lane, adding specific content to be indexed by these indices and then repeatedly searching this content until everything is found (indexed). All the content is created under "/tmp/testing/waitForAsyncIndexing"

        Indices are automatically created, but only if not already present. This method does not delete the indices at the end to avoid generating too much noise on the instance. To completely clean any traces, the user must call uninstall()

        Requires administrative rights to install bundles and to create nodes under "/tmp/testing/waitForAsyncIndexing"

        Parameters:
        timeout - max time to wait, in milliseconds, before throwing TimeoutException
        delay - time to sleep between retries
        Throws:
        java.util.concurrent.TimeoutException - if the timeout was reached before all the indices were updated
        java.lang.InterruptedException - to mark this method as waiting
        ClientException - if an error occurs during http requests/responses
      • waitForAsyncIndexing

        public void waitForAsyncIndexing()
                                  throws java.lang.InterruptedException,
                                         ClientException,
                                         java.util.concurrent.TimeoutException
        Same as waitForAsyncIndexing(long timeout, long delay), but with default values for timeout=1min and delay=500ms.
        Throws:
        java.util.concurrent.TimeoutException - if the timeout was reached before all the indices were updated
        java.lang.InterruptedException - to mark this method as waiting
        ClientException - if an error occurs during http requests/responses
        See Also:
        waitForAsyncIndexing(long, long)
      • install

        public void install()
                     throws ClientException

        Creates the necessary custom indices in the repository, if not already present.

        It is automatically called in each wait, there's no need to explicitly invoke it from the test.

        Throws:
        ClientException - if the installation fails
      • uninstallWithRetry

        public void uninstallWithRetry()
                                throws java.util.concurrent.TimeoutException,
                                       java.lang.InterruptedException

        Retries cleaning all the data generated by install() and waitForAsyncIndexing(long, long).

        User must manually call this if needed, as opposed to install(), which is called automatically.

        Throws:
        java.util.concurrent.TimeoutException - if retry operation times out and the path still exists
        java.lang.InterruptedException - if the retry operation was interrupted by the user