Example Blueprint Tests
Introduction
This section describes some simple tests based on the Getting Started example blueprint:
name: My Web Cluster
location:
jclouds:aws-ec2:
identity: ABCDEFGHIJKLMNOPQRST
credential: s3cr3tsq1rr3ls3cr3tsq1rr3ls3cr3tsq1rr3l
services:
- type: org.apache.brooklyn.entity.webapp.ControlledDynamicWebAppCluster
name: My Web
id: webappcluster
brooklyn.config:
wars.root: http://search.maven.org/remotecontent?filepath=org/apache/brooklyn/example/brooklyn-example-hello-world-sql-webapp/0.8.0-incubating/brooklyn-example-hello-world-sql-webapp-0.8.0-incubating.war
java.sysprops:
brooklyn.example.db.url: >
$brooklyn:formatString("jdbc:%s%s?user=%s&password=%s",
component("db").attributeWhenReady("datastore.url"),
"visitors", "brooklyn", "br00k11n")
- type: org.apache.brooklyn.entity.database.mysql.MySqlNode
name: My DB
id: db
brooklyn.config:
creationScriptUrl: https://bit.ly/brooklyn-visitors-creation-scriptThe following sections contain yaml snippets that be appended to the list of services in the blueprint above, a complete blueprint is also provided below.
Note that unless otherwise specified the following tests are executed in parallel with the deployment of the application services, all timeout values are set accordingly.
Sensor Test
Demonstrates the following sensor assertion:
- asserts that the
webappclusterentityservice.isUpsensor istruewithin 10 minutes of blueprint being deployed.
- type: org.apache.brooklyn.test.framework.TestSensor
name: Check webappcluster isUp
targetId: webappcluster
sensor: service.isUp
timeout: 10m
assert:
- equals: trueHTTP Call Tests
Demonstrates the following HTTP Call assertions against the specified url, which in these examples are being built from the webappcluster entities host.address and proxy.http.port sensors (the tester having flexibility in how the test URL is to be constructed):
- asserts the response status code is 200 within 10 minutes of the blueprint being deployed.
- asserts the response body matches the regex
(?s).*Br[o]{2}klyn Deployed.*within 10 minutes of the blueprint being deployed. Note the presence of the(?s)dotall flag to test a multiline response.
- type: org.apache.brooklyn.test.framework.TestHttpCall
name: Check HTTP Response Status Code
url: >
$brooklyn:formatString("http://%s:%s/newcontext/",
$brooklyn:component("webappcluster").attributeWhenReady("host.address"),
$brooklyn:component("webappcluster").attributeWhenReady("proxy.http.port"))
timeout: 10m
applyAssertionTo: status
assert:
- equals: 200
- type: org.apache.brooklyn.test.framework.TestHttpCall
name: Check HTTP Response Body
url: >
$brooklyn:formatString("http://%s:%s/newcontext/",
$brooklyn:component("webappcluster").attributeWhenReady("host.address"),
$brooklyn:component("webappcluster").attributeWhenReady("proxy.http.port"))
timeout: 10m
applyAssertionTo: body
assert:
- matches: "(?s).*Br[o]{2}klyn Deployed.*"Effector Test (via TestCase entity)
This TestEffector example demonstrates the use of the TestCase and TestSensor entities to ensure the service has started before invoking an effector using the TestEffector entity.
TestCaseentity starts its children sequentially- asserts that the
webappclusterentityservice.isUpsensor istruewithin 10 minutes of the parentTestCaseentity starting. Blocks start of the next child until it obtains a result (or times out). deployeffector invoked to deploy war to anewcontextwith a 5 minute timeout to allow completion of the deploy task.- asserts
/newcontexturl returns a HTTP status code 200 within 5 minutes of the effector being invoked (Note that this timeout is relative to the preceding test entity as they are being sequentially run as children of aTestCaseentity).
- asserts that the
- type: org.apache.brooklyn.test.framework.TestCase
name: Check Deploy Effector
brooklyn.children:
- type: org.apache.brooklyn.test.framework.TestSensor
name: Check webappcluster isUp
targetId: webappcluster
sensor: service.isUp
timeout: 10m
assert:
- equals: true
- type: org.apache.brooklyn.test.framework.TestEffector
name: Invoke Deploy Effector
targetId: webappcluster
effector: deploy
timeout: 5m
params:
url: http://search.maven.org/remotecontent?filepath=org/apache/brooklyn/example/brooklyn-example-hello-world-sql-webapp/0.8.0-incubating/brooklyn-example-hello-world-sql-webapp-0.8.0-incubating.war
targetName: newcontext
- type: org.apache.brooklyn.test.framework.TestHttpCall
name: Check Deployed Webapp Status Code
timeout: 5m
url: >
$brooklyn:formatString("http://%s:%s/newcontext/",
$brooklyn:entity("webappcluster").attributeWhenReady("host.address"),
$brooklyn:entity("webappcluster").attributeWhenReady("proxy.http.port"))
applyAssertionTo: status
assert:
- isEqualTo: 200Full Example
A sample blueprint containing all the tests described above is available here.
This blueprint will deploy the Getting Started application and run all of the test entities, which if successful should appear in the web console as follows.
