Crate Test LayerΒΆ

This layer starts and stops a Crate instance on a give port and a given crate node name:

>>> from crate.testing.layer import CrateLayer
>>> import random

>>> port = 9295

>>> layer =  CrateLayer('crate',
...                     crate_home=crate_path(),
...                     crate_exec=crate_path('bin', 'crate'),
...                     port=port,)

The working directory is defined on layer instantiation. It is sometimes required to know it before starting the layer:

>>> layer.wdPath()
'.../crate.testing.layer.CrateLayer.crate/work'

Lets start the layer:

>>> layer.start()

Now we can access the Crate instance on the defined port:

>>> import requests

>>> stats_uri = "http://127.0.0.1:{0}/_stats".format(port)
>>> response = requests.get(stats_uri)
>>> response.status_code
200

The layer can be shutdown using its stop() method:

>>> layer.stop()