wttech / bobcat

Bobcat is an automated testing framework for functional testing of web applications.
https://cognifide.github.io/bobcat/
Apache License 2.0
90 stars 40 forks source link

PoC: Use systemready to make sure that you can run aem tests #283

Open Shaihuludus opened 6 years ago

Shaihuludus commented 6 years ago

There is a new part of felix https://github.com/apache/felix/tree/trunk/systemready that will be part of AEM 6.5 and can be installed now. We could check if small module could be written to use it to check if instance is running and running tests make sens. Could be used in testing after fresh build to make sure that tests has instance ready for them

What should be done:

marcinkp commented 5 years ago

As Felix System Ready is obsolete and superseded by Apache Felix Health Checks there a following configuration required for AEM project in case one want use it.

  1. Need to install 3 felix packages - not installed by default on AEM 6.4 and 6.5.

    • org.apache.felix.healthcheck.api
    • org.apache.felix.healthcheck.core
    • org.apache.felix.healthcheck.generalchecks

    It can be installed automaticly by GAP. Need to add following instruction to build file of your project:

aem {
    tasks {
       ...
        satisfy {
            packages {
                group("org.apache.felix.healthcheck.api") { url("https://www.apache.org/dist/felix/org.apache.felix.healthcheck.api-2.0.0.jar") }
                group("org.apache.felix.healthcheck.core") { url("https://www.apache.org/dist/felix/org.apache.felix.healthcheck.core-2.0.2.jar") }
                group("org.apache.felix.healthcheck.generalchecks") { url("https://www.apache.org/dist/felix/org.apache.felix.healthcheck.generalchecks-2.0.0.jar") }
            }
        }
    }
}
  1. Define configuration for Health Check Servlet Example file: org.apache.felix.hc.core.impl.servlet.HealthCheckExecutorServlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:primaryType="sling:OsgiConfig"
    servletPath="/system/health"/>

It will expose endpoint /system/health for healthcheck

  1. As there are many AEM parts which can be monitored by Apache Felix Health Checks lets assume that for bobcat puposes one need to check whether some required bundles are running. Lets define configuration for Bundle Started Health Check which is available out of the box

File: org.apache.felix.hc.generalchecks.BundlesStartedCheck.xml

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
  jcr:primaryType="sling:OsgiConfig"
  includesRegex="com.company.aem.example"
  hc.tags="myapplication"
  useCriticalForInactive="true"/>

It defines tag myapplication and check wheter bundles for pattern com.company.aem.example are up and running. By this configuration we force CRITICAL result once any of bundle is inactive

After this configuration is installed one can call http://localhost:4502/system/health/myapplication.json and if there defined bundle is inactive the answer can look like below:

{
    "overallResult": "CRITICAL",
    "results": [
        {
            "name": "Bundles Started",
            "status": "CRITICAL",
            "timeInMs": 0,
            "finishedAt": "2019-04-29T13:41:16.070",
            "tags": [
                "myapplication"
            ],
        "messages": [
            {
                "status": "CRITICAL",
                "message": "Inactive bundle 581 com.company.aem.example: RESOLVED"
            },
            {
                "status": "OK",
                "message": "Found  1 inactive of 1 bundles for pattern com.company.aem.example"
            }
        ]
        }   
    ]
}