Example 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", $brooklyn:external("brooklyn-demo-sample", "hidden-brooklyn-password"))
- type: org.apache.brooklyn.entity.database.mysql.MySqlNode
  name: My DB
  id: db
  brooklyn.config:
    creation.script.password: $brooklyn:external("brooklyn-demo-sample", "hidden-brooklyn-password")
    datastore.creation.script.url: https://bit.ly/brooklyn-visitors-creation-script

The 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 webappcluster entity service.isUp sensor is true within 10 minutes of blueprint being deployed.
- type: org.apache.brooklyn.test.framework.TestSensor
  name: Check webappcluster isUp
  brooklyn.config:
    targetId: webappcluster
    sensor: service.isUp
    timeout: 10m
    assert:
    - equals: true

HTTP 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
  brooklyn.config:
    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
  brooklyn.config:
    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.

  • TestCase entity starts its children sequentially
    • asserts that the webappcluster entity service.isUp sensor is true within 10 minutes of the parent TestCase entity starting. Blocks start of the next child until it obtains a result (or times out).
    • deploy effector invoked to deploy war to a newcontext with a 5 minute timeout to allow completion of the deploy task.
    • asserts /newcontext url 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 a TestCase entity).
- type: org.apache.brooklyn.test.framework.TestCase
  name: Check Deploy Effector
  brooklyn.children:
  - type: org.apache.brooklyn.test.framework.TestSensor
    name: Check webappcluster isUp
    brooklyn.config:
      targetId: webappcluster
      sensor: service.isUp
      timeout: 10m
      assert:
      - equals: true
  - type: org.apache.brooklyn.test.framework.TestEffector
    name: Invoke Deploy Effector
    brooklyn.config:
      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
    brooklyn.config:
      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: 200

Full 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.

Successful Getting Started App deployment and Test execution.

results matching ""

    No results matching ""