Class ReplicationClient

java.lang.Object
org.apache.sling.testing.clients.AbstractSlingClient
org.apache.sling.testing.clients.SlingClient
com.adobe.cq.testing.client.CQClient
com.adobe.cq.testing.client.ReplicationClient
All Implemented Interfaces:
Closeable, AutoCloseable, org.apache.http.client.HttpClient

public class ReplicationClient extends CQClient
Client for all replication related actions: activate, deactivate, agents management.
  • Field Details

  • Constructor Details

    • ReplicationClient

      public ReplicationClient(org.apache.http.impl.client.CloseableHttpClient http, org.apache.sling.testing.clients.SlingClientConfig config) throws org.apache.sling.testing.clients.ClientException
      Throws:
      org.apache.sling.testing.clients.ClientException
    • ReplicationClient

      public ReplicationClient(URI serverUrl, String user, String password) throws org.apache.sling.testing.clients.ClientException
      Throws:
      org.apache.sling.testing.clients.ClientException
  • Method Details

    • activate

      public org.apache.sling.testing.clients.SlingHttpResponse activate(String agent, String nodePath, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Activates(publish) a node on the given agent.
      Parameters:
      agent - agent to send the replication request
      nodePath - path of the node to activate
      expectedStatus - list of expected HTTP status to be returned, if not set, 200 is assumed.
      Returns:
      the response
      Throws:
      org.apache.sling.testing.clients.ClientException - if something fails during the request/response cycle
    • activate

      public org.apache.sling.testing.clients.SlingHttpResponse activate(String nodePath, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Activates (publish) a node.
      Parameters:
      nodePath - path of the node to activate
      expectedStatus - list of expected HTTP status to be returned, if not set, 200 is assumed.
      Returns:
      the response
      Throws:
      org.apache.sling.testing.clients.ClientException - if something fails during the request/response cycle
    • deactivate

      public org.apache.sling.testing.clients.SlingHttpResponse deactivate(String agent, String pagePath, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Deactivates (un-publish) a node on the specified agent.
      Parameters:
      agent - agent to send the replication request
      pagePath - path of the node to deactivate
      expectedStatus - list of expected HTTP status to be returned, if not set, 200 is assumed.
      Returns:
      the response
      Throws:
      org.apache.sling.testing.clients.ClientException - if something fails during the request/response cycle
    • deactivate

      public org.apache.sling.testing.clients.SlingHttpResponse deactivate(String pagePath, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Deactivates (un-publish) a node.
      Parameters:
      pagePath - path of the node to deactivate
      expectedStatus - list of expected HTTP status to be returned, if not set, 200 is assumed.
      Returns:
      the response
      Throws:
      org.apache.sling.testing.clients.ClientException - if something fails during the request/response cycle
    • activateLater

      public org.apache.sling.testing.clients.SlingHttpResponse activateLater(String nodePath, long timeMilliseconds, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Activates a page after a period of time.
      Parameters:
      nodePath - The path to the node which is activated
      timeMilliseconds - The time interval, in milliseconds, from current timestamp, after which the node will be activated
      expectedStatus - list of expected statuses
      Returns:
      the http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • deactivateLater

      public org.apache.sling.testing.clients.SlingHttpResponse deactivateLater(String nodePath, long timeMilliseconds, int... expectedStatus) throws org.apache.sling.testing.clients.ClientException
      Deactivates a page after a period of time.
      Parameters:
      nodePath - The path to the node which is deactivated
      timeMilliseconds - The time interval, in milliseconds, from current timestamp, after which the node will be deactivated
      expectedStatus - list of expected statuses
      Returns:
      the http response
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
    • createReplicationAgent

      public com.fasterxml.jackson.databind.JsonNode createReplicationAgent(String name, String title, String parentPath, String template, org.apache.http.message.BasicNameValuePair... properties) throws org.apache.sling.testing.clients.ClientException, InterruptedException
      Creates a replication agent, if not already present
      Parameters:
      name - name of the agent
      title - title of the agent (page)
      parentPath - where to create the agent. Typical paths for CQ are /etc/replication/agents.author/ and /etc/replication/agents.publish/
      template - template of the agent. Typical value is /libs/cq/replication/templates/agent
      properties - list of properties to be set on the agent
      Returns:
      the json representation of agent's (jcr:content) node
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
      InterruptedException - to mark this method as waiting
    • adaptReplicationAgent

      public com.fasterxml.jackson.databind.JsonNode adaptReplicationAgent(String agentPath, org.apache.http.message.BasicNameValuePair... properties) throws org.apache.sling.testing.clients.ClientException, InterruptedException
      Adapts an existing agent's properties
      Parameters:
      agentPath - the path of the agent
      properties - list of properties to be set on the agent
      Returns:
      the json representation of the agent's (jcr:content) node
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
      InterruptedException - to mark this method as waiting
    • getAgentReplicationQueue

      public com.fasterxml.jackson.databind.JsonNode getAgentReplicationQueue(String agentPath) throws org.apache.sling.testing.clients.ClientException, InterruptedException
      Returns the agent replication queue.
      Parameters:
      agentPath - The location in jcr where the agent is stored.
      Returns:
      the queue as json node
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
      InterruptedException - to mark this method as waiting
    • checkContentDistributionAgentExists

      public Boolean checkContentDistributionAgentExists(String agent) throws org.apache.sling.testing.clients.ClientException
      Checks whether the given agent exists.
      Parameters:
      agent - to check
      Returns:
      true if the given agent exists
      Throws:
      org.apache.sling.testing.clients.ClientException - if an error occurred
    • waitQueueEmptyOfPath

      public boolean waitQueueEmptyOfPath(String agentPath, String replicatedPath) throws Exception
      Checks if the item is empty or if not whether the replicated path is in the list of packages. Sample HTTP response
       {
         "name": "publish",
         "queues": {
           "items": [
             "7ece8e2c-d641-4d50-a0ff-6fcd3c52f7d8-publishSubscriber",
             "0c77809c-cb61-437b-981b-0424c042fd92-publishSubscriber"
           ],
           "7ece8e2c-d641-4d50-a0ff-6fcd3c52f7d8-publishSubscriber": {
             "state": "BLOCKED",
             "items": [
               "package-0@52734825"
             ],
             "itemsCount": 1,
             "empty": false,
             "package-0@52734825": {
               "size": 6073,
               "paths": [
                 "/content/test-site/testpage_8e57dec8-40e8-4e42-a267-ff5142f5c472"
               ],
               "errorMessage": "Failed attempt (12/infinite) to import the distribution package"
           },
           "0c77809c-cb61-437b-981b-0424c042fd92-publishSubscriber": {
             "sling:resourceType": "sling/distribution/service/agent/queue",
             "state": "IDLE",
             "items": [],
             "itemsCount": 0,
             "empty": true
           }
         },
         "log": {
           "sling:resourceType": "sling/distribution/service/log"
         },
         "status": {
           "state": "BLOCKED"
         }
       }
       
      Parameters:
      agentPath - the agent path for which queues to be asserted
      replicatedPath - the path replicated
      Returns:
      true if path empty
      Throws:
      Exception - the exception
    • getPublishReplicationQueue

      public com.fasterxml.jackson.databind.JsonNode getPublishReplicationQueue() throws org.apache.sling.testing.clients.ClientException, InterruptedException
      Returns the default replication agent queue.
      Returns:
      the queue as json node
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
      InterruptedException - to mark this method as waiting
    • getReverseReplicationQueue

      public com.fasterxml.jackson.databind.JsonNode getReverseReplicationQueue() throws org.apache.sling.testing.clients.ClientException, InterruptedException
      Returns the reverse replication agent queue.
      Returns:
      the queue as json node
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails
      InterruptedException - to mark this method as waiting
    • waitAgentReplicationQueueIsEmpty

      public void waitAgentReplicationQueueIsEmpty(String agentPath) throws InterruptedException, org.apache.sling.testing.clients.ClientException
      Waits until the queue of the requested agent is empty
      Parameters:
      agentPath - path to the agent
      Throws:
      org.apache.sling.testing.clients.ClientException - if the queue is not empty after the default timeout (2 min) expires
      InterruptedException - to mark this method as waiting
    • waitPublishReplicationQueueIsEmpty

      public void waitPublishReplicationQueueIsEmpty() throws InterruptedException, org.apache.sling.testing.clients.ClientException
      Throws:
      InterruptedException
      org.apache.sling.testing.clients.ClientException
    • waitReversePublishReplicationQueueIsEmpty

      public void waitReversePublishReplicationQueueIsEmpty() throws InterruptedException, org.apache.sling.testing.clients.ClientException
      Throws:
      InterruptedException
      org.apache.sling.testing.clients.ClientException
    • isConnectionSuccessful

      public boolean isConnectionSuccessful(String agentLocation) throws org.apache.sling.testing.clients.ClientException
      Throws:
      org.apache.sling.testing.clients.ClientException
    • findInLog

      public boolean findInLog(String agentLocation, String[] patterns, Date startTime) throws org.apache.sling.testing.clients.ClientException
      Returns true if the specific at least one pattern was found in the log or false otherwise.
      Parameters:
      agentLocation - agent path
      patterns - list of patterns
      startTime - start time
      Returns:
      true if the pattern was found
      Throws:
      org.apache.sling.testing.clients.ClientException - if the request fails