Breaklets
The Idea
Breaklets are a way to check limits of a platform/aspect/tool. Breaklets
- ... iteratively make things worse
- ... run until either
- a threshold is reached
- R.I.P
- stopped "while in panic" (just create a file "panic" in current working dir)
- ... are scripted (quick to write/change)
The below examples are made for AEM using the the AEM Groovy Console, but the approach of breaklets can be used in any language/platform/program.
Usage
Examples
The quickest way is to modify some of the existing examples:
- breaklet-max-childnodes.groovy
- breaklet-max-childnodes-wait-for-events.groovy
- breaklet-max-childnodes-with-composum-and-CRXDE.groovy
- breaklet-components-per-page.groovy
- breaklet-max-sling-inheritance-levels.groovy
- breaklet-deep-group-hierarchies.groovy
- breaklet-max-changeset-single-commit.groovy
- breaklet-deep-group-hierarchies-functionality-fragments.groovy
Basic Structure
A simple breaklet looks as follows:
//-------------------------------------
// Breaklet Config
//-------------------------------------
def breakForDurationInSec = 60
// insert other vars to be used by closure below
//-------------------------------------
// Breaklet
//-------------------------------------
new Breaklet(this, breakForDurationInSec, sessionUser, sessionPassword).run { breaklet, currentIt, itSession ->
// this is run in iterations
// 'breaklet' makes certain breaklet operations available in the closure (e.g. logOpFinished)
// 'currentIt' contains the iteration number
// 'itSession' contains a session that is created explicitly for this iteration (using sessionUser & sessionPassword
// do something here with the session
breaklet.logOpFinished("My operation finished") // will show in the log and a csv files with timings is automatically created
// once breakForDurationInSec is reached, the iteration will break
}
// include the contents of https://gist.github.com/ghenzler/58ce57794ba9b5a60f2a2e60160be747 below here
Useful operations
NOTE: This is not really an API, it can be changed at any time. Also feel free to suggest improvements to breaklet-base.groovy
Class Breaklet
logMsg("message")
- will log a regular messagebreaklet.logOpFinished("message",...)
- logs a message with timinig (also creates a timings CSV in current working dir)breaklet.performRequest(String requestPath, ...)
- to run a request (uses simple UrlConnection)breaklet.runInBrowser("node.js script")
- will run the given script with chrome headless/puppeteerbreaklet.registerResourceChangeListener(paths)
andbreaklet. waitForResourceChangedEvents(long minimumExpectedChanges, ...)
to wait for resource changed events
JS Functions available in breaklet.runInBrowser()
await waitForCrxdeNodeWithName(page, nodename)
- waits for a nodename in CRXDEawait clickOnIconOfCrxdeNode(page, nodename)
- clicks on the icon of a node in CRXDE to expand/collapse itawait waitForXPath(xpath)
- waits for DOM XPath query (useful to wait for texts that cannot be queried easily with CSS selectorsawait waitForAndClick(page, selector)
- will wait for selector and then clickawait createScreenshot(page, nameSuffix)
- will create a screenshot with a certain name suffixawait sleep(ms)
- will sleep ms