Skip to content

Commit

Permalink
add configurable host to CrateLayer
Browse files Browse the repository at this point in the history
  • Loading branch information
msbt committed Sep 22, 2014
1 parent 6e21462 commit b5bcf11
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/crate/testing/layer.py
Expand Up @@ -25,7 +25,8 @@ def __init__(self,
keepRunning=False,
transport_port=None,
crate_exec=None,
cluster_name=None):
cluster_name=None,
host="localhost"):
"""
:param name: layer name, is also used as the cluser name
:param crate_home: path to home directory of the crate installation
Expand All @@ -37,11 +38,12 @@ def __init__(self,
:param crate_config: alternative crate config file location
:param cluster_name: the name of the cluster to join/build. Will be
generated automatically if omitted.
:param host: the host to bind to. defaults to 'localhost'
"""
self.keepRunning = keepRunning
crate_home = os.path.abspath(crate_home)
servers = ['localhost:%s' % port]
self.crate_servers = ['http://localhost:%s' % port]
servers = ['%s:%s' % (host, port)]
self.crate_servers = ['http://%s:%s' % (host, port)]
if crate_exec is None:
crate_exec = os.path.join(crate_home, 'bin', 'crate')
if crate_config is None:
Expand All @@ -54,7 +56,7 @@ def __init__(self,
'-Des.node.name=%s' % name,
'-Des.cluster.name=%s' % cluster_name,
'-Des.http.port=%s-%s' % (port, port),
'-Des.network.host=localhost',
'-Des.network.host=%s' % host,
'-Des.discovery.type=zen',
'-Des.discovery.zen.ping.multicast.enabled=false',
'-Des.config=%s' % crate_config,
Expand Down
32 changes: 31 additions & 1 deletion src/crate/testing/layer.txt
Expand Up @@ -2,7 +2,7 @@
Crate Test Layer
================

This layer starts and stops a ``Crate`` instance on a given,
This layer starts and stops a ``Crate`` instance on a given host, port,
a given crate node name and, optionally, a given cluster name::

>>> from crate.testing.layer import CrateLayer
Expand All @@ -14,11 +14,19 @@ a given crate node name and, optionally, a given cluster name::
>>> layer = CrateLayer('crate',
... crate_home=crate_path(),
... crate_exec=crate_path('bin', 'crate'),
... host='127.0.0.1',
... port=port,
... transport_port=transport_port,
... cluster_name='my_cluster'
... )


The urls of the crate servers to be instantiated can be obtained
via ``crate_servers``::

>>> layer.crate_servers
['http://127.0.0.1:44209']

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

Expand Down Expand Up @@ -46,3 +54,25 @@ The layer can be shutdown using its ``stop()`` method::
>>> layer.stop()


Starting a ``Crate`` layer leaving out optional parameters will apply the following defaults::

>>> layer_defaults = CrateLayer('crate_defaults',
... crate_path()
... )

The default http port is 4200, the transport_port is 4300, the host defaults
to ``localhost``::

>>> layer_defaults.crate_servers
['http://localhost:4200']

The working directory will be places inside a temporary directory made up using
the layer name::

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

The command to call is ``bin/crate`` inside the ``crate_home`` path.
The default config file is ``config/crate.yml`` inside ``crate_home``.
The default cluster name will be auto generated using the HTTP port.

0 comments on commit b5bcf11

Please sign in to comment.